Skip to content
This repository has been archived by the owner on Feb 19, 2018. It is now read-only.
Andrés edited this page Mar 21, 2015 · 37 revisions

Now with the Stormtrooper Syndrome

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 Enemies are the bad guys that will try to break into your castle and destroy it (like in any Tower Defense), enemy class defines one instance of an enemy and is derived from [game object](Game Object). Each enemy will be a game object that will move through the map following the path map generated, each killed enemy will reward the player with some coins, while each enemy that gets to the destiny will takes one (or more) player life .

The control of enemies comes from that class [game master](Game Master), being the enemy instance only a holder of information and animations thats moves from one point to the other (kind of zombies)

Name Version Header Implementation
Enemy 0.7.6 enemy.h enemy.cpp

Before reading more about enemies, remember to check the page about [enemy attributes](Enemy Attributes),[game object](Game Object) as well as the reference

Enemy_idle.jpg
Example of enemy |"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 Private

  • const enemy_attributes *attributes defines all the general information of the enemy (animations,name, max armor etc..), this information is shared between all enemies of the same kind (same name in same [enemy set](Enemy Set)), the information about the current enemy (spawned on the game) is stored in this enemy class)

  • map<enemy_animation,al_anim> animation stores the animations of the enemy

  • unsigned int life defines the current life of the enemy, if drops to 0, enemy dies 😢

  • unsigned int level defines the level of the enemy (which may change enemy base attributes)

  • double speed current speed of the enemy (in pixels per frame)

  • pair<double,double> destiny position that the enemy will move (in a straight line) if equals to position, enemy don't move and goes to idle state

  • bool reward_given true if the enemy reward has already been given (to avoid giving two times the reward when enemy is dead)

  • enemy_animation current_animation defines the current animation to be drawn (and the enemy status on the last frame)

Some relevant information of the enemy is stored in [Enemy Attributes class](Enemy Attribute)

###Constructors
All constructors will set the active value to false, so spawn method should be called for the enemy to start working

  • enemy() default constructor, set all values to 0 and the coordinates of position/destiny to (-1,-1), set active to false

  • enemy(const enemy_attributes &attributes,unsigned int level,double posx,double posy,const ALLEGRO_TIMER *timer) sets all values to the base attributes, set given level (currently unused) and spawn the enemy to given position, also formats enemy speed according to given Allegro timer

###Destructor

  • ~enemy() clear enemy information without destroying animations

###Methods Public

  • void spawn(double posx,double posy) spawn the enemy in given position this may be a private method in the future, as it should only be called with constructor

  • string get_name() const returns the enemy name (found in attributes)

  • string get_speed() const returns enemy speed (in pixels per seconds)

  • unsigned int get_life() const returns the enemy remaining life

  • unsigned int get_level() const returns enemy level

  • unsigned int get_max_life() const returns the enemy maximum life (which is stored in [attributes](Enemy Attributes)

  • unsigned int get_reward() const returns enemy reward

  • pair<double,double> get_destiny() const return destiny of the enemy (if equals to position, the enemy is on idle stage)

  • bool is_reward_given() true if the reward has already been gived

  • bool alive() const returns true if the enemy still alive(life>0)

  • bool spawned() const returns true if enemy is active (after calling spawn or full constructor)

  • bool idle() const true if enemy is on idle state (position equals destiny)

  • enemy_animation get_current animation() const returns current animation of enemy

  • void stop() sets the destiny to the current position, stopping the movement, making the enemy to be in a idle state

  • void move_to(double x,double y) sets destination, this will make enemy to start moving to given position until reached,stopped or called again to move_to, also sets the current_animation value

  • decrease_life(unsigned int dam) decrease life in dam value (without counting the armor), this should be used for continuous damage,special or magical damage

  • void damage(unsigned int dam) damage the enemy, reducing the damage according to armor, this is recommended for physical damage

  • void kill() sets life automatically to 0 and starts the dead animation

  • unsigned int destiny_reached() destroys the enemy and returns lives taken (this will be called bt [Game Master](Game Master) when the enemy achieves the final destiny

  • void update() updates the movement one frame, also updates the animation between idle,movement and dead. It is important to call this function each timer event (being timer the same timer given at attributes constructor) before calling draw

  • void draw() const draw current animation, should be called after update in the same frame, the bitmap will be drawn over the position, so enemy position will be the down-center of the bitmap (feet of the enemy)

  • bool check() const check the class is working properly, returns false if not

Private

  • void change_movement_animation(enemy_animation anim) if given animation is different to current, change current animation to given, this change will start the next animation in the same frame (this method should only be called for changes between movement animations)

  • void set_to_idle() set enemy to idle (stopping all animations and loading idle animation)

  • void stop_movement_anim() stop all movement animations

  • void set_speed(double spd,const ALLEGRO_TIMER *timer) sets enemy speed in pixels per frame from given speed in pixels per second using convert_speed from [Al Utils](Al Utils)

  • void set_level(unsigned int level) sets enemy level

  • void set_movement_animation() change movement animation according to destiny

  • unsigned int get_level_increment(unsigned int value) const returns the increment of a certain value according to enemy level

DCmC Wiki 0.7.6

Clone this wiki locally