Defining the properties of the enemy

The typical enemy will have the following characteristics:

  • It will have health, armor (to prevent physical damage), and magic resistance (to prevent magic damage)
  • It will have a certain movement speed
  • It will do certain amounts of damage if it reaches the base
  • It will have certain rewards on being killed

Based on these characteristics, we will define the following properties for an enemy in our game:

  • Health
  • Armor
  • Magic resistance
  • Speed
  • Damage
  • Reward

Let's now take a look at an excerpt from the enemy_data.xml file to see how we define the XML structure for the enemy data:

<EnemyDataList>
  <EnemyData animation="enemy_1" health="20" armor="0" magic_resistance="0" speed="0.8" damage="1" reward="10" />
  .
  .
  .
</EnemyDataList>

The root element of the document titled EnemyDataList defines a list of EnemyData tags, one for each type of enemy. The only property that we didn't discuss earlier is the one titled animation. This is nothing but the name of the sprite animation that will be played on this enemy's sprite.

Just like for the tower data, we have a similar struct named EnemyData defined in GameGlobals.h that will be populated as enemy_data.xml is parsed in the LoadData function of the GameGlobals class when the game is launched. This is what EnemyData structure looks like from GameGlobals.h:

struct EnemyData
{
  char animation_name_[256];
  int health_;
  int armor_;
  int magic_resistance_;
  float speed_;
  int damage_;
  int reward_;

  EnemyData() : health_(0),
    armor_(0),
    magic_resistance_(0),
    speed_(0.0f),
    damage_(0),
    reward_(0)
  {
    sprintf(animation_name_, "%s", "");
  }
};

Once again, since this struct is a mirror image of the EnemyData tag and the GameGlobals class maintains a pointer to an EnemyData object for each tag in a vector named enemy_data_. Let's now take a look at how these enemies are batched into waves and sent out; this is in our next section where we will define the XML structure for a typical level.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.32.222