@@ -17,7 +17,6 @@ var mainState = {
1717 game . load . audio ( 'collect' , 'assets/sounds/collect.mp3' ) ;
1818 game . load . audio ( 'wrong' , 'assets/sounds/wrong.mp3' ) ;
1919 game . load . audio ( 'music' , 'assets/sounds/clap.mp3' ) ;
20-
2120} ,
2221
2322restartGameButton : function ( ) {
@@ -39,6 +38,7 @@ actionOnClick: function() {
3938} ,
4039
4140create : function ( ) {
41+ game . paused = true ;
4242music = game . add . audio ( 'music' ) ;
4343
4444 music . play ( ) ;
@@ -83,14 +83,33 @@ this.labelScore = game.add.text(20, 20, "0",
8383 this . userwbc . body . gravity . y = 1000 ;
8484
8585 // Call the 'jump' function when the spacekey is hit
86- var spaceKey = game . input . keyboard . addKey (
87- Phaser . Keyboard . SPACEBAR ) ;
88- spaceKey . onDown . add ( this . jump , this ) ;
86+
8987
88+ var spaceKey = game . input . keyboard . addKey ( Phaser . Keyboard . SPACEBAR ) ;
89+ spaceKey . onDown . add ( this . jump , this ) ;
9090 var leftmouse = game . input . mousePointer . leftButton ;
9191 leftmouse . onDown . add ( this . leftmouse , this ) ;
9292
93+ var spacePauseKey = game . input . keyboard . addKey ( Phaser . Keyboard . SPACEBAR ) ;
94+ var alternatePauseKey = game . input . keyboard . addKey ( Phaser . Keyboard . BACKSPACE ) ;
95+ spacePauseKey . onDown . add ( this . unpause , this ) ;
96+ alternatePauseKey . onDown . add ( this . pause , this ) ;
97+ var leftPmouse = game . input . mousePointer . leftButton ;
98+ leftPmouse . onDown . add ( this . unpause , this ) ;
9399} ,
100+
101+ pause : function ( ) {
102+ if ( game . paused == true ) {
103+ game . paused = false ;
104+ }
105+ else {
106+ game . paused = true ;
107+ }
108+ } ,
109+ unpause : function ( event ) {
110+ game . paused = false ;
111+ console . log ( event ) ;
112+ } ,
94113
95114 ///new code starts
96115
@@ -115,22 +134,21 @@ this.labelScore = game.add.text(20, 20, "0",
115134} ,
116135 ////new code ends here
117136 addOnePipe : function ( x , y ) {
118- // Create a pipe at the position x and y
119- var pipe = game . add . sprite ( x , y , 'pipe' ) ;
120- // Add the pipe to our previously created group
121- this . pipes . add ( pipe ) ;
122-
123- // Enable physics on the pipe
124- game . physics . arcade . enable ( pipe ) ;
125-
126- // Add velocity to the pipe to make it move left
127- pipe . body . velocity . x = - 200 ;
128-
129- // Automatically kill the pipe when it's no longer visible
130- pipe . checkWorldBounds = true ;
131- pipe . outOfBoundsKill = true ;
132-
133- } ,
137+ // Create a pipe at the position x and y
138+ var pipe = game . add . sprite ( x , y , 'pipe' ) ;
139+ // Add the pipe to our previously created group
140+ this . pipes . add ( pipe ) ;
141+
142+ // Enable physics on the pipe
143+ game . physics . arcade . enable ( pipe ) ;
144+
145+ // Add velocity to the pipe to make it move left
146+ pipe . body . velocity . x = - 200 ;
147+
148+ // Automatically kill the pipe when it's no longer visible
149+ pipe . checkWorldBounds = true ;
150+ pipe . outOfBoundsKill = true ;
151+ } ,
134152 ///new code starts
135153 //addRowOfPipes2: function(){
136154 // var hole2 = Math.floor(Math.random() * 1) + 1;
@@ -158,11 +176,26 @@ this.labelScore = game.add.text(20, 20, "0",
158176 //increment score by 1:
159177 //this.score += 1;
160178this . labelScore . text = this . score ;
179+ // var spacePauseKey = game.input.keyboard.addKey(
180+ // Phaser.Keyboard.SPACEBAR);
181+ // spacePauseKey.onDown.add(this.pause, self);
182+
183+ // var leftPmouse = game.input.mousePointer.leftButton;
184+ // leftPmouse.onDown.add(pause, self);
185+ // game.input.onDown.add(pause, self);
186+ // function pause(event) {
187+ // //if(game.paused == true) {
188+ // game.paused = false;
189+ // console.log(game.paused);
190+ // console.log(event);
191+ // // }
192+ // }
161193} ,
162194
163195update : function ( ) {
164196 // If the userwbc is out of the screen (too high or too low)
165197 // Call the 'restartGame' function
198+
166199 if ( this . userwbc . y < 0 || this . userwbc . y > screen . height - 100 ) {
167200 this . userwbc . visible = false ;
168201 this . wrongSound . play ( ) ;
0 commit comments