Creating a Asteroids Flash Game Part 4: Using Keyboard Controls to Move Around the Ship on screen
In the previous section, we created a base class for all our game objects, and created and rendered our space ship.
In this section, we’ll add keyboard control to make our ship be able to move around on screen, and actually see our game start coming to life!
Getting Keyboard Input, and Storing Multiple Key Presses
When the flash window is in focus, whatever is “clicked on” will generally have focus. Using blitting, luckily we only have to worry about the stage having focus, and handling keyboard input from it.
To be able to get when a key has been pressed, we have to modify ‘Main.as’.
(more…)
Creating a Asteroids Flash Game Part 3: Creating and rendering the ship
In the last section we setup our main game class, created our main game loop, and created the background we will be rendering all of our game objects on to.
In this section, we’ll make a base class for all our game objects, create our ship, and use the arrow keys to move it around on screen.
Creating the GameSprite Base Class
The first thing we need to do is create our GameSprite class.
Right click on the folder on your ‘src’ folder on the right, and add a new folder called ‘Entities’. Next right click on that folder, and create a new class called ‘GameSprite’.
This object will include the basic things that all of our game objects will need, including our ship, bullets and asteroids.
Creating a Asteroids Flash Game Part 2: Creating the Game Class and rendering the background
In the previous section, we planned out what we are going to accomplish with the game, and setup the flashdevelop environment for creating our asteroids game,.
The game can’t be asteroids without being in space. For this, we’ll create and add the background bitmapdata to our stage, and create a game class to handle everything associated with creating and handling the game.
Creating the Game class
First, lets create the game class. Right click on the ‘src’ folder and go to “Add-> New Class”, and name it ‘Game’ and click ‘ok’.
Now that you have your Game class, we’ll start filling it in. To be able to draw on the screen, we’ll need to have a bitmap to be able to add to the stage, and a bitmapdata to add to the bitmap.
For the game constructor, we’ll want to pass in the size and width of the screen, so that we can draw on it. So we change Game.as to:
Creating a Asteroids Flash Game Part 1: Setting up FlashDevelop and Planning
This tutorial will create a vector based asteroids game using the completely free, and best solution for creating flash games, FlashDevelop.
Why use FlashDevelop?
FlashDevelop is open source, and much better for programming than the flash IDE (and with a $800 savings!). It is truly a remarkable program, and I suggest you donate and let the guys know you appreciate their hard work and effort.
Some advantages:
- built for programming –you wont get bogged down by the flash IDE which is primarily an animation tool.
- great code hinting: This will help you learn flash commands quicker, and see function parameters without needing to refer to the documentation
- does not crash (compare to flash IDE of several times a day, or as much as every time it is run, when using JSFL or components)
- free + open source (you can literally download the source, open it up, and see how it was made, or add custom plugins to it — if you want)
- faster (compiles faster, faster to switch between files, built for speed)
- Easier to transition to programming in another language/environment (most other programming languages aren’t centered around “timelines” and “stages”, and “adding children to display lists”. I like to be able to have control over the order my objects are rendered in, and be able to know when each piece is updated.
Updated site design
This last weekend I have been working on the site design for the new site. I have changed it to use wordpress, for easier blog posting, since blogger had removed the ability to use ftp to post to my server directly.
I’ll create a write up on creating a custom theme for wordpress in the new few days.
Welcome to the new site!
I changed the site layout, and added wordpress so that I can start putting out more tutorials.
Expect to see Tutorials for making a simple asteroids game soon!



