-
Notifications
You must be signed in to change notification settings - Fork 4
Game Objects
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 Game Objects controls the creation,updating and destroying of [game elements](Game Object) like enemies, towers or attacks, it is usually controlled by [game master](Game Master) and [player controller](Player Controller), all attacks and enemies will be automatically erased when necessary, while towers will only be spawned and destroyed when said. [Text Handlers](Text Handler) will also be drawn and destroyed by this class
Name | Version | Header | Implementation |
---|---|---|---|
Game Objects | 0.7.6 | game_objects.h | game_objects.cpp |
###Definitions
-
typedef unsigned int tower_id
defines an id for a tower (always >=1, 0 reserved for null tile)
###Variables
-
list<enemy> spawned_enemies
all spawned enemies in the game -
map<tower_id,tower> spawned_towers
spawned towers in the game -
map<string,text_handler> texts
[texts](Text Handler) in the game, stored in a map, with text tag used as key -
list<pair<list<enemy>::iterator,tower_atk> > spawned_attacks
all [spawned attacks](Tower Attack), associated to targeted enemy -
unsigned int reward
reward for killing enemies (it will accumulate all the rewards until get_reward is called) -
tower_id current_id
current tower_id to be assigned -
unsigned int killed
count of killed enemies
###Constructors
-
game_objects()
default constructor, with all lists empty
###Destructor
-
~game_objects()
destroy all spawned elements
###Methods
-
void add_enemy(const enemy &new_enemy)
adds a new spawned enemy to the list -
tower_id add_tower(const tower &new_tower)
adds a new tower to the spawned towers, returning the assigned id -
void add_attack(const tower_atk &atk,list<enemy>::iterator target)
adds a new attack, assigning to given target -
void add_text(const text_handler &new_text)
add a new text to gameobjects, removed any text with same tag -
void remove_tower(tower_id)
removes the tower with given id -
void remove_text(const string &tag)
removes text with given tag (does nothing if there is no text with same tag) -
void clear()
clear all data without destroying, only use when copying game_objects or destroying spawned elements outside this class -
unsigned int enemy_size() const
returns number of spawned enemies -
unsigned int tower_size() const
returns number of spawned towers -
unsigned int attack_size() const
returns number of spawned attacks -
unsigned int texts_size() const
returns the number of texts -
bool empty() const
returns true if there is not any spawned objects -
unsigned int killed_enemies() const
returns the number of killed enemies -
unsigned int get_reward()
return the rewards value and sets reward to 0 -
list<enemy>::iterator get_first_enemy()
returns an iterator to the first enemy in the list -
list<enemy>::const_iterator get_first_enemy() const
returns a const_iterator to the first enemy in the list -
list<enemy>::iterator get_last_enemy()
return an iterator to the end of the enemy list -
list<enemy>::const_iterator get_last_enemy() const
return a const_iterator to the end of the enemy list -
tower *get_tower(tower_id id)
return a pointer to the tower with given id -
const tower *get_tower(tower_id id) const
return a const pointer to the tower with given id -
text_handler *get_text(const string &tag)
returns a pointer to the text with given tag -
const text_handler *get_text(string &tag) const
returns a const pointer to the text with given tag -
vector<tower_id> update_towers()
update all the towers,returning the ids of the towers ready to fire -
vector<list<enemy>::iterator> update_enemies()
updates all enemies, destroying all dead enemies (and invalidating attacks to them), returns iterators to all enemies in idle -
void update_attacks()
updates all attacks -
void draw() const
will draw all the game objects, ordered by vertical position (from top to bottom) with the exception of texts, which will always be drawn last (always visible) -
bool check()
checks the class is working properly, returns false if not
Private
-
void invalidate_attacks(vector<list<enemy>::iterator> to_invalidate)
invalidates all the attacks that have given enemies as targets (the attack animation will continue normally, but will not deal any damage) -
void destroy_texts()
destroy all the texts in gameobjects
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