The Spawn Engine

an educational open source Flash game engine

Release of The Spawn Engine version 0.2

Version 0.2 (for CS5) includes the following changes:

* Completely removed all display objects from the stage, all timeline keyframes, and all timeline code.

* “game states” are now handled by the variable “applicationMode”, which is set to one of two constants, AM_IDLE or AM_GAME

* ButtonFactory is now UIFactory

* all “user interface” elements are now created programmatically, using static methods exposed by UIFactory

* the various application modes manipulate the user interface elements by changing their visibility state, as well as changing text strings

* experienced some strangeness with changing the text of TextFields; they seemed to lose their previous formatting. This was worked around by reapplying the previous formatting (see SpawnEngine.updateText()).

* Implemented some tests of procedural buttons via ButtonFactory (static method)

  1. Download the Spawn Engine v 0.2 and get started.
  2. If you have any trouble please comment.

2012/04/24 Posted by | Engine Releases | , , | Leave a comment

How to add more class files

With this tutorial I’m going to show how to add more class files to the Spawn Engine. I’m using version 0.1.2 and CS5. We will add this to later versions of TSE but for now it’ll just be a tutorial showing you how to add it yourself and explaining why this is good practice.

Action Script 3 is an object oriented language (OOP). I’m not going into detail on what OOP is since there are plenty of articles out there doing a better job than I’d do. Check out these two!

First the steps, then we’ll discuss what we’ve won.

1) Right click in your library on the enemy movie clip and choose Properties. There is already a Class linked to this movie clip: Enemy. But that class don’t have any file, so we are going to make one now.

2) Click on the pen button “Edit class definition” and CS5 opens a new tab with an as-file for the class Enemy. The class is empty except for the basic structure (package, import, class and constructor). So we are going to move a few things from the engine to this class.

3) Save the file as Enemy.as in the same folder as your other files for this project.

4) Inside the Enemy class add the line

private var speed:int;

private const MIN_SPEED:int = 7;
private const MAX_DIFF_SPEED:int = 6;

This will be the move speed of the enemy movie clip which earlier was found in the engine. We need to remove it from the engine and only have this data inside the Enemy class.

5) Inside the public function Enemy (the constructor) we add the line

speed = MIN_SPEED + Math.random() * MAX_DIFF_SPEED;

We want each new enemy that is spawned to have its own unique speed. In version 0.1.2 all enemies have the same speed 9 set by a constant. What will the speed of these new enemies be?

6) Under the constructor we add a new function getSpeed that should look like

public function getSpeed():int
{
return speed;
}

Why did we do this?

7) There are a few changes that we need to do in SpawnEngine.as now. Find this lines of code and comment it so it looks like this

//private const ENEMY_SPEED:int = 9;

We no longer need this constant since that data is now stored inside each Enemy object.

8) Find this line

enemies[i].y += ENEMY_SPEED;

and rewrite it to

enemies[i].y += enemies[i].getSpeed();

We want to use the new function that returns the variable speed which now is a unique value for each Enemy object.

8) Test your changes! You should be able to see some enemies moving faster than others. If you want to change the minimum and maximum speed of the enemies you’ll need to go the the Enemy class file and change the constants we added in step 4.

What your Enemy.as should look like now

package {
import flash.display.MovieClip;
public class Enemy extends MovieClip
{
private var speed:int;
private const MIN_SPEED:int = 7;
private const MAX_DIFF_SPEED:int = 6;
public function Enemy()
{
// constructor code
speed = MIN_SPEED + Math.random()*MAX_DIFF_SPEED;
}
public function getSpeed():int
{
return speed;
}
}
}

Why did we do this?

This was just one small step in the right direction. We moved one piece of data, speed, from the engine into a separate class file. The engine don’t need to know everything and do everything. With more class files the engine will be shorter and more manageable. We put the functions and the variables where they belong, inside the class of the object. This also allows us to do things that were difficult to do before, like adding a unique speed to each enemy. Or maybe we want to add health to each enemy or some other value inside each enemy. This is much easier to do when the enemy has its own class. To improve the enemy class we could move more functionality to it from the engine. Each enemy can move itself instead of the engine doing the work for example.

Could we have done this differently?

Now we wrote the Enemy class to fit into the engine. I wanted to show this while making very small changes to the engine. We wrote a function getSpeed and we could of course have done that differently. We could have written a function inside the Enemy class where the enemy moves itself instead of a function that sends the speed to the engine so the engine can move the enemy. Had we written this class file at the same time we wrote the engine things would be different from now when we write the class file after the engine. Future versions of the engine will show this.

What’s next?

Now that we have done this small change on enemies you can do this for the pickups and more.

2012/03/07 Posted by | Tutorials | , , , | Leave a comment

Release of The Spawn Engine version 0.1.2

Version 0.1.2 (for CS5) includes the following changes:

* All “constant numbers” moved to private static constants. The used (and preferred) style for this is all caps, for example: private static THIS_IS_A_CONSTANT:uint = 5;

* The private function showText() is now updateText() to better reflect what it does.

* Fixed a spelling error in the name of the private function checkBulletEnemyCollisions().

* All variable names are now in english. The few ones in swedish have been removed.

* All comments in swedish have been removed. English comments in some future version.

  1. Download the Spawn Engine v 0.1.2 and get started.
  2. If you have any trouble please comment.

 

2012/02/29 Posted by | Engine Releases | , | Leave a comment

NEW Release of the Spawn Engine version 0.1

I’ve cleaned up some curly brackets that were in the wrong places which created problems for students when they were editing the code. I also cleaned up some comments. In future versions there will only be comments in english.

Download the Spawn Engine v 0.1 for CS3. If you have any trouble please comment. For a CS5-version get the 0.1.1 of the Spawn Engine.

I apologize for all the comments in swedish in the code. Remember that this is a project where we work with this engine as a text-book for a swedish programming course. That is also why this version is fully playable yet has a lot of room for improvement.

2011/12/06 Posted by | Engine Releases | , , | Leave a comment

Release of the Spawn Engine version 0.1.1

This is just a small update of version 0.1 to make the engine work for CS5 where fonts needs be embedded. I also did some clean up among comments and there where a few curly brackets in the 0.1 version that where in the wrong places that now have been fixed.

  1. Download the Spawn Engine v 0.1.1 and get started.
  2. If you have any trouble please comment.

I apologize for all the comments in swedish in the code. Remember that this is a project where we work with this engine as a text-book for a swedish programming course. That is also why this version is fully playable yet has a lot of room for improvement. Maybe you can find some things that you don’t like with the engine? Good! Start coding and feel free to post descriptions of what you don’t like with the engine that you have fixed.

2011/11/29 Posted by | Engine Releases | , | Leave a comment