www.NewsDownload.co.uk Page 6
Overview
Asteroids.html
Common.js
Asteroids.js
Digit.js
Text.js
AstroRock.js
AstroShip.js
AstroShot.js
AstroUFO.js
GNU License

Coding a JavaScript Game

2012-03-13 17:00 By Jason Birch

Second in a series of how to code articles. Demonstrating coding an Asteroids Clone game with various technologies. This example using JavaScript, implementing as an application on a web page.

In this article I have converted my Asteroids Clone code into JavaScript. I am now publishing the source code here under the GNU General Public License License as a series of articles describing how to write code using various technologies.

The code here can be freely distributed, but only on the condition that a credit to Jason Birch is maintained in the source code files and running application.

The source code is broken down into the classes which make the application, in the tabs on the left of this article. The tabs are placed in order from the simplest classes to the more complex classes last. There is a commentary accompanying each source code file explaining how the code operates.

The keys to play are: '<' Rotate left, '>' Rotate right, 'Z' Fire, 'X' Thrust, ' ' Hyperspace, '1' Start new game.

Object orientated code can be written in JavaScript, but it is a little awkward and not as tidy as it could be. But considering JavaScript is a scripting language it handles applications like this one better than I would have expected. Other examples of games I have written in JavaScript include:

Required Environment
To run a JavaScript application, any web browser can be used.
To develop JavaScript applications, any text editor can be used.

Writing Code
Any text editor can be used to create and edit JavaScript source code.

Compiling Code
JavaScript code does not need to be compiled. It can be executed directly from the source code.

Distributing Application
The JavaScript source code files are simply copied onto a file system or a web server.

Running Application
JavaScript can be run directly from the operating system by opening an HTML file in a web browser. Or it can be run from a web server in the same way.

Loading...