Game Development Reference
In-Depth Information
returns a random number from 0 to 1, which is scaled between the
MinTime-
ToShoot
and
MaxTimeToShoot
member variables.
The
Update
loop ticks down the
_shootCountDown,
and once it is equal to
or below 0 the enemy fires a bullet. The bullet is made to be slower than the
player bullets and it's shot in the opposite direction. The enemy bullets are also
colored red so it's obvious they're different from the players. Once the enemy
shoots, the
_shootCountDown
timer is reset.
The enemies shoot towards the left of the screen. You may want to make it a
little harder and have the enemies aim at the player. To do this, the enemies
must have a reference to the
PlayerCharacter
. Then it's a simple matter of
working out the direction of the player in reference to the enemy ship. If you
decide to add aiming to the enemies, here's a little snippet of code that
might help.
Vector currentPosition
¼
_sprite.GetPosition();
Vector bulletDir
¼
_playerCharacter.GetPosition() - currentPosition;
bulletDir
¼
bulletDir.Normalize(bulletDir);
bullet.Direction
¼
bulletDir;
This concludes this second refinement of the game. The enemies can fire on the
player and move about in interesting ways. The enemies can be destroyed and
will explode in a satisfying ball of flame.
After two basic iterations of development, we have a wonderful but basic side-
scrolling shooter. There is massive scope for developing this project into some-
thing totally individual. The project is yours now and you can develop it as you
want. If you feel a little lost, here are some suggestions.
A very simple first step is to introduce a new enemy type; just add an extra
else if
and perhaps modify a path or the health. Once you've done that,
consider making a new enemy texture and changing the new enemy to use
this texture. This will suddenly make the game a lot more interesting.
■
A score is important in scrolling shooters. The score can be displayed using
the
Text
class. The score should increase every time the player destroys an
enemy.
■
Search WWH ::
Custom Search