@@ -681,7 +681,7 @@ <h3>Gra zatrzymana</h3>
681681
682682
683683var canvas , renderer , scene , camera , stats , raycaster ,
684- gameState , stairsGeometry , world , cube , FPC , anvilGeometry , socket ;
684+ gameState , stairsGeometry , world , cube , FPC , anvilGeometry , socket , playerObject ;
685685
686686init ( )
687687animate ( )
@@ -700,6 +700,42 @@ <h3>Gra zatrzymana</h3>
700700 socket . on ( "blockUpdate" , function ( block ) {
701701 world . setVoxel ( ...block )
702702 } )
703+ var playersx = { }
704+ socket . on ( "playerUpdate" , function ( players ) {
705+ var sockets = { } ;
706+ Object . keys ( players ) . forEach ( function ( p ) {
707+ sockets [ p ] = true ;
708+ if ( playersx [ p ] == undefined && p != socket . id ) {
709+ loader . load ( 'assets/models/player.fbx' , function ( object ) {
710+ var texturex = new THREE . TextureLoader ( ) . load ( 'assets/textures/steve.png' ) ;
711+ texturex . magFilter = THREE . NearestFilter ;
712+ object . children [ 1 ] . scale . set ( 1 , 1 , 1 )
713+ object . children [ 1 ] . position . set ( 25 , 25 , 25 )
714+ object . children [ 0 ] . material . map = texturex
715+ object . children [ 0 ] . material . color = new THREE . Color ( 0xffffff ) ;
716+ object . children [ 1 ] . scale . set ( 0.5 , 0.5 , 0.5 )
717+ scene . add ( object )
718+ playersx [ p ] = object ;
719+ } ) ;
720+ }
721+ try {
722+ playersx [ p ] . children [ 1 ] . position . set ( players [ p ] . x , players [ p ] . y - 0.5 , players [ p ] . z )
723+ playersx [ p ] . children [ 1 ] . children [ 0 ] . children [ 0 ] . children [ 0 ] . children [ 2 ] . rotation . x = players [ p ] . xyaw ;
724+ playersx [ p ] . children [ 1 ] . children [ 0 ] . rotation . z = players [ p ] . zyaw
725+ } catch ( e ) { }
726+
727+ // setInterval(function (){
728+ // object.children[1].children[0].children[0].children[0].children[2].rotation.x=-camera.rotation.x
729+ // object.children[1].children[0].rotation.z=camera.rotation.y+Math.PI
730+ // })
731+ } )
732+ Object . keys ( playersx ) . forEach ( function ( p ) {
733+ if ( sockets [ p ] == undefined ) {
734+ scene . remove ( playersx [ p ] ) ;
735+ delete playersx [ p ]
736+ }
737+ } )
738+ } )
703739 canvas = document . querySelector ( '#c' ) ;
704740 renderer = new THREE . WebGLRenderer ( {
705741 canvas
@@ -747,20 +783,24 @@ <h3>Gra zatrzymana</h3>
747783 anvilGeometry . rotateX ( - Math . PI / 2 )
748784 anvilGeometry . translate ( 0 , 0.17 , 0 )
749785 } ) ;
750- loader . load ( 'assets/models/villager.fbx' , function ( object ) {
751- // object.scale.set(0.01,0.01,0.01)
752- // console.log(object)
753- var texturex = new THREE . TextureLoader ( ) . load ( 'assets/textures/villager.png' ) ;
754- texturex . magFilter = THREE . NearestFilter ;
755-
756- object . children [ 1 ] . scale . set ( 1 , 1 , 1 )
757- object . children [ 1 ] . position . set ( 26 , 26 , 26 )
758- object . children [ 0 ] . material . map = texturex
759- object . children [ 0 ] . material . color = new THREE . Color ( 0xffffff ) ;
760- object . children [ 1 ] . children [ 0 ] . children [ 1 ] . children [ 2 ] . children [ 0 ] . rotation . x = Math . PI / 5
761- // console.log(object.children[1].children[0].children[1].children[2])
762- scene . add ( object )
763- } ) ;
786+
787+ // loader.load( 'assets/models/player.fbx', function ( object ) {
788+ // // object.scale.set(0.01,0.01,0.01)
789+ // // console.log(object)
790+ // var texturex = new THREE.TextureLoader().load('assets/textures/steve.png');
791+ // texturex.magFilter = THREE.NearestFilter;
792+
793+ // object.children[1].scale.set(1,1,1)
794+ // object.children[1].position.set(25,25,25)
795+ // object.children[0].material.map=texturex
796+ // object.children[0].material.color=new THREE.Color( 0xffffff );
797+ // object.children[1].scale.set(0.5,0.5,0.5)
798+ // setInterval(function (){
799+ // object.children[1].children[0].children[0].children[0].children[2].rotation.x=-camera.rotation.x
800+ // object.children[1].children[0].rotation.z=camera.rotation.y+Math.PI
801+ // })
802+ // scene.add(object)
803+ // });
764804
765805 world = new Terrain ( {
766806 textureAtlas : texture ,
@@ -931,11 +971,20 @@ <h3>Gra zatrzymana</h3>
931971 camera . updateProjectionMatrix ( ) ;
932972 }
933973 if ( gameState == "game" ) {
974+ socket . emit ( "playerUpdate" , {
975+ x :camera . position . x ,
976+ y :camera . position . y ,
977+ z :camera . position . z ,
978+ xyaw :- camera . rotation . x ,
979+ zyaw :camera . rotation . y + Math . PI
980+ } )
934981 FPC . camMicroMove ( )
982+
935983 }
936984 renderer . render ( scene , camera ) ;
937985 world . updateCells ( )
938986 updateCursor ( )
987+
939988}
940989 </ script >
941990 </ body >
0 commit comments