Skip to content

Commit

Permalink
Core game mechanics working, getting ready for a refactor of state/co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
Dave Kerr committed Aug 20, 2013
1 parent 5b3cb08 commit 182890c
Show file tree
Hide file tree
Showing 4 changed files with 501 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
spaceinvaders.sublime-project
spaceinvaders.sublime-workspace
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@ spaceinvaders
=============

Classic Space Invaders game written in JavaScript as a learning exercise.

TODO
----

* Make bomb speeds configurable
* Add configuration options to main page.
* Make the main page instantiate/start the game
* Allow pause.
* Support move and fire at the same time.
* support full size
* refactor settings and state.

TEST
----

* Handle loss by invaders reaching bottom (not ship collision!)
* Make rocket speeds configurable.
* Limit to rocket rate.
52 changes: 52 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<title>Space Invaders</title>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<canvas id="mainCanvas"></canvas>
<p id="gameOver"></p>
<p>Move Ship: Arrow Keys<br />
Fire: Space</p>
<script src="spaceinvaders.js"></script>
<script>
window.addEventListener("keydown", function keydown(e) {
var keycode;
if (window.event) {
keycode = window.event.keyCode;
}
else if (e) {
keycode = e.which;
}
switch(keycode){
case 37: //left
game.moveShip(-5);
break;
case 38: //down
break;
case 39: //right
game.moveShip(5);
break;
case 40: //up
break;
case 32: //space
game.shipFire();
break;
}});

game.onGameLost = function onGameLost(game) {
document.getElementById("gameOver").innerText = "You Lost!";
};

game.onGameWon = function onGameWon(game) {
document.getElementById("gameOver").innerText = "You Won!";
};
</script>
</body>
</html>
Loading

0 comments on commit 182890c

Please sign in to comment.