test

Dependencies:   mbed FXOS8700CQ

Revision:
2:cc9d8ec2e1f4
Parent:
1:48b0bf0bcda8
Child:
3:31ff7b3e2005
--- a/main.cpp	Fri May 15 12:32:47 2020 +0000
+++ b/main.cpp	Fri May 15 17:44:25 2020 +0000
@@ -3,7 +3,7 @@
 #include "Gamepad.h"
 #include "mbed.h"
 #include "FXOS8700CQ.h"
-#include "plane.h"
+#include "chara.h"
 #include "life.h"
 #include "engine.h"
 #include "N5110.h"
@@ -14,16 +14,15 @@
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 FXOS8700CQ device(I2C_SDA,I2C_SCL);
 Gamepad pad;
-plane p;
+chara p;
 life lf;
 engine eg;
 bool n = true;
-bomb bo[20];
-bullet bu[20];
-int bunum = 0;
+obs bo[20];
 int bonum = 0;
 int score = 0;
 int m = 0;
+float fps=15;
 
 void init();
 void welcome();
@@ -31,15 +30,25 @@
 void update();
 void gameover();
 void drawBitmap(int x, int y, int width, int height, int *data);
+void setting();
+void renderj(int x, int y);
+void rendere(int x, int y);
+void rendert(int x, int y);
+void renderp(int x, int y);
+void rendera(int x, int y);
+void renderc(int x, int y);
+void renderk(int x, int y);
 
 int main()
 {
     while(1){
         init();
         welcome();
+        setting();
+        
         while(n){
-            if(m%8 ==0){
-                bo[bonum%20].y = eg.randombomb();
+            if(m%19==0){
+                bo[bonum%20].y = eg.randomobs();
                 bo[bonum%20].x = 82;
                 bonum = bonum + 1;
             }
@@ -48,8 +57,10 @@
             screen();
             update();
             lcd.refresh();
-            wait(0.02);
+            cout<<fps<<endl;
+            wait(fps);
             m = m + 1;
+            
         }
         wait(1);
     }
@@ -64,41 +75,283 @@
     eg.init();
     lcd.setContrast(0.5);
     n = true;
-    bunum = 0;
+
     bonum = 0;
     score = 0;
     m = 0;
     for(int i = 0; i < 20; i++){
-        bu[i].x = -1;
-        bu[i].y = -1;
         bo[i].x = -1;
         bo[i].y = -1;
-        bo[i].width = 8;
-        bo[i].height = 8;
-        int data[64]= {
-                0,0,0,1,1,0,0,0,
-                0,1,1,0,0,1,1,0,
-                0,1,1,1,1,1,1,0,
-                1,0,1,1,1,1,0,1,
-                1,0,1,1,1,1,0,1,
-                0,1,1,1,1,1,1,0,
-                0,1,1,0,0,1,1,0,
-                0,0,0,1,1,0,0,0                 
+        bo[i].width = 9;
+        bo[i].height = 5;
+        int data[45]= {
+                0,1,0,1,0,1,0,1,0,
+                1,0,1,0,1,0,1,0,1,
+                1,1,1,1,1,1,1,1,1,
+                1,0,1,0,1,0,1,0,1,
+                0,1,0,1,0,1,0,1,0
+
+                
         };
+        
         bo[i].data = data;
     }
 }
 
+void renderj(int x,int y){
+    int j[153]={
+        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,1,1,
+        0,0,0,0,0,0,0,1,1,
+        0,0,0,0,0,0,0,1,1,
+        0,0,0,0,0,0,0,1,1,
+        0,0,0,0,0,0,0,1,1,
+        0,0,0,0,0,0,0,1,1,
+        0,0,0,0,0,0,0,1,1,
+        0,0,0,0,0,0,0,1,1,
+        0,0,0,0,0,0,0,1,1,
+        0,0,0,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,1,1,
+        1,1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,1
+    };
+    Bitmap jj(j,17,9);
+    jj.render(lcd, x, y);
+}
+
+void rendere(int x,int y){
+    int e[136]={
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1
+    };
+    Bitmap ee(e,17,8);
+    ee.render(lcd, x, y);
+}
+
+void rendert(int x,int y){
+    int t[170]={
+        1,1,1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,1,1,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0,
+        0,0,0,0,1,1,0,0,0,0
+    };
+    Bitmap tt(t,17,10);
+    tt.render(lcd, x, y);
+}
+
+void renderp(int x,int y){
+    int p[153]={
+        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,1,1,
+        1,1,0,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,1,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,
+        1,1,0,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,0
+    };
+    Bitmap pp(p,17,9);
+    pp.render(lcd, x, y);
+}
+
+void rendera(int x,int y){
+    int a[136]={
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1
+    };
+    Bitmap aa(a,17,8);
+    aa.render(lcd, x, y);
+}
+    
+void renderc(int x,int y){
+    int c[136]={
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,0,0,0,0,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1
+    };
+    Bitmap cc(c,17,8);
+    cc.render(lcd, x, y);
+}
+
+void renderk(int x,int y){
+    int k[187]={
+        1,1,0,0,0,0,0,0,0,1,1,
+        1,1,0,0,0,0,0,0,1,1,1,
+        1,1,0,0,0,0,0,1,1,1,0,
+        1,1,0,0,0,0,1,1,1,0,0,
+        1,1,0,0,0,1,1,1,0,0,0,
+        1,1,0,0,1,1,1,0,0,0,0,
+        1,1,0,1,1,1,0,0,0,0,0,
+        1,1,1,1,1,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,0,0,0,
+        1,1,0,0,0,0,0,0,0,0,0,
+        1,1,1,1,0,0,0,0,0,0,0,
+        1,1,1,1,1,0,0,0,0,0,0,
+        1,1,0,1,1,1,0,0,0,0,0,
+        1,1,0,0,1,1,1,1,0,0,0,
+        1,1,0,0,0,1,1,1,0,0,0,
+        1,1,0,0,0,0,1,1,1,1,1,
+        1,1,0,0,0,0,0,1,1,1,1
+    };
+    Bitmap kk(k,17,11);
+    kk.render(lcd, x, y);
+}
+
+    
 void welcome(){
     lcd.clear();
-    lcd.printString("The plane war!",0,1);  
-    lcd.printString("  Press Start ",0,4);
+    for(int i = 1;i<=60;i++){
+        lcd.clear();
+        int jy = 40-i;
+        if (jy<=0){
+            jy = 1;
+        }
+        int ey = 45-i;
+        if (ey<=0){
+            ey = 1;
+        }
+        int ty = 50-i;
+        if (ty<=0){
+            ty = 1;
+        }
+        int py = 50-i;
+        if (py<=0){
+            py = 1;
+        }
+        int ay = 52-i;
+        if (ay<=0){
+            ay = 1;
+        }
+        int cy = 54-i;
+        if (cy<=0){
+            cy = 1;
+        }
+        int ky = 56-i;
+        if (ky<=0){
+            ky = 1;
+        }
+        
+        renderj(6,jy);
+        rendere(17,ey);
+        rendert(27,ty);
+        renderp(39,py);
+        rendera(50,ay);
+        renderc(60,cy);
+        renderk(70,ky);
+        wait(0.05);
+        lcd.refresh();
+        }
+        lcd.printString("PERSS START",6,5);
+    
     lcd.refresh();
     while( pad.check_event(Gamepad::START_PRESSED) == false){
         pad.leds_on();
         wait(0.1);
         pad.leds_off();
         wait(0.1);
+        
+    }
+}
+
+void setting(){
+    lcd.clear();
+    lcd.printString("SET DIFFICULTY",0,0); 
+    lcd.printString("A EZ",0,2); 
+    lcd.printString("B Default",0,3);
+    lcd.printString("X Difficult",0,4);
+    lcd.printString("Y NIGHTMARE",0,5);
+    lcd.refresh();
+    while(1){
+        if( pad.check_event(Gamepad::A_PRESSED) == true){
+            fps = 0.2;
+            break;
+            }
+        if( pad.check_event(Gamepad::B_PRESSED) == true){
+            fps = 0.1;
+            break;
+            }
+        if( pad.check_event(Gamepad::X_PRESSED) == true){
+            fps = 0.05;
+            break;
+            }
+        if( pad.check_event(Gamepad::Y_PRESSED) == true){
+            fps = 0.01;
+            break;
+            }
+        pad.leds_on();
+        wait(0.1);
+        pad.leds_off();
+        wait(0.1);
+        
     }
 }
 
@@ -109,8 +362,6 @@
     for(int i = 0; i <20; i++){
         if(bo[i].x >=0){
             drawBitmap(bo[i].x, bo[i].y, bo[i].width, bo[i].height, bo[i].data);}
-        if(bu[i].x >=0){
-            lcd.drawRect(bu[i].x, bu[i].y, 2, 2, FILL_BLACK);}
     }
     lcd.refresh();
 }
@@ -119,7 +370,7 @@
     p.update(pad, device);
     for(int i = 0; i<20; i++){
         for(int j = 0; j < 20; j++){
-            events e = eg.evet_check(p, bo[i],pad,bu[j]);
+            events e = eg.evet_check(p, bo[i],pad);
             if(e == DEAD){
                 lf.update();
                 bo[i].x = -1;
@@ -131,12 +382,8 @@
                     pad.tone(1000,0.5);
                     break;
                 }
-            }else if(e == FIRE){
-                eg.fire(p.getxy().x+7, p.getxy().y+3, bu[bunum%20]);
-                bunum = bunum + 1;
             }else if(e == ELMININATE){
                 bo[i].x = -1;
-                bu[j].x = -1;
                 score = score + 5;
                 cout <<score<<endl;
             }
@@ -146,9 +393,6 @@
         if((bo[i].x >=0) && (bo[i].x<=84)){
             bo[i].x = bo[i].x - 1;
         }
-        if(bu[i].x >=0){
-            bu[i].y = bu[i].y + 1;
-        }
     }
     
 }