Part 4: Explosions

While we are on the subject of Enemy and EnemyMissile, we might as well talk about explosions. Explosions are my favorite part of any shooting game, but they are also very hard to pull off. The explosions I have created for HomeWars are pretty lame, but they will suffice for the lessons begin presented.

The game will include two explosions: FExplode and FExpplodeSmall in the library. Neither one has a class associated. They will both be created, managed, and removed from the screen by The HomeWars class.

FExplode is used when an Enemy or the Player is destroyed.

Fexplode

FExplodeSmall is used when the Player shoots one of the EnemyMissiles or hits an Enemy that takes more than 1 hit.

fexplode-small

Part 5: Text Intro

One of the most overlooked considerations when creating an action game is the timing necessary to allow the player to get ready for the action to start. It also useful to give the player some kind of message about the current status of the game. For that reason we will create a TextIntro class. This class will display text on the screen, and fire an event when we want the action to start in the game.

text-intro

FTextIntro in the library looks like this:

We will use the dtext variable in TextIntro to set the value of the text to be displayed on the screen. Here is the code for TextIntro.as


import mx.events.EventDispatcher;
class TextIntro extends MovieClip {

	var wait:Number = 0;
	var dtext:String = "";

	function TextIntro() {
		EventDispatcher.initialize(this);
	}

	function setText(txt:String) {
		dtext=txt;
	}

	function setWait(wt:Number) {
		wait=wt;
	}

	function setLocation(x,y) {
		_x = x;
		_y = y;
	}

	function Display() {
		this._alpha -= (100/wait);
		if (this._alpha <= 0) {
			trace("dispatch EventTextIntroComplete");
			dispatchEvent({type:"EventTextIntroComplete"});
		}
	}
	public function addEventListener(){/*Interface Stub*/}
    public function removeEventListener(){/*Interface Stub*/}
    public function dispatchEvent(){/*Interface Stub*/}     

}

TextIntro uses the wait variable (in frames) to govern how long it will take the text in dtext to fade from the screen. The Display() function sets the current alpha value based on the wait, and Dispatches the EventTextIntroComplete event when finished.

Read the rest of the series: ‘Anatomy of a Flash Game’

  1. Anatomy of a Flash Game: Lesson 1 – Setting up the game
  2. Anatomy of a Flash Game: Lesson 2 – Creating Enemies & The Game Environment
  3. Anatomy of a Flash Game: Lesson 3 – MochiAds, MochiBot and MochiAds Leaderboards