The Legend of the Tomato Quest Tutorial - The Healer

Adding the Healer Image
Firstly we need an image of a Healer to use in our game. Save the following image, and put it into your Resources\images folder.



We also need to add the code that will include this image into a Game.

Modify the LoadImages method in the Resources class within the GameResources.cs source file to look like the following:

This will add our healer image to the game.

Creating the Healer
To create the healer we first need a new source file.

Create a new source file called Healer.cs and add the following code to the source file:

With this, we now have a template for our new Healer AI.

Before we continue we need to make a change to the Character Constructor method and the Character class in Character.cs source file.

Add the following fields of code to the Character class in the Character.cs source file:

Now we have a way to tell our AI if they can attack, move or interact.

Next change the declaration of the Character Constructor method in the Character class to look like the following:

As said before, we need these new Booleans, to tell the AI whether it can move, attack and interact.

We also need to add some code to the Character Constructor method in the 'Character class method. Add the following lines right at the bottom of the constructor method.

This will set the CanMove, CanAttack, and CanInteract, to whatever we pass into the NewCharacter method.

The next step is to create a method that will create all the healers for the map.

Add the following constant to the Game class inside the Game.cs source file.

Next at the follow Constructor for the Healers class

The first thing we have in our code is a constant, called HEALERSPAWN, which replaces all of the instances of HEALERSPAWN with its value, this helps us, because it is easier to remember the name HEALERSPAWN, then it is to remember the value it holds.

Next we have a constructor method Healers, which takes a String, Map, Strength, Vitality, Agility and Event. The Map is used to find all the Spawn X and Y positions for each Healer, and the Strength, Vitality, Agility, Intelligence and Luck settings are what is assigned to the Healers, and the name is simply to tell the method which character image to load. And the event type is passed in, to tell the the map which events to load from.

Next we create an array called healers, which is made to be the size equivalent to the number of HEALERSPAWN's that are found on the map.

Next we go through each item in the healers array, creating a Character. We use the Healer Image, give it the X and Y Position of that particular healer, it's Strength, Vitality, Agility, Intelligence, Luck and whether it can move, attack, and interact.

Add the Healer to the Game
Before we add our Healer, modify the _Player loading line of code in the Game class's Constructor in Game.cs to look like the following.

Now we need to add the Healer to the game.

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

Now add the following lines of code to the Game Class Constructor method in Game.cs source file.

The first new addition creates an array of Characters, called _Healers, which is used to store all of our Healer characters.

We've also create an additional array called _AI, this is going to be used to store all of our AI Characters, whether they are Healers, Enemies or Bosses. We will use it to group them all together so we can process them all at the same time.

The AddRage line we added, resizes the _AI List, to the length of the _Healers.Characters List and puts all the elements of _Healers.Characters into _AI. This way our _AI can keep track of all our AI characters.

Updating the AI
We need to now have some methods to handle our AI. This will be covered in the next tutorial. But for now we will make the template to work with, and also make a method that will Draw our Healers to the screen.

Create a new source file called AIController.cs and add the following code to the source file:

This will serve as a template for all our AI routines.

Now we need to add one more routine to get our Healers to draw to the screen.

Add the following method inside the AIController Class in the AIController.cs source file.

This method takes an List of AI, the Player and the Map. Currently the Player and the Map are not being used right now, but in the next tutorial they will be used alot.

But for now, this method goes through all the AI in the List of AI passed in, and checks if they are on the screen. If they are, the method draws them.

Last Things to do
First add the following field to the Game class in Game.cs

Lastly, we need to add a line of code to the main loop in the Run method in the Game class of Game.cs.

Now all out AI (which at the moment is just Healers, will be updated and drawn to the screen.

Finishing Up
Compile the Game and now you will have Healer NPC's waiting to heal you (the healing part hasn't been implemented yet!).



Project so far
The source code for the project at this point can be found [[Media:RPGTutorial7.zip|Here]]. It is strongly recommended you read through the code while you read this tutorial to get a better understanding of how things are done.

Next we'll get some Enemies into the game!