Skip to content

Commit a91b097

Browse files
committed
Bug fixes
1 parent b898f45 commit a91b097

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

js/keycodes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ function Keycodes() {
1616
left: 37,
1717
right: 39
1818
}
19+
20+
this.touch = {
21+
up: 38,
22+
left: 37,
23+
right: 39
24+
}
1925
}

js/spaceinvaders.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ Game.prototype.touchmove = function(e) {
216216
var currentX = e.changedTouches[0].pageX;
217217
if (previousX > 0){
218218
if (currentX > previousX){
219-
delete this.pressedKeys[keycodes.arrows.left];
220-
this.pressedKeys[keycodes.arrows.right] = true;
219+
delete this.pressedKeys[keycodes.touch.left];
220+
this.pressedKeys[keycodes.touch.right] = true;
221221
}
222222
else{
223-
delete this.pressedKeys[keycodes.arrows.right];
224-
this.pressedKeys[keycodes.arrows.left] = true;
223+
delete this.pressedKeys[keycodes.touch.right];
224+
this.pressedKeys[keycodes.touch.left] = true;
225225
}
226226
}
227227
previousX = currentX;
@@ -375,17 +375,17 @@ PlayState.prototype.update = function(game, dt) {
375375
// event for smooth movement, otherwise the ship would move
376376
// more like a text editor caret.
377377

378-
// Left Movement Keys : A Key / Left Arrow Key
379-
if(game.pressedKeys[keycodes.a] || game.pressedKeys[keycodes.arrows.right]) {
378+
// Left Movement Keys : A Key / Left Arrow Key / Touch Left
379+
if(game.pressedKeys[keycodes.a] || game.pressedKeys[keycodes.arrows.left] || game.pressedKeys[keycodes.touch.left]) {
380380
this.ship.x -= this.shipSpeed * dt;
381381
}
382382

383-
// Right Movement Keys: D Key / Right Arrow Key
384-
if(game.pressedKeys[keycodes.d] || game.pressedKeys[keycodes.arrows.right]){
383+
// Right Movement Keys: D Key / Right Arrow Key / Touch Right
384+
if(game.pressedKeys[keycodes.d] || game.pressedKeys[keycodes.arrows.right] || game.pressedKeys[keycodes.touch.right]){
385385
this.ship.x += this.shipSpeed * dt;
386386
}
387-
// Fire Keys : Space Key / W Key / Up Key
388-
if(game.pressedKeys[keycodes.space] || game.pressedKeys[keycodes.w] || game.pressedKeys[keycodes.arrows.up]) {
387+
// Fire Keys : Space Key / W Key / Up Key / Touch Up
388+
if(game.pressedKeys[keycodes.space] || game.pressedKeys[keycodes.w] || game.pressedKeys[keycodes.arrows.up] || game.pressedKeys[keycodes.touch.up]) {
389389
this.fireRocket();
390390
}
391391

0 commit comments

Comments
 (0)