The Legend of the Tomato Quest Tutorial - Enemies

Enemy Images
Before we can add our enemies, we need their images. Here are the images that are used in this tutorial. Save them into your Resources\images folder in your project directory.



Adding The Enemy Images to our Game
Add the following lines of code in the GameResources.cs source file, in the LoadImages method within the Resources class.

Now we can access these new enemy images.

Making the Enemies
The next step to getting our enemies into the game, is to create a method that will construct the enemies for us.

Create a new source file called Enemy.cs and add the following code as a template that we can build from.

Now that we have a template, the first thing we need to do is to create some constants to represent the Enemy spawn's, much like the PLAYERSPAWN constant we created earlier in the tutorial for our player character.

Add the following constants to the Game class in Game.cs

Remember earlier, we had decided that the boss was Event3, and the Enemies were Events 4 and 5. The benefit of using constants, is that where you use ENEMY1SPAWN or BOSSSPAWN, those labels get replaced with its value, which means we only need to remember the labels, not their values.

Add the following field to the Enemy class in Enemy.cs

Add the following method after the constants in the Enemy class within Enemy.cs:

This method simply goes through each Character element in the List, and creates a new Character method from the Character class, and pass in the name, Strength, Vitality, Agility, Intelligence, Luck, true that it can attack, true that it can move, but false that it can interact.

We also set the experience of the character to whatever was passed into the method. Unlike the main player character, the experience for the AI characters will be used to determine how much experience the Player will gain after defeating an AI.

Combining Multiple AI Types
Firstly, Add these 3 fields to the Game class in Game.cs

To load our enemies Add the following lines of code to the Game class constructor in Game.cs

This new code, is loading all the AI types into their own arrays, and then creates an array called _AI which will hold ALL AI. We then use our new AddRange function to add the content of all the AI into the _AI array.

After this, _AI holds all of our AI, so now when the program calls Update AI, it will update the Critters, Thieves and the Boss as well.

Finishing Up
Compile and build the game, there are some issues that we will address in the next tutorial such as:


 * 1) AI colliding with AI
 * 2) Optimizing the Collisions
 * 3) Making the AI move and attack, only when they are within a reasonable distance
 * 4) Making the AI move and attack, when they are alive.
 * 5) Monitor the AI's health so that when they have no health left, they die.

The Project so far
The Source code for the above tutorial can be found [[Media:RPGTutorial9.zip|Here]].

It is strongly recommended that you read through the code as you go through the tutorial to get a better understanding of how it works.