Thank you for visiting Blazing Games

Dusting Bats

We covered the creation of the dusting animation in an earlier section, so we know that a vampire bat can be killed. The problem right now is that there simply is no way to kill the vampire. For the dusting effect to actually happen in the game the player is going to need to be able to launch stakes at the vampires. When I was creating the game, I actually created the stake well before the bat as part of a test movie, which is why the motion code is embedded as part of the class. What should have been done is the motion control of the stakes should have been part of the main game code. Still, when you are rushing a game into production, you occasionally end up with some bad bits.

The stake needs to know if it is ready to be fired, or if it has been launched. It also has to know how quick to move and has a limited flight time so it will know when to remove itself. All this information is set up in the first frame of the movie. The update function is called every frame for stakes that are visible. Quite simply, it adjusts its location to keep it at the appropriate location on the crossbow if it has not been launched and moves if it has been launched. A launch function launches the stake. The isLaunched function returns true if the stake is moving. Finally loadStake and isReady deal with loading the crossbow.

When I originally created my stake class I only had to worry about a single stake for the test. As with the bat, more than one stake was possible. It is theoretically possible to have an infinite number of stakes, but that is not really necessary, as stakes obviously only need to last until they go off the screen, so if you calculate how many frames it will take to travel the maximum possible distance, you know how long a stake needs to survive. The number of stakes then is the maximum survival time divided by the delay between launching stakes. This is defined in a constant so it can be adjusted later if necessary.

Once a stake has been launched, it continues moving until its lifetime is expired. Movement is in the last angle the stake was facing, and it’s position is recalculated by using a couple of simple trigonometry functions.

The determination as to if a bat has been struck by a stake is done in the bat movement function. Every bat that moves is then checked against every stake. If there is a collision then the bat is dusted. Had we wanted to, we could have just wounded the bat, or destroyed the stake. Currently the stake will travel through dusted bats, but this behaviour would be very simple to change.

You will notice that after every frame, the stakes are updated. The stake update function is called with the player location and direction so that the stake that is going to be launched next can be properly positioned. Player movement is simply handled by using the cursor keys and adjusting the player location based on which key is pressed.

Previous Page
1 2 3 4 5 6 7

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