Skip to content
This repository has been archived by the owner on Feb 19, 2018. It is now read-only.

Enemy Attributes

Andrés edited this page Mar 21, 2015 · 22 revisions

This Documentation is from a code still under heavy development, you may find errors,sudden changes or the answer to life,universe and everything

###Overview All enemies base attributes are defined on a struct as well as the animations needed to draw the enemy

Name Version Header Implementation
Enemy Attributes 0.7.6 enemy_attributes.h enemy_attributes.cpp

Levels Ratio

  • const double level_ratio=0.3 shows the ratio each level will increase base values (default is 0.3, 30%)

Enemies Animations
Each enemy have a set of [animations](Al Animation) which will be used to draw the enemy in the scenery, depending on his actions, currently there are 6 different animations per enemy, these types are defined on the enumeration enemy_animation in enemy.h file (See Reference).

Animation Name Description Example
idle_anim when enemy not moving idle_anim.png
up_anim when moving up in screen up_anim.png
down_anim when moving down down_anim.png
left_anim when moving left left_anim.png
right_anim when moving right rigth_anim.png
dead_anim when enemy dies (not loopeable) dead_anim.png

The example enemy is part of "Medieval fantasy character sprites" art by [Johannes Sjölund] (http://opengameart.org/content/character-animations-clothes-armor-weapons-skeleton-enemy-combat-dummy) under CCLicense

###Variables enemy attributes are given as a struct, so all variables and methods are Public

  • map<enemy_animation,al_anim> animation stores all the needed animations to draw an enemy along with it's type

  • string name the general name for that enemy (shared between enemies of the same kind) you know, those people don't need personal names

  • double speed enemy speed in pixels per second, class enemy will modify this speed according to the timer

  • unsigned int max_life maximum life of the enemy (and life when spawned)

  • unsigned int armor armor of the enemy

  • unsigned int reward reward for killing this enemy

This values are common for each kind of enemy, but them may change in each enemy depending on level

###Constructors

  • enemy_attributes() default constructor, set all info to 0

  • enemy_attributes(XMLElement *enemy_root,const ALLEGRO_TIMER *timer) constructor from an XML file, given the enemy element and timer, this constructor will also load all the animations

  • enemy_attributes(const string &name,unsigned int life,unsigned int armor,double enemy_speed) full constructor (without animations)

  • enemy_attributes(const string &name,unsigned int life,unsigned int armor,double enemy_speed,const map<enemy_animation,al_anim> &animation) full constructor with animations

###Destructor

  • ~enemy_attributes()

###Methods Like variables, all methods are public:

  • bool read_xml(const XMLElement *enemy_root,const ALLEGRO_TIMER *timer) will read the xml element, and return true if it was successfully read

  • bool read_xml(const string &filename,const ALLEGRO_TIMER *timer) load given xml file and load all the info from root

  • void insert_animation(enemy_animation type,const al_anim &anim) inserts new animation of given type, erasing any old animation with same type This behaviour may change in the future to avoid undestroyed bitmaps

  • void clear() clear all info of attribute, but don't destroy [animations](Al Anim)

  • void destroy() destroy animations bitmaps and clear all the data

  • bool check() const check all the attributes are correct, returning false if any problem or incorrect attribute

###XML Example The enemy xml will contain all the enemy info (name,life,etc.) as well as the [animations](Al Animation), however, these animations should have also the attribute "type" to differentiate between the different animations

<Enemy Version="0.7.5">
  <Name>Enemy_0</Name>
  <Life>100</Life>
  <Armor>1</Armor>
  <Speed>50</Speed>
  <Reward>20</Reward>
  <Al_Animation Version="0.7.4" loop="false" type="dead">
    <Width>64</Width>
    <Height>64</Height>
    <Duration>2</Duration>
    <Bitmap_Sheet>resources/spr/enemy_0/dead.png</Bitmap_Sheet>
  </Al_Animation>
  <Al_Animation Version="0.7.4" loop="true" type="down">
    <Width>64</Width>
    <Height>64</Height>
    <Duration>3</Duration>
    <Bitmap_Sheet>resources/spr/enemy_0/down.png</Bitmap_Sheet>
  </Al_Animation>
  <Al_Animation Version="0.7.4" loop="true" type="up">
    <Width>64</Width>
    <Height>64</Height>
    <Duration>3</Duration>
    <Bitmap_Sheet>resources/spr/enemy_0/up.png</Bitmap_Sheet>
  </Al_Animation>
  <Al_Animation Version="0.7.4" loop="true" type="idle">
    <Width>64</Width>
    <Height>64</Height>
    <Duration>3</Duration>
    <Bitmap_Sheet>resources/spr/enemy_0/idle.png</Bitmap_Sheet>
  </Al_Animation>
  <Al_Animation Version="0.7.4" loop="true" type="left">
    <Width>64</Width>
    <Height>64</Height>
    <Duration>3</Duration>
    <Bitmap_Sheet>resources/spr/enemy_0/left.png</Bitmap_Sheet>
  </Al_Animation>
  <Al_Animation Version="0.7.4" loop="true" type="right">
    <Width>64</Width>
    <Height>64</Height>
    <Duration>3</Duration>
    <Bitmap_Sheet>resources/spr/enemy_0/right.png</Bitmap_Sheet>
  </Al_Animation>
</Enemy>

DCmC Wiki 0.7.6

Clone this wiki locally