@@ -14,8 +14,8 @@ var facing = 'left';
1414var jumpTimer = 0 ;
1515var cursors ;
1616var jumpButton ;
17- var box1 ;
18- var box2 ;
17+
18+ var boxes ;
1919
2020function create ( ) {
2121
@@ -39,40 +39,53 @@ function create() {
3939
4040 // game.physics.setBoundsToWorld();
4141
42- game . physics . gravity . y = 20 ;
42+ // game.physics.gravity.y = 9.78;
43+ game . physics . setBoundsToWorld ( true , true , false , true ) ;
44+
45+ game . physics . world . gravity [ 1 ] = - 20 ;
4346 game . physics . friction = 0.5 ;
47+ game . physics . world . solver . stiffness = 1e20 ;
48+ game . physics . world . solver . relaxation = 3 ;
4449
4550 // Materials
4651 var groundMaterial = game . physics . createMaterial ( 'ground' ) ;
4752 var characterMaterial = game . physics . createMaterial ( 'character' ) ;
4853 var boxMaterial = game . physics . createMaterial ( 'box' ) ;
4954
50- player = game . add . sprite ( 32 , 320 , 'dude' ) ;
55+ player = game . add . sprite ( 100 , - 400 , 'dude' ) ;
5156 player . physicsEnabled = true ;
5257 player . body . fixedRotation = true ;
5358 player . body . setMaterial ( characterMaterial ) ;
59+ player . body . mass = 1 ;
60+ player . body . damping = 0.5 ;
5461
5562 player . animations . add ( 'left' , [ 0 , 1 , 2 , 3 ] , 10 , true ) ;
5663 player . animations . add ( 'turn' , [ 4 ] , 20 , true ) ;
5764 player . animations . add ( 'right' , [ 5 , 6 , 7 , 8 ] , 10 , true ) ;
5865
59- box1 = game . add . sprite ( 200 , 300 , 'box' ) ;
60- box1 . physicsEnabled = true ;
61- // box1.body.fixedRotation = true;
62- box1 . body . setMaterial ( boxMaterial ) ;
66+ boxes = game . add . group ( ) ;
6367
64- box2 = game . add . sprite ( 400 , 300 , 'box' ) ;
65- box2 . physicsEnabled = true ;
66- // box2.body.fixedRotation = true;
67- box2 . body . setMaterial ( boxMaterial ) ;
68+ for ( var i = 0 ; i < 50 ; i ++ )
69+ {
70+ var box = boxes . create ( game . rnd . integerInRange ( 200 , 700 ) , game . rnd . integerInRange ( - 200 , 400 ) , 'box' ) ;
71+ // box.scale.set(0.5);
72+ box . scale . set ( game . rnd . realInRange ( 0.2 , 0.7 ) ) ;
73+ box . physicsEnabled = true ;
74+ box . body . mass = 10 ;
75+ box . body . setMaterial ( boxMaterial ) ;
76+ box . body . fixedRotation = true ;
77+ }
6878
6979 // Set the material along the ground
70- game . physics . setWorldMaterial ( groundMaterial , false , false , false , true ) ;
80+ game . physics . setWorldMaterial ( groundMaterial ) ;
7181
7282 var groundCharacterCM = game . physics . createContactMaterial ( groundMaterial , characterMaterial , { friction : 0.0 } ) ; // no friction between character and ground
7383 var boxCharacterCM = game . physics . createContactMaterial ( boxMaterial , characterMaterial , { friction : 0.0 } ) ; // No friction between character and boxes
7484 var boxGroundCM = game . physics . createContactMaterial ( boxMaterial , groundMaterial , { friction : 0.6 } ) ; // Between boxes and ground
7585
86+ console . log ( groundCharacterCM ) ;
87+ console . log ( boxGroundCM ) ;
88+
7689 // game.camera.follow(player);
7790
7891 cursors = game . input . keyboard . createCursorKeys ( ) ;
@@ -82,11 +95,9 @@ function create() {
8295
8396function update ( ) {
8497
85- player . body . velocity . x = 0 ;
86-
8798 if ( cursors . left . isDown )
8899 {
89- player . body . moveLeft ( 150 ) ;
100+ player . body . moveLeft ( 200 ) ;
90101
91102 if ( facing != 'left' )
92103 {
@@ -96,7 +107,7 @@ function update() {
96107 }
97108 else if ( cursors . right . isDown )
98109 {
99- player . body . moveRight ( 150 ) ;
110+ player . body . moveRight ( 200 ) ;
100111
101112 if ( facing != 'right' )
102113 {
@@ -106,6 +117,8 @@ function update() {
106117 }
107118 else
108119 {
120+ player . body . velocity . x = 0 ;
121+
109122 if ( facing != 'idle' )
110123 {
111124 player . animations . stop ( ) ;
@@ -150,7 +163,7 @@ function render () {
150163
151164 // if (player.debug)
152165 // {
153- // game.debug.renderPhysicsBody(player.body);
166+ game . debug . renderPhysicsBody ( player . body ) ;
154167 // game.debug.renderBodyInfo(player, 16, 24);
155168 // }
156169
0 commit comments