3
3
var vendors = [ 'ms' , 'moz' , 'webkit' , 'o' ] ;
4
4
for ( var x = 0 ; x < vendors . length && ! window . requestAnimationFrame ; ++ x ) {
5
5
window . requestAnimationFrame = window [ vendors [ x ] + 'RequestAnimationFrame' ] ;
6
- window . cancelAnimationFrame =
6
+ window . cancelAnimationFrame =
7
7
window [ vendors [ x ] + 'CancelAnimationFrame' ] || window [ vendors [ x ] + 'CancelRequestAnimationFrame' ] ;
8
8
}
9
-
9
+
10
10
if ( ! window . requestAnimationFrame )
11
11
window . requestAnimationFrame = function ( callback , element ) {
12
12
var currTime = new Date ( ) . getTime ( ) ;
13
13
var timeToCall = Math . max ( 0 , 16 - ( currTime - lastTime ) ) ;
14
- var id = window . setTimeout ( function ( ) { callback ( currTime + timeToCall ) ; } ,
14
+ var id = window . setTimeout ( function ( ) { callback ( currTime + timeToCall ) ; } ,
15
15
timeToCall ) ;
16
16
lastTime = currTime + timeToCall ;
17
17
return id ;
18
18
} ;
19
-
19
+
20
20
if ( ! window . cancelAnimationFrame )
21
21
window . cancelAnimationFrame = function ( id ) {
22
22
clearTimeout ( id ) ;
23
23
} ;
24
24
} ( ) ) ;
25
-
26
25
27
- var Game = new function ( ) {
26
+
27
+ var Game = new function ( ) {
28
28
var boards = [ ] ;
29
29
30
30
// Game Initialization
@@ -43,15 +43,15 @@ var Game = new function() {
43
43
44
44
this . setupInput ( ) ;
45
45
46
- this . loop ( ) ;
46
+ this . loop ( ) ;
47
47
48
48
if ( this . mobile ) {
49
49
this . setBoard ( 4 , new TouchControls ( ) ) ;
50
50
}
51
51
52
52
SpriteSheet . load ( sprite_data , callback ) ;
53
53
} ;
54
-
54
+
55
55
56
56
// Handle Input
57
57
var KEY_CODES = { 37 :'left' , 39 :'right' , 32 :'fire' } ;
@@ -67,7 +67,7 @@ var Game = new function() {
67
67
68
68
window . addEventListener ( 'keyup' , function ( e ) {
69
69
if ( KEY_CODES [ e . keyCode ] ) {
70
- Game . keys [ KEY_CODES [ e . keyCode ] ] = false ;
70
+ Game . keys [ KEY_CODES [ e . keyCode ] ] = false ;
71
71
e . preventDefault ( ) ;
72
72
}
73
73
} , false ) ;
@@ -77,21 +77,21 @@ var Game = new function() {
77
77
var lastTime = new Date ( ) . getTime ( ) ;
78
78
var maxTime = 1 / 30 ;
79
79
// Game Loop
80
- this . loop = function ( ) {
80
+ this . loop = function ( ) {
81
81
var curTime = new Date ( ) . getTime ( ) ;
82
82
requestAnimationFrame ( Game . loop ) ;
83
83
var dt = ( curTime - lastTime ) / 1000 ;
84
84
if ( dt > maxTime ) { dt = maxTime ; }
85
85
86
86
for ( var i = 0 , len = boards . length ; i < len ; i ++ ) {
87
- if ( boards [ i ] ) {
87
+ if ( boards [ i ] ) {
88
88
boards [ i ] . step ( dt ) ;
89
89
boards [ i ] . draw ( Game . ctx ) ;
90
90
}
91
91
}
92
92
lastTime = curTime ;
93
93
} ;
94
-
94
+
95
95
// Change an active game board
96
96
this . setBoard = function ( num , board ) { boards [ num ] = board ; } ;
97
97
@@ -100,7 +100,7 @@ var Game = new function() {
100
100
var container = document . getElementById ( "container" ) ,
101
101
hasTouch = ! ! ( 'ontouchstart' in window ) ,
102
102
w = window . innerWidth , h = window . innerHeight ;
103
-
103
+
104
104
if ( hasTouch ) { this . mobile = true ; }
105
105
106
106
if ( screen . width >= 1280 || ! hasTouch ) { return false ; }
@@ -139,9 +139,9 @@ var Game = new function() {
139
139
140
140
141
141
var SpriteSheet = new function ( ) {
142
- this . map = { } ;
142
+ this . map = { } ;
143
143
144
- this . load = function ( spriteData , callback ) {
144
+ this . load = function ( spriteData , callback ) {
145
145
this . map = spriteData ;
146
146
this . image = new Image ( ) ;
147
147
this . image . onload = callback ;
@@ -152,9 +152,9 @@ var SpriteSheet = new function() {
152
152
var s = this . map [ sprite ] ;
153
153
if ( ! frame ) frame = 0 ;
154
154
ctx . drawImage ( this . image ,
155
- s . sx + frame * s . w ,
156
- s . sy ,
157
- s . w , s . h ,
155
+ s . sx + frame * s . w ,
156
+ s . sy ,
157
+ s . w , s . h ,
158
158
Math . floor ( x ) , Math . floor ( y ) ,
159
159
s . w , s . h ) ;
160
160
} ;
@@ -173,7 +173,7 @@ var TitleScreen = function TitleScreen(title,subtitle,callback) {
173
173
ctx . fillStyle = "#FFFFFF" ;
174
174
175
175
ctx . font = "bold 40px bangers" ;
176
- var measure = ctx . measureText ( title ) ;
176
+ var measure = ctx . measureText ( title ) ;
177
177
ctx . fillText ( title , Game . width / 2 - measure . width / 2 , Game . height / 2 ) ;
178
178
179
179
ctx . font = "bold 20px bangers" ;
@@ -191,18 +191,18 @@ var GameBoard = function() {
191
191
this . cnt = { } ;
192
192
193
193
// Add a new object to the object list
194
- this . add = function ( obj ) {
195
- obj . board = this ;
196
- this . objects . push ( obj ) ;
194
+ this . add = function ( obj ) {
195
+ obj . board = this ;
196
+ this . objects . push ( obj ) ;
197
197
this . cnt [ obj . type ] = ( this . cnt [ obj . type ] || 0 ) + 1 ;
198
- return obj ;
198
+ return obj ;
199
199
} ;
200
200
201
201
// Mark an object for removal
202
- this . remove = function ( obj ) {
202
+ this . remove = function ( obj ) {
203
203
var idx = this . removed . indexOf ( obj ) ;
204
204
if ( idx == - 1 ) {
205
- this . removed . push ( obj ) ;
205
+ this . removed . push ( obj ) ;
206
206
return true ;
207
207
} else {
208
208
return false ;
@@ -223,7 +223,7 @@ var GameBoard = function() {
223
223
}
224
224
} ;
225
225
226
- // Call the same method on all current objects
226
+ // Call the same method on all current objects
227
227
this . iterate = function ( funcName ) {
228
228
var args = Array . prototype . slice . call ( arguments , 1 ) ;
229
229
for ( var i = 0 , len = this . objects . length ; i < len ; i ++ ) {
@@ -242,7 +242,7 @@ var GameBoard = function() {
242
242
243
243
// Call step on all objects and them delete
244
244
// any object that have been marked for removal
245
- this . step = function ( dt ) {
245
+ this . step = function ( dt ) {
246
246
this . resetRemoved ( ) ;
247
247
this . iterate ( 'step' , dt ) ;
248
248
this . finalizeRemoved ( ) ;
@@ -253,7 +253,7 @@ var GameBoard = function() {
253
253
this . iterate ( 'draw' , ctx ) ;
254
254
} ;
255
255
256
- // Check for a collision between the
256
+ // Check for a collision between the
257
257
// bounding rects of two objects
258
258
this . overlap = function ( o1 , o2 ) {
259
259
return ! ( ( o1 . y + o1 . h - 1 < o2 . y ) || ( o1 . y > o2 . y + o2 . h - 1 ) ||
@@ -318,9 +318,9 @@ Level.prototype.step = function(dt) {
318
318
319
319
// Start, End, Gap, Type, Override
320
320
// [ 0, 4000, 500, 'step', { x: 100 } ]
321
- while ( ( curShip = this . levelData [ idx ] ) &&
321
+ while ( ( curShip = this . levelData [ idx ] ) &&
322
322
( curShip [ 0 ] < this . t + 2000 ) ) {
323
- // Check if we've passed the end time
323
+ // Check if we've passed the end time
324
324
if ( this . t > curShip [ 1 ] ) {
325
325
remove . push ( curShip ) ;
326
326
} else if ( curShip [ 0 ] < this . t ) {
@@ -343,7 +343,7 @@ Level.prototype.step = function(dt) {
343
343
if ( remIdx != - 1 ) this . levelData . splice ( remIdx , 1 ) ;
344
344
}
345
345
346
- // If there are no more enemies on the board or in
346
+ // If there are no more enemies on the board or in
347
347
// levelData, this level is done
348
348
if ( this . levelData . length === 0 && this . board . cnt [ OBJECT_ENEMY ] === 0 ) {
349
349
if ( this . callback ) this . callback ( ) ;
@@ -371,8 +371,8 @@ var TouchControls = function() {
371
371
372
372
var txtSize = ctx . measureText ( txt ) ;
373
373
374
- ctx . fillText ( txt ,
375
- x + blockWidth / 2 - txtSize . width / 2 ,
374
+ ctx . fillText ( txt ,
375
+ x + blockWidth / 2 - txtSize . width / 2 ,
376
376
y + 3 * blockWidth / 4 + 5 ) ;
377
377
} ;
378
378
@@ -400,10 +400,10 @@ var TouchControls = function() {
400
400
x = touch . pageX / Game . canvasMultiplier - Game . canvas . offsetLeft ;
401
401
if ( x < unitWidth ) {
402
402
Game . keys [ 'left' ] = true ;
403
- }
403
+ }
404
404
if ( x > unitWidth && x < 2 * unitWidth ) {
405
405
Game . keys [ 'right' ] = true ;
406
- }
406
+ }
407
407
}
408
408
409
409
if ( e . type == 'touchstart' || e . type == 'touchend' ) {
0 commit comments