-
Notifications
You must be signed in to change notification settings - Fork 4
Enemy
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, defined on enemy.h and enemy.cpp
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).
- idle_anim: animation to use when enemy is not moving
- up_anim: animation when enemy is moving up in the screen
- down_anim: when moving down
- left_anim: when moving left
- right_anim: when moving right
- dead_anim: when enemy die
Up,down,left and right animations are used when the enemy is moving, changing between them depending on the direction of movement These set of animations may be updated with new not necessary animations like combat or special effects
To check the latest features involving enemies, click here
###Variables Private
-
string name
defines the enemy type name, this name is used to identify spawned enemies types, and should be the same name for each type (e.g. archer,swordsman etc.) -
unsigned int life
defines the actual life of the enemy, if drops to 0, enemy dies 😢 -
defines the level of the enemy (which may change enemy base attributes) currently unusedunsigned int level
-
unsigned int armor
enemy armor, physical damage taken will be reduced the armor value -
double speed
enemy speed on the scenery -
pair<double,double> position
current position of the enemy to be drawn _currently is the top-left pixel of the enemy, but it may change to be the center of the bitmap -
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 active
if active, enemy will react to update method and will be drawn into the scenery -
map<enemy_animation,al_anim> animation
all the animation set for the enemy, with one animation per enemy_animation enum value -
enemy_animation current_animation
defines the current animation to be drawn (and the enemy status on the last frame)
###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 to (-1,-1) -
enemy(const string &name,unsigned int life,unsigned int armor,double speed,const map<enemy_animation,al_anim> &animation)
full constructor, set all values except position and destiny, this constructor also makes active=false -
enemy(const string &name,unsigned int life,unsigned int armor,double speed)
constructor without animation set, which should be defined using the specific methods
###Methods
Public
-
void set_life(unsigned int life)
sets enemy life -
set_armor(unsigned int armor)
sets enemy armor -
void set_speed(double speed)
sets enemy speed, if speed<=0 a warning will be logged ([See Debug Log](Debug Log)), if speed is negative, it will automatically set to positive -
void set_idle_animation(const al_anim &idle)
set the [animation](Al Animation) to use when enemy is in idle state (not moving) -
void set_dead_animation(const al_anim &dead)
set the animation for the enemy dying, this animation will not be looped, drawing the final frame (corpse) until deactivate is called -
void set_movement_animation(const al_anim &up,const al_anim &down,const al_anim &left,const al_anim &right)
sets the different animation for enemy movement(one per axis), these animations will be used simultaneously and is recommended to have the same size -
string get_name() const
returns the enemy name -
unsigned int get_life() const
returns the enemy remaining life -
pair<double,double> get_position() const
return current position given in a pair of coordinates x,y -
pair<double,double> get_destiny() const
return destiny of the enemy (if equals to position, the neemy is on idle) -
bool alive() const
true if the enemy still alive(life>0) -
bool spawned() const
true if enemy is active (after calling spawn) -
bool idle() const
true if enemy is on idle state (position equals destiny) -
void spawn(double posx,double posy)
sets the enemy to active (spawned) in the position given, the enemy will be on idle state by default (dead if life=0) until move_to is called -
void stop()
sets the destiny to the current position, stopping the movement, making the enemy to be in a idle state -
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 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 -
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 -
void deactivate()
deactivates the enemy, so no longer will be drawn or updated (recommended to call this after the enemy was killed) -
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 constructor) before calling draw -
void draw()
draw current animation, should be called after update in the same frame
Private
*void insert_animation(enemy_animation anim,const al_anim &animation)
insert given animation into animation map, with key anim, overriding any previous animation
-
void set_to_idle()
set enemy to idle (stopping all animations and loading idle animation) -
void stop_movement_anim()
stop all movement animations -
void check()
checks the enemy is ready to spawn (all animations and values set correctly) showing the errors with [Debug Log](Debug Log)
Don't Crush My Castle Wiki is under CC License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
_______________________
/ Don't Crush My Castle \
\ is a cool name /
-----------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
DCmC Wiki 0.7.6
- [Home] (Home)
- [Getting Started] (Getting Started)
- Documentation
- Reference
- Attributions