ELEC2645 (2018/19) / Mbed 2 deprecated el17dg

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Revision:
22:4dc3c95f2146
Parent:
21:0eb394495b8a
Child:
23:240bc00ef25b
diff -r 0eb394495b8a -r 4dc3c95f2146 game/game.cpp
--- a/game/game.cpp	Wed Mar 27 00:00:32 2019 +0000
+++ b/game/game.cpp	Wed Mar 27 16:35:52 2019 +0000
@@ -11,7 +11,7 @@
 #include "gameobject.h"
 
 #include "enemies.h"
-
+#include "constants.h"
 
 bool game_over = true;
 int small_star_delay;
@@ -47,7 +47,7 @@
 
 #include "hud.h"
 
-/**
+/**@brief
  * Will move every active blast to the left with blast speed.
  * Will deactivate blasts when they live screen, for future reuse
  */
@@ -66,7 +66,11 @@
     }
 }
 
-
+/**@brief
+  * This function searches the array for the inactive blasts,
+  * If a blast is set to not active, it will set it active and start drawing
+  * it accross the screen until it reaches the LCD border line.
+  */
 void Game::fireNewBlast() {
     // Search the array of blasts if inactive we can use it.
     int found = -1;
@@ -83,7 +87,12 @@
         blasts[found].pos.y = player.pos.y + (spaceship1_height/2);
     }
 }
-
+/**@brief
+  * This function checks whether the requirments for the collision of the two objects,
+  * are met. When those requirments are met the collision of two objects function will
+  * be checking wheter the boundaries of the objects colide. If they do, the blast
+  * becomes inactive, in game score increases and enemy dies.
+  */
 void Game::collideEnemiesAndBlasts() {
     for (int i = 0; i < max_enemies; ++i) {
         for (int j = 0; j < MAX_BLASTS; ++j) {
@@ -104,6 +113,13 @@
     }
 }
 
+/**@brief
+  * This code does the same work as the one before but with two other object.
+  * It checks whether the requirments for the collision of the two objects,
+  * are met. When those requirments are met the collision of two objects function will
+  * be checking wheter the boundaries of the objects colide. If they do, the blast
+  * becomes inactive, in game score increases and enemy dies.
+  */
 void Game::collideEnemiesBlastsAndPlayer() {
     for (int i = 0; i < max_enemy_blasts; ++i) {
         GameObject& blast = enemies.enemy_blasts[i];
@@ -119,18 +135,23 @@
         }
     } 
 }
-
-void Game::shipMovment(){
-    if(x_dir.read() > 0.6f){
+/**@brief
+  * The function reads the analog input signal from joystick and moves the 
+  * player's ship on the LCD accordingly.(move joystic, the ship moves up
+  * move joystick right, the ship moves right). Also, It prevents the player's 
+  * ship to go beyond the playing zone limits.
+  */
+void Game::playerShipMovement(){
+    if(x_dir.read() > joy_threshold_max_x){
        player.pos.x -= ship_speed;
     }
-    else if(x_dir.read() < 0.4f){
+    else if(x_dir.read() < joy_threshold_min_x){
        player.pos.x += ship_speed;
     }
-    if(y_dir.read() > 0.6f){
+    if(y_dir.read() > joy_threshold_max_y){
        player.pos.y -= ship_speed; 
     }
-    else if(y_dir.read() < 0.4f){
+    else if(y_dir.read() < joy_threshold_min_y){
        player.pos.y += ship_speed; 
     }
     //Limits player ship on screen
@@ -142,7 +163,11 @@
     if (player.pos.y > max_player_y) player.pos.y = max_player_y;
 }
 
-
+/**@brief
+  * This function resets all values to their intial values when the game is
+  * first starts and when the player dies and wants to restart the game.
+  * It does not reset the values when the game is paused.
+  */
 void Game::startNewGame() {
     game_over = false;
     player.pos.x = 0;
@@ -167,8 +192,7 @@
     if (game_over) {
         startNewGame();
     }
-    
-    shipMovment();
+    playerShipMovement();
     if (gamepad.check_event(gamepad.X_PRESSED)){
         fireNewBlast();
     }