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