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

1

Index

Contributeurs

Statistiques

16,442 visites, 20,737 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 4: Shooting the enemies

This part of the tutorial is made blissfully easy thanks to the (at the time of writing) new turret behaviour. Update: Based on responses to this tutorial I've added another page (page five) to further explain in detail how to use the turret behaviour.

The first thing we want to do is assign our turrets a target, but only if they’ve been placed down (as earlier – if they’re not floating). That’s a simple measure and can be seen above.

Next, we spawn an arrow object each time the turret issues a shoot command (according to its rate of fire, and whether or not an enemy is in range – these are the sorts of properties that you’d change if you included tower upgrades in your game).

Our third event is simple: test to see if an arrow collides with an enemy (I’ve given my enemies extra large collision padding to make this a little easier). If it happens, reduce the hit enemy’s HitPoints variable by the arrow’s Damage variable (you’d also increase this with tower upgrades).

Finally, we want to kill off the enemy if its HP drops to zero or below. We’ll also reward our player with a little bit of cash (according to the current wave; you could also have multiple enemy types that yield different amounts) for their efforts to enable them to build more towers for the next level.

We have one last task to do, and that's setting up the Ready button that starts each new wave. You could alternatively tie this system to a timer, but for the purposes of this tutorial I've kept it easy on the player.

This button tests to see if there are zero enemies left on the map, and, if so, increments the wave number by one and resets the timer and enemy counter to zero.

And that’s it. Please download the fully-commented capx that contains the finished product. It also includes a few cleanup events and bits and pieces that weren’t covered in the text but should make complete sense once you see them in action. You must have Construct 2 release R116 (beta) or above to open this file.

I hope you found this tutorial to be useful if you’ve ever wanted to make a tower defence game but weren’t sure where to begin. Obviously the game in this example isn’t particularly difficult, but as you add new enemy types, new towers, building placement challenges and even boss characters, it’ll be possible to create a varied and interesting tower defence game from these fundamentals.

  • 0 Comments

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