THE MAZE OF GALIOUS 2 EDITOR

TUTORIAL 3: HOW TO CREATE INTERACTIONS

This tutorial will show you how to define INTERACTIONS with the MOG2 EDITOR. I will show you how to make an enemy that collides with a weapon (arrow, sword, or whatever) to explode. Tutorial 2 is needed to do this third tutorial.

STEP 1: Creating the explosion
STEP 2: Setting up the enemy and the weapon
STEP 3: Creating the interaction

STEP 1: Creating the explosion:

1.1 - Create the graphics for your objects in a PCX/GIF/BMP or whatever graphic file using whatever drawing program (I recommend you to use Deluxe Paint, that is quite old, but allows you a great control at pixel level). You should draw all the bitmaps (one for each frame of the explosion) and the transparency and collision masks. You should have something like this (you can use the basic.pcx in the "graphics/alternate" folder for following this tutorial instead of drawing your own):

Notice that i've only drawn one mask per bitmap. This is because as the explosion will have no collision, I haven't defined any collision mask.

1.2 - Add the graphics to the project. In the BITMAP list you should see something like this:

1.3 - Create an object and name it ENEMY_EXPLOSION or something like that:

1.4 - Add the three bitmaps to the object. You should have this:

1.5 - Add a normal STATE to the object with the button STATE:

1.6 - Let's create the ANIMATION SCRIPT for the state. A script like this one will do (change it at your own taste). It's just a loop of the 3 frames of the explosion:

1.7 - Let's now create the ACTION SCRIPT. This simple script will do (leave the animation 32 cycles - PAUSE(32) - and then destroy it with the TERMINATE command)

Ok, that's all for the EXPLOSION. The nice thing is that you can use this explosion for several enemies. Let's go now with the next step.

STEP 2: Setting up the enemy and the weapon:

In order to create the interaction in a proper way uou have to set some variables to their appropiate values. All the WEAPON type of objects (like the enemies and the weapons) have two predefined variables: DAMAGE and DAMAGE_TYPE. You can just ignore them and use your own variables. But I think that you should use them. DAMAGE_TYPE contains a STRING represeting the TYPE of the damage that a weapon inflicts (i.e. "fire_damage", "physical_damage", etc. You can define as many types of damage as you want). DAMAGE is suposed to contain the strength of the weapon.

To continue following this tutorial, you need an enemy defined and at least one "player weapon". You can make Tutorial 2 now if you don't have an enemy defined. However, for the "player weapon", there is still no tutorial explaining how to create one, you can use the sword of the predefined POPOLON object in the TEST.MG2 example fie that comes with the editor. From now on, we will assume that you have an ENEMY and a WEAPON created.

2.1 - Define DAMAGE and DAMAGE_TYPE. For this tutorial we will define two types of damage: "physical" and "enemy_physical". Go to the OBJECT VARIABLES dialog (you will find this button just below the buttons to add/sub states) of the weapon and set the variables to DAMAGE = 1 and DAMAGE_TYPE = "physical":

To set the value of a variable, right click over it ans select VALUE.

2.2 - Now go to the enemy and set the variables to DAMAGE = 1 and DAMAGE_TYPE = "enemy_physical". It is important that the enemy has a different damage type than the weapon since if the damage type of the enemy is the same than the damage type of the weapon, if two enemies collide, they will kill each other! You can now also set the ENERGY variable of the enemy to the amount of times that you need to hit it before it dies.

STEP 3: Creating the interaction:

To create this interaction, we will create two CONDITIONAL STATES. A conditional state is a state that is triggered by a condition. The first of them will be triggered by the collision and will substract the damage inflicted by the weapon to the enemy. The second one will be executed when the energy of the enemy goes below 0.

3.1 - Create the two conditional states. Press twice the button "C.STATE" to add a couple of conditional states. You will get this two states:

Each conditional state has 4 fields: CONDITION, ANIMATION, ACTION and EXCLUSIVE. The CONDITION is the trigger of the state, ANIMATION and ACTION are obvious and EXCLUSIVE is a flag with the following function: if EXCLUSIVE = false, the object will execute inparallel this state and its normal behavior, and if EXCLUSIVE = true, only this state will be executed. We will only set the CONDITION and ACTION of this two states and leave the rest unchanged.

3.2 - The condition of the first conditional state is: "collision with a WEAPON with WEAPON_DAMAGE = physical". That reified as a condition script can be expresed like this:

Let's stop a little bit now to explain how the previous script works. The basis is the COLLISION_WITH_OBJECT command. This command needs two parameters: a STRING and a CONDITION. The string is a CONSTITUTION (none, solid, weapon, ladder, character or item). The COLLISION_WITH_OBJECT command, will search for ALL the objects of the specified constitution that collide with the current object. For each of them will test if the CONDITION is satisfied. The pseudo-code for the command is:

for each colliding object OBJ with constitution = CONSTITUTION do
begin
foreign = OBJ
execute CONDITION
if CONDITION = true, return TRUE
end
foreign = NULL
return FALSE

The FOREIGN register is a local variable of each object that points to another object. The command GET_FOREIGN_VAR can read the contents of a variable from the object pointed by the FOREIGN register. Therefore, the CONDITION specified in the preivious script means that the DAMATE_TYPE variable of the foreign object has to be equal to "physical".

Notice, that as the variable referenced by the command GET_FOREIGN_VAR is not a local variable, the parameter accepted by GET_FOREIGN_VAR is a STRING and not a VARIABLE.

3.3 - Once the previous condition is met. The action in that conditional state should be to substract the damage from the enemy's energy. This can be easyly done if you know that the contents of the FOREIGN register is kept intact with the value that the COLLISION_WITH_OBJECT has set to it. The script is simply this one:

Easy, isn't it? However, at this point. I would like to introduce a slightly "advanced" topic. Notice that if the weapon collides with 8 enemies at the same time, it will hit them all. Some weapons (as the SWORD or the ARROWS in MoG) can only hit one enemy. To simulate this feature, you can add an extra variable to all the weapons called HIT_ONCE. We can set HIT_ONCE = 1 to all the weapons that can only hit one enemy, and HIT_ONCE = 0 to all the weapons (as the CERAMIC_ARROWS) that can hit several enemies. Then, we can extend the previous script in this way:

We have added another command that will be executed in PARALLEL with the previous one: an IF statement. If the weapon has HIT_ONCE = 0 (i.e. different than 1). We will set the DAMAGE inflicted by the weapon to 0 so that it cannot inflict any damage to any other enemy.

3.4 - Let's go now with the second state. The trigger condition is when the ENERGY reaches 0, so the condition script is:

3.5 - The action of this second state has to be to create the EXPLOSION and to KILL the enemy, so we have these two actions in PARALLEL:

Now, you can test how you can kill enemies with you sword, arrow or whatever weapon that has DAMAGE_TYPE = "physical"!!

That's all for this third tutorial. I hope that you have learned something with it!