test avoid bulled game

Dependencies:   C12832_lcd LCD_fonts mbed mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
kaku_jyoko
Date:
Wed Dec 14 11:42:25 2016 +0000
Parent:
59:6a99ec97eebd
Child:
61:d44faf074743
Commit message:
Refactoring main.cpp

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Dec 14 10:53:38 2016 +0000
+++ b/main.cpp	Wed Dec 14 11:42:25 2016 +0000
@@ -19,26 +19,28 @@
 Mutex jump_mtx;
 Mutex update_mtx;
 Mutex bullet_mtx;
+
 Person h;
 Stage stage;
 Serial pc(USBTX, USBRX); // tx, rx
 Bullet* b = NULL;
 Timer t;
-int white_board[LCD_Y][LCD_X];
+
 int* wall_height;
 
-
-void reset_white_board()
-{
-    for(int i = 0; i < LCD_Y; i++){
+Bitmap make_wall(){
+    Converter converter;
+    wall_height = stage.getStage();
+    int white_board[LCD_Y][LCD_X];
+    
+    
+    //initialize white board
+     for(int i = 0; i < LCD_Y; i++){
         for (int j = 0; j < LCD_X; j++){
             white_board[i][j] = 0;
         }
     }
-}
-
-void make_wall(){
-    wall_height = stage.getStage();
+    
     for(int i = 0; i < LCD_Y; i++){
         for(int j = 0; j < LCD_X ; j++){
             if(wall_height[j] > (LCD_Y - 1 - i)){
@@ -46,6 +48,9 @@
             }
         }
     }
+    
+    return converter.convert(white_board);
+    
 }
 
 void call_jump(){
@@ -170,8 +175,9 @@
     bool gameover = false;
     bool isDisplay = false;
     srand((int)(aIn * 100));
-    Converter converter;
-    Bitmap picture;
+    Bitmap wall;
+    
+    
     printf("New Game Start\n");
     printf("Bullet Option\n");
     printf("       slow    normal  fast\n");
@@ -181,15 +187,13 @@
     
     while(true){
         if(!gameover){
-            reset_white_board();
-            make_wall();
+            wall = make_wall();
             update_mtx.lock();
             p_person = h.update(wall_height[3]);
             //p_person = h.update(1);
             if(b != NULL){
                 p_bullet = b->update();
             }
-            picture = converter.convert(white_board);
             
             update_mtx.unlock();
             
@@ -198,7 +202,7 @@
             
             lcd.cls();
             lcd.print_bm(bitmPlayer,p_person.x,p_person.y);
-            lcd.print_bm(picture,0,0);
+            lcd.print_bm(wall,0,0);
             if(b != NULL){
                 lcd.print_bm(bitmBullet_graphics, p_bullet.x, p_bullet.y);
             }
@@ -206,7 +210,7 @@
             wait(0.02);
             lcd.cls();
             lcd.print_bm(bitmPlayerB,p_person.x,p_person.y);
-            lcd.print_bm(picture,0,0);
+            lcd.print_bm(wall,0,0);
             if(b != NULL){
                 lcd.print_bm(bitmBullet_graphics, p_bullet.x, p_bullet.y);
             }