Construindo um jogo de Torre de Defesa com o comportamento de torre

1

Index

Contributeurs

Statistiques

16,367 visites, 20,636 vues

Outils

Partager

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 18 Sep, 2017. Last updated 25 Feb, 2019

Part 3: The enemies

*For the purpose of this tutorial, I’ve chosen to create a false timer to keep track of each wave. It’s currently not used for anything but to start each wave, but you could additionally have it count the total time of each wave and perhaps award players for finishing quickly.

The timer works as follows: at the start of the layout, it’s at -1 and not ticking. It’ll only increment by 1.0 per second if it’s at zero or higher. And it only goes to zero once the player presses the Ready button.*

We’ll start by setting up the enemies’ pathing, which simply has them moving from one instance of the Destination object to the next, in the order that they were placed in the layout view. Our first event tests whether or not the timer has been started (if it’s at zero). If so, a sub-event creates a new enemy every 1.0 second if CurrentEnemies is less than TotalEnemies (for a larger project, you could alter the TotalEnemies each round if you wish). As each enemy is spawned, 1 is added to CurrentEnemies.

The second event allocates the enemy’s HitPoints variable. I’ve chosen to set it at CurrentWave*5, but you’ll have to play around with the balance to get to something you’re comfortable with.

The third event sees us set the Enemy.Destination (our instance variable) to the next destination in the layout according to its IID. We know that the IIDs increment by one for each new instance created that currently exists, so by placing our destinations in the layout in the order we want our enemies to travel, we’ve created a simple train of motions.

Next, we’ll set the angle of each enemy (as bullets, they travel in a straight line according to their current angle) towards its current destination. It’s important that you do this for each enemy, otherwise all enemies will change their direction as the first one reaches a new destination. There are multiple ways to address this problem; this is just the method I chose.

Last, we destroy the enemy if it ever manages to reach its goal, and subtract 1 from Lives. The layout will reset if lives reaches zero or below.

  • 0 Comments

Want to leave a comment? Login or Register an account!