-
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.
Name | Version | Header | Implementation |
---|---|---|---|
Enemy | 0.2 | enemy.h | enemy.cpp |
To see the latest version, Click here
Before reading more about enemies, remember to check the page about [enemy attributes](Enemy Attributes) as well as the reference
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
###Variables Private
-
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), also, to avoid redundancy, all enemy animations are stored in attributes (even if they are changed in enemy class) -
unsigned int life
defines the current life of the enemy, if drops to 0, enemy dies 😢 -
defines the level of the enemy (which may change enemy base attributes) (currently unused, check issue #30)unsigned int level
-
double speed
current speed of the enemy (in pixels per frame) -
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 -
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(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
###Methods
Public
-
sets enemy level (currently unused, check issue #30)void set_level(unsigned int life)
-
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) -
unsigned int get_life() const
returns the enemy remaining life -
unsigned int get_max_life() const
returns the enemy maximum life (which is stored in [attributes](Enemy Attributes) -
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 enemy is on idle stage) -
bool alive() const
true if the enemy still alive(life>0) -
bool spawned() const
true if enemy is active (after calling spawn or ful constructor) -
bool idle() const
true if enemy is on idle state (position equals destiny) -
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 -
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 -
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 attributes constructor) before calling draw -
void draw()
draw current animation, should be called after update in the same frame
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 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