@@ -2,78 +2,11 @@ Space Invaders
22==============
33
44The classic Space Invaders game written in JavaScript as a learning exercise.
5- No jQuery or any other third party libraries, just raw js/html.
6-
7- See it Live: http://www.dwmkerr.com/experiments/spaceinvaders
8-
9- ![ Space Invaders Screenshot] ( http://www.dwmkerr.com/experiments/spaceinvaders/screenshot.jpg " Space Invaders Screenshot ")
10-
11- Intro
12- -----
13-
14- What's there to say? It's Space Invaders in JavaScript! Create the game, give it a
15- div to draw to, tell it when the keyboard is mashed and that's all you need to
16- add Space Invaders to a wesite.
17-
18- The Space Invaders Javascript code is all in one file - why is this? Well this is actually
19- part of a series of experiments that are used as tutorials, and at this stage we're keeping
20- things simple with single files.
21-
22- Adding Space Invaders to a Web Page
23- -----------------------------------
24-
25- First, drop the spaceinvaders.js file into the website.
265
27- Now add a canvas to the page.
28-
29- ```` HTML
30- <canvas id =" gameCanvas" ></canvas >
31- ````
32-
33- Finally, add the Space Invaders game code. You create the game,
34- intialise it with the canvas, start it and make sure you tell
35- it when a key is pressed or released. That's it!
36-
37- ```` HTML
38- <script >
39- // Setup the canvas.
40- var canvas = document .getElementById (" gameCanvas" );
41- canvas .width = 800 ;
42- canvas .height = 600 ;
43-
44- // Create the game.
45- var game = new Game ();
46-
47- // Initialise it with the game canvas.
48- game .initialise (canvas);
49-
50- // Start the game.
51- game .start ();
52-
53- // Listen for keyboard events.
54- var pressedKeys = [];
55- window .addEventListener (" keydown" , function keydown (e ) {
56- var keycode = window .event .keycode || e .which ;
57- if (! pressedKeys[keycode])
58- pressedKeys[keycode] = true ;
59- // Supress further processing of left/right/space (37/29/32)
60- if (keycode == 37 || keycode == 39 || keycode == 32 ) {
61- e .preventDefault ();
62- }
63- game .keyDown (keycode);
64- });
65- window .addEventListener (" keyup" , function keydown (e ) {
66- var keycode = window .event .keycode || e .which ;
67- if (pressedKeys[keycode])
68- delete pressedKeys[keycode];
69- game .keyUp (keycode);
70- });
71- </script >
72- ````
6+ No jQuery or any other third party libraries, just raw js/html.
737
74- References
75- ----------
8+ Demo: https://prouser123.github.io/spaceinvaders/
769
77- Other bits and peices that are uesful can be dropped here.
10+ Original Project: https://github.com/dwmkerr/spaceinvaders
7811
79- * The sounds came from http://www.classicgaming.cc/classics/spaceinvaders/sounds.php
12+ Sounds: http://www.classicgaming.cc/classics/spaceinvaders/sounds.php
0 commit comments