Initial publish
Dependencies: mbed
Fork of el17dg by
Diff: game/enemies.h
- Revision:
- 29:579e00b7f118
- Parent:
- 28:35af3843de8f
- Child:
- 30:d454d0cb72bc
--- a/game/enemies.h Wed Apr 10 15:42:10 2019 +0000 +++ b/game/enemies.h Mon Apr 15 12:59:51 2019 +0000 @@ -5,18 +5,26 @@ #include "geometry.h" #include "game.h" +/** A bool that changes states between whehter to go up or down in y-direction.*/ bool switch_enemy_y_dir = false; +/** Enemy speed movement - increasing the value will increase the speed.*/ extern int enemy_speed = 1; +/** Enemy blast speed - increasing the value will increase the speed.*/ extern int enemy_blast_speed = 3; +/** Maximum enemies allowed on the screen */ const int max_enemies = 4; +/** Maximum enemies' blasts allowed on the screen*/ const int max_enemy_blasts = max_enemies*2; -/**@brief - * This is a class to describe the states of one enemy ship +/** Enemy Class + * @brief A class to describe the states of one enemy ship. + * @author Dmitrijs Griskovs + * @date 15/04/2019 */ class Enemy : public GameObject { public: -/**This function spawns an enemy on the right side of the screen at the +/** @brief Enemy spawn function. + * @details This function spawns an enemy on the right side of the screen at the * x-direction LCD limit(84) and at random position in the y-direction. */ void spawn() { @@ -27,17 +35,26 @@ dead_counter = 0; blast_countdown = 0; } -/** This is a death function of an nemy when the the collision between the - * player blast and enemy ship is true. It sets the enemy ship to not active. +/** @brief enemy death sound and status reset. + * @details A function that resets the status of death of the enemy to be True, + * and plays a death sound when an enemy was hit. */ void die() { - gamepad.tone(87,0.1); - gamepad.tone(187,0.2); gamepad.tone(123,0.3); dead = true; dead_counter = 3; } -/** This function draws each individual enemy ship on the screen. +/** @brief Draws and updates enemy sprites on the screen and substracts the score + * if the ship leaves the screen limits. + * + * @details The function draws each individual enemy ship on the screen, and + * changes their x and y positions each time the function is called. It + * contains "if" statment for the the y-direction movement border limits so + * that when they are reached, the ship would move the opposite way in y-direction. + * Also, this function monitors the death status of the enemy ships, if + * TRUE, then it calls for the enemy explosion animation to be executed. + * To conclude, it sets the "active" status of the ship to FALSE when it leaves + * the screen limits and substracts the in game score by -50. */ void updateAndDraw() { pos.x -= enemy_speed; @@ -51,27 +68,27 @@ switch_enemy_y_dir = true; } } - if (!dead) { - drawSprite(pos, enemy_sprite); - } else { - updateAndDrawDeathExplosion(); - } + if (!dead) { drawSprite(pos, enemy2_sprite);} + else { updateAndDrawDeathExplosion();} + if (pos.x < 0) { game_score -= 50; score_count_for_difficulty -= 50; active = false; } } -/** This is an explosion function that draws the enemy ships explosion sprites - * when the player's shot hits it/ +/** @brief The function draws enemy explosion sprite + * @details This is an explosion function that draws the enemy ships explosion + * sprites when the player's shot hits them or when the player collides with them. + * the animation consists of two sprites "Exploded" and "Half exploded". */ void updateAndDrawDeathExplosion() { if (dead_counter > 0) { dead_counter--; if (dead_counter == 2){ - drawSprite(pos, enemy_half_exploded_sprite); + drawSprite(pos, enemy2_half_exploded_sprite); } else if (dead_counter == 1){ - drawSprite(pos, enemy_exploded_sprite); + drawSprite(pos, enemy2_exploded_sprite); } } else { active = false; @@ -84,14 +101,15 @@ }; -/**@brief - * This class describes the states and actions of several enemy ships, including - * random position generation (y - position) and enemy ship shooting drawing (also describing - * intervals between shots). +/** Enemies Class + * @brief The class that describes the states and actions of several enemy ships. + * @details It includes random position generation (y - position),enemy ship + * shoots drawing and control of time intervals between enemy shots. + * @author Dmitrijs Griskovs + * @date 15/04/2019 */ class Enemies { public: - Enemy enemy_blasts[max_enemy_blasts]; Enemy enemies[max_enemies]; CircleBounds enemy_bounds; @@ -109,7 +127,9 @@ enemy_blast_bounds.center.y = 1; enemy_blast_bounds.radius = 1; } -/** This function spawns a new enemy when there is a free spance in the enemy aray. +/** @brief This function spawns a new enemy on the screen. + * @details It spawns a new enemy on the screen when there is a free space + * in the enemy aray. */ void spawnNewEnemy() { int found = -1; @@ -124,7 +144,8 @@ enemies[found].spawn(); } } -/** This function draws the enemy ships and enemy blasts whenever they are +/** @brief Draws the ships and the blasts. + * This function draws the enemy ships and enemy blasts whenever they are * avaialbe to move. Also, it limits the fire rate of the enemy ships. */ void updateAndDrawEnemies() { @@ -143,7 +164,8 @@ } } } -/** This function fires a blast whenever it is free in the blast array. +/** @brief activates a blast and gives the start positions + * @details This function fires a blast whenever it is free in the blast array. * If the blast is free to be shot, it will become active and will get the. * positions of x and y in front of the enemy ship */ @@ -164,8 +186,9 @@ } return false; } -/** Whenever the blast is active, this function draws the blast accross the - * x- direction of the screen until it reaches the left screen limit and then +/** @brief draws the blasts on the screen. + * @details Whenever the blast is active, this function draws the blast accross + * the x-direction of the screen until it reaches the left screen limit and then * becomes inactive, therefore freeing a space in the blast array. */ void updateAndDrawEnemyBlasts() {