Yuheng Huo
/
hyh_copy
test
Diff: main.cpp
- Revision:
- 3:31ff7b3e2005
- Parent:
- 2:cc9d8ec2e1f4
--- a/main.cpp Fri May 15 17:44:25 2020 +0000 +++ b/main.cpp Fri May 15 20:32:27 2020 +0000 @@ -1,423 +0,0 @@ -#include "Bitmap.h" -#include "N5110.h" -#include "Gamepad.h" -#include "mbed.h" -#include "FXOS8700CQ.h" -#include "chara.h" -#include "life.h" -#include "engine.h" -#include "N5110.h" -#include "Gamepad.h" -#include<iostream> - -using namespace std; -N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); -FXOS8700CQ device(I2C_SDA,I2C_SCL); -Gamepad pad; -chara p; -life lf; -engine eg; -bool n = true; -obs bo[20]; -int bonum = 0; -int score = 0; -int m = 0; -float fps=15; - -void init(); -void welcome(); -void screen(); -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%19==0){ - bo[bonum%20].y = eg.randomobs(); - bo[bonum%20].x = 82; - bonum = bonum + 1; - } - - lcd.clear(); - screen(); - update(); - lcd.refresh(); - cout<<fps<<endl; - wait(fps); - m = m + 1; - - } - wait(1); - } -} - -void init(){ - device.init(); - lcd.init(); - pad.init(); - p.init(); - lf.init(); - eg.init(); - lcd.setContrast(0.5); - n = true; - - bonum = 0; - score = 0; - m = 0; - for(int i = 0; i < 20; i++){ - bo[i].x = -1; - bo[i].y = -1; - 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(); - 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); - - } -} - -void screen(){ - lcd.clear(); - p.display(lcd); - lf.display(lcd); - 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);} - } - lcd.refresh(); -} - -void update(){ - 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); - if(e == DEAD){ - lf.update(); - bo[i].x = -1; - pad.tone(1000,0.2); - if(lf.liferest()==0){ - gameover(); - i = 20; - j = 20; - pad.tone(1000,0.5); - break; - } - }else if(e == ELMININATE){ - bo[i].x = -1; - score = score + 5; - cout <<score<<endl; - } - } - } - for(int i = 0; i<20; i++){ - if((bo[i].x >=0) && (bo[i].x<=84)){ - bo[i].x = bo[i].x - 1; - } - } - -} - -void gameover(){ - cout <<"game over"<< endl; - lcd.clear(); - lcd.printString("GAMEOVER ",0,1); - lcd.printString("SCORE ",0,2); - char buffer1[14]; - sprintf(buffer1,"%2d",score); - lcd.printString(buffer1,0,3); - lcd.printString(" Press A ",0,4); - lcd.refresh(); - while ( pad.check_event(Gamepad::A_PRESSED) == false) { - pad.leds_on(); - wait(0.1); - pad.leds_off(); - wait(0.1); - } - n = false; -} - -void drawBitmap(int x, int y, int width, int height, int *data){ - Bitmap p(data, height, width); - p.render(lcd, x, y); -} -