Skip to content

Commit 6c63c3c

Browse files
committed
Remove extra spaces
1 parent 19d242b commit 6c63c3c

File tree

2 files changed

+54
-56
lines changed

2 files changed

+54
-56
lines changed

engine.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
var vendors = ['ms', 'moz', 'webkit', 'o'];
44
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
55
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
6-
window.cancelAnimationFrame =
6+
window.cancelAnimationFrame =
77
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
88
}
9-
9+
1010
if (!window.requestAnimationFrame)
1111
window.requestAnimationFrame = function(callback, element) {
1212
var currTime = new Date().getTime();
1313
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); },
1515
timeToCall);
1616
lastTime = currTime + timeToCall;
1717
return id;
1818
};
19-
19+
2020
if (!window.cancelAnimationFrame)
2121
window.cancelAnimationFrame = function(id) {
2222
clearTimeout(id);
2323
};
2424
}());
25-
2625

27-
var Game = new function() {
26+
27+
var Game = new function() {
2828
var boards = [];
2929

3030
// Game Initialization
@@ -43,15 +43,15 @@ var Game = new function() {
4343

4444
this.setupInput();
4545

46-
this.loop();
46+
this.loop();
4747

4848
if(this.mobile) {
4949
this.setBoard(4,new TouchControls());
5050
}
5151

5252
SpriteSheet.load(sprite_data,callback);
5353
};
54-
54+
5555

5656
// Handle Input
5757
var KEY_CODES = { 37:'left', 39:'right', 32 :'fire' };
@@ -67,7 +67,7 @@ var Game = new function() {
6767

6868
window.addEventListener('keyup',function(e) {
6969
if(KEY_CODES[e.keyCode]) {
70-
Game.keys[KEY_CODES[e.keyCode]] = false;
70+
Game.keys[KEY_CODES[e.keyCode]] = false;
7171
e.preventDefault();
7272
}
7373
},false);
@@ -77,21 +77,21 @@ var Game = new function() {
7777
var lastTime = new Date().getTime();
7878
var maxTime = 1/30;
7979
// Game Loop
80-
this.loop = function() {
80+
this.loop = function() {
8181
var curTime = new Date().getTime();
8282
requestAnimationFrame(Game.loop);
8383
var dt = (curTime - lastTime)/1000;
8484
if(dt > maxTime) { dt = maxTime; }
8585

8686
for(var i=0,len = boards.length;i<len;i++) {
87-
if(boards[i]) {
87+
if(boards[i]) {
8888
boards[i].step(dt);
8989
boards[i].draw(Game.ctx);
9090
}
9191
}
9292
lastTime = curTime;
9393
};
94-
94+
9595
// Change an active game board
9696
this.setBoard = function(num,board) { boards[num] = board; };
9797

@@ -100,7 +100,7 @@ var Game = new function() {
100100
var container = document.getElementById("container"),
101101
hasTouch = !!('ontouchstart' in window),
102102
w = window.innerWidth, h = window.innerHeight;
103-
103+
104104
if(hasTouch) { this.mobile = true; }
105105

106106
if(screen.width >= 1280 || !hasTouch) { return false; }
@@ -139,9 +139,9 @@ var Game = new function() {
139139

140140

141141
var SpriteSheet = new function() {
142-
this.map = { };
142+
this.map = { };
143143

144-
this.load = function(spriteData,callback) {
144+
this.load = function(spriteData,callback) {
145145
this.map = spriteData;
146146
this.image = new Image();
147147
this.image.onload = callback;
@@ -152,9 +152,9 @@ var SpriteSheet = new function() {
152152
var s = this.map[sprite];
153153
if(!frame) frame = 0;
154154
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,
158158
Math.floor(x), Math.floor(y),
159159
s.w, s.h);
160160
};
@@ -173,7 +173,7 @@ var TitleScreen = function TitleScreen(title,subtitle,callback) {
173173
ctx.fillStyle = "#FFFFFF";
174174

175175
ctx.font = "bold 40px bangers";
176-
var measure = ctx.measureText(title);
176+
var measure = ctx.measureText(title);
177177
ctx.fillText(title,Game.width/2 - measure.width/2,Game.height/2);
178178

179179
ctx.font = "bold 20px bangers";
@@ -191,18 +191,18 @@ var GameBoard = function() {
191191
this.cnt = {};
192192

193193
// 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);
197197
this.cnt[obj.type] = (this.cnt[obj.type] || 0) + 1;
198-
return obj;
198+
return obj;
199199
};
200200

201201
// Mark an object for removal
202-
this.remove = function(obj) {
202+
this.remove = function(obj) {
203203
var idx = this.removed.indexOf(obj);
204204
if(idx == -1) {
205-
this.removed.push(obj);
205+
this.removed.push(obj);
206206
return true;
207207
} else {
208208
return false;
@@ -223,7 +223,7 @@ var GameBoard = function() {
223223
}
224224
};
225225

226-
// Call the same method on all current objects
226+
// Call the same method on all current objects
227227
this.iterate = function(funcName) {
228228
var args = Array.prototype.slice.call(arguments,1);
229229
for(var i=0,len=this.objects.length;i<len;i++) {
@@ -242,7 +242,7 @@ var GameBoard = function() {
242242

243243
// Call step on all objects and them delete
244244
// any object that have been marked for removal
245-
this.step = function(dt) {
245+
this.step = function(dt) {
246246
this.resetRemoved();
247247
this.iterate('step',dt);
248248
this.finalizeRemoved();
@@ -253,7 +253,7 @@ var GameBoard = function() {
253253
this.iterate('draw',ctx);
254254
};
255255

256-
// Check for a collision between the
256+
// Check for a collision between the
257257
// bounding rects of two objects
258258
this.overlap = function(o1,o2) {
259259
return !((o1.y+o1.h-1<o2.y) || (o1.y>o2.y+o2.h-1) ||
@@ -318,9 +318,9 @@ Level.prototype.step = function(dt) {
318318

319319
// Start, End, Gap, Type, Override
320320
// [ 0, 4000, 500, 'step', { x: 100 } ]
321-
while((curShip = this.levelData[idx]) &&
321+
while((curShip = this.levelData[idx]) &&
322322
(curShip[0] < this.t + 2000)) {
323-
// Check if we've passed the end time
323+
// Check if we've passed the end time
324324
if(this.t > curShip[1]) {
325325
remove.push(curShip);
326326
} else if(curShip[0] < this.t) {
@@ -343,7 +343,7 @@ Level.prototype.step = function(dt) {
343343
if(remIdx != -1) this.levelData.splice(remIdx,1);
344344
}
345345

346-
// If there are no more enemies on the board or in
346+
// If there are no more enemies on the board or in
347347
// levelData, this level is done
348348
if(this.levelData.length === 0 && this.board.cnt[OBJECT_ENEMY] === 0) {
349349
if(this.callback) this.callback();
@@ -371,8 +371,8 @@ var TouchControls = function() {
371371

372372
var txtSize = ctx.measureText(txt);
373373

374-
ctx.fillText(txt,
375-
x+blockWidth/2-txtSize.width/2,
374+
ctx.fillText(txt,
375+
x+blockWidth/2-txtSize.width/2,
376376
y+3*blockWidth/4+5);
377377
};
378378

@@ -400,10 +400,10 @@ var TouchControls = function() {
400400
x = touch.pageX / Game.canvasMultiplier - Game.canvas.offsetLeft;
401401
if(x < unitWidth) {
402402
Game.keys['left'] = true;
403-
}
403+
}
404404
if(x > unitWidth && x < 2*unitWidth) {
405405
Game.keys['right'] = true;
406-
}
406+
}
407407
}
408408

409409
if(e.type == 'touchstart' || e.type == 'touchend') {

game.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ var sprites = {
1010
};
1111

1212
var enemies = {
13-
straight: { x: 0, y: -50, sprite: 'enemy_ship', health: 10,
13+
straight: { x: 0, y: -50, sprite: 'enemy_ship', health: 10,
1414
E: 100 },
15-
ltr: { x: 0, y: -100, sprite: 'enemy_purple', health: 10,
15+
ltr: { x: 0, y: -100, sprite: 'enemy_purple', health: 10,
1616
B: 75, C: 1, E: 100, missiles: 2 },
17-
circle: { x: 250, y: -50, sprite: 'enemy_circle', health: 10,
17+
circle: { x: 250, y: -50, sprite: 'enemy_circle', health: 10,
1818
A: 0, B: -100, C: 1, E: 20, F: 100, G: 1, H: Math.PI/2 },
19-
wiggle: { x: 100, y: -50, sprite: 'enemy_bee', health: 20,
19+
wiggle: { x: 100, y: -50, sprite: 'enemy_bee', health: 20,
2020
B: 50, C: 4, E: 100, firePercentage: 0.001, missiles: 2 },
2121
step: { x: 0, y: -50, sprite: 'enemy_circle', health: 10,
2222
B: 150, C: 1.2, E: 75 }
@@ -38,8 +38,8 @@ var startGame = function() {
3838
Game.setBoard(0,new Starfield(20,0.4,100,true));
3939
Game.setBoard(1,new Starfield(50,0.6,100));
4040
Game.setBoard(2,new Starfield(100,1.0,50));
41-
}
42-
Game.setBoard(3,new TitleScreen("Alien Invasion",
41+
}
42+
Game.setBoard(3,new TitleScreen("Alien Invasion",
4343
"Press fire to start playing",
4444
playGame));
4545
};
@@ -67,13 +67,13 @@ var playGame = function() {
6767
};
6868

6969
var winGame = function() {
70-
Game.setBoard(3,new TitleScreen("You win!",
70+
Game.setBoard(3,new TitleScreen("You win!",
7171
"Press fire to play again",
7272
playGame));
7373
};
7474

7575
var loseGame = function() {
76-
Game.setBoard(3,new TitleScreen("You lose!",
76+
Game.setBoard(3,new TitleScreen("You lose!",
7777
"Press fire to play again",
7878
playGame));
7979
};
@@ -82,13 +82,13 @@ var Starfield = function(speed,opacity,numStars,clear) {
8282

8383
// Set up the offscreen canvas
8484
var stars = document.createElement("canvas");
85-
stars.width = Game.width;
85+
stars.width = Game.width;
8686
stars.height = Game.height;
8787
var starCtx = stars.getContext("2d");
8888

8989
var offset = 0;
9090

91-
// If the clear option is set,
91+
// If the clear option is set,
9292
// make the background black instead of transparent
9393
if(clear) {
9494
starCtx.fillStyle = "#000";
@@ -139,7 +139,7 @@ var Starfield = function(speed,opacity,numStars,clear) {
139139
};
140140
};
141141

142-
var PlayerShip = function() {
142+
var PlayerShip = function() {
143143
this.setup('ship', { vx: 0, reloadTime: 0.25, maxVel: 200 });
144144

145145
this.reload = this.reloadTime;
@@ -154,7 +154,7 @@ var PlayerShip = function() {
154154
this.x += this.vx * dt;
155155

156156
if(this.x < 0) { this.x = 0; }
157-
else if(this.x > Game.width - this.w) {
157+
else if(this.x > Game.width - this.w) {
158158
this.x = Game.width - this.w;
159159
}
160160

@@ -182,7 +182,7 @@ PlayerShip.prototype.hit = function(damage) {
182182
var PlayerMissile = function(x,y) {
183183
this.setup('missile',{ vy: -700, damage: 10 });
184184
this.x = x - this.w/2;
185-
this.y = y - this.h;
185+
this.y = y - this.h;
186186
};
187187

188188
PlayerMissile.prototype = new Sprite();
@@ -194,8 +194,8 @@ PlayerMissile.prototype.step = function(dt) {
194194
if(collision) {
195195
collision.hit(this.damage);
196196
this.board.remove(this);
197-
} else if(this.y < -this.h) {
198-
this.board.remove(this);
197+
} else if(this.y < -this.h) {
198+
this.board.remove(this);
199199
}
200200
};
201201

@@ -209,9 +209,9 @@ var Enemy = function(blueprint,override) {
209209
Enemy.prototype = new Sprite();
210210
Enemy.prototype.type = OBJECT_ENEMY;
211211

212-
Enemy.prototype.baseParameters = { A: 0, B: 0, C: 0, D: 0,
212+
Enemy.prototype.baseParameters = { A: 0, B: 0, C: 0, D: 0,
213213
E: 0, F: 0, G: 0, H: 0,
214-
t: 0, reloadTime: 0.75,
214+
t: 0, reloadTime: 0.75,
215215
reload: 0 };
216216

217217
Enemy.prototype.step = function(dt) {
@@ -253,7 +253,7 @@ Enemy.prototype.hit = function(damage) {
253253
if(this.health <=0) {
254254
if(this.board.remove(this)) {
255255
Game.points += this.points || 100;
256-
this.board.add(new Explosion(this.x + this.w/2,
256+
this.board.add(new Explosion(this.x + this.w/2,
257257
this.y + this.h/2));
258258
}
259259
}
@@ -275,7 +275,7 @@ EnemyMissile.prototype.step = function(dt) {
275275
collision.hit(this.damage);
276276
this.board.remove(this);
277277
} else if(this.y > Game.height) {
278-
this.board.remove(this);
278+
this.board.remove(this);
279279
}
280280
};
281281

@@ -299,5 +299,3 @@ Explosion.prototype.step = function(dt) {
299299
window.addEventListener("load", function() {
300300
Game.initialize("game",sprites,startGame);
301301
});
302-
303-

0 commit comments

Comments
 (0)