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.
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:
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.
- 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.