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

Replies to BR 3D VG - TWEENS DOES NOT WORK rss

Title Name Language When
Re: BR 3D VG - TWEENS DOES NOT WORK Gruff Sloth javascript 1 Year ago.