Thank you for visiting Blazing Games

Life Cycle of the Vampire

Humans are born, pay taxes, and then die. Vampire bats are spawned, fly towards the tax payer, and then either have a feast or get dusted. While being spawned is equivalent to being born and getting dusted is equivalent to dying, flying towards the player is probably far more enjoyable than paying taxes. We have already covered the dusting sequence earlier section, so this section is really about the spawning and flying that the vampire bat does.

The bat movement is tied to the main event loop of the game. In Flash I have found that the best way to handle a game event loop is by taking advantage of the OnEnterFrame function. This function is called every time that a frame is entered so you can place all the logic necessary to handle the movement of the bats here. There are two ways of using this function. The easiest is to just override the function by writing a new function called OnEnterFrame. The other way is to simply assign a function to the OnEnterFrame variable, which is the route I took. The advantage of assigning a function to OnEnterFrame is quite simply that you can then have more than one function which you can change by simply re-assigning the variable. As I have occasional need to have no action, I have a function called gameHalted which does nothing. You could use null instead, but I prefer a function it makes the code a bit more readable and there is always the off chance that in future versions, I will need to do stuff even when the game is halted.

The main game event loop is called gameInProgress. It simply calls the moveBats and checkMove functions which handle the bat movement and player movement (covered in a later section). After that, it updates the dynamic text field that displays the bats remaining. This info_txt field was initially used to check the frame rate that the game was getting. The code for handling the frame rate calculations is commented out for those of you who are curious about it.

The moveBats function actually handles both the spawning and movement of the bat. This is done by looping through the array of bats. If a bat is visible it needs to be moved. The movement is done by using the findAngle function we wrote earlier to find the direction the bat has to move and then using trigonometry to move the bat a unit in that direction. We also set a flag that indicated that there are bats on the screen. The purpose of this flag is to make sure the level complete message doesn’t appear until the bats are fully dusted.

If the bat is not visible, we then have to decide if we need to spawn a new bat. Obviously we limit the number of bats per level, so if all the bats needed for the level have been spawned, we are not going to spawn any more bats. The other factor determining if we spawn a bat is the lastRespawn variable which is increased each frame. Until this variable is greater than the RESPAWN_DELAY constant that I defined at the start of the game (again, placed near the top for easy access when tweaking the game), no bat is spawned. As soon as a bat is about to be spawned, this variable is reset to 0. The spawning is done by calling the spawnBat function with the array index of the bat to be created.

The spawnBat function places the bat along the edge of the screen by randomly determining which edge to place the new bat on and then randomly determining where on that edge the bat will appear. The bat is brought back to life by making it visible. This is actually cheating a bit, as we are taking advantage of the fact that the bat movie will loop back to the first frame once the death animation is finished where the batAlive variable will be set to true again. A better approach would be to have a function that makes the bat alive and call it, but I’m lazy.

After the bat movement bat loop is done, we check to see if bats were active. If not, we see if there are bats remaining to be spawned. If there are no bats remaining, the level is completed so we move to the next level. If all the levels of the game have been completed, we move to the win game sequence.

Previous Page
1 2 3 4 5 6 7

About - Privacy Policy - Contact - Links - FAQ
Copyright © 2004-2006 Blazing Games Inc. All Rights Reserved.