Initial publish

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Noximilien
Date:
Mon Apr 15 12:59:51 2019 +0000
Parent:
28:35af3843de8f
Commit message:
Added a lot of comments.

Changed in this revision

Models/models.cpp Show annotated file Show diff for this revision Revisions of this file
Models/models.h Show annotated file Show diff for this revision Revisions of this file
game/constants.h Show annotated file Show diff for this revision Revisions of this file
game/enemies.h Show annotated file Show diff for this revision Revisions of this file
game/game.cpp Show annotated file Show diff for this revision Revisions of this file
game/game.h Show annotated file Show diff for this revision Revisions of this file
game/gameobject.h Show annotated file Show diff for this revision Revisions of this file
game/geometry.h Show annotated file Show diff for this revision Revisions of this file
game/hud.h Show annotated file Show diff for this revision Revisions of this file
game/player.h Show annotated file Show diff for this revision Revisions of this file
game/stars.h Show annotated file Show diff for this revision Revisions of this file
main/main.cpp Show annotated file Show diff for this revision Revisions of this file
main/main.h Show annotated file Show diff for this revision Revisions of this file
menu/menu.cpp Show annotated file Show diff for this revision Revisions of this file
menu/menu.h Show annotated file Show diff for this revision Revisions of this file
tutorial/tutorial.cpp Show annotated file Show diff for this revision Revisions of this file
tutorial/tutorial.h Show annotated file Show diff for this revision Revisions of this file
--- a/Models/models.cpp	Wed Apr 10 15:42:10 2019 +0000
+++ b/Models/models.cpp	Mon Apr 15 12:59:51 2019 +0000
@@ -6,6 +6,9 @@
 const int enemy2_height = 7;
 const int enemy2_width = 11;
 
+const int enemy1_height = 17;
+const int enemy1_width = 11;
+
 const int spaceShip1[110] = {     //10 by 11
     0,0,0,0,1,1,1,0,0,0,
     0,0,0,1,0,0,0,0,0,0,
@@ -19,7 +22,7 @@
     0,0,0,1,0,0,0,0,0,0,
     0,0,0,0,1,1,1,0,0,0,
 };
-const SpriteOnTop player_spaceship1_sprite(10, 11, spaceShip1);
+const Sprite player_spaceship1_sprite(10, 11, spaceShip1);
 
 const int starSmall[9] = {
     0,1,0,
@@ -36,7 +39,8 @@
     1,0,0,0,1
 };
 const Sprite medium_star_sprite(5, 5, starMedium);
-const int starBig[49] = {
+
+const int starBig[49] = {           // 7 by 7
     1,0,0,1,0,0,1,
     0,1,0,1,0,1,0,
     0,0,1,1,1,0,0,
@@ -45,8 +49,9 @@
     0,1,0,1,0,1,0,
     1,0,0,1,0,0,1
 };
+const Sprite big_star_sprite(7, 7, starBig);
 
-const int enemyShip1 [187] = { 
+const int enemyShip1 [187] = {      //11 by 17
     0,0,0,0,0,0,1,1,1,1,1,
     0,0,0,0,0,0,1,1,1,1,1,
     0,0,0,0,0,0,1,1,1,1,1,
@@ -65,8 +70,9 @@
     0,0,0,0,0,0,1,1,1,1,1,
     0,0,0,0,0,0,1,1,1,1,1
 };
+const Sprite enemy1_sprite(11, 17, enemyShip1);
 
-const int enemyShip2 [77] = {
+const int enemyShip2 [77] = {       // 11 by 7
     0,0,0,1,1,1,1,1,1,0,0,
     0,0,0,0,0,0,1,1,1,0,0,
     0,0,0,1,1,1,0,1,0,1,0,
@@ -76,7 +82,7 @@
     0,0,0,1,1,1,1,1,1,0,0    
 };
 
-const Sprite enemy_sprite(11, 7, enemyShip2);
+const Sprite enemy2_sprite(11, 7, enemyShip2);
 
 const int enemyHalfExploded [77] = {
     0,0,0,0,0,1,1,1,1,0,0,
@@ -88,7 +94,7 @@
     0,0,0,1,1,1,0,0,1,0,0
     
 };
-const Sprite enemy_half_exploded_sprite(11, 7, enemyHalfExploded);
+const Sprite enemy2_half_exploded_sprite(11, 7, enemyHalfExploded);
 
 const int enemyExploded [77] = {
     1,0,1,0,1,0,0,1,1,0,0,
@@ -99,10 +105,9 @@
     0,0,1,0,0,0,1,0,0,0,0,
     1,0,0,1,0,1,1,1,1,0,0
 };
-const Sprite enemy_exploded_sprite(11, 7, enemyExploded);
+const Sprite enemy2_exploded_sprite(11, 7, enemyExploded);
 
-/*
-const int planet1 [289] = {
+const int planet1 [289] = {             // 17 by 17
     0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,
     0,0,0,0,1,1,1,1,1,1,0,1,1,0,0,0,0,
     0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,
@@ -121,7 +126,7 @@
     0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,
     0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0    
 };
-*/
+const Sprite planet1_sprite(17, 17, planet1);
 
 const int introLineOne [893] = {        //63 by 11
     1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,
@@ -136,6 +141,7 @@
     0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,0,0,1,0,0,0,
     0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,0,0,0,0,0,0,1,0,0,0   
 };
+const Sprite intro_line_one_sprite(63, 11, introLineOne);
 
 const int introLineOneStars [156] = {   //12 by 13
     1,0,0,1,0,0,1,0,0,0,0,0,
@@ -151,8 +157,8 @@
     0,0,0,0,0,0,0,0,1,1,1,0,
     0,0,0,0,0,0,0,0,1,1,1,0,
     0,0,0,0,0,0,0,1,0,0,0,1
-    
 };
+const Sprite intro_line_one_stars_sprite(12, 13, introLineOneStars);
 
 const int introLineTwoShips [460] = {   //46 by 10
     0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@@ -166,6 +172,7 @@
     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 };
+const Sprite intro_line_two_ships_sprite(46, 10, introLineTwoShips);
 
 const int introLineTwo [330] = {        //30 by 11
     0,0,1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,1,0,0,1,1,1,1,1,1,0,0,0,0,
@@ -180,6 +187,7 @@
     0,1,1,0,0,0,0,0,1,0,0,1,0,0,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,
     0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0
 };
+const Sprite intro_line_two_sprite(30, 11, introLineTwo);
 
 const int introLineThree [1482] = {     //78 by 19
     0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,
@@ -202,6 +210,7 @@
     0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,1,0,0,0,1,0,0,1,1,0,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,1,1,1,
     0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,0,0,0,0,1,1,1,1,1,1,0,0,1,0,0,0,0,1,1
 };
+const Sprite intro_line_three_sprite(78, 19, introLineThree);
 
 const int gameOverSprite [406] = {               //29 by 14
     1,1,1,1,1,1,1,0,0,1,1,1,0,0,1,1,0,0,0,1,0,1,1,1,1,1,0,0,0,
@@ -219,6 +228,7 @@
     0,0,0,0,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,0,0,1,1,0,1,0,
     0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,1,1,0,1,1,0,0,1
 };
+const Sprite game_over_sprite(29, 14, gameOverSprite);
 
 const int youDiedSprite [336] = {                //24 by  14
     1,0,0,0,1,0,0,1,1,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0,
@@ -235,8 +245,9 @@
     0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,0,0,1,
     0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,0,0,1,0,0,1,
     0,0,0,0,0,1,1,1,0,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0
-    
 };
+const Sprite you_died_sprite(24, 14, youDiedSprite);
+
 const int tutorialArrowRight [70] = {          //10 by 7
     0,0,0,0,0,0,1,0,0,0,
     0,0,0,0,0,0,0,1,0,0,
@@ -247,6 +258,8 @@
     0,0,0,0,0,0,1,0,0,0
 
 };
+const Sprite tutorial_arrow_right_sprite(10, 7, tutorialArrowRight);
+
 const int tutorialArrowLeft [70] = {          //10 by 7
     0,0,0,1,0,0,0,0,0,0,
     0,0,1,0,0,0,0,0,0,0,
@@ -255,4 +268,5 @@
     0,1,0,0,0,0,0,0,0,0,
     0,0,1,0,0,0,0,0,0,0,
     0,0,0,1,0,0,0,0,0,0
-};
\ No newline at end of file
+};
+const Sprite tutorial_arrow_left_sprite(10, 7, tutorialArrowLeft);
--- a/Models/models.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/Models/models.h	Mon Apr 15 12:59:51 2019 +0000
@@ -7,27 +7,12 @@
 extern const int spaceship1_height;
 extern const int enemy2_height;
 extern const int enemy2_width;
-extern const int spaceShip1[110];
-extern const int starSmall[9];
-extern const int starMedium[25];
-extern const int starBig[49];
-extern const int enemyShip1 [187];
-extern const int enemyShip2 [77];
-extern const int enemyHalfExploded [77];
-extern const int enemyExploded [77];
+
 
-extern const int introLineOne [893];
-extern const int introLineOneStars [156];
-extern const int introLineTwoShips [460];
-extern const int introLineTwo [330];
-extern const int introLineThree [1482];
-
-extern const int gameOverSprite [406];
-extern const int youDiedSprite [336];
-
-extern const int tutorialArrowRight[70];
-extern const int tutorialArrowLeft[70];
-
+/** @brief a function to put a sprite and its data in one variable.
+  * @details A struct that alows to create an object containing a sprite, its width and height.
+  * It is used with another function located in main.h. 
+  */
 struct Sprite {
     Sprite(int _width, int _height, const int* _data) : width(_width), height(_height), data(_data) {}
     int width;
@@ -35,18 +20,32 @@
     const int* data;
 };
 
-struct SpriteOnTop {
-    SpriteOnTop(int _width, int _height, const int* _data) : width(_width), height(_height), data(_data) {}
-    int width;
-    int height;
-    const int* data;
-};
+/** Sprite Objects to use for other files. */
 
-extern const Sprite enemy_sprite;
-extern const Sprite enemy_half_exploded_sprite;
-extern const Sprite enemy_exploded_sprite;
+// Enemy sprites.
+extern const Sprite enemy1_sprite;                  // NOT in use
+extern const Sprite enemy2_sprite;
+extern const Sprite enemy2_half_exploded_sprite;
+extern const Sprite enemy2_exploded_sprite;
+// Stars sprites.
 extern const Sprite small_star_sprite;
 extern const Sprite medium_star_sprite;
-extern const SpriteOnTop player_spaceship1_sprite;
+extern const Sprite big_star_sprite;                // NOT in use
+// Planet sprites.
+extern const Sprite planet1_sprite;
+// Intro sprites.
+extern const Sprite intro_line_one_sprite;
+extern const Sprite intro_line_one_stars_sprite;
+extern const Sprite intro_line_two_ships_sprite;
+extern const Sprite intro_line_two_sprite;
+extern const Sprite intro_line_three_sprite;
+// Game Over and You Died sprites.
+extern const Sprite game_over_sprite;
+extern const Sprite you_died_sprite;
+// Tutorial Arrows sprites.
+extern const Sprite tutorial_arrow_right_sprite;
+extern const Sprite tutorial_arrow_left_sprite;
+// Player sprites.
+extern const Sprite player_spaceship1_sprite;
 
 #endif
\ No newline at end of file
--- a/game/constants.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/game/constants.h	Mon Apr 15 12:59:51 2019 +0000
@@ -2,9 +2,9 @@
 #define CONSTANTS_H
 
 #include "N5110.h"
-/**@brief
-  * This file containts the constants that are used accross the whole game,
-  */
+/**
+ * This file containts the constants that are used accross the whole game,
+ */
 const int screen_width = WIDTH;
 const int screen_height = HEIGHT;    
 
--- 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() {
--- a/game/game.cpp	Wed Apr 10 15:42:10 2019 +0000
+++ b/game/game.cpp	Mon Apr 15 12:59:51 2019 +0000
@@ -14,17 +14,21 @@
 #include "player.h"
 #include "hud.h"
 
+// The speed of every counter is 1Hz
 bool game_over = true;
 int game_score;
 int high_score = 0;
 int score_count_for_difficulty;
 int player_lifes = 3;
+int low_frequency_music_counter = 0;
+int high_frequency_music_counter = 0;
 bool red_led_state;
 int red_led_flashing;
 int enemy_ship_delay_counter;
 
 const int increase_difficulty = 50;
 int enemy_ship_delay_max = 40;
+bool led_state = false;
 
 Enemies enemies;
 Stars stars;
@@ -34,6 +38,57 @@
 Hud hud;
 
 /**@brief
+    * This is the main function of game.cpp, where the actual gameplay happens.
+    * Here all other functions are activeated, and when the player dies, it
+    * returns back to main menu "main.cpp". 
+    */
+bool Game::updateAndDraw() {
+    printf("update \n");
+    if (game_over) {
+        printf("start game \n");
+        startNewGame();
+    }
+    if (gamepad.check_event(gamepad.X_PRESSED)){
+        // Checking the button second time to prevent double blast.
+        gamepad.check_event(gamepad.X_PRESSED); 
+        playerShip.fireNewBlast();
+        gamepad.tone(200,0.1);
+    }
+    playerShip.playerShipMovement();
+    stars.starsSpawnDelay();
+    increaseGameDifficultyAndEnemySpawnDelay();
+    hud.displayLifes();
+    playerShip.updateAndDrawBlasts();
+    stars.updateAndDrawSmallStars();
+    stars.updateAndDrawMediumStars();
+    enemies.updateAndDrawEnemies();
+    collideEnemiesAndBlasts();
+    collideEnemiesBlastsAndPlayer();
+    collideEnemiesAndPlayer();
+    enemies.updateAndDrawEnemyBlasts();
+    hud.drawScore();
+    
+    /**@brief
+        * This small statment checks whether the pause button was pressed or not.
+        * If it was pressed, then the game will go back to main menu and will save 
+        * the current status of the object until the game is continued.
+        */
+    bool want_to_pause = false;
+    game_over = checkForGameOver();
+    if (game_over){
+        printf("game over happened\n");
+        gameOver();
+        want_to_pause = true;
+    }
+    if (gamepad.check_event(gamepad.START_PRESSED)){
+        printf("pausing the game\n");
+        gamepad.check_event(gamepad.START_PRESSED);
+        want_to_pause = true;
+    }
+    return want_to_pause;
+}
+
+/**@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
@@ -51,6 +106,7 @@
                 );
                 if (collision) {
                     enemy.die();
+                    printf("enemy got hit and dies from blast");
                     game_score += 30;
                     score_count_for_difficulty +=30;
                     blast.active = false;
@@ -76,11 +132,9 @@
                 blast.pos, enemies.enemy_blast_bounds
             );
             if (collision) {
-                gamepad.tone(87,0.3);
-                gamepad.tone(287,0.2);
-                gamepad.tone(423,0.4);
-                printf("lost a life. left: %i \n", player_lifes);
+                gamepad.tone(423,0.4); 
                 player_lifes -= 1;
+                printf("lost a life from blst. left: %i \n", player_lifes);
                 blast.active = false;
             }
         }
@@ -101,7 +155,9 @@
             );
             if (collision) {
                 player_lifes -= 1;
+                printf("lost a life from enemy col. left: %i \n", player_lifes);
                 enemy.die();
+                printf("enemy got hit from collsion and dies");
             }
         }
     } 
@@ -139,9 +195,9 @@
     for (int i = 0; i < max_enemy_blasts; ++i) {
         enemies.enemy_blasts[i].active = false;
     }
-        //Reset start button event
-    gamepad.check_event(gamepad.START_PRESSED);
-
+        //Reset start and Y button event to avoid errors
+        gamepad.check_event(gamepad.START_PRESSED);
+        gamepad.check_event(gamepad.Y_PRESSED);
 }
 
 /**@brief
@@ -157,22 +213,18 @@
     lcd.printString("Press Y",0,4);
     lcd.printString("to restart",0,5);
     lcd.refresh();
-    bool led_state = false;
-    while (!gamepad.check_event(gamepad.Y_PRESSED)){//////////////////////////////
-        gamepad.led(1,(float)led_state);
-        gamepad.led(2,(float)!led_state);
-        gamepad.led(3,(float)led_state);
-        gamepad.led(4,(float)!led_state);
-        gamepad.led(5,(float)led_state);
-        gamepad.led(6,(float)!led_state);
-        wait(0.5);
-        led_state = !led_state;
+    gamepad.check_event(gamepad.START_PRESSED);
+    while (!gamepad.check_event(gamepad.Y_PRESSED)){/////////////////////////////////
+        musicGameOver();
+        ledsGameOver();
     }
 }
 
 /**@brief
     * A function tbat delays enemy spawn on low game score.
     * It decreases the enemy spawn delay as in game score increases.
+    * The enemy spawn delay is located in game.cpp because the game difficulty
+    * depends on the on how fast enemy appears.
     */
 void Game::increaseGameDifficultyAndEnemySpawnDelay(){
     if  (enemy_ship_delay_counter <= 0){ 
@@ -182,8 +234,8 @@
     else { enemy_ship_delay_counter -= 1;}
     
     if (enemy_ship_delay_max >= 4 && score_count_for_difficulty >= increase_difficulty){
+        //decrease enemy delay spawn.
         enemy_ship_delay_max -= 3;
-        
         if (enemy_ship_delay_max <= 20 && enemy_ship_delay_max >= 15){
             enemy_blast_speed += 1;
             enemy_speed += 1;   
@@ -193,70 +245,83 @@
 }
 
 /**@brief
-    * This is the main function of game.cpp, where the actual gameplay happens.
-    * Here all other functions are activeated, and when the player dies, it
-    * returns back to main menu "main.cpp". 
-    */
-bool Game::updateAndDraw() {
-    //printf("update \n");
-    if (game_over) {
-        printf("start game \n");
-        startNewGame();
-    }
-    
-    if (gamepad.check_event(gamepad.X_PRESSED)){
-        // Checking the button second time to prevent double blast.
-        gamepad.check_event(gamepad.X_PRESSED); 
-        playerShip.fireNewBlast();
-        gamepad.tone(200,0.1);
-    }
-    
-    playerShip.playerShipMovement();
-    stars.starsSpawnDelay();
-    increaseGameDifficultyAndEnemySpawnDelay();
-    hud.displayLifes();
-    playerShip.updateAndDrawBlasts();
-    stars.updateAndDrawSmallStars();
-    stars.updateAndDrawMediumStars();
-    enemies.updateAndDrawEnemies();
-    collideEnemiesAndBlasts();
-    collideEnemiesBlastsAndPlayer();
-    collideEnemiesAndPlayer();
-    enemies.updateAndDrawEnemyBlasts();
-    hud.drawScore();
-    
-    /**@brief
-        * This small statment checks whether the pause button was pressed or not.
-        * If it was pressed, then the game will go back to main menu and will save 
-        * the current status of the object until the game is continued.
-        */
-    bool want_to_pause = false;
-    game_over = checkForGameOver();
-    if (game_over){
-        printf("game over happened\n");
-        gameOver();
-        want_to_pause = true;
-    }
-    if (gamepad.check_event(gamepad.START_PRESSED)){
-        printf("pausing the game\n");
-        gamepad.check_event(gamepad.START_PRESSED);
-        want_to_pause = true;
-    }
-    return want_to_pause;
-}
-/**@brief
     * This is a single line function to set the player lifes to 0 when the.
     * game is over. 
     */
 bool Game::checkForGameOver() {
     return player_lifes == 0;
 }
+
+/**@brief
+    * A separate function that draws game over. */
 void Game::drawGameOver(){
     for (int i = 0; i < 42; i++){
+        musicGameOver();
         lcd.clear();
-        lcd.drawSprite(gameOverLogo.pos.x + i, gameOverLogo.pos.y, 14, 29, (int*)gameOverSprite);
-        lcd.drawSprite(youDied.pos.x - i, youDied.pos.y, 14, 24, (int*)youDiedSprite);
+        gameOverLogo.pos.x += 1;
+        youDied.pos.x -= 1;
+        drawSprite(gameOverLogo.pos, game_over_sprite);
+        drawSprite(youDied.pos, you_died_sprite);
         lcd.refresh();
         wait(0.1);
     } 
+}
+
+void Game::ledsGameOver(){
+    gamepad.led(1,(float)led_state);
+    gamepad.led(2,(float)!led_state);
+    gamepad.led(3,(float)led_state);
+    gamepad.led(4,(float)!led_state);
+    gamepad.led(5,(float)led_state);
+    gamepad.led(6,(float)!led_state);
+    wait(0.5);
+    led_state = !led_state;   
+}
+
+void Game::musicGameOver(){
+    lowFrequencyPartMusic();
+    highFrequencyPartMusic();
+    high_frequency_music_counter ++;
+    low_frequency_music_counter ++;       //remove this for epic game over beat.
+    printMusicCountersTest();
+}
+
+void Game::lowFrequencyPartMusic(){
+    // Low frequency            //
+    //60:1, 50:1, 40:1, 30:1, 40:0.5, 50:0.5, 40:0.5, 30:0.5, 40:1, 30:2 = 9s;
+    if (low_frequency_music_counter == 0){ gamepad.tone(60,3);}
+    else if (low_frequency_music_counter == 3){gamepad.tone(90,3);}
+    else if (low_frequency_music_counter == 6){gamepad.tone(60,3);}
+    else if (low_frequency_music_counter == 9){gamepad.tone(80,3);}
+    else if (low_frequency_music_counter == 12){gamepad.tone(70,2);}
+    else if (low_frequency_music_counter == 14){gamepad.tone(60,2);}
+    else if (low_frequency_music_counter == 16){gamepad.tone(70,3);}
+    else if (low_frequency_music_counter == 19){gamepad.tone(50,1);}
+    else if (low_frequency_music_counter == 20){gamepad.tone(40,3);}
+    else if (low_frequency_music_counter== 23){
+        gamepad.tone(60,2);
+        low_frequency_music_counter = 0;
+    } 
+}
+
+void Game::highFrequencyPartMusic(){
+    // High frequency
+    if ( high_frequency_music_counter == 0){ gamepad.tone(300,0.1);}
+    else if (high_frequency_music_counter == 3){gamepad.tone(250,0.1);}
+    else if (high_frequency_music_counter == 6){gamepad.tone(230,0.2);}
+    else if (high_frequency_music_counter == 9){gamepad.tone(250,0.1);}
+    else if ( high_frequency_music_counter == 12){gamepad.tone(250,0.2);}
+    else if ( high_frequency_music_counter == 14){gamepad.tone(220,0.1);}
+    else if ( high_frequency_music_counter == 16){gamepad.tone(210,0.3);}
+    else if ( high_frequency_music_counter == 19){gamepad.tone(200,1);}
+    else if ( high_frequency_music_counter == 21){gamepad.tone(250,1);}
+    else if ( high_frequency_music_counter == 22){
+        gamepad.tone(200,1);
+        high_frequency_music_counter = 0;
+    }
+}
+
+void Game::printMusicCountersTest(){
+    printf("Low frequency counter value:: %i\n", low_frequency_music_counter);
+    printf("high frequency counter value:: %i\n", high_frequency_music_counter);
 }
\ No newline at end of file
--- a/game/game.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/game/game.h	Mon Apr 15 12:59:51 2019 +0000
@@ -1,8 +1,7 @@
 #ifndef GAME_H
 #define GAME_H
 
-#include "geometry.h"
-
+/** This variable is used in game.cpp, enemy.h, player.h and hud.h*/
 extern int game_score;
 extern int score_count_for_difficulty;
 extern int player_lifes;
@@ -10,17 +9,25 @@
 extern int red_led_flashing;
 extern int high_score;
 
+/** Game Class
+ * @brief A library for drawing the game.
+ * @author Dmitrijs Griskovs
+ * @date 15/04/2019
+ */
 class Game{
 public:
-/**   This is the main function of game.cpp, where the actual gameplay happens.
-    * Here all other functions are activeated, and when the player dies, it
-    * returns back to main menu "main.cpp". 
-    */
+/** @brief The main game function where all the gamplay happens.
+ * @details This is the main function of game.cpp, where the actual gameplay happens.
+ * Here all other functions are activeated, and when the player dies, it
+ * returns back to main menu "main.cpp".
+ * @returns bool want_to_pause, when "START" butto nis pressed.
+ */
     bool updateAndDraw();
-/** This function resets all the values to their intial states when the game is
-    * first began when the player dies and wants to restart the game.
-    * It does not reset the values when the game is paused.
-    */  
+/** @brief Resets all the in game variable when new game begins.
+ * @details This function resets all the values to their intial states when 
+ * the game is first began when the player dies and wants to restart the game.
+ * It does not reset the values when the game is paused.
+ */  
     void startNewGame();
 private:
     bool checkForGameOver();
@@ -31,6 +38,11 @@
     void increaseGameDifficultyAndEnemySpawnDelay();
     void gameOver();
     void drawGameOver();
+    void ledsGameOver();
+    void musicGameOver();
+    void printMusicCountersTest();
+    void lowFrequencyPartMusic();
+    void highFrequencyPartMusic();
 };
 
 
--- a/game/gameobject.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/game/gameobject.h	Mon Apr 15 12:59:51 2019 +0000
@@ -4,10 +4,17 @@
 #include "geometry.h"
 
 /////////////////////////////////////////////////////////////////////
+/** GameObject Class
+ * @brief A library for a pointing the positions of x and y int pos.
+ * @author Dmitrijs Griskovs
+ * @date 15/04/2019
+ */
 class GameObject {
 public:
-/**This function assigns the position to the obejsts (sprites)
-  */
+/** @brief This function assigns the position to the objects (sprites), using 
+ * using Point structure.
+ * @param spawn_pos sets position of x and y into pos (Point).
+ */
     void spawn(Point spawn_pos) {
         pos = spawn_pos;
         active = true;
@@ -15,5 +22,4 @@
     Point pos;
     bool active;
 };
-
 #endif
\ No newline at end of file
--- a/game/geometry.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/game/geometry.h	Mon Apr 15 12:59:51 2019 +0000
@@ -2,10 +2,15 @@
 #define GEOMETRY_H
 
 #include <math.h>
-////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/**
+ * A structure to represent the positions of sprites 
+ */
 struct Point {
-    int x;
-    int y;
+    /*@{*/
+    int x; /**< the x position */
+    int y; /**< the y position */
     Point() : x(0), y(0) {}
     Point(int _x, int _y) : x(_x), y(_y) {}
     
@@ -21,15 +26,32 @@
         return x * x + y * y;
     }
 };
-
+/** CicleBounds Class
+ * @brief A library for appointing the sprites' bounds.
+ * @author Dmitrijs Griskovs
+ * @date 15/04/2019
+ */
 class CircleBounds {
 public:
+///////////////////////////////////////////////////////////////////////////////////////
+    /** Constructor */
     CircleBounds() {};
     CircleBounds(Point _center, float _radius): center(_center), radius(_radius) {};
     Point center;
     float radius;
 };
-
+/** @brief a function that determines whether the two sprites have collided.
+ * @details the function takes in the position and the bounds (center and radius)
+ * two sprites (x and y positions and the circle area of a sprite) then performs the 
+ * pythagoras calaculation and returns a bool statment if there is an overlap
+ * in the circle area of two sprites.
+ *
+ * @param pos_a positon of x and y of first sprite. (const Point&).
+ * @param bounds_a center point and radius of the first sprite. (const CircleBounds&).
+ * @param pos_b positon of x and y of second sprite. (const Point&).
+ * @param bounds_b center point and radius of the second sprite. (const CircleBounds&).
+ * @return difference.lengthSquared() if the areas of two sprites overlap, it will return true.
+ */
 inline bool circleCollideTwoObjects(
     const Point& pos_a, const CircleBounds& bounds_a, 
     const Point& pos_b, const CircleBounds& bounds_b
@@ -40,6 +62,4 @@
     return difference.lengthSquared() <= pow(bounds_a.radius + bounds_b.radius, 2);
 }
 
-
-
 #endif
\ No newline at end of file
--- a/game/hud.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/game/hud.h	Mon Apr 15 12:59:51 2019 +0000
@@ -3,30 +3,34 @@
 
 #include "game.h"
 
+/**Hud Class
+ * @brief A library for describing the player's heads up display(hud).
+ * @author Dmitrijs Griskovs
+ * @date 15/04/2019
+ */
 class Hud {
 
 public:
-/** Draws an in-game score on the screen.  
-  */
+/** @brief Draws an in-game score on the screen during the gameplay. */
     void drawScore(){
         char buffer[16];
         sprintf(buffer," Score: %i",game_score);
         lcd.printString(buffer,0,0);    
     }
-    
+/**@brief Displays the highest score reached in the main menu. */
     void drawHighScore(){
         if (high_score < game_score){
             high_score = game_score;
         }
-    //Displays the highest score reached.
     char buffer[16];
     sprintf(buffer,"High Score %i",high_score);
     lcd.printString(buffer,0,0);
     }
      
-/** Cheks the palyer's life value and lights the LEDs on/off accordingly to
-  * how many lifes are left. 
-  */
+/** @brief mointors, updates and shows the player's lives
+ * @details Checks the palyer's life value and lights the LEDs on/off accordingly to
+ * how many lifes are left. green = 3, yellow = 2 and red = 1.
+ */
     void displayLifes(){
         //printf("displayLifes:: %i\n", player_lifes);
         if (player_lifes == 3){
@@ -69,7 +73,6 @@
             red_led_state = !red_led_state;
         }        
         red_led_flashing += 1;
-        
     }
 };
 
--- a/game/player.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/game/player.h	Mon Apr 15 12:59:51 2019 +0000
@@ -6,19 +6,25 @@
 
 const int max_player_blasts = 5;
 const int ship_speed = 2;
+const int blast_speed = 5;
 
 GameObject blasts[max_player_blasts];
 GameObject player;
 CircleBounds player_bounds;
 CircleBounds blast_bounds;
 
-
+/**Player Class
+ * @brief A library for describing the player's ship.
+ * @author Dmitrijs Griskovs
+ * @date 15/04/2019
+ */
 class Player{
 public:
 
-/** A constructor for the palyer's sprite body circle area and the blast circle 
-  * area. It sets the circle radius for collsion callculations.
-  */
+/** @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 = 7;
@@ -28,18 +34,20 @@
     blast_bounds.center.y = 1;
     blast_bounds.radius = 1;
 }
-   /** Will move every active blast to the left with blast speed.
-     * Will deactivate blasts when they live screen, for future reuse.
-     */
+/** @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() {
-        const int blast_speed = 5;
         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 -= 50;
+                    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);
@@ -47,11 +55,12 @@
             }
         }
     }
-        
-    /** 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.
-      */
+    
+/** @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.
         int found = -1;
@@ -60,18 +69,19 @@
                 found = i;
                 break;
             }
-        }
-        
+        }   
         if (found != -1) {
             blasts[found].active = true;
             blasts[found].pos.x = player.pos.x + spaceship1_width;
             blasts[found].pos.y = player.pos.y + (spaceship1_height/2);
         }
-    }    
-    /** 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). 
-      */
+    }
+        
+/** @brief Updates and draws player's ship 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). 
+ */
     void playerShipMovement(){
         if(x_dir.read() > joy_threshold_max_x){
            player.pos.x -= ship_speed;
@@ -86,12 +96,12 @@
            player.pos.y += ship_speed; 
         }
         shipMovementLimits();
-        drawSpriteOnTop(player.pos, player_spaceship1_sprite);
+        drawSprite(player.pos, player_spaceship1_sprite);
     }
 private:
 /** Prevents the player's ship to go beyond the playing zone limits.*/
     void shipMovementLimits(){
-        //Limits player ship on screen
+        // Limits player ship on screen
         if (player.pos.x < game_area_x){ player.pos.x = game_area_x;}     
         if (player.pos.y < game_area_y) { player.pos.y = game_area_y;}
         int max_player_x = game_area_x + game_area_width - spaceship1_width;
--- a/game/stars.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/game/stars.h	Mon Apr 15 12:59:51 2019 +0000
@@ -8,15 +8,21 @@
 const int stars_delay_max = 5;
 int stars_delay;
 
+/**Stars Class
+ * @brief A library for describing the background stars.
+ * @author Dmitrijs Griskovs
+ * @date 15/04/2019
+ */
 class Stars {
 public:
     GameObject small_stars[max_small_stars];
     GameObject medium_stars[max_medium_stars];
     
-  /** Searches through the small stars array and if a star is not active,
-    * it becomes active and is given the position of x (which is 0) and.
-    * and random position of y.
-    */
+/** @brief Makes a small star active and gives it the start positions.
+ * @details Searches through the small stars array and if a star is not active,
+ * it becomes active and is given the position of x (which is 0) and.
+ * and random position of y.
+ */
     void newSmallStarFlies() {
         // Search the array of stars if inactive we can use it. - the same as with blasts
         int found = -1;
@@ -33,26 +39,27 @@
             small_stars[found].pos.y = rand() % screen_height + game_area_y;
         }
     }
-/** when a small star is active, this function updates the position and draws it
-    * on the screen.
-    */
+/** @brief draws small stars on the screen.
+  * @details when a small star is active, this function updates the position and
+  * draws it on the screen. Also, When the star leaves the screen limits it
+  * deactivates the star for a new star to fly.
+  */
     void updateAndDrawSmallStars(){
         for (int i = 0; i < max_small_stars; ++i) {
             if (small_stars[i].active) {
                 small_stars[i].pos.x -= small_star_speed;
                 if (small_stars[i].pos.x <= 0){
                     small_stars[i].active = false;   
-                }
-                
+                }       
                 drawSprite(small_stars[i].pos, small_star_sprite);
             }
-        }
-        
+        }        
     }
-/** Searches through the medium stars array and if a star is not active,
-    * it becomes active and is given the position of x (which is 0) and.
-    * and random position of y.
-    */
+/** @brief Makes a medium star active and gives it the start positions. 
+  * @details Searches through the medium stars array and if a star is not active,
+  * it becomes active and is given the position of x (which is 0) and.
+  * and random position of y.
+  */
     void newMediumStarFlies() {
         // Search the array of stars if inactive we can use it. - the same as with blasts
         int found = -1;
@@ -62,16 +69,17 @@
                 break;
             }
         }
-        
         if (found != -1) {
             medium_stars[found].active = true;
             medium_stars[found].pos.x = screen_width;
             medium_stars[found].pos.y = rand() % screen_height + game_area_y;
         }
     }
-/** when a medium star is active, this function updates the position and draws it
-    * on the screen.
-    */
+/** @brief draws medium stars on the screen.
+ * @details when a medium star is active, this function updates the position and
+ * draws it on the screen. Also, When the star leaves the screen limits it
+ * deactivates the star for a new star to fly.
+ */
     void updateAndDrawMediumStars(){
         for (int i = 0; i < max_medium_stars; ++i) {
             if (medium_stars[i].active) {
@@ -84,7 +92,7 @@
         }
     }
     
-    /** A separate function for delaying the stars spawn time.*/
+/** @brief A separate function for delaying the stars spawn time.*/
     void starsSpawnDelay(){
         if  (stars_delay == stars_delay_max){ 
         //This is dealy between stars generation.
--- a/main/main.cpp	Wed Apr 10 15:42:10 2019 +0000
+++ b/main/main.cpp	Mon Apr 15 12:59:51 2019 +0000
@@ -18,11 +18,8 @@
 #include "gameobject.h"
 
 
-
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 
-Gamepad gamepad;
-
 AnalogIn pot(PTB2);
 AnalogIn x_dir(PTB11);
 AnalogIn y_dir(PTB10);
@@ -31,6 +28,7 @@
 Menu menu;
 Game game;
 Tutorial tutorial;
+Gamepad gamepad;
 
 GameObject lineOne;
 GameObject lineOneStars;
@@ -38,6 +36,7 @@
 GameObject lineTwoShips;
 GameObject lineThree;
 
+void setupIntroValues();
 void updateAndDrawIntroPartOne();
 void updateAndDrawIntroPartTwo();
 void introPartOneText();
@@ -45,6 +44,7 @@
 void pointer(int x, int y);
 void pointer_position(int menu_number);
 void ship_movement();
+void menuSelection();
 
 ScreenOption current_screen = ScreenOption_Menu;
 
@@ -53,40 +53,38 @@
 int main(){
     lcd.init();
     gamepad.init();
-    printf("Intro starts"); 
+    //printf("Intro starts\n"); 
     intro();
     srand(rand_y * 1000000);                            //Makeing the generated y position for the enemy to be trully random.
     
     while(1){                                           //Waiting for the option "start game" to be selected and for the button B to be pressed
         lcd.clear();
-        
-        if (current_screen == ScreenOption_Game) {
-            bool game_is_paused = game.updateAndDraw();
-            
-            if (game_is_paused) {
-                current_screen = ScreenOption_Menu;
-            }
-        } 
-        if (current_screen == ScreenOption_Tutorial) {
-            bool back_to_menu = tutorial.updateAndWriteTutorial();
-            
-            if (back_to_menu) {
-                current_screen = ScreenOption_Menu;
-            }
-        } 
-        else if (current_screen == ScreenOption_Menu) {
-            bool wantsToChangeScreen = menu.updateAndDraw();
-            if (wantsToChangeScreen) {
-                current_screen = menu.getCurrentScreenSelection();
-            }
-        }
-        
+        menuSelection();
         lcd.refresh();
         wait_ms(1000/fps);
     }
 }
 
 void intro(){
+    setupIntroValues();
+    int start_game_text_counter = 0;
+    updateAndDrawIntroPartOne();
+    updateAndDrawIntroPartTwo();
+    wait(1);
+    //Stop just a few pixels above the bottom screen border.
+    while (!gamepad.check_event(gamepad.START_PRESSED)){
+        lcd.clear();
+        introPartOneText();
+        if (start_game_text_counter >= 2){
+            lcd.printString("Press START",10,5);
+            if (start_game_text_counter == 4){start_game_text_counter = 0;}  
+        }
+        start_game_text_counter += 1;
+        lcd.refresh();          
+    }
+}
+
+void setupIntroValues(){
     lineOne.pos.x = -63;                                         // The width of the sprite.    
     lineOne.pos.y = 1;                                           // This just will be an intro for the game.//////////////////
     lineOneStars.pos.x = screen_width;
@@ -94,30 +92,14 @@
     
     lineTwo.pos.y = 15;
     lineTwo.pos.x = screen_width;
-    lineTwoShips.pos.x = -46;                                   // Starting position outside the screen limits, with the length of the sprite.
-    lineTwoShips.pos.y = 14;                                    // the height of the "The last One" and a few pixels for gaps. 
+    lineTwoShips.pos.x = -46;                 // Starting position outside the screen limits, with the length of the sprite.
+    lineTwoShips.pos.y = 14;                  // the height of the "The last One" and a few pixels for gaps. 
     
     lineThree.pos.x = 2;
-    lineThree.pos.y = screen_height;                       // Starting outside the screen limits on the botto - the screen's height + the sprite's height.
-    
-    int start_game_text_counter = 0;
+    lineThree.pos.y = screen_height;          // Starting outside the screen limits on the botto - the screen's height + the sprite's height.
     
-    updateAndDrawIntroPartOne();
-    updateAndDrawIntroPartTwo();
-    wait(1);
-    //Stop just a few pixels above the bottom screen border.
-    while (!gamepad.check_event(gamepad.START_PRESSED)){
-        lcd.clear();
-        introPartOneText();
-        if (start_game_text_counter == 2){
-            lcd.printString("Press START",10,5);
-            start_game_text_counter = 0;   
-        }
-        start_game_text_counter += 1;
-        lcd.refresh();          
-    }
-}
     
+}    
 
 void updateAndDrawIntroPartOne(){
     // the width of the line one + 2.
@@ -127,7 +109,7 @@
         if (lineOneStars.pos.x > 70){ lineOneStars.pos.x  -= 1; }
         // to stop moving at the position of its width.
         if (lineTwo.pos.x > screen_width - 30){ lineTwo.pos.x -=1; }
-        if ( lineTwoShips.pos.x < 0){ lineTwoShips.pos.x += 1; }
+        if (lineTwoShips.pos.x < 0){ lineTwoShips.pos.x += 1; }
         
         introPartOneText();
         
@@ -141,8 +123,7 @@
         lcd.clear();
         lineThree.pos.y -= 1;
         introPartOneText();
-        lcd.drawSprite(lineThree.pos.x, lineThree.pos.y, 19, 78, (int*)introLineThree);
-        
+        drawSprite(lineThree.pos, intro_line_three_sprite);
         lcd.refresh();
         wait(0.1);
     } 
@@ -152,8 +133,30 @@
     * it is being called several times in this file
     */
 void introPartOneText(){
-    lcd.drawSprite(lineOne.pos.x, lineOne.pos.y, 11, 63, (int*)introLineOne);
-    lcd.drawSprite(lineOneStars.pos.x, lineOneStars.pos.y, 13, 12, (int*)introLineOneStars);
-    lcd.drawSprite(lineTwo.pos.x, lineTwo.pos.y, 11, 30, (int*)introLineTwo);
-    lcd.drawSprite(lineTwoShips.pos.x, lineTwoShips.pos.y, 10, 46, (int*)introLineTwoShips); 
+    drawSprite(lineOne.pos, intro_line_one_sprite);
+    drawSprite(lineOneStars.pos, intro_line_one_stars_sprite);
+    drawSprite(lineTwo.pos, intro_line_two_sprite);
+    drawSprite(lineTwoShips.pos, intro_line_two_ships_sprite); 
+}
+
+void menuSelection(){
+    if (current_screen == ScreenOption_Game) {
+        bool game_is_paused = game.updateAndDraw();
+        if (game_is_paused) {
+            current_screen = ScreenOption_Menu;
+        }
+    } 
+    if (current_screen == ScreenOption_Tutorial) {
+        bool back_to_menu = tutorial.updateAndWriteTutorial();
+        
+        if (back_to_menu) {
+            current_screen = ScreenOption_Menu;
+        }
+    } 
+    else if (current_screen == ScreenOption_Menu) {
+        bool wantsToChangeScreen = menu.updateAndDraw();
+        if (wantsToChangeScreen) {
+            current_screen = menu.getCurrentScreenSelection();
+        }
+    }
 }
\ No newline at end of file
--- a/main/main.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/main/main.h	Mon Apr 15 12:59:51 2019 +0000
@@ -8,8 +8,8 @@
 #include "models.h"
 
 /** Global variable readings from the gamepad are shared for all the files to
-  * use.
-  */
+ * use.
+ */
 extern N5110 lcd;
 extern Gamepad gamepad;
 extern AnalogIn pot;
@@ -18,21 +18,24 @@
 
 static const int fps = 10;
 
-/** This is a specific function I made to simplify drawing the sprites.
-    * It only works with spawn() function in gameobject.h.
-    * The parameters for this function are given in the models.cpp for the
-    * sprites.
-    */
+/** @brief A simplified function to draw sprites.
+  * @details This is a specific function I made to simplify drawing the sprites.
+  * It only works with spawn() function in gameobject.h.
+  * The parameters for this function are given in the models.cpp for the
+  * sprites.
+  */
 static void drawSprite(Point pos, const Sprite& sprite) {
     lcd.drawSprite(pos.x, pos.y, sprite.height, sprite.width, (int*)sprite.data);
 }
 
-/** This is an exactly the same function as before, but for the drawing sprite
-    * function that draws the black pixels on top the white pixels when the 
-    * sprites overlap.
-    */
-static void drawSpriteOnTop(Point pos, const SpriteOnTop& spriteOnTop) {
-    lcd.drawSpriteOnTop(pos.x, pos.y, spriteOnTop.height, spriteOnTop.width, (int*)spriteOnTop.data);
+/** @brief A simplified function to draw sprites. But this draw black pixels on top of white pixels.
+  * @details This is an exactly the same function as before, but for the drawing
+  * sprite function that draws the black pixels on top the white pixels when the 
+  * sprites overlap.
+  */
+static void drawSpriteOnTop(Point pos, const Sprite& sprite) {
+    lcd.drawSpriteOnTop(pos.x, pos.y, sprite.height, sprite.width, (int*)sprite.data);
 }
 
+
 #endif
\ No newline at end of file
--- a/menu/menu.cpp	Wed Apr 10 15:42:10 2019 +0000
+++ b/menu/menu.cpp	Mon Apr 15 12:59:51 2019 +0000
@@ -9,6 +9,7 @@
 
 Hud highScore;
 
+//MAYBE CHANGE LATER ON.
 int cursor[84] = {
     0,0,0,0,1,0,0,0,0,0,1,1,
     0,0,1,1,1,1,0,0,0,1,0,0,
--- a/menu/menu.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/menu/menu.h	Mon Apr 15 12:59:51 2019 +0000
@@ -13,11 +13,12 @@
 
 class Menu {
     public:
-    /** A constructor for Menu*/
-        Menu();
-    /** Updates and draws menu input. Also, allows to select an option availabe   
-      * from the enum. It return "true" statment if the user picked a menu option.
-      */                            
+/** A constructor for the Menu*/
+        Menu();    
+/** brief@ Updates and Draws menu.
+  * details@ Updates and draws menu input. Also, allows to select an option availabe   
+  * from the enum. It return "true" statment if the user picked a menu option.
+  */                            
         bool updateAndDraw();  
 
         ScreenOption getCurrentScreenSelection(); 
--- a/tutorial/tutorial.cpp	Wed Apr 10 15:42:10 2019 +0000
+++ b/tutorial/tutorial.cpp	Mon Apr 15 12:59:51 2019 +0000
@@ -3,21 +3,58 @@
 #include "tutorial.h"
 #include "constants.h"
 #include "models.h"
+#include "gameobject.h"
 
 
-const int total_pages = 7;
-const float time_delay = 100;
 
 Tutorial::Tutorial() {                              
     current_page = 0;                     
 }                                          
 
+GameObject arrowLeft;
+GameObject arrowRight;
+
 /**@brief
   * This function just displays some strings of the dysplaye to tell the player
   * how to use the controls and what to do.
   */
 bool Tutorial::updateAndWriteTutorial(){
-    if(x_dir.read() > joy_threshold_max_x){
+    turnPages();
+    drawArrowsAndExitButton();
+    
+    if (current_page == 0){ tutorialPage0();}
+    else if (current_page == 1){ tutorialPage1();}
+    else if (current_page == 2){ tutorialPage2();}
+    else if (current_page == 3){ tutorialPage3();}
+    else if (current_page == 4){ tutorialPage4();}
+    else if (current_page == 5){ tutorialPage5();}
+    else if (current_page == 6){ tutorialPage6();}
+    
+    bool back_to_menu = false;    
+    if (gamepad.check_event(gamepad.B_PRESSED)){
+        gamepad.check_event(gamepad.B_PRESSED);
+        back_to_menu = true; 
+    }
+    return back_to_menu;   
+}
+
+void Tutorial::drawArrowsAndExitButton(){
+    char buffer[16];
+    sprintf(buffer,"page #%i", current_page);
+    lcd.printString(buffer,20,0);
+    
+    arrowLeft.pos.x = left_arrow_pos_x;
+    arrowLeft.pos.y = arrows_pos_y;
+    arrowRight.pos.x = right_arrow_pos_x;
+    arrowRight.pos.y = arrows_pos_y;
+  
+    drawSprite(arrowRight.pos, tutorial_arrow_right_sprite);
+    drawSprite(arrowLeft.pos, tutorial_arrow_left_sprite);
+    lcd.printString("Push B to Exit",0,5);
+}
+
+void Tutorial::turnPages(){
+     if(x_dir.read() > joy_threshold_max_x){
         current_page -= 1;
         wait_ms(time_delay);    
     } 
@@ -30,68 +67,49 @@
     }
     if (current_page >= total_pages) {
         current_page -= total_pages;
-    }
-    
-    
-    bool back_to_menu = false;
-    
-    if (current_page == 0){
+    }  
+}
+
+void Tutorial::tutorialPage0(){
     lcd.printString("X - shoot",0,1);
     lcd.printString("START - Pause",0,2);
     lcd.printString("JOYSTICK - is ",0,3);
     lcd.printString("ship movement",0,4);
-    }
-    
-    else if (current_page == 1){
+}
+
+void Tutorial::tutorialPage1(){
     lcd.printString("Evade enemy ",0,1);
     lcd.printString("shots and",0,2);
     lcd.printString("don't let ",0,3);
-    lcd.printString("them pass.",0,4);   
-    }
-    
-    else if (current_page == 2){
+    lcd.printString("them pass.",0,4);
+}
+
+void Tutorial::tutorialPage2(){
     lcd.printString("Your health is",0,1);
     lcd.printString("shown below",0,2);
     lcd.printString("the screen ",0,3);
-    lcd.printString("Its LEDs. ",0,4);
-    }
-    
-    else if (current_page == 3){
-    lcd.printString("Also. ",0,1);
+    lcd.printString("It's LEDs. ",0,4);
+}
+
+void Tutorial::tutorialPage3(){
     lcd.printString("Kill the ",5,2);
     lcd.printString("Enemies!!! ",10,3);
-    }
-    
-    else if (current_page == 4){
+}
+
+void Tutorial::tutorialPage4(){
     lcd.printString("foe died= 30",0,1);
     lcd.printString("miss shot= -10",0,2);
     lcd.printString("foe left= -50",0,3);
     lcd.printString("Be careful ",10,4);
-    }
-    
-    else if (current_page == 5){
+}
+
+void Tutorial::tutorialPage5(){
     lcd.printString("As your score",0,1);
     lcd.printString("increase, so ",0,2);
     lcd.printString("does the game ",0,3);
     lcd.printString("difficulty ",10,4);
-    }
-    
-    else if (current_page == 6){
+}
+
+void Tutorial::tutorialPage6(){
     lcd.printString("Good Luck!!! ",0,3);
-    }
-    
-    char buffer[1];
-    sprintf(buffer,"page #%i", current_page);
-    lcd.printString(buffer,20,0);  
-    
-    lcd.drawSpriteOnTop(right_arrow_pos_x, arrows_pos_y, 7, 10, (int *)tutorialArrowRight);
-    lcd.drawSpriteOnTop(left_arrow_pos_x, arrows_pos_y, 7, 10, (int *)tutorialArrowLeft);
-    lcd.printString("Push B to Exit",0,5);
-    
-    if (gamepad.check_event(gamepad.B_PRESSED)){
-        gamepad.check_event(gamepad.B_PRESSED);
-        back_to_menu = true; 
-    }
-    return back_to_menu;   
-        
-}   
\ No newline at end of file
+}
\ No newline at end of file
--- a/tutorial/tutorial.h	Wed Apr 10 15:42:10 2019 +0000
+++ b/tutorial/tutorial.h	Mon Apr 15 12:59:51 2019 +0000
@@ -4,18 +4,33 @@
 const int right_arrow_pos_x = 66;
 const int left_arrow_pos_x = 5;
 const int arrows_pos_y = 0;
+const int total_pages = 7;
+const float time_delay = 100;
 
+/**Tutorial Class
+  * @brief A library for describing the Tutorial.
+  * @author Dmitrijs Griskovs
+  * @date 15/04/2019
+*/
 class Tutorial{
     public:
-    /** A constructor for the Tutorial's page number*/
+/** A constructor for the Tutorial's page number*/
     Tutorial();
-  /** Updates and draws a text that explains the game rules and gameplay
+/** @brief Updates and draws a text that explains the game rules and gameplay
     */
     bool updateAndWriteTutorial();
     
     private:
     int current_page;
+    void drawArrowsAndExitButton();
+    void turnPages();
+    void tutorialPage0();
+    void tutorialPage1();
+    void tutorialPage2();
+    void tutorialPage3();
+    void tutorialPage4();
+    void tutorialPage5();
+    void tutorialPage6();
+    
 };
-
-
 #endif
\ No newline at end of file