Facebook
From Ronalds Mazītis, 2 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 175
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8" />
  5.     <meta
  6.       name="viewport"
  7.       content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
  8.     />
  9.     <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  10.     <title>3D ONLINE GAME 2 (game engine for various glb files) - http://mytechservinginternetmeals.blogspot.com/2022/02/video-game-development-4.html</title>
  11.     <link rel="stylesheet" href="/css/examples.css?ver=1.0.0" />
  12.     <script src="/js/examples.js?ver=1.1.1"></script>
  13.     <script src="/lib/phaser.min.js?ver=3.52.0"></script>
  14.     <script src="/lib/enable3d/enable3d.phaserExtension.0.25.0.min.js"></script>
  15.               <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  16.  
  17.          
  18.  
  19.   <!---<script src="https://code.jquery.com/jquery-1.10.2.js"></script> -->
  20.  
  21.    
  22.  
  23.   </head>
  24.  
  25.   <body>
  26.    <!--- <div id="info-text">Use WASD, SPACE and your Mouse.<br />Try to play it on your mobile device :)</div> -->
  27.    
  28.  
  29.   <center>
  30.    <h1>
  31.           <?php  
  32.    include_once 'db.php';
  33.  
  34. $sessionid = $_SESSION['user_id'];
  35.  
  36. echo $user_data['username'];
  37.  
  38. //if(empty($sessionid)){
  39.             //header('Location: index.php');
  40.  
  41. ////echo $sessionid;
  42.  
  43. //}
  44.  
  45.  
  46. //skripts kurš pie katras čaraktera kustību apstājas updeito tabulas sadaļu *location*
  47. //skripts kurš katru lietotāju kura datetime sakrīt ar intervālu pēdējās 15 min, zīmē ekrānā
  48.  
  49.  
  50.  
  51.  
  52.  
  53.    ?>
  54.  
  55.    </h1>  <a href="logout.php">Logout.</a>http://mytechservinginternetmeals.blogspot.com/2022/02/video-game-development-4.html ZAJEBAL
  56.    </center>
  57.    
  58.    
  59.    
  60.     <script>
  61.                
  62.  
  63.  
  64.                        
  65.                        
  66.                
  67.       const {
  68.         enable3d,
  69.         Scene3D,
  70.         Canvas,
  71.         ThirdDimension,
  72.         THREE,
  73.         JoyStick,
  74.         ExtendedObject3D,
  75.         ThirdPersonControls,
  76.         PointerLock,
  77.         PointerDrag
  78.       } = ENABLE3D
  79.  
  80.       /**
  81.        * Is touch device?
  82.        */
  83.       const isTouchDevice = 'ontouchstart' in window
  84.         var choicef = 1;
  85.        
  86.        
  87.         var textbubble = [];
  88.       class MainScene extends Scene3D {
  89.         constructor() {
  90.           super({ key: 'MainScene' })
  91.         }
  92.  
  93.         init() {
  94.           this.accessThirdDimension({ maxSubSteps: 10, fixedTimeStep: 1 / 120 })
  95.           this.third.renderer.outputEncoding = THREE.LinearEncoding
  96.           this.canJump = true
  97.           this.move = false
  98.  
  99.           this.moveTop = 0
  100.           this.moveRight = 0
  101.         }
  102.  
  103.         async create() {
  104.           const { lights } = await this.third.warpSpeed('-ground', '-orbitControls')
  105.  
  106.           const { hemisphereLight, ambientLight, directionalLight } = lights
  107.           const intensity = 0.65
  108.           hemisphereLight.intensity = intensity
  109.           ambientLight.intensity = intensity
  110.           directionalLight.intensity = intensity
  111.  
  112.           //this.third.physics.add.box({ y: 10, x: 35 }, { lambert: { color: 'red' } })
  113.  
  114.           // this.third.physics.debug.enable()
  115.  
  116.           /**
  117.            * Medieval Fantasy Book by Pixel (https://sketchfab.com/stefan.lengyel1)
  118.            * https://sketchfab.com/3d-models/medieval-fantasy-book-06d5a80a04fc4c5ab552759e9a97d91a
  119.            * Attribution 4.0 International (CC BY 4.0)
  120.            
  121.            E4E717
  122.            */
  123.            
  124.            /**
  125.            google maps fragment from real map mixed with random skatepark armatures (hand drawn),
  126.            some grass added but glb file does not loads textures,
  127.            enable3d javascript engine does not show the color file added to it
  128.            writing in computer does not really change anything, or does it, cause where is that thing?
  129.            on screen
  130.            **/
  131.            //const groundGeometry = new PlaneGeometry( 20000, Const groundTexture = new TextureLoader().load('assets/img/grass.jpg');
  132.  
  133. //var positions = []
  134. //positions.push(new THREE.Vector3(-1,0,0))
  135. //positions.push(new THREE.Vector3(+1,0,0))
  136. //var mesh = new THREEx.createGrassTufts(positions)
  137. //scene.add(mesh)
  138. this.third.physics.collisionEvents.on('collision', data => {
  139.   const { bodies, event } = data
  140.   console.log("test", bodies[0].name, bodies[1].name, event)
  141. })
  142.  
  143.            
  144.            //console.log("/assets/glb/TEST.glb");
  145.            //console.log("/assets/glb/one_building.glb");
  146.           this.third.load.gltf('/assets/glb/outside_the_box3.glb').then(object => {
  147.             const scene = object.scenes[0]
  148.  
  149.             const book = new ExtendedObject3D()
  150.             book.name = 'scene'
  151.             book.add(scene)
  152.             this.third.add.existing(book)
  153.  
  154.             // add animations
  155.             // sadly only the flags animations works
  156.             object.animations.forEach((anim, i) => {
  157.               book.mixer = this.third.animationMixers.create(book)
  158.               // overwrite the action to be an array of actions
  159.               book.action = []
  160.               book.action[i] = book.mixer.clipAction(anim)
  161.               book.action[i].play()
  162.             })
  163.  
  164.             book.traverse(child => {
  165.               if (child.isMesh) {
  166.                 child.castShadow = child.receiveShadow = false
  167.                 child.material.metalness = 0
  168.                 child.material.roughness = 1
  169.  
  170.                 if (/mesh/i.test(child.name)) {
  171.                   this.third.physics.add.existing(child, {
  172.                     shape: 'concave',
  173.                     mass: 0,
  174.                     collisionFlags: 1,
  175.                     autoCenter: false
  176.                   })
  177.                   child.body.setAngularFactor(0, 0, 0)
  178.                   child.body.setLinearFactor(0, 0, 0)
  179.                 }
  180.               }
  181.             })
  182.           })
  183.          
  184.           //console.log("grass_field.glb");
  185.          
  186.           //this.third.load.gltf('/assets/glb/grass_field.glb').then(object => {
  187.           //this.third.load.gltf('/assets/glb/box.glb').then(object => {
  188.             //const scene = object.scenes[0]
  189.  
  190.             //const book = new ExtendedObject3D()
  191.             //book.name = 'scene2'
  192.             //book.add(scene)
  193.             //this.third.add.existing(book)
  194.  
  195.              //add animations
  196.              //sadly only the flags animations works
  197.             //object.animations.forEach((anim, i) => {
  198.               //book.mixer = this.third.animationMixers.create(book)
  199.                //overwrite the action to be an array of actions
  200.               //book.action = []
  201.               //book.action[i] = book.mixer.clipAction(anim)
  202.               //book.action[i].play()
  203.             //})
  204.  
  205.             //book.traverse(child => {
  206.               //if (child.isMesh) {
  207.                 //child.castShadow = child.receiveShadow = false
  208.                 //child.material.metalness = 0
  209.                 //child.material.roughness = 1
  210.  
  211.                 //if (/mesh/i.test(child.name)) {
  212.                   //this.third.physics.add.existing(child, {
  213.                     //shape: 'concave',
  214.                     //mass: 0,
  215.                     //collisionFlags: 1,
  216.                     //autoCenter: false
  217.                   //})
  218.                   //child.body.setAngularFactor(0, 0, 0)
  219.                   //child.body.setLinearFactor(0, 0, 0)
  220.                 //}
  221.               //}
  222.             //})
  223.           //})
  224.          
  225.          
  226.           //this.third.load.gltf('/assets/glb/box.glb').then(object => {
  227.             //const scene = object.scenes[0]
  228.  
  229.             //const book2 = new ExtendedObject3D()
  230.             //book2.name = 'scene3'
  231.             //book2.add(scene)
  232.             //this.third.add.existing(book2)
  233.                         //this.book2.position.set(-454.2014, 1, -205.63472)
  234.  
  235.             //// add animations
  236.             //// sadly only the flags animations works
  237.             //object.animations.forEach((anim, i) => {
  238.               //book2.mixer = this.third.animationMixers.create(book)
  239.               //// overwrite the action to be an array of actions
  240.               //book2.action = []
  241.               //book2.action[i] = book.mixer.clipAction(anim)
  242.               //book2.action[i].play()
  243.             //})
  244.  
  245.             //book2.traverse(child => {
  246.               //if (child.isMesh) {
  247.                 //child.castShadow = child.receiveShadow = false
  248.                 //child.material.metalness = 0
  249.                 //child.material.roughness = 1
  250.  
  251.                 //if (/mesh/i.test(child.name)) {
  252.                   //this.third.physics.add.existing(child, {
  253.                     //shape: 'concave',
  254.                     //mass: 0,
  255.                     //collisionFlags: 1,
  256.                     //autoCenter: false
  257.                   //})
  258.                   //child.body.setAngularFactor(0, 0, 0)
  259.                   //child.body.setLinearFactor(0, 0, 0)
  260.                 //}
  261.               //}
  262.             //})
  263.           //})
  264.          
  265.          
  266.  
  267.          
  268.          
  269.          
  270.  
  271.  
  272.           var skins = [];
  273.           $.ajax({
  274.               type: "GET",
  275.               async: false,
  276.               url: 'loadskins.php',
  277.               data: {},
  278.               success: function (data) {
  279.                   skins = data.split(",").map(String);
  280.               }
  281.           });
  282.  
  283.                        
  284.                          
  285.                          
  286.   //console.log(vertibasx);
  287.  
  288.           for (var i = 0; i < skins.length - 1; i++) {
  289.               let skin = skins[i];  
  290.                                
  291.                                
  292.                                 console.log("times", i);
  293.               const lokacijumasivs = [];
  294.                          
  295.                         //// let objstr = obj[i].toString().split("");
  296.                          //let objstr = obj[i];
  297.                          
  298.  
  299.  
  300.  
  301.                          ////console.log(objstr);
  302.                           //console.log("x", vertibasx[i]);
  303.                           //console.log("y", vertibasy[i]);
  304.                           //console.log("z", vertibasz[i]);
  305.  
  306.  
  307.  
  308.  
  309.                         var obj = [];
  310.                       $.ajax({
  311.                           type: "GET",
  312.                           async: false,
  313.                           url: 'getlocation.php',
  314.                           data: {},
  315.                           success: function (data) {
  316.                                                 obj = data.split("*").map(String);
  317.  
  318.                           }
  319.  
  320.                       });
  321.            
  322.  
  323.  
  324.                         // console.log("obj", obj);
  325.                          
  326.  const vertibasx = obj.slice(0,1);
  327.                          const vertibasy = obj.slice(1,2);
  328.                          const vertibasz = obj.slice(2,3);
  329.                          
  330.  
  331.                           //console.log(vertibasx);
  332.                           //console.log(vertibasy);
  333.                           //console.log(vertibasz);
  334.  
  335.           /**
  336.            * box_man.glb by Jan Bláha
  337.            * https://github.com/swift502/Sketchbook
  338.            * CC-0 license 2018
  339.            */
  340.            
  341.            ///update shito ik pa laikam ar chata table saturu, paradit visiem
  342.            ///paradit tukshu vai pazudinat ja ieraksts veikts paris sekundes pirms
  343.            
  344.                 var getchat = [];
  345.                                 window.setInterval(function(){
  346.  
  347.                       $.ajax({
  348.                           type: "GET",
  349.                           async: false,
  350.                           url: 'getchat.php',
  351.                           data: {},
  352.                           success: function (data) {
  353.                                                getchat = data.split("*").map(String);
  354.  
  355.                           }
  356.  
  357.                       });
  358.                         }, 600);
  359.                      
  360.                           //for (var i = 0; i < getchat.length - 1; i++) {
  361.                           var uu;
  362.                           var location2;
  363.                           var location3;
  364.                           var location4;
  365.                 window.setInterval(function(){
  366.                 uu = getchat[0]
  367.                 location2 = parseInt(obj[0]);
  368.                 location3 = location2 + 185;
  369.                 location4 = location3.toString();
  370.                 console.log("uu", location4);
  371.                 }, 600);
  372.                
  373. const foo = () => {
  374. this.add.text(location4,328, uu, { fontSize: '24px' });
  375. }
  376.  
  377.                 window.setInterval(function(){
  378. foo();
  379.                 }, 600);
  380.  
  381.  
  382.                        
  383.  
  384. //}
  385.  
  386.  
  387.  
  388.  
  389.  
  390.            
  391.            var object = await this.third.load.gltf(skin)
  392.          
  393.           ///this.third.load.gltf('/assets/glb/box_man.glb').then(object => {
  394.             const man = object.scene.children[0]
  395.  console.log("zb", man);
  396.  
  397.  
  398.  
  399.             this.man = new ExtendedObject3D()
  400.             this.man.name = 'man'
  401.             this.man.rotateY(Math.PI + 0.1) // a hack
  402.             this.man.add(man)
  403.             this.man.rotation.set(0, Math.PI * 1.5, 0)
  404.             //console.log("uzstada", vertibasx, vertibasy, vertibasx);
  405.            
  406.             console.log("iteracija", i);
  407.                         //if(vertibasx !== null && vertibasy !== null && vertibasz !== null){
  408.                         //let verx = vertibasx[i];
  409.                         //let very = vertibasy[i];
  410.                         //let verz = vertibasz[i];
  411.                        
  412.                        
  413. //console.log("shitais?", verx);
  414. //console.log("2shitais?", very);
  415. //console.log("3shitais?", verz);
  416.  
  417.  
  418.                                         if(vertibasx && vertibasy && vertibasz){
  419.                                     this.man.position.set(vertibasx, vertibasy, vertibasz)
  420.                                         } else {
  421.                                                                                     this.man.position.set(754.2014, 1, -205.63472)
  422.                                         }
  423.                
  424.                 //} else {
  425.                 //let verx = 754.2014;
  426.                 //let very = 1000;
  427.                 //let verz = -205.63472;
  428.                
  429.                             //this.man.position.set(verx, very, verz)
  430.  
  431.                 //}
  432.             //this.man.position.set(59, 0, 79)
  433.  
  434.             // add shadow
  435.             this.man.traverse(child => {
  436.               if (child.isMesh) {
  437.                 child.castShadow = child.receiveShadow = true
  438.                 // https://discourse.threejs.org/t/cant-export-material-from-blender-gltf/12258
  439.                 child.material.roughness = 1
  440.                 child.material.metalness = 0
  441.               }
  442.             })
  443.  
  444.             /**
  445.              * Animations
  446.              */
  447.             this.third.animationMixers.add(this.man.animation.mixer)
  448.             object.animations.forEach(animation => {
  449.               if (animation.name) {
  450.                 this.man.animation.add(animation.name, animation)
  451.               }
  452.             })
  453.             this.man.animation.play('idle')
  454.  
  455.             /**
  456.              * Add the player to the scene with a body
  457.              */
  458.             this.third.add.existing(this.man)
  459.             this.third.physics.add.existing(this.man, {
  460.               shape: 'sphere',
  461.               radius: 0.25,
  462.               width: 0.5,
  463.               offset: { y: -0.25 }
  464.             })
  465.             this.man.body.setFriction(0.8)
  466.             this.man.body.setAngularFactor(0, 0, 0)
  467.  
  468.             // https://docs.panda3d.org/1.10/python/programming/physics/bullet/ccd
  469.             this.man.body.setCcdMotionThreshold(1e-7)
  470.             this.man.body.setCcdSweptSphereRadius(0.25)
  471.  
  472.             /**
  473.              * Add 3rd Person Controls
  474.              */
  475.             this.controls = new ThirdPersonControls(this.third.camera, this.man, {
  476.               offset: new THREE.Vector3(0, 1, 0),
  477.               targetRadius: 3
  478.             })
  479.             // set initial view to 90 deg theta
  480.             this.controls.theta = 90
  481.  
  482.             /**
  483.              * Add Pointer Lock and Pointer Drag
  484.              */
  485.             if (!isTouchDevice) {
  486.               let pl = new PointerLock(this.game.canvas)
  487.               let pd = new PointerDrag(this.game.canvas)
  488.               pd.onMove(delta => {
  489.                 if (pl.isLocked()) {
  490.                   this.moveTop = -delta.y
  491.                   this.moveRight = delta.x
  492.                 }
  493.               })
  494.             }
  495.          // })
  496.  
  497.           /**
  498.            * Add Keys
  499.            */    
  500.            
  501.                        
  502.  
  503.  
  504.           /**
  505.            * Add joystick
  506.            */
  507.           if (isTouchDevice) {
  508.             const joystick = new JoyStick()
  509.             const axis = joystick.add.axis({
  510.               styles: { left: 35, bottom: 35, size: 100 }
  511.             })
  512.             axis.onMove(event => {
  513.               /**
  514.                * Update Camera
  515.                */
  516.               const { top, right } = event
  517.               this.moveTop = top * 3
  518.               this.moveRight = right * 3
  519.             })
  520.             const buttonA = joystick.add.button({
  521.               letter: 'A',
  522.               styles: { right: 35, bottom: 110, size: 80 }
  523.             })
  524.             buttonA.onClick(() => this.jump())
  525.             const buttonB = joystick.add.button({
  526.               letter: 'B',
  527.               styles: { right: 110, bottom: 35, size: 80 }
  528.             })
  529.             buttonB.onClick(() => (this.move = true))
  530.             buttonB.onRelease(() => (this.move = false))
  531.           }
  532.         }
  533.  
  534. }
  535.  
  536.         jump() {
  537.           if (!this.man || !this.canJump) return
  538.           this.canJump = false
  539.           this.man.animation.play('jump_running', 500, false)
  540.           this.time.addEvent({
  541.             delay: 650,
  542.             callback: () => {
  543.               this.canJump = true
  544.               this.man.animation.play('idle')
  545.             }
  546.           })
  547.           this.man.body.applyForceY(6)
  548.         }
  549.  
  550.         update(time, delta) {
  551.                        
  552.  
  553.                
  554.    this.keys = {
  555.        
  556.             a: this.input.keyboard.addKey('a'),
  557.             w: this.input.keyboard.addKey('w'),
  558.             d: this.input.keyboard.addKey('d'),
  559.             s: this.input.keyboard.addKey('s'),
  560.             space: this.input.keyboard.addKey(32)
  561.           }
  562.  
  563.  
  564. if(choicef === 1) {
  565.                    this.keys = {
  566.        
  567.             a: this.input.keyboard.addKey('a'),
  568.             w: this.input.keyboard.addKey('w'),
  569.             d: this.input.keyboard.addKey('d'),
  570.             s: this.input.keyboard.addKey('s'),
  571.             space: this.input.keyboard.addKey(32)
  572.           }
  573.           }
  574.          
  575. if(choicef === 2){
  576. this.input.keyboard.removeCapture('W,S,A,D');
  577. this.input.keyboard.removeCapture([ 32 ]);
  578.  
  579.           }
  580.  
  581.  
  582. var area = document.getElementById('textarea');
  583. area.addEventListener('click', (e) => {
  584.  //alert("uzlieku pa virsu");
  585.  choicef = 2;
  586. });
  587.  
  588.  
  589.  
  590. var elem = document.getElementById('enable3d-phaser-canvas');
  591. elem.addEventListener('click', (e) => {
  592.         console.log("uzlieku pa virsu");
  593.  choicef = 1;
  594. });
  595.  
  596. area.addEventListener('keyup', (e) => {
  597. if (e.keyCode === 13) {
  598.     // Cancel the default action, if needed
  599.     e.preventDefault();
  600.     // Trigger the button element with a click
  601.        var textarea = document.getElementById('textarea').value;
  602.         //avar groupidTRIM = document.getElementById("groupchatID").innerHTML;
  603.     //var groupid = "grupa";   
  604.         //alert(111);
  605.  
  606. //alert(111);
  607.  
  608. var username;
  609.  $.ajax({
  610.                           type: "GET",
  611.                           async: false,
  612.                           url: 'getusername.php',
  613.                           data: {},
  614.                           success: function (data) {
  615.                                                username = data;
  616.  
  617.                           }
  618.  
  619.                       });
  620.                      
  621.                       var kopadata = username + " " + textarea;
  622.                      
  623.                       //console.log(kopadata);
  624.                      
  625.                      
  626. if(textarea){
  627.     $.ajax({
  628.       type: "post",
  629.       url: "groupchatfunction.php",
  630.       data: {
  631.         textarea: textarea
  632.       },
  633.       cache: false,
  634.       success: function(html) {
  635.                                    
  636.                                    //izmēģinam ievietot kastīti ja aizsūtas ziņa
  637.                                   // this.third.physics.add.box({ y: 10, x: 754.2014 }, { lambert: { color: 'red' } })
  638.                        
  639.                        
  640.                         /// tekstu ieposto datubāzē , izmaina globālo masīvu ar tekstu un tā īpašnieku
  641.                         /// vēlāk globālo masīvu zīmē gluži kā čarakteru iekš update funkcijas, iekļauj sarakstā visas ziņas
  642.                         // un uzzīmē thought buble virs čaraktera galvas ar iedomāto tekstu
  643.                         var kopadata2 = kopadata;
  644.                        
  645.                       var doit = textbubble.push(kopadata2);
  646.                  //var messageelements = '<div class="msg_a"><span data-tooltip="now" data-tooltip-position="bottom">' + textarea + '</span></div><br>';
  647.  
  648.  
  649. //$( "#outputmessages" ).append(messageelements);
  650.  
  651.  
  652.                 //window.setTimeout(function(){
  653.                 //var elem = document.getElementById('msg_body');
  654.                 //elem.scrollTop = elem.scrollHeight;
  655.                 //}, 1200);
  656.                
  657.                
  658.       }
  659.  
  660.  
  661.  
  662.     });
  663. }
  664.    
  665.                         document.getElementById('textarea').value = '';
  666.  
  667.  
  668. }
  669. });
  670.  
  671.                          
  672.           if (this.man && this.man.body) {
  673.             /**
  674.              * Update Controls
  675.              */
  676.             this.controls.update(this.moveRight * 2, -this.moveTop * 2)
  677.             if (!isTouchDevice) this.moveRight = this.moveTop = 0
  678.             /**
  679.              * Player Turn
  680.              */
  681.                 //console.log("globals mainigais speed", speed);
  682.                
  683.                
  684.             const v3 = new THREE.Vector3()
  685.             const rotation = this.third.camera.getWorldDirection(v3)
  686.             var rotati = [];
  687.                       $.ajax({
  688.                           type: "GET",
  689.                           async: false,
  690.                           url: 'getrotation.php',
  691.                           data: {},
  692.                           success: function (data) {
  693.                                                 rotati = data.split("*").map(String);
  694.                           }
  695.  
  696.                       });
  697.  
  698.             const theta = Math.atan2(rotation.x, rotation.z)
  699.             const rotationMan = this.man.getWorldDirection(v3)
  700.             for (var i = 0; i < rotati.length - 1; i++) {
  701.               let rotatine = rotati[i];  
  702.                         //console.log(rotatine);
  703.                                 if(rotatine){
  704.             const thetaMan = Math.atan2(rotationMan.x, rotationMan.z)
  705.               $.post(
  706.                           "postrotation.php", {
  707.                               rotation: thetaMan
  708.                           },
  709.                           function (data) {
  710.                                                                 //console.log("rotacija", thetaMan);
  711.                               //console.log("izsaukta", v3);
  712.                           }
  713.                       );
  714.                      
  715.                       this.man.body.setAngularVelocityY(0)
  716.  
  717.             const l = Math.abs(theta - thetaMan)
  718.                
  719.             let rotationSpeed = isTouchDevice ? 2 : 4
  720.             let d = Math.PI / 24
  721.  
  722.             if (l > d) {
  723.               if (l > Math.PI - d) rotationSpeed *= -1
  724.               if (theta < thetaMan) rotationSpeed *= -1
  725.               this.man.body.setAngularVelocityY(rotationSpeed)
  726.             }
  727.                          } else {
  728.                          const thetaMan = rotatine;
  729.                          
  730.                            $.post(
  731.                           "postrotation.php", {
  732.                               rotation: thetaMan
  733.                           },
  734.                           function (data) {
  735.                                                                 //console.log("rotacija", thetaMan);
  736.                               //console.log("izsaukta", v3);
  737.                           }
  738.                       );
  739.                          
  740.                
  741.            
  742.                                  
  743.                      
  744.                      
  745.             this.man.body.setAngularVelocityY(0)
  746.  
  747.             const l = Math.abs(theta - thetaMan)
  748.                
  749.             let rotationSpeed = isTouchDevice ? 2 : 4
  750.             let d = Math.PI / 24
  751.  
  752.             if (l > d) {
  753.               if (l > Math.PI - d) rotationSpeed *= -1
  754.               if (theta < thetaMan) rotationSpeed *= -1
  755.               this.man.body.setAngularVelocityY(rotationSpeed)
  756.             }
  757.            
  758.                 }
  759. }
  760.  
  761.  
  762.  
  763.             /**
  764.              * Player Move
  765.              */
  766.            
  767.            
  768.              
  769.             if (this.keys.w.isDown || this.move) {
  770.               if (this.man.animation.current === 'idle' && this.canJump) this.man.animation.play('run')
  771.                                           $.post(
  772.                           "postanimation.php", {
  773.                               animation: this.man.animation.current
  774.                           },
  775.                           function (data) {
  776.                                                                 //console.log("viens", x);
  777.                               //console.log("izsaukta", v3);
  778.                           }
  779.                       );
  780.                      
  781.                      
  782.  const speed = [];
  783.               var getspeed = [];
  784.                       $.ajax({
  785.                           type: "GET",
  786.                           async: false,
  787.                           url: 'getspeed.php',
  788.                           data: {},
  789.                           success: function (data) {
  790.                                                 getspeed = data.split("*").map(String);
  791.                                                                         //console.log("getsp", getspeed);
  792.                           }
  793.  
  794.                       });
  795.                                                  
  796.               for (var i = 0; i < getspeed.length - 1; i++) {
  797.                                 let getsp = getspeed[i];  
  798.                                 //console.log("speed", getsp);
  799.                       speed.push(getsp);
  800.                 }
  801.                
  802.                                                                                                 //console.log("speed.length", speed);
  803.                
  804.                
  805.             const v3 = new THREE.Vector3()
  806.  
  807.            
  808.  
  809.             var rotati = [];
  810.                       $.ajax({
  811.                           type: "GET",
  812.                           async: false,
  813.                           url: 'getrotation.php',
  814.                           data: {},
  815.                           success: function (data) {
  816.                                                 rotati = data.split("*").map(String);
  817.  
  818.                           }
  819.  
  820.                       });
  821.                         console.log("rotāciju masīvs", rotati);
  822.                        
  823.                        
  824.                        
  825.                        
  826.                        
  827.                 if(rotati){
  828.                
  829.                 for (var i = 0; i < rotati.length; i++) {
  830.                
  831.                                 const rotation = rotati[i];
  832.                                
  833.                                 //
  834.  
  835.                 }      
  836.                
  837.                 } else {
  838.                              const rotation = this.third.camera.getWorldDirection(v3)
  839.  
  840.                 }
  841.                
  842.                
  843.                 console.log("rotation", rotation);
  844.                
  845.                
  846.                
  847.                
  848.                          
  849.             const theta = Math.atan2(rotation.x, rotation.z)
  850.             const rotationMan = this.man.getWorldDirection(v3)
  851.  
  852.  
  853.  
  854. //console.log("globals mainigais speed", speed);
  855. //console.log("theta", theta);
  856.  
  857.                 for (var i = 0; i < speed.length; i++) {
  858.                
  859.                
  860.                
  861.                                         //console.log("xT", Math.sin(theta));
  862.  
  863.                         let speedi = parseInt(speed[i]);
  864.                 //console.log("spee",typeof(parseInt(speedi)));
  865.                
  866.                         //console.log("speed array2", speedi);
  867.                                         //console.log("xT2", Math.sin(theta));
  868.  
  869.               const x = Math.sin(theta) * 4,
  870.                 y = this.man.body.velocity.y,
  871.                 z = Math.cos(theta) * 4
  872.                
  873.                 console.log("y mainas randomā", y);
  874.  
  875.                 var obj2 = [];
  876.                       $.ajax({
  877.                           type: "GET",
  878.                           async: false,
  879.                           url: 'getlocation.php',
  880.                           data: {},
  881.                           success: function (data) {
  882.                                                 obj2 = data.split("*").map(String);
  883.  
  884.                           }
  885.  
  886.                       });
  887.            
  888.  
  889.  
  890.                          //console.log("obj2", obj2);
  891.                          
  892.                          let vertibasx = obj2.slice(0,1);
  893.                          let vertibasy = obj2.slice(1,2);
  894.                          let vertibasz = obj2.slice(2,3);
  895.                               let xv = parseInt(vertibasx[i]) + x;
  896.                               let zv = parseInt(vertibasz[i]) + z;
  897.  
  898.                          
  899.  
  900.                
  901.                 //nepareizā lokācija
  902.                
  903.                 if(xv){
  904.            //$.post(
  905.                           //"postlocation.php", {
  906.                               //x: xv,
  907.                               //y: 0,
  908.                              //z: zv,
  909.                              
  910.                           //},
  911.                           //function (data) {
  912.                                                                 ////console.log("viens", x);
  913.                               ////console.log("izsaukta", v3);
  914.                           //}
  915.                       //);
  916.                                  
  917.                                  
  918.               this.man.body.setVelocity(x, y, z)
  919.                   //}
  920.           }
  921.   }
  922.                  
  923.                  
  924.                  
  925.             } else {
  926.                                
  927.                                             const v3 = new THREE.Vector3()
  928.  
  929.                         const rotation = this.third.camera.getWorldDirection(v3)
  930.             const theta = Math.atan2(rotation.x, rotation.z)
  931.             const rotationMan = this.man.getWorldDirection(v3)
  932.                                  const x = Math.sin(theta) * 4,
  933.                 y = this.man.body.velocity.y,
  934.                 z = Math.cos(theta) * 4
  935.                                 var obj2 = [];
  936.                       $.ajax({
  937.                           type: "GET",
  938.                           async: false,
  939.                           url: 'getlocation.php',
  940.                           data: {},
  941.                           success: function (data) {
  942.                                                 obj2 = data.split("*").map(String);
  943.  
  944.                           }
  945.                       });
  946.                          //console.log("obj2", obj2);
  947.                          let vertibasx = obj2.slice(0,1);
  948.                          let vertibasy = obj2.slice(1,2);
  949.                          let vertibasz = obj2.slice(2,3);
  950.                               let xv = parseInt(vertibasx[i]) + x;
  951.                               let zv = parseInt(vertibasz[i]) + z;
  952.  
  953.                 //nepareizā lokācija
  954.                
  955.                 if(xv){
  956.            //$.post(
  957.                           //"postlocation.php", {
  958.                               //x: xv,
  959.                               //y: 0,
  960.                              //z: zv,
  961.                              
  962.                           //},
  963.                           //function (data) {
  964.                                                                 ////console.log("viens", x);
  965.                               ////console.log("izsaukta", v3);
  966.                           //}
  967.                       //);
  968.                                   }
  969.  
  970.                                 //šeit jābūt kodam kas updeitos koordinātes ja nespiež nevienu pogu bet papriekšu custom rotācija
  971.                
  972.               if (this.man.animation.current === 'run' && this.canJump) this.man.animation.play('idle')
  973.                                                   $.post(
  974.                           "postanimation.php", {
  975.                               animation: this.man.animation.current
  976.                           },
  977.                           function (data) {
  978.                                                                 //console.log("viens", x);
  979.                               //console.log("izsaukta", v3);
  980.                           }
  981.                       );
  982.             }
  983.  
  984.             /**
  985.              * Player Jump
  986.              */
  987.             if (this.keys.space.isDown && this.canJump) {
  988.               this.jump()
  989.             }
  990.           }
  991.         }
  992.       }
  993.  
  994.  
  995.  
  996.        
  997.        
  998.        
  999.       const config = {
  1000.         type: Phaser.WEBGL,
  1001.         transparent: true,
  1002.         scale: {
  1003.           mode: Phaser.Scale.FIT,
  1004.           autoCenter: Phaser.Scale.CENTER_BOTH,
  1005.           width: window.innerWidth * Math.max(1, window.devicePixelRatio / 2),
  1006.           height: window.innerHeight * Math.max(1, window.devicePixelRatio / 2)
  1007.         },
  1008.         scene: [MainScene],
  1009.         ...Canvas({ antialias: false })
  1010.       }
  1011.  
  1012.       window.addEventListener('load', () => {
  1013.         enable3d(() => new Phaser.Game(config)).withPhysics('/lib/ammo/kripken')
  1014.       })
  1015.     </script>
  1016.   </body>
  1017. </html>
  1018. © 2022 GitHub, Inc.
  1019. Terms
  1020. Privacy
  1021. Security
  1022. Status
  1023. Docs
  1024. Contact GitHub
  1025. Pricing
  1026. API
  1027. Training
  1028. Blog
  1029. About
  1030.