ELEC2645 (2018/19) / Mbed 2 deprecated el17dg

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Revision:
31:becb8f6bf7b7
Parent:
30:d454d0cb72bc
Child:
32:5403bb974294
--- a/game/player.h	Tue Apr 16 21:16:33 2019 +0000
+++ b/game/player.h	Tue Apr 23 18:18:57 2019 +0000
@@ -8,47 +8,50 @@
 const int ship_speed = 2;
 const int blast_speed = 5;
 
-GameObject blasts[max_player_blasts];
-GameObject player;
-CircleBounds player_bounds;
-CircleBounds blast_bounds;
-Game force_shield_check;
-
-/**Player Class
- * @brief A library for describing the player's ship.
+/**
+ * Player Class
+ * @brief Manages player's ship.
  * @author Dmitrijs Griskovs
  * @date 15/04/2019
  */
 class Player{
 public:
 
-/** @brief A constructor of the player's ship.
- * @details A constructor for the palyer's sprite body circle area and the
- * blast circle area. It sets the circle radius for collsion callculations.
- */
-Player() {
-    player_bounds.center.x = 5;
-    player_bounds.center.y = 8;
-    player_bounds.radius = 7;
+    GameObject blasts[max_player_blasts];
+    GameObject player;
+    CircleBounds player_bounds;
+    CircleBounds blast_bounds;
+    Game force_shield_check;
+    /** 
+     * @brief A constructor of the player's ship.
+     * @details A constructor for the palyer's sprite body circle area and the
+     * blast circle area. It sets the circle radius for collsion callculations.
+     */
+    Player() {
+        player_bounds.center.x = 5;
+        player_bounds.center.y = 8;
+        player_bounds.radius = 7;
+    
+        blast_bounds.center.x = 0;
+        blast_bounds.center.y = 1;
+        blast_bounds.radius = 1;
+    }
 
-    blast_bounds.center.x = 0;
-    blast_bounds.center.y = 1;
-    blast_bounds.radius = 1;
-}
-/** @brief Draws the player's blasts on the screen
- * @details This function Will draw every activated blast to the left with the blast_speed.
- * It will deactivate blasts when they leave the screen, for future reuse.
- * If the blast does miss the enemy and leaves the screen limits, the function will
- * substract 10 points in game_score.
- */
+    /** 
+     * @brief Draws the player's blasts on the screen
+     * @details This function Will draw every activated blast to the left with the blast_speed.
+     * It will deactivate blasts when they leave the screen, for future reuse.
+     * If the blast does miss the enemy and leaves the screen limits, the function will
+     * substract 10 points in game_score.
+     */
     void updateAndDrawBlasts() {
         for (int i = 0; i < max_player_blasts; ++i) {
             if (blasts[i].active) {
                 blasts[i].pos.x += blast_speed;
                 if (blasts[i].pos.x >= screen_width){
                     blasts[i].active = false;
-                    game_score -= 10;
-                    score_count_for_difficulty -= 10;
+                    GameGlobals::game_score -= 10;
+                    GameGlobals::score_count_for_difficulty -= 10;
                 }
                 lcd.setPixel(blasts[i].pos.x,   blasts[i].pos.y, 1);
                 lcd.setPixel(blasts[i].pos.x+1, blasts[i].pos.y, 1);
@@ -57,13 +60,14 @@
         }
     }
     
-/** @brief Makes a blast active and gives it the start positions.
- * @details This function searches the array for the inactive blasts,
- * If a blast is not active, it will set it to active and will start drawing
- * it accross the screen until it reaches the LCD border line.
- */
+    /** 
+     * @brief Makes a blast active and gives it the start positions.
+     * @details This function searches the array for the inactive blasts,
+     * If a blast is not active, it will set it to active and will start drawing
+     * it accross the screen until it reaches the LCD border line.
+     */
     void fireNewBlast() {
-    // Search the array of blasts if inactive we can use it.
+        // Search the array of blasts if inactive we can use it.
         int found = -1;
         for (int i = 0; i < max_player_blasts; ++i) {
             if (!blasts[i].active) {
@@ -78,34 +82,34 @@
         }
     }
         
-/** @brief Updates and draws player's ship (including with force shield sprite) positon.
- * @details The function reads the analog input signal from joystick and
- * moves the player's ship on the LCD accordingly.(move joystick, the ship 
- * moves up, move joystick right, the ship moves right). Also, this function checks
- * whether the force shield was activated in game.cpp, if it was then the player's
- * ship is replaced the exactky the same sip but with the added force shield. 
- */
+    /** 
+     * @brief Updates and draws player's ship (including with force shield sprite) positon.
+     * @details The function reads the analog input signal from joystick and
+     * moves the player's ship on the LCD accordingly.(move joystick, the ship 
+     * moves up, move joystick right, the ship moves right). Also, this function checks
+     * whether the force shield was activated in game.cpp, if it was then the player's
+     * ship is replaced the exactky the same sip but with the added force shield. 
+     */
     void playerShipMovement(){
-        if(x_dir.read() > joy_threshold_max_x){
+        if(x_dir.read() > joy_threshold_max_x) {
            player.pos.x -= ship_speed;
-        }
-        else if(x_dir.read() < joy_threshold_min_x){
+        } else if(x_dir.read() < joy_threshold_min_x) {
            player.pos.x += ship_speed;
         }
-        if(y_dir.read() > joy_threshold_max_y){
+        if(y_dir.read() > joy_threshold_max_y) {
            player.pos.y -= ship_speed; 
-        }
-        else if(y_dir.read() < joy_threshold_min_y){
+        } else if(y_dir.read() < joy_threshold_min_y) {
            player.pos.y += ship_speed; 
         }
         shipMovementLimits();
         if (force_shield_check.forceShildActivate()){
             drawSpriteOnTop(player.pos, player_spaceship1_shield_sprite);   
+        } else { 
+            drawSpriteOnTop(player.pos, player_spaceship1_sprite);
         }
-        else{ drawSpriteOnTop(player.pos, player_spaceship1_sprite);}
     }
 private:
-/** Prevents the player's ship to go beyond the playing zone limits.*/
+    /** Prevents the player's ship to go beyond the playing zone limits.*/
     void shipMovementLimits(){
         // Limits player ship on screen
         if (player.pos.x < game_area_x){ player.pos.x = game_area_x;}