ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19zf

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
el19zf
Date:
Thu May 14 16:45:20 2020 +0000
Parent:
12:009895f6b6e4
Child:
14:42b8a91e463c
Commit message:
using Doxygen style to comment the code and debug some function;

Changed in this revision

Collision/Collision.cpp Show annotated file Show diff for this revision Revisions of this file
Collision/Collision.h Show annotated file Show diff for this revision Revisions of this file
Interface/Interface.cpp Show annotated file Show diff for this revision Revisions of this file
Interface/Interface.h Show annotated file Show diff for this revision Revisions of this file
PeopleEngine/People-test.h Show annotated file Show diff for this revision Revisions of this file
PeopleEngine/People.cpp Show annotated file Show diff for this revision Revisions of this file
PeopleEngine/People.h Show annotated file Show diff for this revision Revisions of this file
PeopleEngine/PeopleEngine.cpp Show annotated file Show diff for this revision Revisions of this file
PeopleEngine/PeopleEngine.h Show annotated file Show diff for this revision Revisions of this file
Sound/Sound.cpp Show annotated file Show diff for this revision Revisions of this file
Sound/Sound.h 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
shot/shot.cpp Show annotated file Show diff for this revision Revisions of this file
shot/shot.h Show annotated file Show diff for this revision Revisions of this file
--- a/Collision/Collision.cpp	Mon May 11 14:43:16 2020 +0000
+++ b/Collision/Collision.cpp	Thu May 14 16:45:20 2020 +0000
@@ -1,5 +1,15 @@
 #include "Collision.h"
 
+const int heart_sprite[7][9] = {
+    {0,1,1,0,0,0,1,1,0},
+    {1,1,1,1,0,1,1,1,1},
+    {1,1,1,1,1,1,1,1,1},
+    {0,1,1,1,1,1,1,1,0},
+    {0,0,1,1,1,1,1,0,0},
+    {0,0,0,1,1,1,0,0,0},
+    {0,0,0,0,1,0,0,0,0},
+};
+
 Collision::Collision() 
 {
     
@@ -21,16 +31,17 @@
 {
     _check_index = 0;
     //check every sprite set points
-    if(lcd.getPixel(_people_pos.x+1,_people_pos.y)) {  _check_index = 1; }
-    if(lcd.getPixel(_people_pos.x+2,_people_pos.y)) {  _check_index = 1; }
-    if(lcd.getPixel(_people_pos.x,_people_pos.y+1)) {  _check_index = 1; }
-    if(lcd.getPixel(_people_pos.x+1,_people_pos.y+1)) {  _check_index = 1; }
     if(lcd.getPixel(_people_pos.x+2,_people_pos.y+1)) {  _check_index = 1; }
-    if(lcd.getPixel(_people_pos.x+3,_people_pos.y+1)) {  _check_index = 1; }
-    if(lcd.getPixel(_people_pos.x+1,_people_pos.y+2)) {  _check_index = 1; }
+    if(lcd.getPixel(_people_pos.x+2,_people_pos.y+1)) {  _check_index = 1; }
     if(lcd.getPixel(_people_pos.x+2,_people_pos.y+2)) {  _check_index = 1; }
     if(lcd.getPixel(_people_pos.x+1,_people_pos.y+3)) {  _check_index = 1; }
     if(lcd.getPixel(_people_pos.x+2,_people_pos.y+3)) {  _check_index = 1; }
+    if(lcd.getPixel(_people_pos.x+3,_people_pos.y+3)) {  _check_index = 1; }
+    if(lcd.getPixel(_people_pos.x+2,_people_pos.y+4)) {  _check_index = 1; }
+    if(lcd.getPixel(_people_pos.x+1,_people_pos.y+5)) {  _check_index = 1; }
+    if(lcd.getPixel(_people_pos.x+1,_people_pos.y+5)) {  _check_index = 1; }
+    if(lcd.getPixel(_people_pos.x+1,_people_pos.y+6)) {  _check_index = 1; }
+    if(lcd.getPixel(_people_pos.x+1,_people_pos.y+6)) {  _check_index = 1; }
     //printf("index = %d\n",_check_index);
     //printf("people_pos = %f,%f\n",_people_pos.x+2,_people_pos.y+3);
     if((_check_index == 1)&&(_health > 0)) { 
@@ -60,6 +71,32 @@
         lcd.drawRect(1,1,_health*2,3,FILL_BLACK);
 }
 
+void Collision::draw_basic(N5110 &lcd)
+{   
+    lcd.printString("    HEALTH   ",0,0);
+    lcd.drawRect(1,10,WIDTH-2,3,FILL_BLACK);
+    lcd.drawRect(1,11,5,HEIGHT-10,FILL_BLACK);
+    lcd.drawRect(78,11,5,HEIGHT-10,FILL_BLACK);
+}
+void Collision::draw_collision(N5110 &lcd)
+{
+    lcd.clear();
+    draw_basic(lcd);
+    lcd.drawRect(1,1,(get_health()+1)*2,3,FILL_BLACK);
+    for(int i =0; i <get_health()+1;i++)
+        lcd.drawSprite(18*i+20,24,7,9,(int*)heart_sprite);
+    lcd.refresh();
+    wait(1);
+
+    lcd.clear();
+    draw_basic(lcd);
+    lcd.drawRect(1,1,get_health()*2,3,FILL_BLACK);
+    for(int i =0; i <get_health();i++)
+        lcd.drawSprite(18*i+20,24,7,9,(int*)heart_sprite);
+    lcd.refresh();
+    wait(1);
+}
+
 int Collision::get_health() 
 {
     return _health;
@@ -70,7 +107,17 @@
     return _check_des_index;
 }
 
+bool Collision::get_check_col()
+{
+    return _check_index;
+}
+
 void Collision::set_pos(Vector2D pos) 
 {
     _people_pos = pos;
 }
+
+void Collision::set_check_col()
+{
+    _check_index = 0;
+}
\ No newline at end of file
--- a/Collision/Collision.h	Mon May 11 14:43:16 2020 +0000
+++ b/Collision/Collision.h	Thu May 14 16:45:20 2020 +0000
@@ -16,24 +16,49 @@
 class Collision{
     
 public:    
-    Collision();//constructor
-    ~Collision();//destructor
+    /**constructor*/
+    Collision();
+    /**destructor*/
+    ~Collision();
+    
+    /**init health and index*/
+    void init();
     
-    //init
-    void init();
-    //check whether there is a collision
+    /**check whether there is a collision
+    *@return whether collide
+    */
     bool check(N5110 &lcd);
-    //check whether people reach destination
+    
+    /**check whether people reach destination
+    *@return whether reach destination
+    */
     bool check_des(N5110 &lcd);
     
+    /**draw current health at the left top of lcd*/
     void draw(N5110 &lcd);
-    //get health of people
+    
+    /**draw basic elements in collision interface*/
+    void draw_basic(N5110 &lcd);
+    
+    /**draw the collision interface to tell gamer health - 1*/
+    void draw_collision(N5110 &lcd);
+    
+    /**get health of people
+    *@return health of people
+    */
     int get_health();
     
+    /**get dex_index
+    *@return game informance 
+    */
     int get_des();
-    //accessors 
+    
+    bool get_check_col();
+    /**accessors*/
     void set_pos(Vector2D pos);
     
+    void set_check_col();
+    
 private:
     
     int _health;
--- a/Interface/Interface.cpp	Mon May 11 14:43:16 2020 +0000
+++ b/Interface/Interface.cpp	Thu May 14 16:45:20 2020 +0000
@@ -31,12 +31,16 @@
 
 void Interface::Welcome(N5110 &lcd,Gamepad &pad)
 {
-    lcd.printString("   Welcome!   ",0,1);
-    lcd.printString("   Game by    ",0,2);
-    lcd.printString("   Z. FENG    ",0,3);
-    lcd.refresh();
     while (!pad.start_pressed()) 
     {
+        lcd.clear();
+        lcd.printString("   Welcome!   ",0,1);
+        lcd.printString("   Game by    ",0,2);
+        lcd.printString("   Z. FENG    ",0,3);
+        lcd.setContrast( pad.read_pot1());
+        lcd.drawRect(0,44,int(pad.read_pot1()*WIDTH),2,FILL_BLACK);
+        //printf("WIDTH of contrast = %d, contrast = %f\n",(int)pad.read_pot1()*WIDTH,pad.read_pot1());
+        lcd.refresh();
         pad.leds_on();
         wait(0.1);
         pad.leds_off();
@@ -71,6 +75,7 @@
 void Interface::game_over(N5110 &lcd,Gamepad &pad)
 {
     lcd.clear();
+    pad.init();
     while(!pad.B_pressed()){
         lcd.printString("  Game over   ",0,1);
         lcd.printString("  Press B to  ",0,2);
@@ -101,7 +106,7 @@
 int Interface::count_down(N5110 &lcd,int count_flag)
 {
     char buffer[6];
-    sprintf(buffer,"%d",(int)count_flag/6);
+    sprintf(buffer,"%d",int(count_flag/6));
     lcd.printString(buffer,40,2);
     //printf("count: %d\n",count_flag);
     count_flag--;
@@ -111,6 +116,7 @@
 void Interface::exit(N5110 &lcd,Gamepad &pad)
 {
     lcd.clear();
+    pad.init();
     pad.leds_off();
     while(!pad.B_pressed()){
         lcd.printString(" Press B back ",0,2);
@@ -123,6 +129,7 @@
 void Interface::victory(N5110 &lcd,Gamepad &pad)
 {
     lcd.clear();
+    pad.init();
     while(!pad.B_pressed()){
         lcd.printString("   Victory!  ",0,1);
         lcd.printString(" Press B back ",0,2);
--- a/Interface/Interface.h	Mon May 11 14:43:16 2020 +0000
+++ b/Interface/Interface.h	Thu May 14 16:45:20 2020 +0000
@@ -6,10 +6,11 @@
 #include "N5110.h"
 
 /** Interface class
-    @welcome,meun,pause interface
-    @author Zeyu Feng
-    @10 MAY 2020
-   */
+*@welcome,meun,pause interface
+*@author Zeyu Feng
+*@10 MAY 2020
+*/
+/**struct of fsm for menu option*/
 struct State{
     int option;
     int next_state[2];
@@ -19,34 +20,36 @@
     
 public:
     
-    Interface();//Constructor
-        
-    ~Interface();//Destructor
+    /**Constructor*/
+    Interface();
+    
+    /**Destructor*/
+    ~Interface();
         
     void init();
         
-        //set a welcome interface for my game
+    /** set a welcome interface for my game*/
     void Welcome(N5110 &lcd,Gamepad &pad);
         
-        //set an option menu
+    /** set an option menu*/
     int menu(N5110 &lcd,Gamepad &pad,int option_flag);
         
-        //if health of people is zero, game over~
+    /** if health of people is zero, game over~*/
     void game_over(N5110 &lcd,Gamepad &pad);
         
-        //check pause for start botton
+    /** check pause for start botton*/
     int check_pause(N5110 &lcd,Gamepad &pad,int paused_flag);
         
-        //count down and draw in lcd
+    /** count down and draw in lcd*/
     int count_down(N5110 &lcd,int count_flag);
     
-        //Exit interface
+    /** Exit interface*/
     void exit(N5110 &lcd,Gamepad &pad);
         
-        //Victory interface
+    /** Victory interface*/
     void victory(N5110 &lcd,Gamepad &pad);
     
-        //make the game simple
+    /** make the game simple*/
     void simple_game(N5110 &lcd,Gamepad &pad);
     
     int get_sim_flag();
--- a/PeopleEngine/People-test.h	Mon May 11 14:43:16 2020 +0000
+++ b/PeopleEngine/People-test.h	Thu May 14 16:45:20 2020 +0000
@@ -20,17 +20,17 @@
     
     
     //set the velocity
-    people.set_velocity(S,0.3f);
+    people.set_velocity(S,0.4);
     
-    //update position(10,13)
+    //update position(10,12)
     people.update();
     
     //read test position
     Vector2D pos_test1 = people.get_pos();
     //printf("test_pos1 = %f,%f\n",pos_test1.x,pos_test1.y);
     
-    //test twice(6,9)
-    people.set_velocity(NW,0.9f);
+    //test twice(6,8)
+    people.set_velocity(NW,0.9);
     
     people.update();
     
@@ -40,8 +40,8 @@
     //Check the position
     bool success_flag = true;
     if (pos_init.x !=10|| pos_init.y!=10||
-        pos_test1.x!=10||pos_test1.y!=13||
-        pos_test2.x!=6 ||pos_test2.y!=9)
+        pos_test1.x!=10||pos_test1.y!=12||
+        pos_test2.x!=6 ||pos_test2.y!=8)
         success_flag = false;
         
     return success_flag;
--- a/PeopleEngine/People.cpp	Mon May 11 14:43:16 2020 +0000
+++ b/PeopleEngine/People.cpp	Thu May 14 16:45:20 2020 +0000
@@ -1,33 +1,94 @@
 #include "People.h"
 #define INIT_x 1
-#define INIT_y 23
+#define INIT_y 20
 
+const int people_sprite[8][5] = {
+        {0,1,1,1,0},
+        {0,1,1,1,0},
+        {0,0,1,0,0},
+        {1,1,1,1,1},
+        {0,0,1,0,0},
+        {0,1,0,1,0},
+        {0,1,0,1,0},
+        {0,1,0,1,0},
+};//try to draw a people, but for the operability of game, it seems not a good implementation..
 
-const int people_sprite[4][4] = {
-        {0,1,1,0},
-        {1,1,1,1},
-        {0,1,1,0},
-        {0,1,1,0},
-};//try to draw a people, but for the operability of game, seems not good..
+const int running_people_sprite[8][5] = {
+        {0,1,1,1,0},
+        {0,1,1,1,0},
+        {0,0,1,0,0},
+        {1,1,1,1,1},
+        {0,0,1,0,0},
+        {0,1,0,1,0},
+        {1,0,0,0,1},
+        {1,0,0,0,1},
+};
 
-People::People() {
+People::People() 
+{
     
 }
 
-People::~People() {
+People::~People() 
+{
     
 }
     
-void People::init() {
-    
+void People::init() 
+{    
     _x = INIT_x;
     _y = INIT_y;//Set initial postion of people
+    _index = 0;
 }
-void People::draw(N5110 &lcd) {
+
+void People::draw(N5110 &lcd,int flag) 
+{
+    if(int(_mag*5)!=0&&flag!=0){
+        if(!_index){
+            lcd.drawSprite(_x,_y,8,5,(int*)people_sprite);//Draw sprite to represent a people
+        // printf("drawSprite");
+            _index = 1;
+        }else{
+            lcd.drawSprite(_x,_y,8,5,(int*)running_people_sprite);
+            _index = 0;
+        }
+    }else{
+        lcd.drawSprite(_x,_y,8,5,(int*)people_sprite);
+    }      
+}
+
+/*control people by Joystick in different angle and magnitude
+    */
+void People::update()
+{
+    if(_d == S)        {
+        _x += 0;            _y += int(_mag*5);
+    } else if(_d == SE){
+        _x += int(_mag*5);   _y += int(_mag*5);
+    } else if(_d == E){
+        _x += int(_mag*5);   _y += 0;
+    } else if(_d == NE){
+        _x += int(_mag*5);   _y -= int(_mag*5);
+    } else if(_d == N){
+        _x -= 0;            _y -= int(_mag*5);
+    } else if(_d == NW){
+        _x -= int(_mag*5);   _y -= int(_mag*5);
+    } else if(_d == W){
+        _x -= int(_mag*5);   _y -= 0;
+    } else if(_d == NW){
+        _x -= int(_mag*5);   _y += int(_mag*5);
+    }
+    //printf("Mag = %f,Direction = %d,Coordinate = %d, %d\n",_mag,_d,_x,_y);
     
-    //Draw sprite to represent a people
-    lcd.drawSprite(_x,_y,4,4,(int*)people_sprite);
-    // printf("drawSprite");
+    control_lim();//without going off screen
+}
+
+void People::control_lim()
+{
+    if (_x < 1) { _x = 1;}//left
+    else if (_x > 78) { _x = 78;}//right
+    else if (_y < 1) {_y = 1;}//top
+    else if (_y > 41) {_y = 41;}//bottom
 }
 
 void People::set_pos(Vector2D p)
@@ -48,53 +109,4 @@
     //printf("Coord = %f,%f\n",p.x,p.y);
     return p;
 }
-
-void People::update()
-{
-    if (_d == S) {
-        if(_mag < 0.25f)        {   _x += 0;    _y += 1;} else
-        if(0.25f < _mag < 0.5f) {   _x += 0;    _y += 2;} else
-        if(0.5f < _mag < 0.75f) {   _x += 0;    _y += 3;} else 
-                                {   _x += 0;    _y += 4;}}else
-    if (_d == SE){
-        if(_mag < 0.25f)        {   _x += 1;    _y += 1;} else
-        if(0.25f < _mag < 0.5f) {   _x += 2;    _y += 2;} else
-        if(0.5f < _mag < 0.75f) {   _x += 3;    _y += 3;} else 
-                                {   _x += 4;    _y += 4;}}else
-    if (_d == E) {              
-        if(_mag < 0.25f)        {   _x += 1;    _y += 0;} else
-        if(0.25f < _mag < 0.5f) {   _x += 2;    _y += 0;} else
-        if(0.5f < _mag < 0.75f) {   _x += 3;    _y += 0;} else 
-                                {   _x += 4;    _y += 0;}}else  
-    if (_d == NE){
-        if(_mag < 0.25f)        {   _x += 1;    _y -= 1;} else
-        if(0.25f < _mag < 0.5f) {   _x += 2;    _y -= 2;} else
-        if(0.5f < _mag < 0.75f) {   _x += 3;    _y -= 3;} else 
-                                {   _x += 4;    _y -= 4;}}else
-    if (_d == N) {
-        if(_mag < 0.25f)        {   _x += 0;    _y -= 1;} else
-        if(0.25f < _mag < 0.5f) {   _x += 0;    _y -= 2;} else
-        if(0.5f < _mag < 0.75f) {   _x += 0;    _y -= 3;} else 
-                                {   _x += 0;    _y -= 4;}}else
-    if (_d == NW){
-        if(_mag < 0.25f)        {   _x -= 1;    _y -= 1;} else
-        if(0.25f < _mag < 0.5f) {   _x -= 2;    _y -= 2;} else
-        if(0.5f < _mag < 0.75f) {   _x -= 3;    _y -= 3;} else 
-                                {   _x -= 4;    _y -= 4;}}else
-    if (_d == W) {
-        if(_mag < 0.25f)        {   _x -= 1;    _y -= 0;} else
-        if(0.25f < _mag < 0.5f) {   _x -= 2;    _y -= 0;} else
-        if(0.5f < _mag < 0.75f) {   _x -= 3;    _y -= 0;} else 
-                                {   _x -= 4;    _y -= 0;}}else
-    if (_d == NW){
-        if(_mag < 0.25f)        {   _x -= 1;    _y += 1;} else
-        if(0.25f < _mag < 0.5f) {   _x -= 2;    _y += 2;} else
-        if(0.5f < _mag < 0.75f) {   _x -= 3;    _y += 3;} else 
-                                {   _x -= 4;    _y += 4;}}
-    //without going off screen
-    if (_x < 1) { _x = 1;} else
-    if (_x > 79) { _x = 79;} else
-    if (_y < 1) {_y = 1;} else
-    if (_y > 43) {_y = 43;} 
-}
-    
\ No newline at end of file
+ 
\ No newline at end of file
--- a/PeopleEngine/People.h	Mon May 11 14:43:16 2020 +0000
+++ b/PeopleEngine/People.h	Thu May 14 16:45:20 2020 +0000
@@ -6,30 +6,47 @@
 #include "N5110.h"
 
 /** People class
-    @set a basic element of my project
-    @author Zeyu Feng
-    @9 April 2020
-   */
+@set a basic element of my project
+@author Zeyu Feng
+@9 April 2020
+*/
 
 class People {
 
 public:
-    People(); //Constructor
-        
-    ~People(); //Destructor
-        
+    /**Constructor*/
+    People();
+    
+    /**Destructor*/    
+    ~People(); 
+    
+    /**initialize the position of people*/
     void init();
-        
-    void draw(N5110 &lcd);
+    
+    /**draw it on lcd and alternating type of people when running
+    *@param lcd
+    *@param type flag of people
+    */
+    void draw(N5110 &lcd,int flag);
     
+    /**update the position of people*/
     void update();
+    /** limit the people without going off screen*/
+    void control_lim();
         
-    //accessors   
+    /**accessors   set the position of people only for test
+    *@param pos(Vector2D)
+    */
     void set_pos(Vector2D p);
+    /**accessors   control the people by Joystick
+    *@param Direction (Direction)
+    *@param Mag(float)
+    */  
+    void set_velocity(Direction d,float mag);//control by gamepad
         
-    void set_velocity(Direction d,float mag);
-        
-    //mutators
+    /**mutators get the position of people only for test
+    *@return pos(Vector2D)
+    */
     Vector2D get_pos();
        
 private:
@@ -37,6 +54,7 @@
     float _mag;
     int _x;
     int _y;
+    int _index;//choose the type of people
 };
 #endif
         
\ No newline at end of file
--- a/PeopleEngine/PeopleEngine.cpp	Mon May 11 14:43:16 2020 +0000
+++ b/PeopleEngine/PeopleEngine.cpp	Thu May 14 16:45:20 2020 +0000
@@ -19,7 +19,7 @@
     //directions held in an enum and magnitude in polar coordinates
     _d = pad.get_direction();
     _mag = pad.get_mag();
-    //printf("velocity = %f,%f\n",_v.x,_v.y);
+    //printf("velocity = %d,%f\n",_d,_mag);
 }
 void PeopleEngine::update()
 {
@@ -29,13 +29,13 @@
    //printf("position = %f,%f\n",_p.x,_p.y);
 }
    
-void PeopleEngine::draw(N5110 &lcd)
+void PeopleEngine::draw(N5110 &lcd,int flag)
 {
     //lcd.clear();
-    _people.draw(lcd);
-    lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);//help our design
-    lcd.drawCircle(0,HEIGHT/2,6,FILL_TRANSPARENT);//destination
-    lcd.drawCircle(WIDTH-1,HEIGHT/2,6,FILL_TRANSPARENT);//starting point
+    _people.draw(lcd,flag);
+    lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);//box of the game
+    lcd.drawCircle(0,HEIGHT/2,7,FILL_TRANSPARENT);//destination
+    lcd.drawCircle(WIDTH-1,HEIGHT/2,7,FILL_TRANSPARENT);//starting point
 } 
 
 Vector2D PeopleEngine::get_pos() 
--- a/PeopleEngine/PeopleEngine.h	Mon May 11 14:43:16 2020 +0000
+++ b/PeopleEngine/PeopleEngine.h	Thu May 14 16:45:20 2020 +0000
@@ -7,33 +7,44 @@
 #include "People.h"
 
 /** PeopleEngine class
-    @set a Engine of 'People' and do some basic check
-    @author Zeyu Feng
-    @12 April 2020
-   */
+@set a Engine of 'People' and do some basic check
+@author Zeyu Feng
+@12 April 2020
+*/
 
 class PeopleEngine
 {
     
-public:   
-    PeopleEngine();//constructor
-    ~PeopleEngine();//destructor
+public:  
+    /**constructor*/
+    PeopleEngine();
     
+    /**destructor*/
+    ~PeopleEngine();
+    
+    /**initialize the position of people*/
     void init();
+    
+    /**read the polar input from Joystick*/
     void read_input(Gamepad &pad);
+    
+    /**update the position of people according to pad input(Joystick)*/
     void update();
-    void draw(N5110 &lcd);
     
+    /**draw the basic element of game: box,start circle and destination circle and main object(people)
+    *@param lcd
+    *@param flag(int)
+    */
+    void draw(N5110 &lcd,int flag);
+    /**mutators check whether the collision happens*/
     Vector2D get_pos();
-    
 
 private:
 
-    People _people;
+    People _people;//People class
     Direction _d;
+    float _mag;
     Vector2D _p;
-    float _mag;
-
 };
 #endif
     
--- a/main.cpp	Mon May 11 14:43:16 2020 +0000
+++ b/main.cpp	Thu May 14 16:45:20 2020 +0000
@@ -10,7 +10,6 @@
 Date:11/3/2020
 */
 
-// includes
 #include "mbed.h"
 #include "Gamepad.h"
 #include "N5110.h"
@@ -19,7 +18,7 @@
 #include "shot.h"
 #include "Collision.h"
 #include "Interface.h"
-#include "tests.h"
+# include "tests.h"
 
 // objects
 Gamepad pad;
@@ -38,26 +37,27 @@
 volatile int paused_flag = 0;
 volatile int option_flag = 0;
 
-//    functions
+//    prototypes
 void flip(){    timer_flag = 1; }
 void time_out(){    timeout_flag = 1;   }
 void init();
+void init_value();
 void control_check();
 void update();
-void shot_update();
 void init_timeout();
 void main_game(float,int);
-void init_value();
 void simp_game();
 
 int main()
 {
+#ifdef WITH_TESTING
     int failures = run_all_tests();
+#endif
     //initial
     init();
     
     interface.Welcome(lcd,pad);
-
+    
     //a infinite loop 
     while(1) {
         init();
@@ -65,10 +65,10 @@
         int option_flag= interface.menu(lcd,pad,option_flag);
         switch(option_flag){
             case 0:
-                main_game(0.7,25);
+                main_game(0.05,20);
                 break;
             case 1:
-                main_game(4,40);
+                main_game(1,40);
                 simp_game();
                 break;
             case 2:
@@ -84,11 +84,12 @@
     timeout.attach(&time_out,3);//set a timeout
     
     while((collision.get_health() > 0)&&(!collision.get_des()))
-    {   //   increase shots with a ticker
-        shot.gen_shot(timer_flag,increment,max);    
+    {   
         lcd.clear();
+        //   increase shots with a ticker
+        shot.gen_shot(timer_flag,increment,max);    
         //   shot update
-        shot_update();
+        shot.update(lcd);
         
         //   set a count down and update lcd
         update();
@@ -107,75 +108,12 @@
 void init()
 {
     lcd.init();
-    lcd.setContrast(0.5);
     engine.init();
     pad.init();
     shot.init();
     collision.init();
     lcd.refresh();
-}
-
-void control_check()
-{
-    engine.read_input(pad);
-    engine.update();
-    collision.set_pos(engine.get_pos());
-    // if people is shotted, health -1 and reset the game
-    if(collision.check(lcd)) {
-        if(!collision.get_health()){
-            interface.game_over(lcd,pad);
-            lcd.clear();
-        } else{
-            init_timeout();
-            lcd.clear();
-        }
-    }
-}
-
-void update()
-{
-    if(timeout_flag)
-        control_check();
-    //control people and check collision
-    engine.draw(lcd);
-    collision.draw(lcd);
-    if(collision.check_des(lcd)){
-        interface.victory(lcd,pad);
-        lcd.clear();
-    }
-    if(!timeout_flag)
-        count_flag = interface.count_down(lcd,count_flag);
-}
-
-void shot_update()
-{
-    shot.update();
-    // delete invalid shots
-    shot.delete_shot();
-    //generate shot to keep constant number of shots
-    shot.init_shot();
-    shot.draw(lcd);
-}
-
-
-void init_timeout()
-{   
-    lcd.clear();
-    lcd.drawRect(1,1,(collision.get_health()+1)*2,3,FILL_BLACK);
-    lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
-    lcd.refresh();
-    wait(0.5);
-    lcd.clear();
-    lcd.drawRect(1,1,collision.get_health()*2,3,FILL_BLACK);
-    lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
-    lcd.refresh();
-    wait(0.5);
-    engine.init();
-    shot.init();
-    //initialise time out
-    timeout.attach(&time_out,3);
-    timeout_flag = 0;
-    count_flag = 18;
+    interface.init();
 }
 
 void init_value()
@@ -187,13 +125,65 @@
     option_flag = 0;
 }   
 
+void control_check()
+{
+    engine.read_input(pad);
+    engine.update();
+    collision.set_pos(engine.get_pos());
+    // if people is shotted, health -1 and reset the game
+    if(collision.check(lcd)) {
+        if(!collision.get_health()){
+            interface.game_over(lcd,pad);
+        } else{
+            init_timeout();
+        }
+        lcd.clear();
+    }
+}
+
+void update()
+{
+    if(timeout_flag){
+        control_check();
+    }else{
+        //if timeout_flag count down number and Joystick have been banned 
+        count_flag = interface.count_down(lcd,count_flag);
+    }
+    //control people and check collision
+    if(!collision.get_check_col()){
+        engine.draw(lcd,timeout_flag);
+        collision.draw(lcd);
+    }else{
+        collision.set_check_col();
+    }
+    //printf("timeout_flag = %d\n",timeout_flag);
+    //check destination
+    if(collision.check_des(lcd)){
+        interface.victory(lcd,pad);
+        lcd.clear();
+    }
+}
+
+//reset timeout after collision (health > 0)
+void init_timeout()
+{   
+    collision.draw_collision(lcd);
+    engine.init();
+    shot.init();
+    //initialise time out
+    timeout.attach(&time_out,3);
+    timeout_flag = 0;
+    count_flag = 18;
+}
+
 void simp_game()
 {
     if(!interface.get_victory_flag()){
+        
         interface.simple_game(lcd,pad);
         if(interface.get_sim_flag()){
             init();
-            main_game(2.5,30);
+            main_game(0.5,30);
         }
     }
     interface.init();
--- a/shot/shot.cpp	Mon May 11 14:43:16 2020 +0000
+++ b/shot/shot.cpp	Thu May 14 16:45:20 2020 +0000
@@ -1,10 +1,21 @@
 #include "shot.h"
 
 int shots[4][3][3] = {
-    {       {0,1,0},{1,1,1},{0,1,0},        },
-    {       {1,1,1},{0,1,1},{0,0,1},        },
-    {       {1,1,1},{0,1,0},{0,1,0},        },
-    {       {1,1,0},{1,1,0},{0,0,1},        }
+    {       {0,1,0},
+            {1,1,1},
+            {0,1,0},        },//shot type1
+            
+    {       {1,1,1},
+            {0,1,1},
+            {0,0,1},        },//shot type2
+    
+    {       {1,1,1},
+            {0,1,0},
+            {0,1,0},        },//shot type3
+    
+    {       {1,1,0},
+            {1,1,0},
+            {0,0,1},        }//shot type4
 };
 
 shot::shot()
@@ -21,6 +32,7 @@
 {
 
     _size = 10;
+    _size_f = 10.0;
     _p.resize(_size);
     srand(time(NULL));
     for (std::vector<shot_posandtype>::iterator i = _p.begin(); i < _p.end(); i++) {
@@ -62,19 +74,7 @@
 
 }
 
-void shot::init_shot()
-{
-    _p.resize(_size);
-    for(std::vector<shot_posandtype>::iterator i = _p.begin(); i < _p.end(); i++) {
-        if(((*i).x == 0)&&((*i).y == 0)) {
-            init_pos(i);
-            (*i).type = rand() % 4;//randomise initial type
-            (*i).dir = rand() % 6;//randomise initial direction
-        }
-    }
-}
-
-void shot::update()
+void shot::update(N5110 &lcd)
 {
     for (std::vector<shot_posandtype>::iterator i = _p.begin(); i < _p.end(); i++) {
         if ((*i).dir == 0) {
@@ -97,8 +97,24 @@
             (*i).y +=1;//SW
         }
     }
+    // delete invalid shots
+    delete_shot();
+    //generate shot to keep constant number of shots
+    update_shot();
+    draw(lcd);
 }
 
+void shot::update_shot()
+{
+    _p.resize(_size);
+    for(std::vector<shot_posandtype>::iterator i = _p.begin(); i < _p.end(); i++) {
+        if(((*i).x == 0)&&((*i).y == 0)) {
+            init_pos(i);
+            (*i).type = rand() % 4;//randomise initial type
+            (*i).dir = rand() % 6;//randomise initial direction
+        }
+    }
+}
 
 void shot::draw(N5110 &lcd)
 {
@@ -114,16 +130,32 @@
         // if beyoud border, delete it and generate new one, keep total number constant
         if(((*i).x < 0)||((*i).x > WIDTH)||((*i).y < 0)||((*i).y > HEIGHT)||
         //keep shots away from starting point
-            (((*i).x==3)&&((*i).y==27))   ||   (((*i).x==3)&&((*i).y==18))||
-            (((*i).x==80)&&((*i).y==17))  ||   (((*i).x==80)&&((*i).y==28)))  
+            (((*i).x==3)&&((*i).y==18))   ||   (((*i).x==4)&&((*i).y==28))||
+            (((*i).x==79)&&((*i).y==16))  ||   (((*i).x==79)&&((*i).y==29)))  
         {
-            init_pos(i);
+            init_pos(i);//generate new shots to keep the total number
             (*i).type = ((*i).type + 2)%4;
             (*i).dir = ((*i).dir + 1)%6; // increase randomness
         }
     }
 }
 
+/*  increment(number of shots is generated during 1000/6 ms)
+    and maximum number of shots
+    control degree of difficulty of the game*/
+void shot::gen_shot(int timer_flag, float increment, int max)
+{
+    if(_size < max){
+        if(timer_flag == 1){
+            timer_flag = 0;
+            _size_f = _size_f + increment;
+            int size = int(_size_f);
+            //printf("Generate\n");
+            set_size(size);
+        }
+    }
+}
+
 void shot::set_size(int size) 
 {
     _size = size;
@@ -133,16 +165,4 @@
 {
     return _size;
 }
-
-void shot::gen_shot(int timer_flag, float increment, int max)
-{
-    if(get_size() < max){
-        if(timer_flag == 1){
-            timer_flag = 0;
-            int size = get_size()+ (int)increment;
-            //printf("Generate\n");
-            set_size(size);
-        }
-    }
-}
-    
\ No newline at end of file
+ 
\ No newline at end of file
--- a/shot/shot.h	Mon May 11 14:43:16 2020 +0000
+++ b/shot/shot.h	Thu May 14 16:45:20 2020 +0000
@@ -9,11 +9,11 @@
 #include <stdlib.h>
 
 /** shot class
-    @set several kinds of shot and come from all around
-    @author Zeyu Feng
-    @13 April 2020
-   */
-
+@set several kinds of shot and come from all around
+@author Zeyu Feng
+@13 April 2020
+*/
+/**struct of shot position type and direction*/
 struct shot_posandtype {
     int x;
     int y;
@@ -25,33 +25,51 @@
 {
 
 public:
-    //constructor
+
+    /**constructor*/
     shot();
-    //destructor
+    /**destructor*/
     ~shot();
-    //generate first 10 shots
+    /**generate first 10 shots*/
     void init();
-    //random pos
+    
+    /**produce a random_pos(21,0)(42,0)(63,0)(21,45)(42,45)(63,45)
+    *@param vector_i(shot_posandtype*)
+    */
     void init_pos(shot_posandtype* i);
-    //increase number of shots along with time
-    void init_shot();
-    //moving function
-    void update();
-
+    
+    /**move shots in their own directions*/
+    void update(N5110 &lcd);
+    
+    /**generate shots as time goes on*/
+    void update_shot();
+    
+    /**draw updated shots*/
     void draw(N5110 &lcd);
-    //if beyoud border, delete it and generate new one, keep total number constant
+    
+    /**if beyoud border, delete it and generate new one, keep total number constant*/
     void delete_shot();
-    //accessors  
+    /**control difficulty of game(size)
+    *@param timerflag(int)
+    *@param increment(float)
+    *@param max(int)
+    */
+    void gen_shot(int timer_flag, float increment, int max);
+
+    /**accessors  resize shots
+    *@param size(int)
+    */
     void set_size(int size);
-    ////mutators
+
+    /**mutators get size
+    *@return current size
+    */
     int get_size();
-    
-    void gen_shot(int timer_flag, float increment, int max);
 
 private:
     std::vector<shot_posandtype> _p;
-    
     int _size;
+    float _size_f;
 };
 #endif