The following techniques will be covered in this tutorial: creating a grid-based system for placing towers, using the new turret behaviour, using global and local variables, and testing collisions. This tutorial is suitable for beginner Construct 2 users who have at least a working knowledge of the software. This is not a full step-by-step tutorial; I will gloss over simple tasks like creating objects and variables, but I've included a number of hyperlinks to topics that beginners may not be familiar with.
This tutorial is suitable for users with the free version of Construct 2, but I strongly recommend a purchased version that unlocks use of the family function if you plan on developing a larger game with multiple enemy types.
If you'd like to follow along using the completed capx, you can download that here [R116 or later required]. If you'd like to skip straight to setting up the turret behaviour, go to page four and five of this tutorial.
Part 1: Setting up
First we’ll create all of our objects to use in the game. The input objects will be keyboard and mouse. The player-visible objects will be: a basic tower (I’ve called mine an arrow tower; it has the turret behaviour); that tower’s projectile (an arrow; with bullet and destroy outside layout behaviour); the enemy sprite (also with bullet behaviour); a “ready” button (which the player presses to commence the wave); an arrow tower button (which the player clicks on to build a new tower); and separate text objects to show current lives, wave and cash. There’s also a failure text object.
We’ll also create a few objects that will be invisible to the player (you should use cosmetic, non-blocking sprites to show where the player is allowed to build, where the enemy path is and so on). These will be: a grid-system that shows where towers can be placed; an enemy spawner; enemy destinations; and an enemy goal.
Place everything into a layout according to how you’d like your map to be laid out. Place a single instance of the tower, arrow and enemy outside of the layout. The grid should always be offset by 32,32 and be in units of 64 (in this case, at least).
Create global variables called Lives, Timer, CurrentCash, CurrentWave, CurrentEnemies, TotalEnemies, and InHand.
Create an instance variable for the tower object called Floating (boolean - set to true by default); create another variable for the arrow called Damage (number); create variables for the enemy called CurrentDestination and HitPoints (both numbers).