This code contains the game Starship designed for the STM32F429i-DISC1 board. It requires a keyboard to play.

Dependencies:   Starship LCD_DISCO_F429ZI USBHost mbed

Dependents:   Starship

Files at this revision

API Documentation at this revision

Comitter:
Oshyrath
Date:
Fri Nov 17 02:23:33 2017 +0000
Parent:
0:c9afe145b57b
Commit message:
First Publish of the code.

Changed in this revision

BSP_DISCO_F429ZI.lib Show annotated file Show diff for this revision Revisions of this file
Bullet.c Show annotated file Show diff for this revision Revisions of this file
Bullet.h Show annotated file Show diff for this revision Revisions of this file
Constants.h Show annotated file Show diff for this revision Revisions of this file
Enemy.c Show annotated file Show diff for this revision Revisions of this file
Enemy.h Show annotated file Show diff for this revision Revisions of this file
Game.c Show annotated file Show diff for this revision Revisions of this file
Game.h Show annotated file Show diff for this revision Revisions of this file
Player.c Show annotated file Show diff for this revision Revisions of this file
Player.h Show annotated file Show diff for this revision Revisions of this file
PowerUp.c Show annotated file Show diff for this revision Revisions of this file
PowerUp.h Show annotated file Show diff for this revision Revisions of this file
RandomVar.c Show annotated file Show diff for this revision Revisions of this file
RandomVar.h Show annotated file Show diff for this revision Revisions of this file
USBHost.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/BSP_DISCO_F429ZI.lib	Sun Sep 17 17:05:27 2017 +0000
+++ b/BSP_DISCO_F429ZI.lib	Fri Nov 17 02:23:33 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/ST/code/BSP_DISCO_F429ZI/#2371382139dd
+https://os.mbed.com/users/Oshyrath/code/Starship/#2c2a847598bb
--- a/Bullet.c	Sun Sep 17 17:05:27 2017 +0000
+++ b/Bullet.c	Fri Nov 17 02:23:33 2017 +0000
@@ -1,5 +1,11 @@
 #include "Bullet.h"
-void addEnemyBullet(uint16_t x_pos, uint16_t y_pos)
+
+struct Bullet * enemyBulletPTR;
+struct Bullet * playerBulletPTR;
+int16_t enemyBulletCount;
+int16_t playerBulletCount;
+
+void addEnemyBullet(int16_t x_pos, int16_t y_pos)
 {
     struct Bullet * newBullet = (struct Bullet *) malloc(sizeof(struct Bullet));
     newBullet->x_pos = x_pos;
@@ -21,7 +27,7 @@
     tempNext->prev = newBullet;
     newBullet->next = tempNext;
 }
-void addPlayerBullet(uint16_t x_pos, uint16_t y_pos, uint16_t x_vel, uint16_t y_vel, uint8_t power)
+void addPlayerBullet(int16_t x_pos, int16_t y_pos, int16_t x_vel, int16_t y_vel, int8_t power, int8_t bomb)
 {
     struct Bullet * newBullet = (struct Bullet *) malloc(sizeof(struct Bullet));
     newBullet->x_pos = x_pos;
@@ -30,6 +36,7 @@
     newBullet->y_vel = y_vel;
     newBullet->powerShot = power;
     newBullet->isPlayerBullet = 1;
+    newBullet->isBombBullet = bomb;
     playerBulletCount++;
     if(playerBulletCount==1)
     {
@@ -51,7 +58,7 @@
         if(playerBulletCount <= 0)
             return;
         playerBulletCount--;
-        if(playerBulletCount == 1)
+        if(playerBulletCount == 0)
             playerBulletPTR = (struct Bullet *) 0;
         else
         {
@@ -66,7 +73,7 @@
         if(enemyBulletCount <= 0)
             return;
         enemyBulletCount--;
-        if(enemyBulletCount == 1)
+        if(enemyBulletCount == 0)
             enemyBulletPTR = (struct Bullet *) 0;
         else
         {
@@ -112,6 +119,12 @@
     int yp = bullet->y_pos;
     if(bullet->isPlayerBullet)
     {
+        if(!(bullet->isBombBullet))
+        {
+            if(yp <= -BULLET_SIZE)
+                removeBullet(bullet);
+            return;
+        }
         if((xp <= -BULLET_SIZE)||(xp>=LCD_WIDTH)||(yp <= -BULLET_SIZE)||(yp>=LCD_HEIGHT))
             removeBullet(bullet);
     }  
@@ -137,6 +150,6 @@
 }
 void callMultiFuncBullet()
 {
+    removeBulletIfOOB_ALL();   
     bulletMovement_ALL();
-    removeBulletIfOOB_ALL();
 }
\ No newline at end of file
--- a/Bullet.h	Sun Sep 17 17:05:27 2017 +0000
+++ b/Bullet.h	Fri Nov 17 02:23:33 2017 +0000
@@ -7,33 +7,30 @@
 {
     struct Bullet * prev;
     struct Bullet * next;
-    uint16_t x_pos;
-    uint16_t y_pos;
-    uint16_t x_vel;
-    uint16_t y_vel;
-    uint8_t powerShot;
-    uint8_t isPlayerBullet;
+    int16_t x_pos;
+    int16_t y_pos;
+    int16_t x_vel;
+    int16_t y_vel;
+    int8_t powerShot;
+    int8_t isPlayerBullet;
+    int8_t isBombBullet;
 };
 
-static struct Bullet * enemyBulletPTR;
-static struct Bullet * playerBulletPTR;
-static uint16_t enemyBulletCount;
-static uint16_t playerBulletCount;
-
+extern struct Bullet * enemyBulletPTR;
+extern struct Bullet * playerBulletPTR;
+extern int16_t enemyBulletCount;
+extern int16_t playerBulletCount;
 
-//Across the board
-void addEnemyBullet(uint16_t x_pos, uint16_t y_pos);//---------------------------------------------------MAIN CARES!!!
-void addPlayerBullet(uint16_t x_pos, uint16_t y_pos, uint16_t x_vel, uint16_t y_vel, uint8_t power); //--MAIN CARES!!!
+//User interface functions.
+void addEnemyBullet(int16_t x_pos, int16_t y_pos);
+void addPlayerBullet(int16_t x_pos, int16_t y_pos, int16_t x_vel, int16_t y_vel, int8_t power, int8_t bomb);
+void clearBullets();
+void callMultiFuncBullet();
 void removeBullet(struct Bullet * bullet);
-void clearBullets();//-----------------------------------------------------------------------------------MAIN CARES!!!
 
-//Specific to 1 Bullet
+//Functions user does not need to worry about.
 void bulletMovement(struct Bullet * bullet);
 void bulletMovement_ALL();
 void removeBulletIfOOB(struct Bullet * bullet);
 void removeBulletIfOOB_ALL(); 
-
-//Call functions noramlly called in the loop without parameters.
-void callMultiFuncBullet();//------------------------------------------------------------MAIN CARES!!!
-
 #endif
\ No newline at end of file
--- a/Constants.h	Sun Sep 17 17:05:27 2017 +0000
+++ b/Constants.h	Fri Nov 17 02:23:33 2017 +0000
@@ -1,23 +1,62 @@
 #ifndef __CONSTS
 #define __CONSTS
-//LCD Size
-#define LCD_WIDTH 272
-#define LCD_HEIGHT 480
+//LCD SIZE
+#define LCD_WIDTH 240
+#define LCD_HEIGHT 320
 //ENEMY
-#define ENEMY_WIDTH 4
-#define ENEMY_HEIGHT 4
+#define ENEMY_WIDTH 20
+#define ENEMY_HEIGHT 30
 #define FREEZE_TIME 40
-#define ENEMY_BULLET_WAIT_TIME 10
-#define X_ID 0
-#define Y_ID 1//DON'T delete
+#define ENEMY_BULLET_WAIT_TIME 40
+#define X_ID 1
+#define Y_ID 0//DON'T delete
+#define SLOWEST_ENEMY_X_VELOCITY 1
+#define SLOWEST_ENEMY_Y_VELOCITY 1
 //BULLET
 #define BULLET_SIZE 4
 #define DEFAULT_BULLET_SPEED 10
+//#define SPEED_FIRE_BULLET_SPEED (2*DEFAULT_BULLET_SPEED)
+#define POWER_BULLET_ID 1
+#define DEFAULT_BULLET_ID 0
+#define BOMB_BULLET_ID 1
+#define NOT_BOMB_ID 0
+#define NORMAL_BULLET_DAMAGE 1
+#define POWER_BULLET_DAMAGE 4
+#define WIDE_SHOT_X_VELOCITY_FACTOR 0.25 //Fraction of Bullet Speed.
+#define NUMBER_OF_BULLETS_PER_EXPLOSION 12
 //PLAYER
+#define DEFAULT_POWERUP_TIME 140
 #define PLAYER_WIDTH ENEMY_WIDTH
 #define PLAYER_HEIGHT ENEMY_HEIGHT
-#define PLAYER_VELOCITY 10
-#define SHIELD_TIME
-#define RAPID_FIRE_TIME
-#define WIDE_SHOT_TIME
+#define PLAYER_VELOCITY 11
+#define PLAYER_FIRE_PERIOD 4
+#define SHIELD_TIME 50
+#define RAPID_FIRE_TIME 30
+#define RFT_PERIOD 0
+#define WIDE_SHOT_TIME DEFAULT_POWERUP_TIME
+#define POWER_SHOT_TIME DEFAULT_POWERUP_TIME
+#define LEFT_DIR -1
+#define RIGHT_DIR 1
+#define UP_DIR -1
+#define DOWN_DIR 1
+#define NO_DIR 0
+#define PLAYER_STARTING_HEALTH 10
+//POWER UP
+#define POWER_UP_SIZE 20
+#define PROPABILITY_DROP_POWERUP 0.5
+#define POWER_UP_EXPERATION_TIME 110
+#define NUMBER_OF_POWER_UPS_TYPES 7
+//KEYS
+#define KEY_UP 82
+#define KEY_DOWN 81
+#define KEY_LEFT 80
+#define KEY_RIGHT 79
+#define KEY_FIRE 2
+#define KEY_START 40
+#define KEY_PAUSE 40
+//OTHER
+#define PI 3.14159265359
+#define STARTING_LIFE_TOTAL 5
+#define GAME_WAIT_TIME 0.05
+#define HEALTH_BAR_SIZE 4
 #endif
\ No newline at end of file
--- a/Enemy.c	Sun Sep 17 17:05:27 2017 +0000
+++ b/Enemy.c	Fri Nov 17 02:23:33 2017 +0000
@@ -1,15 +1,19 @@
 #include "Enemy.h"
 
-
+struct Enemy * enemyPTR;
+int16_t enemyCount;
 
-void addEnemy(uint16_t x_pos, uint16_t x_vel,uint16_t y_vel, uint16_t health)
+void addEnemy(int16_t x_pos, int16_t x_vel,int16_t y_vel, int16_t health)
 {
     struct Enemy * newEnemy = (struct Enemy *) malloc(sizeof(struct Enemy));
     newEnemy->x_pos = x_pos;
-    newEnemy->y_pos = -ENEMY_HEIGHT;
+    newEnemy->y_pos = 0;
     newEnemy->x_vel = x_vel;
     newEnemy->y_vel = y_vel;
     newEnemy->health = health;
+    newEnemy->maxHealth = health;
+    newEnemy->freezeTimer = 0;
+    newEnemy->gunTimer = 0;
     enemyCount++;
     if(enemyCount==1)
     {
@@ -29,7 +33,7 @@
     if(enemyCount <= 0)
         return;
     enemyCount--;
-    if(enemyCount == 1)
+    if(enemyCount == 0)
         enemyPTR = (struct Enemy *) 0;
     else
     {
@@ -54,9 +58,9 @@
         enemyPTR = enemyPTR->next;
     }
 }
-uint16_t getBulletPos(struct Enemy * enemy,uint8_t XOrY)
+int16_t getEnemyBulletPos(struct Enemy * enemy,int8_t XOrY)
 {
-    if(XOrY==X_ID)
+    if(XOrY)
         return enemy->x_pos+ENEMY_WIDTH/2-BULLET_SIZE/2;
     return enemy->y_pos+ENEMY_HEIGHT-BULLET_SIZE/2;
 }
@@ -64,7 +68,7 @@
 {
     if(enemy->freezeTimer)
         return;
-    if(enemy->x_pos + ENEMY_WIDTH >= LCD_WIDTH-ENEMY_WIDTH && enemy->x_vel>0)
+    if(enemy->x_pos + ENEMY_WIDTH >= LCD_WIDTH && enemy->x_vel>0)
         enemy->x_vel = -enemy->x_vel;
     else if(enemy->x_pos<=0 && enemy->x_vel<0)
         enemy->x_vel = -enemy->x_vel;
@@ -84,7 +88,7 @@
 void updateEnemyTimers(struct Enemy * enemy)
 {
     enemy->freezeTimer = enemy->freezeTimer ? (enemy->freezeTimer -1) : 0;
-    enemy->gunTimer = enemy->gunTimer ? (enemy->gunTimer  -1) : 0;
+    enemy->gunTimer = enemy->gunTimer ? (enemy->gunTimer  -1) : ENEMY_BULLET_WAIT_TIME ;
 }
 void updateEnemyTimers_ALL()
 {
@@ -97,7 +101,7 @@
 }
 void removeEnemyIfOOB(struct Enemy * enemy)
 {
-    if(enemy->x_pos>=LCD_HEIGHT)
+    if(enemy->y_pos>=LCD_HEIGHT)
         removeEnemy(enemy);
 }
 void removeEnemyIfOOB_ALL()
@@ -109,19 +113,19 @@
         removeEnemyIfOOB(enemyPTR);
     }
 }
-uint8_t dealDamage(struct Enemy * enemy, uint8_t damage)
+int8_t dealDamageToEnemy(struct Enemy * enemy, int8_t damage)
 {
-    enemy->health-=damage;
-    if(enemy->health<=0)
+    if(enemy->health<=damage)
     {
         removeEnemy(enemy);
         return 1;
     }
+    enemy->health-=damage;
     return 0;
 }
 void callMultiFuncEnemy()
 {
-    removeEnemyIfOOB_ALL();
-    updateEnemyTimers_ALL();
+    removeEnemyIfOOB_ALL();//DEBUG!!!
+    updateEnemyTimers_ALL();//DEBUG!!!
     enemyMovement_ALL();
 }
\ No newline at end of file
--- a/Enemy.h	Sun Sep 17 17:05:27 2017 +0000
+++ b/Enemy.h	Fri Nov 17 02:23:33 2017 +0000
@@ -7,35 +7,35 @@
 {
     struct Enemy * prev;
     struct Enemy * next;
-    uint16_t x_pos;
-    uint16_t y_pos;
-    uint16_t x_vel;
-    uint16_t y_vel;
-    uint16_t health;
-    uint16_t freezeTimer;
-    uint16_t gunTimer;
+    int16_t x_pos;
+    int16_t y_pos;
+    int16_t x_vel;
+    int16_t y_vel;
+    int16_t health;
+    int16_t maxHealth;
+    int16_t freezeTimer;
+    int16_t gunTimer;
 };
 
-static struct Enemy * enemyPTR;
-static uint16_t enemyCount;
+extern struct Enemy * enemyPTR;
+extern int16_t enemyCount;
 
-//Across the board
-void addEnemy(uint16_t x_pos, uint16_t x_vel,uint16_t y_vel, uint16_t health); //--MAIN CARES!!!
+//User interface functions.
+void addEnemy(int16_t x_pos, int16_t x_vel,int16_t y_vel, int16_t health);
+void clearEnemies(); 
+void freezeEnemies();
+int16_t getEnemyBulletPos(struct Enemy * enemy,int8_t XOrY);
+int8_t dealDamageToEnemy(struct Enemy * enemy, int8_t damage);
+void callMultiFuncEnemy();
+
+//Functions user does not need to worry about.
 void removeEnemy(struct Enemy * removePTR); 
-void clearEnemies(); //------------------------------------------------------------MAIN CARES!!!
-void freezeEnemies();//------------------------------------------------------------MAIN CARES!!!
-uint16_t getBulletPos(struct Enemy * enemy,uint8_t XOrY);//------------------------------------------------------------MAIN CARES!!!
-
-//Specific to 1 Enemy
 void enemyMovement(struct Enemy * enemy);
 void enemyMovement_ALL();//mf
 void updateEnemyTimers(struct Enemy * enemy);
 void updateEnemyTimers_ALL();//mf
 void removeEnemyIfOOB(struct Enemy * enemy);
 void removeEnemyIfOOB_ALL(); //mf
-uint8_t dealDamage(struct Enemy * enemy, uint8_t damage);//------------------------MAIN CARES!!!
 
-//Call functions noramlly called in the loop without parameters.
-void callMultiFuncEnemy();//------------------------------------------------------------MAIN CARES!!!
 
 #endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game.c	Fri Nov 17 02:23:33 2017 +0000
@@ -0,0 +1,247 @@
+#include "Game.h"
+
+
+int16_t level;
+int16_t levelScore;
+int16_t totalScore;
+int16_t lives;
+int8_t  X_DIR;
+int8_t  Y_DIR;
+int8_t didUserRequestFire;
+
+void newGame()
+{
+    lives = STARTING_LIFE_TOTAL;   
+    level = 1;
+    levelScore = 0;
+    totalScore = 0;
+}
+void newLevel()
+{
+    X_DIR = NO_DIR;
+    Y_DIR = NO_DIR;
+    clearEnemies();
+    clearBullets();
+    resetPlayer();
+    clearPowerUps();
+    levelScore = 0;
+}
+char didLoseLife()
+{
+    return player.health ? 0 : 1;
+}
+char isGameOver()
+{
+    return lives ? 0 : 1;
+}
+int8_t shouldAddEnemy()
+{
+    return enemyCount<(level+2) ? 1 : 0;
+}
+void addRandomEnemy()
+{
+    int16_t x_pos = randomInt(0,LCD_WIDTH-ENEMY_WIDTH);
+    int8_t x_vel_var = level>=3 ? 3 : level;
+    int16_t x_vel = randomInt(-x_vel_var,x_vel_var)*SLOWEST_ENEMY_X_VELOCITY;
+    int8_t y_vel_var = level>=3 ? 3 : level;
+    int16_t y_vel = randomInt(1,y_vel_var)*SLOWEST_ENEMY_Y_VELOCITY;
+    int16_t health = randomInt(1,level);
+    addEnemy(x_pos,x_vel,y_vel,health);
+}
+char didLevelUp()
+{
+    if(levelScore>= level*4+6)
+        return 1;
+    return 0;
+}
+void callMultiFunc()
+{
+    callMultiFuncEnemy();
+    callMultiFuncBullet();
+    callMultiFuncPowerUp();//DEBUG!!!
+    callMultiFuncPlayer();//DEBUG!!!
+}
+void addWideShotBullets()
+{
+    int16_t xP = getPlayerBulletPos(X_ID);
+    int16_t yP = getPlayerBulletPos(Y_ID);
+    int16_t yV = -DEFAULT_BULLET_SPEED;    
+    int16_t xV_Right = (int16_t)(yV * WIDE_SHOT_X_VELOCITY_FACTOR);
+    int16_t xV_Left = -xV_Right;
+    int8_t powr = player.powerShotTimer ? POWER_BULLET_ID : DEFAULT_BULLET_ID;
+    addPlayerBullet(xP, yP, xV_Right, yV, powr, NOT_BOMB_ID);
+    addPlayerBullet(xP, yP, xV_Left, yV, powr, NOT_BOMB_ID);
+}
+
+void firePlayerBullet()
+{
+    player.gunTimer = PLAYER_FIRE_PERIOD;
+    int16_t xP = getPlayerBulletPos(X_ID);
+    int16_t yP = getPlayerBulletPos(Y_ID);
+    int16_t xV = 0;
+    int16_t yV = -DEFAULT_BULLET_SPEED;
+    int8_t powr = player.powerShotTimer ? POWER_BULLET_ID : DEFAULT_BULLET_ID;
+    addPlayerBullet(xP, yP, xV, yV, powr, NOT_BOMB_ID);
+    if(player.wideShotTimer)
+        addWideShotBullets();
+}
+int8_t didBulletHitEnemy(struct Enemy * enemy, struct Bullet * bullet)
+{
+    return !((bullet->y_pos>enemy->y_pos+ENEMY_HEIGHT)||
+        (bullet->y_pos+BULLET_SIZE<enemy->y_pos)||
+        (bullet->x_pos>enemy->x_pos+ENEMY_WIDTH)||
+        (bullet->x_pos+BULLET_SIZE<enemy->x_pos));
+ 
+}
+int8_t didBulletHitPlayer(struct Bullet * bullet)
+{
+    return !((bullet->y_pos>player.y_pos+PLAYER_HEIGHT)||
+        (bullet->y_pos+BULLET_SIZE<player.y_pos)||
+        (bullet->x_pos>player.x_pos+PLAYER_WIDTH)||
+        (bullet->x_pos+BULLET_SIZE<player.x_pos));  
+}
+int8_t didPlayerCollideWithEnemy(struct Enemy * enemy)
+{
+    return !((enemy->y_pos>player.y_pos+PLAYER_HEIGHT)||
+        (enemy->y_pos+ENEMY_HEIGHT<player.y_pos)||
+        (enemy->x_pos>player.x_pos+PLAYER_WIDTH)||
+        (enemy->x_pos+ENEMY_WIDTH<player.x_pos)) &&
+        !player.shieldTimer;  
+}
+void collideBulletsWithPlayer()
+{
+        int j;
+        for(j = enemyBulletCount; j;j--)
+        {
+            enemyBulletPTR=enemyBulletPTR->next;
+            if(didBulletHitPlayer(enemyBulletPTR))
+            {
+                dealDamageToPlayer();
+                removeBullet(enemyBulletPTR);
+            }
+        } 
+}
+void checkIfBulletsHitEnemies()
+{
+    int i;
+    for(i = enemyCount; i; i--)
+    {
+        enemyPTR = enemyPTR->next;
+        int j;
+        for(j = playerBulletCount; j;j--)
+        {
+            playerBulletPTR=playerBulletPTR->next;
+            if(didBulletHitEnemy(enemyPTR,playerBulletPTR))
+            {
+                int16_t PowUpPosX = enemyPTR->x_pos + ENEMY_WIDTH/2 - POWER_UP_SIZE/2;
+                int16_t PowUpPosY = enemyPTR->y_pos + ENEMY_HEIGHT/2 - POWER_UP_SIZE/2;
+                int8_t points = dealDamageToEnemy(enemyPTR,playerBulletPTR->powerShot ? POWER_BULLET_DAMAGE : NORMAL_BULLET_DAMAGE);
+                if(points && probabilityOfSuccess(PROPABILITY_DROP_POWERUP))
+                        addPowerUp(PowUpPosX,PowUpPosY);
+                levelScore+=points;
+                totalScore+=points;
+                removeBullet(playerBulletPTR);
+                if(points)
+                    break;
+            }
+        } 
+    }
+}
+void enemiesFireBullet()
+{
+    int i;
+    for(i = enemyCount; i; i--)
+    {
+        if(!(enemyPTR->gunTimer))
+            addEnemyBullet(getEnemyBulletPos(enemyPTR,X_ID),getEnemyBulletPos(enemyPTR,Y_ID));
+        enemyPTR = enemyPTR->next;
+    }
+}
+void generateExplosion()
+{
+    int16_t xP = getPlayerBulletPos(X_ID);
+    int16_t yP = getPlayerBulletPos(Y_ID);
+    int16_t i;
+    for(i = 0; i<NUMBER_OF_BULLETS_PER_EXPLOSION; i++)
+    {
+        double angle = PI * 2.0 /  NUMBER_OF_BULLETS_PER_EXPLOSION * i;
+        int16_t xV = (int16_t)(sin(angle)*DEFAULT_BULLET_SPEED);
+        int16_t yV = (int16_t)(cos(angle)*DEFAULT_BULLET_SPEED);
+        addPlayerBullet(xP, yP, xV, yV, POWER_BULLET_ID, BOMB_BULLET_ID);
+    }
+}
+void usePowerUpAbility(enum PowerUpType type)
+{
+    switch(type)
+    {
+            case PU_RapidFire:
+                player.rapidFireTimer = RAPID_FIRE_TIME;
+                return;
+            case PU_PowerShot:
+                player.powerShotTimer = POWER_SHOT_TIME;
+                return;
+            case PU_FreezeEnemies:
+                freezeEnemies();
+                return;
+            case PU_WideShot:
+                player.wideShotTimer = WIDE_SHOT_TIME;
+                return;
+            case PU_Explosion:
+                generateExplosion();
+                return;
+            case PU_BonusHealth:
+                player.health = PLAYER_STARTING_HEALTH;
+                return;
+            case PU_Shield:
+                player.shieldTimer = SHIELD_TIME;
+                return;                
+    }  
+}
+int8_t didPlayerHitPowerUp(struct PowerUp * powerUp)
+{
+    return !((powerUp->y_pos>player.y_pos+PLAYER_HEIGHT)||
+        (powerUp->y_pos+POWER_UP_SIZE<player.y_pos)||
+        (powerUp->x_pos>player.x_pos+PLAYER_WIDTH)||
+        (powerUp->x_pos+POWER_UP_SIZE<player.x_pos));    
+}
+void pickUpPowerUps()
+{
+    int i;
+    for(i = powerUpCount; i; i--)
+    {
+        powerUpPTR = powerUpPTR->next;
+        if(didPlayerHitPowerUp(powerUpPTR))
+        {   
+            usePowerUpAbility(powerUpPTR->type);
+            removePowerUp(powerUpPTR);  
+        }
+    }
+}
+void collideWithEnemies()
+{
+    int i;
+    for(i = enemyCount; i; i--)
+    {
+        enemyPTR = enemyPTR->next;
+        if(didPlayerCollideWithEnemy(enemyPTR))
+        {
+            player.health = 0;
+            break;
+        }
+    }
+}
+void loopIteration()
+{    
+        if(shouldFire(didUserRequestFire))
+            firePlayerBullet();
+        didUserRequestFire = 0;
+        if(shouldAddEnemy())
+            addRandomEnemy();
+        checkIfBulletsHitEnemies();
+        movePlayer(X_DIR,Y_DIR);
+        enemiesFireBullet();
+        pickUpPowerUps();
+        collideBulletsWithPlayer();
+        collideWithEnemies();
+        callMultiFunc();     
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game.h	Fri Nov 17 02:23:33 2017 +0000
@@ -0,0 +1,39 @@
+#ifndef __GAME
+#define __GAME
+#include "Enemy.h"
+#include "Bullet.h"
+#include "Player.h"
+#include "PowerUp.h"
+#include "RandomVar.h"
+#include <math.h>
+extern int16_t level;
+extern int16_t levelScore;
+extern int16_t totalScore;
+extern int16_t lives;
+extern int8_t  X_DIR;
+extern int8_t  Y_DIR;
+extern int8_t didUserRequestFire;
+
+void newGame();
+void newLevel();
+int8_t shouldAddEnemy();
+void addRandomEnemy();
+void addWideShotBullets();
+void callMultiFunc();
+int8_t didBulletHitEnemy(struct Enemy * enemy, struct Bullet * bullet);
+void checkIfBulletsHitEnemies();
+void enemiesFireBullet();
+void firePlayerBullet();
+void usePowerUpAbility();
+void generateExplosion();
+int8_t didPlayerHitPowerUp(struct PowerUp * powerUp);
+int8_t didBulletHitPlayer(struct Bullet * bullet);
+int8_t didPlayerCollideWithEnemy(struct Enemy * enemy);
+void collideBulletsWithPlayer();
+void collideWithEnemies();
+void pickUpPowerUps();
+void loopIteration();
+char didLoseLife();
+char isGameOver();
+char didLevelUp();
+#endif
\ No newline at end of file
--- a/Player.c	Sun Sep 17 17:05:27 2017 +0000
+++ b/Player.c	Fri Nov 17 02:23:33 2017 +0000
@@ -1,16 +1,34 @@
 #include "Player.h"
-void movePlayer(uint8_t x_vel, uint8_t y_vel)
+
+struct Player player;
+
+void resetPlayer()
 {
-    player.x_pos += x_vel;
-    player.y_pos -= y_vel;
+    player.x_pos = LCD_WIDTH/2-PLAYER_WIDTH/2;
+    player.y_pos = LCD_HEIGHT-PLAYER_HEIGHT-HEALTH_BAR_SIZE;
+    player.health = PLAYER_STARTING_HEALTH;
+    player.rapidFireTimer = 0;
+    player.powerShotTimer = 0;
+    player.wideShotTimer = 0;
+    player.shieldTimer = 0;
+    player.gunTimer = 0;
+    //player.fastMovementTimer = 0;
+    player.RFT_Timer = 0;
+    //player.speedFireTimer = 0;
+}
+void movePlayer(int8_t x_dir, int8_t y_dir)
+{
+    player.x_pos += PLAYER_VELOCITY * x_dir;
+    player.y_pos += PLAYER_VELOCITY * y_dir;
+    //}
     if(player.x_pos<=0)
         player.x_pos=0;
     else if(player.x_pos>=LCD_WIDTH-PLAYER_WIDTH)
         player.x_pos = LCD_WIDTH-PLAYER_WIDTH;
     if(player.y_pos<=0)
         player.y_pos = 0;
-    else if(player.y_pos>=LCD_HEIGHT-PLAYER_HEIGHT)
-        player.y_pos = LCD_HEIGHT-PLAYER_HEIGHT;
+    else if(player.y_pos>=LCD_HEIGHT-PLAYER_HEIGHT-HEALTH_BAR_SIZE)
+        player.y_pos = LCD_HEIGHT-PLAYER_HEIGHT-HEALTH_BAR_SIZE;
 }
 void updatePlayerTimers()
 {
@@ -19,4 +37,39 @@
     player.wideShotTimer = player.wideShotTimer ? player.wideShotTimer-1 : 0;
     player.shieldTimer = player.shieldTimer ? player.shieldTimer-1 : 0;
     player.gunTimer = player.gunTimer ? player.gunTimer-1 : 0;
-}
\ No newline at end of file
+    //player.fastMovementTimer = player.fastMovementTimer ? player.fastMovementTimer-1 : 0;
+    //player.speedFireTimer = player.speedFireTimer ? player.speedFireTimer-1 : 0;
+    player.RFT_Timer = player.RFT_Timer ? player.RFT_Timer-1 : RFT_PERIOD;
+}
+int16_t getPlayerBulletPos(int8_t XorY)
+{
+    if(XorY)
+        return player.x_pos+PLAYER_WIDTH/2-BULLET_SIZE/2;
+    return player.y_pos-BULLET_SIZE/2;
+}
+int8_t dealDamageToPlayer()
+{
+    if(player.shieldTimer)
+        return 0;
+    player.health--;
+    return !(player.health) ? 1 : 0;
+}
+int8_t shouldFire(int8_t didUserRequestFire)
+{
+    if(player.rapidFireTimer)
+    {
+        return !player.RFT_Timer ? 1 : 0;     
+    }
+    return !player.gunTimer && didUserRequestFire ? 1 : 0;
+}
+void callMultiFuncPlayer()
+{
+    updatePlayerTimers();
+}
+/*
+int8_t callMultiFuncPlayer(int8_t x_dir, int8_t y_dir, int8_t didUserRequestFire)
+{
+    movePlayer(x_dir,y_dir);
+    updatePlayerTimers();
+    return shouldFire(didUserRequestFire);
+}*/
\ No newline at end of file
--- a/Player.h	Sun Sep 17 17:05:27 2017 +0000
+++ b/Player.h	Fri Nov 17 02:23:33 2017 +0000
@@ -4,18 +4,30 @@
 #include "stdint.h"
 struct Player
 {
-    uint16_t x_pos;
-    uint16_t y_pos;
-    uint16_t health;
-    uint16_t rapidFireTimer;
-    uint16_t powerShotTimer;
-    uint16_t wideShotTimer;
-    uint16_t shieldTimer;
-    uint16_t gunTimer;
+    int16_t x_pos;
+    int16_t y_pos;
+    int16_t health;
+    int16_t rapidFireTimer;
+    int16_t RFT_Timer;
+    int16_t powerShotTimer;
+    int16_t wideShotTimer;
+    int16_t shieldTimer;
+    int16_t gunTimer;
 };
 
-static struct Player player;
+extern struct Player player;
 
-void movePlayer(uint8_t x_vel, uint8_t y_vel);
+//User interface functions.
+void resetPlayer();
+int16_t getPlayerBulletPos(int8_t XorY);
+int8_t dealDamageToPlayer();
+//int8_t callMultiFuncPlayer(int8_t x_dir, int8_t y_dir, int8_t didUserRequestFire);
+void callMultiFuncPlayer();
+void movePlayer(int8_t x_dir, int8_t y_dir);
+int8_t shouldFire(int8_t didUserRequestFire);
+
+//Functions user does not need to worry about.
+
 void updatePlayerTimers();
+
 #endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PowerUp.c	Fri Nov 17 02:23:33 2017 +0000
@@ -0,0 +1,95 @@
+#include "PowerUp.h"
+
+struct PowerUp * powerUpPTR;
+int16_t powerUpCount;
+
+enum PowerUpType getRandomType()//fix!!!
+{
+    int randVal = randomInt(0,NUMBER_OF_POWER_UPS_TYPES-1);
+    switch(randVal)
+    {
+        case 0: return PU_RapidFire;
+        case 1: return PU_PowerShot;
+        case 2: return PU_FreezeEnemies;
+        case 3: return PU_WideShot;
+        case 4: return PU_Explosion;
+        case 5: return PU_BonusHealth;
+        case 6: return PU_Shield;
+    }
+    return PU_BonusHealth;
+}
+void addPowerUp(int16_t x_pos, int16_t y_pos)
+{
+    struct PowerUp * newPowerUp = (struct PowerUp *) malloc(sizeof(struct PowerUp));
+    newPowerUp->x_pos = x_pos;
+    newPowerUp->y_pos = y_pos;
+    newPowerUp->type = getRandomType();
+    newPowerUp->expirationTimer = POWER_UP_EXPERATION_TIME;
+    powerUpCount++;
+    if(powerUpCount==1)
+    {
+        newPowerUp->prev = newPowerUp;
+        newPowerUp->next = newPowerUp;
+        powerUpPTR = newPowerUp;
+        return;
+    }
+    struct PowerUp * tempNext = powerUpPTR->next;
+    powerUpPTR->next = newPowerUp;
+    newPowerUp->prev = powerUpPTR;
+    tempNext->prev = newPowerUp;
+    newPowerUp->next = tempNext;
+}
+
+void removePowerUp(struct PowerUp * removePTR)
+{
+    if(powerUpCount<=0)
+        return;
+    powerUpCount--;
+    if(powerUpCount == 0)
+        powerUpPTR = (struct PowerUp *) 0;
+    else
+    {
+        powerUpPTR = removePTR->prev;
+        struct PowerUp * tempNext = removePTR->next;
+        powerUpPTR->next = tempNext;
+        tempNext->prev = powerUpPTR;
+    }
+    free(removePTR);
+}
+void clearPowerUps()
+{
+    while(powerUpCount)
+        removePowerUp(powerUpPTR);
+}
+void updatePowerUpTimer(struct PowerUp * powerUp)
+{
+    powerUp->expirationTimer = powerUp->expirationTimer ? (powerUp->expirationTimer - 1) : 0;
+}
+void updatePowerUpTimer_All()
+{
+    int i;
+    for(i = powerUpCount; i; i--)
+    {
+        updatePowerUpTimer(powerUpPTR);
+        powerUpPTR = powerUpPTR->next;
+    }
+}
+void removePowerUpIfExpired(struct PowerUp * powerUp)
+{
+    if(!(powerUp->expirationTimer))
+        removePowerUp(powerUp);
+}
+void removePowerUpIfExpired_All()
+{
+    int i;
+    for(i = powerUpCount; i; i--)
+    {
+        powerUpPTR = powerUpPTR->next;
+        removePowerUpIfExpired(powerUpPTR);
+    }
+}
+void callMultiFuncPowerUp()
+{
+    removePowerUpIfExpired_All();
+    updatePowerUpTimer_All();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PowerUp.h	Fri Nov 17 02:23:33 2017 +0000
@@ -0,0 +1,42 @@
+#ifndef __POWER_UP
+#define __POWER_UP
+#include "Constants.h"
+#include <stdint.h>
+enum PowerUpType
+{
+    PU_RapidFire,
+    PU_PowerShot,
+    PU_FreezeEnemies,
+    PU_WideShot,
+    PU_Explosion,
+    PU_BonusHealth,
+    PU_Shield
+    
+};
+
+struct PowerUp
+{
+    struct PowerUp * prev;
+    struct PowerUp * next;
+    int16_t x_pos;
+    int16_t y_pos;
+    enum PowerUpType type;
+    int expirationTimer;
+};
+
+extern struct PowerUp * powerUpPTR;
+extern int16_t powerUpCount;
+
+//User interface functions.
+void addPowerUp(int16_t x_pos, int16_t y_pos);
+void removePowerUp(struct PowerUp * powerUp);
+void clearPowerUps();
+void callMultiFuncPowerUp();
+
+//Functions user does not need to worry about.
+enum PowerUpType getRandomType();//-------------------------------------NEEDS RANDOM!!!
+void updatePowerUpTimer(struct PowerUp * powerUP);
+void updatePowerUpTimer_All();
+void removePowerUpIfExpired(struct PowerUp * powerUp);
+void removePowerUpIfExpired_All();
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RandomVar.c	Fri Nov 17 02:23:33 2017 +0000
@@ -0,0 +1,13 @@
+#include "RandomVar.h"
+int8_t probabilityOfSuccess(float prob)
+{
+    int randInt = rand();
+    float maxInt = RAND_MAX*prob;
+    return randInt<maxInt ? 1 : 0;
+}
+int randomInt(int min,int max)
+{
+    int range = max - min + 1;
+    int result = (int)((rand()/((float)RAND_MAX))*range) + min;
+    return result==max+1 ? max : result;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RandomVar.h	Fri Nov 17 02:23:33 2017 +0000
@@ -0,0 +1,7 @@
+#ifndef __RANDVAR
+#define __RANDVAR
+#include <stdlib.h>
+#include <stdint.h>
+int8_t probabilityOfSuccess(float prob);
+int randomInt(int min,int max);
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHost.lib	Fri Nov 17 02:23:33 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBHost/#7c3b59bb364e
--- a/main.cpp	Sun Sep 17 17:05:27 2017 +0000
+++ b/main.cpp	Fri Nov 17 02:23:33 2017 +0000
@@ -1,52 +1,358 @@
-#include "mbed.h"
-#include "LCD_DISCO_F429ZI.h"
-#include "Enemy.h"
+#include "main.h"
+LCD_DISCO_F429ZI lcd;
+DigitalOut led1(LED1);
+enum Stage stage;
+char pauseOrStartPressed;
+char scoreText[100];
+void onKey(uint8_t key,uint8_t mod) {//MODIFY THIS FUNC
+
+    didUserRequestFire = mod;
+    pauseOrStartPressed = 0;
+    switch(key)
+    {
+        case KEY_UP:
+            X_DIR = NO_DIR;
+            Y_DIR = UP_DIR;
+            break;
+        case KEY_DOWN:
+            X_DIR = NO_DIR;
+            Y_DIR = DOWN_DIR;
+            break;           
+        case KEY_LEFT:
+            X_DIR = LEFT_DIR;
+            Y_DIR = NO_DIR;
+            break;
+        case KEY_RIGHT:
+            X_DIR = RIGHT_DIR;
+            Y_DIR = NO_DIR;
+            break;
+        case KEY_START:
+            pauseOrStartPressed = 1;
+            break;
+    }
+}
+void keyboard_task(void const *) {
+    
+    USBHostKeyboard keyboard;
+    
+    while(1) {
+        while(!keyboard.connect())
+            Thread::wait(500);
+    
+      
+        keyboard.attach(onKey);
+        
+
+        while(keyboard.connected())
+            Thread::wait(500);
+    }
+}
+void drawHealthBar(int16_t xPos,int16_t yPos,float percentage)
+{
+        yPos += 2; 
+        int16_t width = (int16_t)(ENEMY_WIDTH*percentage);
+        int16_t height = HEALTH_BAR_SIZE-2;
+        lcd.SetTextColor(LCD_COLOR_RED);
+        lcd.FillRect(xPos, yPos, width, height);
+        lcd.FillRect(xPos, yPos, width, height);  
+}
+void drawPowerUps()
+{
+    int16_t radius = POWER_UP_SIZE/2;
+    int j;
+    for(j = powerUpCount; j;j--)
+    {
+            powerUpPTR=powerUpPTR->next;
+            switch(powerUpPTR->type)
+            {
+                case PU_RapidFire:
+                    lcd.SetTextColor(LCD_COLOR_ORANGE);
+                    break;
+                case PU_PowerShot:
+                    lcd.SetTextColor(LCD_COLOR_RED);
+                    break;
+                case PU_FreezeEnemies:
+                    lcd.SetTextColor(LCD_COLOR_LIGHTBLUE);
+                    break;
+                case PU_WideShot:
+                    lcd.SetTextColor(LCD_COLOR_PURPLE);
+                    break;
+                case PU_Explosion:
+                    lcd.SetTextColor(LCD_COLOR_YELLOW);
+                    break;
+                case PU_BonusHealth:
+                    lcd.SetTextColor(LCD_COLOR_GREEN);
+                    break;
+                case PU_Shield:
+                    lcd.SetTextColor(LCD_COLOR_WHITE);
+                    break;                
+            } 
+ 
+        int16_t xPos = powerUpPTR->x_pos+radius;
+        int16_t yPos = powerUpPTR->y_pos+radius;
+ 
+        lcd.FillCircle(xPos,yPos,radius);
+        lcd.FillCircle(xPos,yPos,radius);
+    }
+}
+void drawPlayerBullets()
+{
+    int j;
+    for(j = playerBulletCount; j;j--)
+    {
+        playerBulletPTR=playerBulletPTR->next;
+        int16_t xPos = playerBulletPTR->x_pos;
+        int16_t yPos = playerBulletPTR->y_pos;
+        int16_t width = BULLET_SIZE;
+        int16_t height = BULLET_SIZE;
+        if(playerBulletPTR->powerShot)
+            lcd.SetTextColor(LCD_COLOR_RED);
+        else
+            lcd.SetTextColor(LCD_COLOR_BLUE);
+        lcd.FillRect(xPos, yPos, width, height);
+        lcd.FillRect(xPos, yPos, width, height);
+    }
+}
+void drawEnemyBullets()
+{
+    int i;
+    for(i = enemyBulletCount; i;i--)
+    {
+        enemyBulletPTR = enemyBulletPTR->next;
+        int16_t xPos = enemyBulletPTR->x_pos;
+        int16_t yPos = enemyBulletPTR->y_pos;
+        int16_t width = BULLET_SIZE;
+        int16_t height = BULLET_SIZE;
+        lcd.SetTextColor(LCD_COLOR_GREEN);
+        lcd.FillRect(xPos, yPos, width, height);
+        lcd.FillRect(xPos, yPos, width, height);
+    }
+}
+void drawPlayer()
+{
 
-LCD_DISCO_F429ZI lcd;
+        
+        lcd.SetTextColor(LCD_COLOR_BLUE);
+        uint16_t x1 = player.x_pos;
+        uint16_t x2 = player.x_pos + PLAYER_WIDTH;
+        uint16_t x3 = player.x_pos + PLAYER_WIDTH/2;
+        uint16_t y1 = player.y_pos + PLAYER_HEIGHT;
+        uint16_t y2 = y1;
+        uint16_t y3 = player.y_pos;
+        if(player.shieldTimer)
+        {
+            lcd.SetTextColor(LCD_COLOR_WHITE);
+            int16_t radius = PLAYER_HEIGHT/2+6;
+            int16_t xPos = player.x_pos + PLAYER_WIDTH/2;
+            int16_t yPos = player.y_pos + PLAYER_HEIGHT/2+3;
+            if(yPos<radius)
+                radius = yPos;
+            lcd.FillCircle(xPos,yPos,radius);
+            lcd.FillCircle(xPos,yPos,radius);
+        }
+        lcd.SetTextColor(LCD_COLOR_BLUE);
+        lcd.FillTriangle(x1,x2,x3,y1,y2,y3);
+        lcd.FillTriangle(x1,x2,x3,y1,y2,y3);
+        int16_t xPos = player.x_pos;
+        int16_t yPos = player.y_pos;
+        drawHealthBar(xPos, yPos+PLAYER_HEIGHT,player.health/((float)PLAYER_STARTING_HEALTH));
+}
+void drawEnemies()
+{
+    lcd.SetTextColor(LCD_COLOR_GREEN);
+    int i;
+    for(i = enemyCount; i; i--)
+    {    
+        enemyPTR = enemyPTR->next;
+        int16_t xPos = enemyPTR->x_pos;
+        int16_t yPos = enemyPTR->y_pos;
+                
+        uint16_t x1 = enemyPTR->x_pos;
+        uint16_t x2 = enemyPTR->x_pos+ENEMY_WIDTH;
+        uint16_t x3 = enemyPTR->x_pos+ENEMY_WIDTH/2;
+        uint16_t y1 = enemyPTR->y_pos;
+        uint16_t y2 = y1;
+        uint16_t y3 = enemyPTR->y_pos+ENEMY_HEIGHT;
+        if(enemyPTR->freezeTimer)
+            lcd.SetTextColor(LCD_COLOR_LIGHTBLUE);
+        else
+            lcd.SetTextColor(LCD_COLOR_GREEN); 
+        lcd.FillTriangle(x1,x2,x3,y1,y2,y3);
+        lcd.FillTriangle(x1,x2,x3,y1,y2,y3);      
+        drawHealthBar(xPos, yPos+ENEMY_HEIGHT,enemyPTR->health/((float)enemyPTR->maxHealth));
+    } 
+}
+void drawBackground()
+{
+    lcd.clear(LCD_COLOR_BLACK);
+}
+void drawScore()
+{
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    sprintf(scoreText,"KILLS: %d/%d",levelScore,level*4+6);
+    lcd.DisplayStringAt(0, LINE(0), (uint8_t *) scoreText, CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(0), (uint8_t *) scoreText, CENTER_MODE);
+}
+void drawAll()
+{ 
+    drawBackground();
+    drawPowerUps();
+    drawEnemies();
+    drawEnemyBullets();
+    drawPlayer();
+    drawPlayerBullets();
+    drawScore();
+}
+void drawGameOver()
+{
+    drawBackground();
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "GAME OVER", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "GAME OVER", CENTER_MODE);
+    
+    lcd.DisplayStringAt(0, LINE(2), (uint8_t *) "TOTAL KILLS", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(2), (uint8_t *) "TOTAL KILLS", CENTER_MODE);
+    
+    sprintf(scoreText,"%d",totalScore);
+    lcd.DisplayStringAt(0, LINE(3), (uint8_t *) scoreText, CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(3), (uint8_t *) scoreText, CENTER_MODE);     
+}
+void drawLostLife()
+{
+    drawBackground();
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "LOST A LIFE", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "LOST A LIFE", CENTER_MODE);
+    
+    lcd.DisplayStringAt(0, LINE(2), (uint8_t *) "LIVES LEFT:", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(2), (uint8_t *) "LIVES LEFT:", CENTER_MODE);
+    
+    sprintf(scoreText,"%d",lives);
+    lcd.DisplayStringAt(0, LINE(3), (uint8_t *) scoreText, CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(3), (uint8_t *) scoreText, CENTER_MODE);      
+}
+void drawPause()
+{
+    drawBackground();
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "PAUSE", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "PAUSE", CENTER_MODE);     
+}
+void drawLevelUp()
+{
+    drawBackground();
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "LEVEL UP", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "LEVEL UP", CENTER_MODE);  
+}
+void drawStart()
+{
+    drawBackground();
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "PRESS ENTER", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *) "PRESS ENTER", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(2), (uint8_t *) "TO START", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(2), (uint8_t *) "TO START", CENTER_MODE);  
+}
+char checkPOSP()
+{
+    char ans = pauseOrStartPressed;
+    pauseOrStartPressed = 0;
+    return ans;
+}
+void startGame()
+{
+    newGame();
+    newLevel();
+    stage = Start;
+    pauseOrStartPressed = 0;
+    while(1)
+    {
+        switch(stage)
+        {
+            case Start:
+                drawStart();
+                if(checkPOSP())
+                {
+                    stage = Play;
+                    break;
+                }
+                wait(GAME_WAIT_TIME);
+                break;
+            case Play:
+                loopIteration();
+                drawAll();
+                if(checkPOSP())
+                {
+                    stage = Pause;
+                    break;
+                }
+                if(didLoseLife())
+                {
+                    lives--;
+                    stage = LostLife;
+                    newLevel();
+                    break;
+                }
+                if(didLevelUp())
+                {
+                    level++;
+                    newLevel();
+                    stage = NextLevel;
+                    break;
+                }
+                wait(GAME_WAIT_TIME);
+                break;            
+            case Pause:
+                drawPause();
+                if(checkPOSP())
+                {
+                    stage = Play;
+                    break;
+                }
+                wait(GAME_WAIT_TIME);
+                break;
+            case NextLevel:
+                drawLevelUp();
+                if(checkPOSP())
+                {
+                    stage = Play;
+                    break;
+                }
+                wait(GAME_WAIT_TIME);
+                break;
+            case LostLife:
+                drawLostLife();
+                if(isGameOver())
+                {
+                    stage = GameOver;
+                    newGame();
+                    newLevel();
+                    break;               
+                }
+                if(checkPOSP())
+                    stage = Play;
+                wait(GAME_WAIT_TIME);
+                break;
+            case GameOver:
+                drawGameOver();
+                if(checkPOSP())
+                    stage = Play;
+                wait(GAME_WAIT_TIME);
+                break;
+        }
 
-DigitalOut led1(LED1);
-
+    }    
+}
 int main()
 {      
     led1 = 1;
   
     BSP_LCD_SetFont(&Font20);
-    lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE);
-    wait(1);
-  
-    while(1)
-    {      
-      lcd.Clear(LCD_COLOR_BLUE);
-      lcd.SetBackColor(LCD_COLOR_BLUE);
-      lcd.SetTextColor(LCD_COLOR_WHITE);
-      wait(0.3);
-      lcd.DisplayStringAt(0, LINE(4), (uint8_t *)"DISCOVERY", CENTER_MODE);
-      lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"STM32F429ZI", CENTER_MODE);
-      wait(1);
+    Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 1024 * 4);
+    startGame();
 
-      lcd.Clear(LCD_COLOR_GREEN);
-      
-      lcd.SetTextColor(LCD_COLOR_BLUE);
-      lcd.FillRect(10, 20, 50, 50);
-      wait(0.1);
-      lcd.SetTextColor(LCD_COLOR_BROWN);
-      lcd.FillCircle(80, 80, 50);
-      wait(0.1);
-      lcd.SetTextColor(LCD_COLOR_YELLOW);
-      lcd.FillEllipse(150, 150, 50, 100);
-      wait(0.1);
-      lcd.SetTextColor(LCD_COLOR_RED);
-      lcd.FillCircle(200, 200, 40);
-      wait(1);
-
-      lcd.SetBackColor(LCD_COLOR_ORANGE);
-      lcd.SetTextColor(LCD_COLOR_CYAN);
-      BSP_LCD_SetFont(&Font24);
-      lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"HAVE FUN !!!", CENTER_MODE);
-      wait(1);
-
-      led1 = !led1;
-      wait(0.5);
-    }
 }
 
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Fri Nov 17 02:23:33 2017 +0000
@@ -0,0 +1,11 @@
+#ifndef __MAIN
+#define __MAIN
+extern "C"
+{
+#include "Game.h"
+}
+#include "mbed.h"
+#include "LCD_DISCO_F429ZI.h"
+#include "USBHostKeyboard.h"
+enum Stage{Start,Play,Pause,NextLevel,LostLife,GameOver};
+#endif
\ No newline at end of file