Facebook
From Gruff Sloth, 1 Year ago, written in JavaScript.
This paste is a reply to BR 3D VG - TWEENS DOES NOT WORK from Ronalds Mazitis - view diff
Embed
Download Paste or View Raw
Hits: 162
  1.  
  2.  
  3. <!DOCTYPE html>
  4. <html lang="en">
  5.   <head>
  6.     <meta charset="UTF-8" />
  7.     <meta
  8.       name="viewport"
  9.       content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
  10.     />
  11.     <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  12.     <title>3D ONLINE GAME 2</title>
  13.     <link rel="stylesheet" href="css/examples.css?ver=1.0.0" />
  14.     <script src="js/examples.js?ver=1.1.1"></script>
  15.     <script src="lib/phaser.min.js?ver=3.52.0"></script>
  16.     <script src="lib/enable3d/enable3d.phaserExtension.0.25.0.min.js"></script>
  17.           <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  18.  
  19.         <script src="lib/tween.umd.js"></script>
  20.  
  21.  
  22.   </head>
  23.  
  24.   <body>
  25.    <!--- <div id="info-text">Use WASD, SPACE and your Mouse.<br />Try to play it on your mobile device :)</div> -->
  26.    
  27.  <center>
  28.    <h1>
  29.           <?php  
  30.    include_once '/db.php';
  31.  
  32. $sessionid = $_SESSION['user_id'];
  33.  
  34. echo $user_data['username'];
  35.  
  36. if(empty($sessionid)){
  37.           //  header('Location: index.php');
  38.  
  39. //echo $sessionid;
  40.  
  41. } else {
  42.        
  43.        
  44.         ?>
  45.         <script>
  46.                 ///LOADS ONLINE TABLE
  47.                                                     window.setInterval(function () {
  48.  
  49.                                         $.ajax({
  50.                           type: "GET",
  51.                           async: false,
  52.                           url: 'loadonline.php',
  53.                           data: {},
  54.                           success: function (data) {
  55.                           }
  56.  
  57.                       });
  58.                                                   }, 2000);
  59.  
  60.                       //REMOVES OLD ONLINE TABLE ROWS MUST TO IN LONGER INTERVAL LIKE ONCE IN HALF MINS
  61.                      
  62.                                     window.setInterval(function () {
  63.  
  64.                                         $.ajax({
  65.                           type: "GET",
  66.                           async: false,
  67.                           url: 'removeonline.php',
  68.                           data: {},
  69.                           success: function (data) {
  70.                           }
  71.  
  72.                       });
  73.                                   }, 4000);
  74.  
  75. </script>
  76. <?php
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. //skripts kurš pie katras čaraktera kustību apstājas updeito tabulas sadaļu *location*
  85. //skripts kurš katru lietotāju kura datetime sakrīt ar intervālu pēdējās 15 min, zīmē ekrānā
  86.  
  87.  
  88.  
  89.  
  90.  
  91.    ?>
  92.  
  93.    </h1>  <a href="logout.php">Logout.</a>http://mytechservinginternetmeals.blogspot.com/2022/02/video-game-development-4.html
  94.    
  95.    <br>
  96.    <b>Things need to be implemented: 1)physics between two 3d objects besides map object 2)shadered and textured maps 3)animations for special objects 4)multiplayer and quests</b>
  97.    </center>
  98.     <script>
  99.                
  100.                
  101.                
  102.  
  103.  
  104.  
  105.  
  106.  
  107.       const {
  108.         enable3d,
  109.         Scene3D,
  110.         Canvas,
  111.         ThirdDimension,
  112.         THREE,
  113.         JoyStick,
  114.         ExtendedObject3D,
  115.         ThirdPersonControls,
  116.         PointerLock,
  117.         PointerDrag
  118.       } = ENABLE3D
  119.  
  120.       /**
  121.        * Is touch device?
  122.        */
  123.       const isTouchDevice = 'ontouchstart' in window
  124.  
  125.       class MainScene extends Scene3D {
  126.         constructor() {
  127.           super({ key: 'MainScene' })
  128.         }
  129.  
  130.         init() {
  131.           this.accessThirdDimension({ maxSubSteps: 10, fixedTimeStep: 1 / 120 })
  132.           this.third.renderer.outputEncoding = THREE.LinearEncoding
  133.           this.canJump = true
  134.           this.move = false
  135.  
  136.           this.moveTop = 0
  137.           this.moveRight = 0
  138.         }
  139.  
  140.         async create() {
  141.           const { lights } = await this.third.warpSpeed('-ground', '-orbitControls')
  142.  
  143.           const { hemisphereLight, ambientLight, directionalLight } = lights
  144.           const intensity = 0.65
  145.           hemisphereLight.intensity = intensity
  146.           ambientLight.intensity = intensity
  147.           directionalLight.intensity = intensity
  148.  
  149.  
  150.  
  151.  
  152.                         var updeitot;       /// mainīgais kas noteiks vai updeitot lokāciju un čata ziņas
  153.  
  154.  
  155.  
  156.  
  157.           /** KARTE
  158.            * Medieval Fantasy Book by Pixel (https://sketchfab.com/stefan.lengyel1)
  159.            * https://sketchfab.com/3d-models/medieval-fantasy-book-06d5a80a04fc4c5ab552759e9a97d91a
  160.            * Attribution 4.0 International (CC BY 4.0)
  161.            
  162.            E4E717
  163.            */
  164.           this.third.load.gltf('/jurmalastreets3d/assets/glb/book6.glb').then(object => {
  165.             const scene = object.scenes[0]
  166.  
  167.             const book = new ExtendedObject3D()
  168.             book.name = 'scene'
  169.             book.add(scene)
  170.             this.third.add.existing(book)
  171.  
  172.             // add animations
  173.             // sadly only the flags animations works
  174.             object.animations.forEach((anim, i) => {
  175.               book.mixer = this.third.animationMixers.create(book)
  176.               // overwrite the action to be an array of actions
  177.               book.action = []
  178.               book.action[i] = book.mixer.clipAction(anim)
  179.               book.action[i].play()
  180.             })
  181.  
  182.             book.traverse(child => {
  183.               if (child.isMesh) {
  184.                 child.castShadow = child.receiveShadow = false
  185.                 child.material.metalness = 0
  186.                 child.material.roughness = 1
  187.  
  188.                 if (/mesh/i.test(child.name)) {
  189.                   this.third.physics.add.existing(child, {
  190.                     shape: 'concave',
  191.                     mass: 0,
  192.                     collisionFlags: 1,
  193.                     autoCenter: false
  194.                   })
  195.                   child.body.setAngularFactor(0, 0, 0)
  196.                   child.body.setLinearFactor(0, 0, 0)
  197.                 }
  198.               }
  199.             })
  200.           })
  201.          
  202.          
  203.          
  204.          
  205.            
  206.  
  207.  
  208.           /** ELEMENTS MĀJA
  209.            * box_man.glb by Jan Bláha
  210.            * https://github.com/swift502/Sketchbook
  211.            * CC-0 license 2018
  212.            */
  213.           this.third.load.gltf('/jurmalastreets3d/assets/glb/house.glb').then(object => {
  214.             const house = object.scene.children[0]
  215.                        
  216.        
  217.             this.house = new ExtendedObject3D()
  218.             this.house.name = 'house'
  219.             this.house.rotateY(Math.PI + 0.1) // a hack
  220.             this.house.add(house)
  221.             this.house.rotation.set(0, Math.PI * 1.5, 0)
  222.  
  223.                           var obj;
  224.                           $.ajax({
  225.                                            type: "GET",
  226.                                            async: false,
  227.                                            url: 'getlocation.php',
  228.                                            data:{},
  229.                                            success:function(html) {
  230.                                                                 obj = JSON.parse(html);
  231.                                                         console.log("noliek", obj);
  232.                                            }
  233.  
  234.                                   });
  235.  
  236.                         this.house.position.set(804.2014, 10, -205.63472)
  237.            
  238.            
  239.            
  240.                        
  241.             // add shadow
  242.             this.house.traverse(child => {
  243.               if (child.isMesh) {
  244.                 child.castShadow = child.receiveShadow = true
  245.                 // https://discourse.threejs.org/t/cant-export-material-from-blender-gltf/12258
  246.                 child.material.roughness = 1
  247.                 child.material.metalness = 0
  248.               }
  249.             })
  250.  
  251.             /**
  252.              * Animations
  253.              */
  254.             this.third.animationMixers.add(this.house.animation.mixer)
  255.             object.animations.forEach(animation => {
  256.               if (animation.name) {
  257.                 this.house.animation.add(animation.name, animation)
  258.               }
  259.             })
  260.             this.house.animation.play('idle')
  261.  
  262.             /**
  263.              * Add the player to the scene with a body
  264.              */
  265.             this.third.add.existing(this.house)
  266.             this.third.physics.add.existing(this.house, {
  267.               shape: 'sphere',
  268.               radius: 0.25,
  269.               width: 0.5,
  270.               offset: { y: -0.25 }
  271.             })
  272.             this.house.body.setFriction(0.8)
  273.             this.house.body.setAngularFactor(0, 0, 0)
  274.  
  275.             // https://docs.panda3d.org/1.10/python/programming/physics/bullet/ccd
  276.             this.house.body.setCcdMotionThreshold(1e-7)
  277.             this.house.body.setCcdSweptSphereRadius(0.25)
  278.  
  279.             /**
  280.              * Add 3rd Person Controls
  281.              */
  282.             this.controls = new ThirdPersonControls(this.third.camera, this.house, {
  283.               offset: new THREE.Vector3(0, 1, 0),
  284.               targetRadius: 3
  285.             })
  286.             // set initial view to 90 deg theta
  287.             this.controls.theta = 90
  288.  
  289.             /**
  290.              * Add Pointer Lock and Pointer Drag
  291.              */
  292.             if (!isTouchDevice) {
  293.               let pl = new PointerLock(this.game.canvas)
  294.               let pd = new PointerDrag(this.game.canvas)
  295.               pd.onMove(delta => {
  296.                 if (pl.isLocked()) {
  297.                   this.moveTop = -delta.y
  298.                   this.moveRight = delta.x
  299.                 }
  300.               })
  301.             }
  302.           })
  303.  
  304.  
  305.  
  306.           /**
  307.            *
  308.            * IELĀDĒT PLAYER LOKĀCIJAS KURA VAR NOTIKT TIKAI UZ MAINĪGĀ BĀZES
  309.            *
  310.            */
  311.  
  312.  
  313. window.objx = [];
  314. window.objy = [];
  315. window.objz = [];
  316.                               //let counter = 0;
  317.                                                           //let objxl = objx.length;
  318.                                         Array.prototype.clear = function() {
  319.     this.splice(0, this.length);
  320. };
  321.  
  322.  
  323.               window.setInterval(function () {
  324.                   if (updeitot = 1) {
  325.                                          
  326.                                          
  327.                                             //$.ajax({
  328.                                                   //type: "GET",
  329.                                                   //async: false,
  330.                                                   //url: 'getlocation.php',
  331.                                                   //data: {},
  332.                                                   //success: function (data) {
  333.                                                           //var nameArr = data.split(',');
  334.                                                          
  335.                                                           //console.log("idioti");
  336.                                                         //for(let i=0; i<nameArr.length; i++){
  337.                                                                                                                           //console.log("pushes skins");
  338.  
  339.                                                                 //if(nameArr[i]){
  340.                                                                 //skins.push(nameArr[i]);
  341.                                                         //}
  342.                                                                         //}
  343.                                                                        
  344.                                                                        
  345.                                                          
  346.                                                   //}
  347.                                           //});
  348.                                           objx.clear();
  349.                                           objy.clear();
  350.                                           objz.clear();
  351.                                
  352.                                
  353.                        //satur lokācijas
  354.                       $.ajax({
  355.                           type: "GET",
  356.                           async: false,
  357.                           url: 'getlocation.php',
  358.                           data: {},
  359.                           success: function (data) {
  360.                                                           var data2 = data.split("*");
  361.                               //objx = data2.x
  362.                               ////objy = data2.y
  363.                               console.log("garums", data2.length);
  364.                               for(var i = 0; i < data2.length - 1; i++){
  365.                                                                   var data3 = JSON.parse(data2[i]);
  366.                                                                                         console.log("dati no datubazes",i, data3);
  367.                                                                                        
  368.                                                                                        
  369.                                                                 objx.push(data3.x);
  370.                                                                 objy.push(data3.y);
  371.                                                                 objz.push(data3.z);
  372.  
  373.                                                           }
  374.                              
  375.                               ////objz = data2.z
  376.                              
  377.                               //console.log("lokacijas x", data2.x);
  378.                               //console.log("lokacijas y", data2.y);
  379.                               //console.log("lokacijas z", data2.z);
  380.                              // console.log("notiek dahuja");
  381.                              
  382.                              
  383.                              //ja visi masīva pēdējie pievienotie elementi nesakrīt jau ar esošajiem pievienot masīvam citus
  384.                              
  385.                              // koordinātēm jābūt vienādai kārtībai ar čaraktera user id
  386.                            
  387.                              
  388.                                                        
  389.                                                           //    counter++;
  390.                                                        
  391.                                                                        
  392.                                                                        
  393.  
  394.                           }
  395.                       });
  396.                   }
  397.               }, 400);
  398.              
  399.              
  400.  
  401. window.objx2 = [];
  402. window.objy2 = [];
  403. window.objz2 = [];
  404.  
  405.  
  406.  
  407.               window.setInterval(function () {
  408.                   if (updeitot = 1) {
  409.                                          
  410.                                          
  411.                                             //$.ajax({
  412.                                                   //type: "GET",
  413.                                                   //async: false,
  414.                                                   //url: 'getlocation.php',
  415.                                                   //data: {},
  416.                                                   //success: function (data) {
  417.                                                           //var nameArr = data.split(',');
  418.                                                          
  419.                                                           //console.log("idioti");
  420.                                                         //for(let i=0; i<nameArr.length; i++){
  421.                                                                                                                           //console.log("pushes skins");
  422.  
  423.                                                                 //if(nameArr[i]){
  424.                                                                 //skins.push(nameArr[i]);
  425.                                                         //}
  426.                                                                         //}
  427.                                                                        
  428.                                                                        
  429.                                                          
  430.                                                   //}
  431.                                           //});
  432.                                           objx2.clear();
  433.                                           objy2.clear();
  434.                                           objz2.clear();
  435.                                
  436.                                
  437.                        //satur lokācijas
  438.                       $.ajax({
  439.                           type: "GET",
  440.                           async: false,
  441.                           url: 'getlocation.php',
  442.                           data: {},
  443.                           success: function (data) {
  444.                                                           var data2 = data.split("*");
  445.                               //objx = data2.x
  446.                               ////objy = data2.y
  447.                               console.log("garums", data2.length);
  448.                               for(var i = 0; i < data2.length - 1; i++){
  449.                                                                   var data3 = JSON.parse(data2[i]);
  450.                                                                                         console.log("dati no datubazes velak",i, data3);
  451.                                                                                        
  452.                                                                                        
  453.                                                                 objx2.push(data3.x);
  454.                                                                 objy2.push(data3.y);
  455.                                                                 objz2.push(data3.z);
  456.  
  457.                                                           }
  458.                              
  459.                               ////objz = data2.z
  460.                              
  461.                               //console.log("lokacijas x", data2.x);
  462.                               //console.log("lokacijas y", data2.y);
  463.                               //console.log("lokacijas z", data2.z);
  464.                              // console.log("notiek dahuja");
  465.                              
  466.                              
  467.                              //ja visi masīva pēdējie pievienotie elementi nesakrīt jau ar esošajiem pievienot masīvam citus
  468.                              
  469.                              // koordinātēm jābūt vienādai kārtībai ar čaraktera user id
  470.                            
  471.                              
  472.                                                        
  473.                                                           //    counter++;
  474.                                                        
  475.                                                                        
  476.                                                                        
  477.  
  478.                           }
  479.                       });
  480.                   }
  481.               }, 800);
  482.              
  483.              
  484.              
  485.               console.log("kas ir iekš x ", objx);
  486.              
  487.               // uzskaita pareizu skaitu hujņu
  488.              
  489.              
  490.  
  491.         //if(counter > objxl.length){
  492.         //counter = objxl.length;
  493.         //}
  494.  
  495.                
  496.  
  497.                                 //console.log("tryx", objx); // hz kāpēc masīvs tukšss
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.               var getchat = [];
  505.               window.setInterval(function () {
  506.  
  507.  
  508.                   if (updeitot = 1) {
  509.  
  510.                       $.ajax({
  511.                           type: "GET",
  512.                           async: false,
  513.                           url: 'getchat.php',
  514.                           data: {},
  515.                           success: function (data) {
  516.                               getchat = data.split("*").map(String);
  517.  
  518.                           }
  519.  
  520.                       });
  521.                   }
  522.               }, 600);
  523.      
  524.                        
  525.                        
  526.                        
  527.                        
  528.                        
  529.                        
  530.                        
  531.                        
  532.                        
  533.                        
  534.                        
  535.                        
  536.  
  537.                           var uu;
  538.                           var location2;
  539.                           var location3;
  540.                           var location4;
  541.                                                                         window.setInterval(function(){
  542.                                                                         uu = getchat[0]
  543.                                                                         location2 = parseInt(objx[0]);
  544.                                                                         location3 = location2 + 185;
  545.                                                                         location4 = location3.toString();
  546.                                                                         console.log("uu", location4);
  547.                                                                         }, 600);
  548.                                                                        
  549.                                                         const foo = () => {
  550.                                                                 //chatbubbles.php
  551.                                                                 //
  552.                                                         this.add.text(location4,328, uu, { fontSize: '24px' });
  553.                                                         }
  554.  
  555.                                                                         window.setInterval(function(){
  556.                                                         foo();
  557.                                                                         }, 610);
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.           /**
  565.            *
  566.            * IELĀDĒT SKINUS FUNKCIJA KURA VAR NOTIKT TIKAI UZ MAINĪGĀ BĀZES
  567.            *
  568.            */
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.                                           var skins = [];
  576.                                           var skins2 = [];
  577.                                           var userskin = [];
  578.                                           var userid = [];
  579.                                           let skin;
  580.                                           let skin2;
  581.                                          
  582.                                          
  583.  
  584.                                           $.ajax({
  585.                                                   type: "GET",
  586.                                                   async: false,
  587.                                                   url: 'loadskins.php',
  588.                                                   data: {},
  589.                                                   success: function (data) {
  590.                                                           var nameArr = data.split(',');
  591.                                                          
  592.                                                          // console.log("idioti");
  593.                                                         for(let i=0; i<nameArr.length; i++){
  594.                                                                                                                           console.log("pushes skins");
  595.  
  596.                                                                 if(nameArr[i]){
  597.                                                                 skins.push(nameArr[i]);
  598.                                                         }
  599.                                                                         }
  600.                                                                        
  601.                                                                        
  602.                                                          
  603.                                                   }
  604.                                           });
  605.                                
  606.                                                    
  607.                                                    
  608.                                                    
  609.  
  610.                                           $.ajax({
  611.                                                   type: "GET",
  612.                                                   async: false,
  613.                                                   url: 'loadskins2.php',
  614.                                                   data: {},
  615.                                                   success: function (data) {
  616.                                                           var nameArr2 = data.split(',');
  617.                                                          
  618.                                                          // console.log("idioti");
  619.                                                         for(let i=0; i<nameArr2.length; i++){
  620.                                                                                                                           console.log("pushes skins2");
  621.                                                         if(nameArr2[i]){
  622.                                                                 skins2.push(nameArr2[i]);
  623.                                                         }
  624.                                                         }
  625.                                                                        
  626.                                                                        
  627.                                                          
  628.                                                   }
  629.                                           });
  630.                                                    
  631.                                                    
  632.                                                    
  633.                                                    
  634.                                        
  635.                                           $.ajax({
  636.                                                   type: "GET",
  637.                                                   async: false,
  638.                                                   url: 'loaduserskin.php',
  639.                                                   data: {},
  640.                                                   success: function (data) {
  641.                                                           var nameArr = data.split(',');
  642.                                                          
  643.                                                           //console.log("idioti");
  644.                                                         for(let i=0; i<nameArr.length; i++){
  645.                                                                                                                           console.log("pushes skins");
  646.  
  647.                                                                 if(nameArr[i]){
  648.                                                                 userskin.push(nameArr[i]);
  649.                                                         }
  650.                                                                         }
  651.                                                                        
  652.                                                                        
  653.                                                          
  654.                                                   }
  655.                                           });      
  656.                                           $.ajax({
  657.                                                   type: "GET",
  658.                                                   async: false,
  659.                                                   url: 'loaduserid.php',
  660.                                                   data: {},
  661.                                                   success: function (data) {
  662.                                                           var nameArr = data.split(',');
  663.                                                          
  664.                                                           //console.log("idioti");
  665.                                                         for(let i=0; i<nameArr.length; i++){
  666.                                                                                                                           console.log("pushes skins");
  667.  
  668.                                                                 if(nameArr[i]){
  669.                                                                 userid.push(nameArr[i]);
  670.                                                         }
  671.                                                                         }
  672.                                                                        
  673.                                                                        
  674.                                                          
  675.                                                   }
  676.                                           });      
  677.                                                    
  678.                                                    
  679.                                                    
  680.                                
  681.                                
  682.                                
  683.           /**
  684.            *
  685.            * IELĀDĒ CHARAKTERUS NO IEGUTAS INFORMACIJAS
  686.            *
  687.            
  688.            *
  689.            *
  690.            *          IEČĒKOT TABULAS online SATURU UN attiecīgās lokācijas skinus un ja tie eksistē un ir tādi paši kā tabulā users, tad tos ievietot spēlē updeitojot
  691.            *
  692.            */
  693.                                 //let object;
  694.  
  695.  
  696.                                
  697.                                 //setInterval(function (third) {
  698.                                                                 //console.log("saturs", skins);
  699.                                                                
  700.                                                                
  701.                                                                 //skinsIZR = skinsZ[0].split(",").map(String); 
  702.                                                                 //console.log("IZR", skinsIZR[0]);
  703.                                                                
  704.                                                         console.log("speletaju skaits", skins.length);
  705.                                                                
  706.                                                                
  707.                                                                 var cooords = [];
  708.                                                                
  709.                                                                 for (let step = 0;  step < skins.length; step++) {
  710.        
  711.                                                                                
  712.                                                         //const object = this.third.load.gltf(skins[step])
  713.  
  714. //console.log("trust", object.scene);
  715.  
  716.  
  717.    var object = await this.third.load.gltf(skins[step])
  718.          
  719.           ///this.third.load.gltf('/assets/glb/box_man.glb').then(object => {
  720.             const scene2 = object.scene.children[0]
  721.            
  722.            
  723.   //this.third.load.gltf(skins[step]).then(object => {
  724.         //const scene2 = object.scenes[0]
  725.  
  726.                                                         const man = object.scene.children[0]
  727.  
  728.                                                         ///this.third.load.gltf('/assets/glb/box_man.glb').then(object => {
  729.                                                        
  730.                                                         console.log("zb", man);
  731.  
  732.  
  733.  
  734.                                                         this.man = new ExtendedObject3D()
  735.                                                         this.man.name = 'man'
  736.                                                         this.man.rotateY(Math.PI + 0.1) // a hack
  737.                                                         this.man.add(man)
  738.                                                         this.man.rotation.set(0, Math.PI * 1.5, 0)
  739.                                                        
  740.                                                        
  741.                                                         let that = this.man;
  742.                                                        
  743.  
  744.                                                        
  745.                                                         this.man.position.set(804.2014, 10, -205.63472)
  746.                                                        
  747.                                                         let coords2 = this.man.position.clone()
  748.                                                         cooords.push(coords2);
  749.                                                         //console.log("iteracija", i);
  750.                                                         //if(vertibasx !== null && vertibasy !== null && vertibasz !== null){
  751.                                
  752.                                                  
  753.  
  754.                                                         //const coords2 = this.man.position.clone();
  755.  
  756.                                                        
  757.                                                         // add shadow
  758.                                                         this.man.traverse(child => {
  759.                                                                 if (child.isMesh) {
  760.                                                                         child.castShadow = child.receiveShadow = true
  761.                                                                         // https://discourse.threejs.org/t/cant-export-material-from-blender-gltf/12258
  762.                                                                         child.material.roughness = 1
  763.                                                                         child.material.metalness = 0
  764.                                                                 }
  765.                                                         })
  766.  
  767.                                                         /**
  768.                                                          * Animations
  769.                                                          */
  770.                                                         this.third.animationMixers.add(this.man.animation.mixer)
  771.                                                         object.animations.forEach(animation => {
  772.                                                                 if (animation.name) {
  773.                                                                         this.man.animation.add(animation.name, animation)
  774.                                                                 }
  775.                                                         })
  776.                                                         this.man.animation.play('idle')
  777.  
  778.                                                         /**
  779.                                                          * Add the player to the scene with a body
  780.                                                          */
  781.                                                         this.third.add.existing(this.man)
  782.                                                         this.third.physics.add.existing(this.man, {
  783.                                                                 shape: 'sphere',
  784.                                                                 radius: 0.25,
  785.                                                                 width: 0.5,
  786.                                                                 offset: {
  787.                                                                         y: -0.25
  788.                                                                 }
  789.                                                         })
  790.                                                         this.man.body.setFriction(0.8)
  791.                                                         this.man.body.setAngularFactor(0, 0, 0)
  792.  
  793.                                                         // https://docs.panda3d.org/1.10/python/programming/physics/bullet/ccd
  794.                                                         this.man.body.setCcdMotionThreshold(1e-7)
  795.                                                         this.man.body.setCcdSweptSphereRadius(0.25)
  796.  
  797.                                        
  798.                                                
  799.                                                                        
  800.                                                                
  801.                                                                 //}, 500);
  802.                                                                
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.                                                 /**
  814.                                                  * Add 3rd Person Controls
  815.                                                  */
  816.                                                 this.controls = new ThirdPersonControls(this.third.camera, this.man, {
  817.                                                         offset: new THREE.Vector3(0, 1, 0),
  818.                                                         targetRadius: 3
  819.                                                 })
  820.                                                 // set initial view to 90 deg theta
  821.                                                 this.controls.theta = 90
  822.  
  823.                                                 /**
  824.                                                  * Add Pointer Lock and Pointer Drag
  825.                                                  */
  826.                                                 if (!isTouchDevice) {
  827.                                                         let pl = new PointerLock(this.game.canvas)
  828.                                                         let pd = new PointerDrag(this.game.canvas)
  829.                                                         pd.onMove(delta => {
  830.                                                                 if (pl.isLocked()) {
  831.                                                                         this.moveTop = -delta.y
  832.                                                                         this.moveRight = delta.x
  833.                                                                 }
  834.                                                         })
  835.                                                 }
  836.                                                 // })
  837.                                                
  838.                                                
  839.                                                
  840.                                                
  841.                                                
  842.                                                
  843.                                                
  844.                                                
  845.                                                
  846.  
  847.                                                 /**
  848.                                                  * Add Keys
  849.                                                  */
  850.  
  851.  
  852.  
  853.  
  854.                                                 /**
  855.                                                  * Add joystick
  856.                                                  */
  857.                                                 if (isTouchDevice) {
  858.                                                         const joystick = new JoyStick()
  859.                                                         const axis = joystick.add.axis({
  860.                                                                 styles: {
  861.                                                                         left: 35,
  862.                                                                         bottom: 35,
  863.                                                                         size: 100
  864.                                                                 }
  865.                                                         })
  866.                                                         axis.onMove(event => {
  867.                                                                 /**
  868.                                                                  * Update Camera
  869.                                                                  */
  870.                                                                 const {
  871.                                                                         top,
  872.                                                                         right
  873.                                                                 } = event
  874.                                                                 this.moveTop = top * 3
  875.                                                                 this.moveRight = right * 3
  876.                                                         })
  877.                                                         const buttonA = joystick.add.button({
  878.                                                                 letter: 'A',
  879.                                                                 styles: {
  880.                                                                         right: 35,
  881.                                                                         bottom: 110,
  882.                                                                         size: 80
  883.                                                                 }
  884.                                                         })
  885.                                                         buttonA.onClick(() => this.jump())
  886.                                                         const buttonB = joystick.add.button({
  887.                                                                 letter: 'B',
  888.                                                                 styles: {
  889.                                                                         right: 110,
  890.                                                                         bottom: 35,
  891.                                                                         size: 80
  892.                                                                 }
  893.                                                         })
  894.                                                         buttonB.onClick(() => (this.move = true))
  895.                                                         buttonB.onRelease(() => (this.move = false))
  896.                                                 }
  897.  
  898.  
  899.                                                        
  900.                                        
  901.                                                
  902.                                                
  903.                                                
  904.                                                
  905.                                                
  906.                                                         //console.log("uzstada", vertibasx, vertibasy, vertibasx);
  907.  
  908.                                                                        
  909.                                                                        
  910.                                                                        
  911.                                                                        
  912.                                                                        
  913.                                                                        
  914.  
  915.  
  916.         };
  917.  
  918.  
  919.  
  920.  
  921.          
  922.          
  923.  
  924. //setInterval(greet, 8000);
  925.  
  926.                
  927.  
  928.  
  929.                                                                 ////// ideja ka nepieciešams priekļūt this.man.position iekš intervāla, lai izmainītu vertibas xyz kuras passtāvīgi tiek updeitotas no datubāzes ar intervālu pirms tam.
  930.                                                         //////setInterval(function (man) {
  931.                                                                 //////if(vertibasx != vertibasxPIRMSTAM){
  932.                                                                 //function greet(){
  933.                                                                                                                                                 ////console.log("man inside");
  934.  
  935.                                                                 //////if (updeitot = 1) {
  936.                                                                         //////refreshoja charakteru
  937.                                                                         ////if (window.localStorage.getItem('x') && window.localStorage.getItem('y') && window.localStorage.getItem('z')) {
  938.                                                                                                                                                                                                                                 //console.log("man inside2");
  939.                                                                                                                                                                                                                                 //console.log("changes?", that.position);
  940.  
  941.                                                                                 //that.position.set(window.localStorage.getItem('x'), window.localStorage.getItem('y'), window.localStorage.getItem('z'))
  942.                                                                         ////} else {
  943.                                                                                 ////this.man.position.set(754.2014, 10, -205.63472)
  944.                                                                         //}
  945.                                                                 ////}
  946.                                                         ////}
  947.                                                 var vertibasx = objx;
  948.                  var vertibasy = objy;
  949.                   var vertibasz = objz;
  950.                  
  951.                   console.log("xxxx", vertibasx);
  952.                   console.log("yyyy", vertibasy);
  953.                   console.log("zzzz", vertibasz);
  954.                  
  955.                                                         //let verx = vertibasx[step];
  956.                                                         //let very = 3;
  957.                                                         //let verz = vertibasz[step];
  958.                                                        
  959.  
  960.                        
  961.                                                                 for (let stepe = 0;  stepe < cooords.length; stepe++) {
  962.  
  963.  
  964.  
  965.                                                         let insidecoords = cooords[stepe];
  966.                        
  967.                         console.log("inside", insidecoords);
  968.                         setInterval(function () {
  969.                                                                         console.log("izsauc tween");
  970.  
  971.                                                                                         tween(this.man, insidecoords, { x: vertibasx, y: vertibasy, z: vertibasz }, 1000, 1000)
  972.  
  973.                                                   }, 2000);
  974.                                                  
  975.                                                  
  976.                                                   function tween(man,insidecoords, moveTo, time = 1000, delay = 0) {
  977.         let xc = "804.201";
  978.         let yc = "10";
  979.         let zc = "-205.63472";
  980.         console.log("notiek tweeens");
  981.                                 console.log("inside2", insidecoords);
  982.  
  983.                         const tween2 = new TWEEN.Tween(insidecoords)
  984.             .to({ x: moveTo.xc, y: moveTo.yc, z: moveTo.zc }, time)
  985.             .easing(TWEEN.Easing.Quadratic.Out)
  986.             .onUpdate(() => {
  987.                                                         console.log("notiek tweens2");
  988.  
  989.  
  990.             this.man.position.set(insidecoords.x, insidecoords.y, insidecoords.z)
  991.               if (this.man.body) this.man.body.needUpdate = true
  992.             })
  993.           }  
  994. }
  995.  
  996. }
  997.        
  998.                                                        
  999.  
  1000.  
  1001.  
  1002.                                                                
  1003.    
  1004.  
  1005.  
  1006.     //tween(man, moveTo, time = 1000, delay = 0) {
  1007.  
  1008. //console.log("middle");
  1009. //const coords = this.man.position.clone()
  1010. //console.log("coords", this.man.position);
  1011. //console.log("coords2", coords);
  1012. //console.log("moveTo", moveTo);
  1013. //console.log("moveTox", moveTo.x);
  1014.           //const tween = new TWEEN.Tween(coords)
  1015.             //.to({ x: moveTo.x, y: moveTo.y, z: moveTo.z }, time)
  1016.             //.easing(TWEEN.Easing.Quadratic.Out)
  1017.             //.onUpdate(() => {
  1018.                                                         //console.log("notiek tweens");
  1019.  
  1020.  
  1021.             //this.man.position.set(coords.x, coords.y, coords.z)
  1022.               //if (this.man.body) this.man.body.needUpdate = true
  1023.             //})
  1024.            
  1025.            
  1026.                          //this.man.position.set(coords.x, coords.y, coords.z)
  1027.  
  1028.             //console.log(this.man.position);
  1029.             //console.log("tweeen", tween);
  1030.             //console.log("end");
  1031.  
  1032.           //}  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.                                         /// iegūst no datubāzes vai leciens ir animācija
  1042.                                         jump() {
  1043.                                                 if (!this.man || !this.canJump) return
  1044.                                                 this.canJump = false
  1045.                                                 this.man.animation.play('jump_running', 500, false)
  1046.                                                 this.time.addEvent({
  1047.                                                         delay: 650,
  1048.                                                         callback: () => {
  1049.                                                                 this.canJump = true
  1050.                                                                 this.man.animation.play('idle')
  1051.                                                         }
  1052.                                                 })
  1053.                                                 this.man.body.applyForceY(6)
  1054.                                         }
  1055.                                         //ja tas notiek updeito datubāzi ar to ka palecās
  1056.  
  1057.  
  1058.  
  1059.  
  1060.                                         update(time, delta) {
  1061.  
  1062.  
  1063.  
  1064.                                                 this.keys = {
  1065.  
  1066.                                                         a: this.input.keyboard.addKey('a'),
  1067.                                                         w: this.input.keyboard.addKey('w'),
  1068.                                                         d: this.input.keyboard.addKey('d'),
  1069.                                                         s: this.input.keyboard.addKey('s'),
  1070.                                                         space: this.input.keyboard.addKey(32)
  1071.                                                 }
  1072.                                                 var choicef = 1;
  1073.  
  1074.  
  1075.                                                 if (choicef === 1) {
  1076.  
  1077.  
  1078.                                                         this.keys = {
  1079.  
  1080.                                                                 a: this.input.keyboard.addKey('a'),
  1081.                                                                 w: this.input.keyboard.addKey('w'),
  1082.                                                                 d: this.input.keyboard.addKey('d'),
  1083.                                                                 s: this.input.keyboard.addKey('s'),
  1084.                                                                 space: this.input.keyboard.addKey(32)
  1085.                                                         }
  1086.                                                 }
  1087.  
  1088.                                                 if (choicef === 2) {
  1089.                                                         this.input.keyboard.removeCapture('W,S,A,D');
  1090.                                                         this.input.keyboard.removeCapture([32]);
  1091.  
  1092.                                                 }
  1093.  
  1094.  
  1095.                                                 var area = document.getElementById('textarea');
  1096.  
  1097.  
  1098.  
  1099.  
  1100.                                                 area.addEventListener('click', (e) => {
  1101.                                                         //alert("uzlieku pa virsu");
  1102.                                                         choicef = 2;
  1103.                                                 });
  1104.  
  1105.  
  1106.  
  1107.                                                 var elem = document.getElementById('enable3d-phaser-canvas');
  1108.                                                 elem.addEventListener('click', (e) => {
  1109.                                                         console.log("uzlieku pa virsu");
  1110.                                                         choicef = 1;
  1111.                                                 });
  1112.  
  1113.                                                 area.addEventListener('keyup', (e) => {
  1114.                                                         if (e.keyCode === 13) {
  1115.                                                                 // Cancel the default action, if needed
  1116.                                                                 e.preventDefault();
  1117.                                                                 // Trigger the button element with a click
  1118.                                                                 var textarea = document.getElementById('textarea').value;
  1119.                                                                 //avar groupidTRIM = document.getElementById("groupchatID").innerHTML;
  1120.                                                                 //var groupid = "grupa";       
  1121.                                                                 //alert(111);
  1122.  
  1123.                                                                 //alert(111);
  1124.  
  1125.                                                                 var username;
  1126.  
  1127.                                                                 $.ajax({
  1128.                                                                         type: "GET",
  1129.                                                                         async: false,
  1130.                                                                         url: 'getusername.php',
  1131.                                                                         data: {},
  1132.                                                                         success: function (data) {
  1133.                                                                                 username = data;
  1134.                                                                                 //alert(username)
  1135.                                                                         }
  1136.  
  1137.                                                                 });
  1138.  
  1139.                                                                 var kopadata = username + " " + textarea;
  1140.  
  1141.                                                                 console.log("uzpeld", kopadata);
  1142.  
  1143.  
  1144.  
  1145.                                                                 if (textarea) {
  1146.  
  1147.                                                                         console.log("suta zinju", textarea);
  1148.  
  1149.  
  1150.                                                                         $.ajax({
  1151.                                                                                 type: "post",
  1152.                                                                                 url: "groupchatfunction.php",
  1153.                                                                                 data: {
  1154.                                                                                         textarea: textarea
  1155.                                                                                 },
  1156.                                                                                 cache: false,
  1157.                                                                                 success: function (html) {
  1158.                                                                                         console.log("aizsutija");
  1159.  
  1160.                                                                                         //izmēģinam ievietot kastīti ja aizsūtas ziņa
  1161.                                                                                         // this.third.physics.add.box({ y: 10, x: 754.2014 }, { lambert: { color: 'red' } })
  1162.  
  1163.  
  1164.                                                                                         /// tekstu ieposto datubāzē , izmaina globālo masīvu ar tekstu un tā īpašnieku
  1165.                                                                                         /// vēlāk globālo masīvu zīmē gluži kā čarakteru iekš update funkcijas, iekļauj sarakstā visas ziņas
  1166.                                                                                         // un uzzīmē thought buble virs čaraktera galvas ar iedomāto tekstu
  1167.                                                                                         var kopadata2 = kopadata;
  1168.  
  1169.                                                                                         var doit = textbubble.push(kopadata2);
  1170.                                                                                         var messageelements = '<div class="msg_a"><span data-tooltip="now" data-tooltip-position="bottom">' + textarea + '</span></div><br>';
  1171.  
  1172.  
  1173.                                                                                         $("#outputmessages").append(messageelements);
  1174.  
  1175.  
  1176.                                                                                         //window.setTimeout(function(){
  1177.                                                                                         //var elem = document.getElementById('msg_body');
  1178.                                                                                         //elem.scrollTop = elem.scrollHeight;
  1179.                                                                                         //}, 1200);
  1180.  
  1181.  
  1182.                                                                                 }
  1183.  
  1184.  
  1185.  
  1186.                                                                         });
  1187.                                                                 }
  1188.  
  1189.                                                                 document.getElementById('textarea').value = '';
  1190.  
  1191.  
  1192.                                                         }
  1193.                                                 });
  1194.  
  1195.  
  1196.  
  1197.  
  1198.                                                 if (this.man && this.man.body) {
  1199.                                                         /**
  1200.                                                          * Update Controls
  1201.                                                          */
  1202.                                                         this.controls.update(this.moveRight * 2, -this.moveTop * 2)
  1203.                                                         if (!isTouchDevice) this.moveRight = this.moveTop = 0
  1204.                                                         /**
  1205.                                                          * Player Turn
  1206.                                                          */
  1207.                                                         const speed = 4
  1208.                                                         const v3 = new THREE.Vector3()
  1209.  
  1210.                                                         const rotation = this.third.camera.getWorldDirection(v3)
  1211.                                                         const theta = Math.atan2(rotation.x, rotation.z)
  1212.                                                         const rotationMan = this.man.getWorldDirection(v3)
  1213.                                                         const thetaMan = Math.atan2(rotationMan.x, rotationMan.z)
  1214.                                                         this.man.body.setAngularVelocityY(0)
  1215.  
  1216.                                                         const l = Math.abs(theta - thetaMan)
  1217.                                                         let rotationSpeed = isTouchDevice ? 2 : 4
  1218.                                                         let d = Math.PI / 24
  1219.  
  1220.                                                         if (l > d) {
  1221.                                                                 if (l > Math.PI - d) rotationSpeed *= -1
  1222.                                                                 if (theta < thetaMan) rotationSpeed *= -1
  1223.                                                                 this.man.body.setAngularVelocityY(rotationSpeed)
  1224.                                                         }
  1225.  
  1226.                                                         /**
  1227.                                                          * Player Move
  1228.                                                          */
  1229.                                                         if (this.keys.w.isDown || this.move) {
  1230.                                                                                 //chatbubbles.php
  1231.                                                                                
  1232.                                                                                
  1233.                                                                                
  1234.                                                                 /// vajadzētu atcelt funkciju kas veic lokāciju pārlādi
  1235.                                                                 var updeitot = 0;
  1236.  
  1237.  
  1238.                                                                 if (this.man.animation.current === 'idle' && this.canJump) this.man.animation.play('run')
  1239.  
  1240.                                                                 const x = Math.sin(theta) * speed,
  1241.                                                                         y = this.man.body.velocity.y,
  1242.                                                                         z = Math.cos(theta) * speed
  1243.                                        
  1244.                                        
  1245.                                         var sutit = {"x":x, "y":y, "z":10};
  1246.                 console.log("sutit",sutit);
  1247.  
  1248.                                         $.ajax({
  1249.                           type: "POST",
  1250.                           async: false,
  1251.                           url: 'postlocation.php',
  1252.                           data: { sutit:sutit },
  1253.                           success: function (data) {
  1254.                                                           console.log("nomainija datubazi");
  1255.                                                           //var data2 = JSON.parse(data);
  1256.                               //objx = data2.x
  1257.                               //objy = data2.y
  1258.                               //objz = data2.z
  1259.                               //console.log("lokacijas x", data2.x);
  1260.                               //console.log("lokacijas y", data2.y);
  1261.                               //console.log("lokacijas z", data2.z);
  1262.  
  1263.                           }
  1264.                       });
  1265.                      
  1266.                      
  1267.                      
  1268.                                                                 this.man.body.setVelocity(x, y, z)
  1269.                                                                 this.man.position.set(804.2014, 10, -205.63472)
  1270.                                                         } else {
  1271.                                                                 var updeitot = 1;
  1272.                                                                 if (this.man.animation.current === 'run' && this.canJump) this.man.animation.play('idle')
  1273.                                                         }
  1274.  
  1275.                                                         /**
  1276.                                                          * Player Jump
  1277.                                                          */
  1278.                                                         if (this.keys.space.isDown && this.canJump) {
  1279.                                                                 this.jump()
  1280.                                                         }
  1281.                                                 }
  1282.                                         }
  1283.  
  1284.                                         }
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.       const config = {
  1291.         type: Phaser.WEBGL,
  1292.         transparent: true,
  1293.         scale: {
  1294.           mode: Phaser.Scale.FIT,
  1295.           autoCenter: Phaser.Scale.CENTER_BOTH,
  1296.           width: window.innerWidth * Math.max(1, window.devicePixelRatio / 2),
  1297.           height: window.innerHeight * Math.max(1, window.devicePixelRatio / 2)
  1298.         },
  1299.         scene: [MainScene],
  1300.         ...Canvas({ antialias: false })
  1301.       }
  1302.  
  1303.       window.addEventListener('load', () => {
  1304.         enable3d(() => new Phaser.Game(config)).withPhysics('lib/ammo/kripken')
  1305.       })
  1306.     </script>
  1307.   </body>
  1308. </html>
  1309. © 2022 GitHub, Inc.
  1310. Terms
  1311. Privacy
  1312. Security
  1313. Status
  1314. Docs
  1315. Contact GitHub
  1316. Pricing
  1317. API
  1318. Training
  1319. Blog
  1320. About
  1321. s
  1322.  
  1323.