Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iLikeGrape committed Nov 19, 2024
1 parent a685821 commit 63ecae7
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions spaceinvaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ window.onload = function() { //when game starts
shipImg.onload = function() {
context.drawImage(shipImg, ship.x, ship.y, ship.width, ship.height);
}
}

requestAnimationFrame(update);
document.addEventListener("Keydown", moveShip);
}
document.addEventListener("Keydown", moveShip(e));
function update(){
//preping for next frame
requestAnimationFrame(update);
Expand All @@ -53,20 +53,10 @@ function update(){
}

function moveShip(e) {
if (e.code == "ArrowLeft") { // checks to see if it should move left
if (e.code == "ArrowRight"){

}
else{
ship.y = Math.min(ship.y - 0.5, 0)
}
}

if (e.code == "ArrowRight") { //checks to see if it should move right
if (e.code == "ArrowLeft"){
}
else{
ship.y = Math.max(ship.y + 0.5, 436)
}
}
if (gameOver) {
return;
};
if (e.key == "ArrowLeft") { // checks to see if it should move left
ship.x -= 5;
};
}

0 comments on commit 63ecae7

Please sign in to comment.