勇帜 周
/
2645_Final_project_1
bird
Diff: bird/bird.h
- Revision:
- 3:d9c2fc1d5984
- Parent:
- 2:fb9c05867677
- Child:
- 4:cd9a60a75717
--- a/bird/bird.h Sun May 05 18:46:58 2019 +0000 +++ b/bird/bird.h Sun May 05 18:52:46 2019 +0000 @@ -12,10 +12,206 @@ }; -/** Cylinder Class +/** bird Class *@brief Data used to make the bird *@anthor Zhou Yongzhi *@data May 2019 + +@code + + +#include "structure.h" +#include "structure_2.h" + +void init(); +void welcome(); +void render(); +void render1(); +void check(); +void check1(); +void death(); + + + +//pin +N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); +Gamepad pad; +bird bird; +structure structure; +structure_2 structure_2; + + + +int main() +{ +while (1){ + init();//初始化 + lcd.drawRect(0,0,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,47,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(83,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + welcome(); + + +while (pad.check_event(Gamepad::BACK_PRESSED) == false){ + lcd.clear(); + lcd.printString(" A NORMAL ",1,1); + lcd.printString(" B HARD ",1,2); + lcd.printString(" Y MESSAGE ",1,3); + lcd.drawRect(0,0,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,47,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(83,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.refresh(); + + wait(0.5); + + if (pad.check_event(Gamepad::A_PRESSED) == true) { + while (pad.check_event(Gamepad::BACK_PRESSED) == false) { + render(); + wait(0.5); + check(); + }//BACK +}//A + + + if (pad.check_event(Gamepad::B_PRESSED) == true) { + while (pad.check_event(Gamepad::BACK_PRESSED) == false) { + render1(); + wait(0.5); + check1(); + }//BACK +}//B + + if (pad.check_event(Gamepad::Y_PRESSED) == true) { + while (pad.check_event(Gamepad::BACK_PRESSED) == false) { + lcd.clear(); + lcd.printString(" Programme by:",0,1); + lcd.printString(" Zhou Yongzhi",0,2); + lcd.printString(" 201090418 ",0,3); + lcd.printString(" 2016110306 ",0,4); + lcd.refresh(); + }//BACK +}//C + + +} +} +} + + +void init() +{ + lcd.init(); + pad.init(); + bird.init(); + structure.init(); + structure_2.init(); +} + + +void render()//A nomal +{ // clear screen, re-draw and refresh + lcd.clear(); + Data1 data1 = structure.get_data1(); + lcd.drawRect(0,0,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,47,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(83,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + bird.draw(lcd); + structure.draw(lcd); + char buffer1[14]; + sprintf(buffer1,"%2d",data1.t); + lcd.printString(buffer1,1,1); + lcd.drawRect(1,1,15,15,FILL_TRANSPARENT); + bird.check(pad,lcd); + lcd.refresh(); +} + + +void render1()//A nomal +{ // clear screen, re-draw and refresh + lcd.clear(); + Data2 data2 = structure_2.get_data2(); + lcd.drawRect(0,0,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,47,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(83,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + bird.draw(lcd); + structure_2.draw(lcd); + char buffer1[14]; + sprintf(buffer1,"%2d",data2.tt); + lcd.printString(buffer1,1,1); + lcd.drawRect(1,1,15,15,FILL_TRANSPARENT); + bird.check(pad,lcd); + lcd.refresh(); +} + + +void welcome() { + lcd.printString(" Flappy Bird ",1,1); + lcd.printString(" Press Start ",1,4); + lcd.refresh(); + // wait flashing LEDs until start button is pressed LED灯闪到按Press + while (pad.check_event(Gamepad::START_PRESSED) == false) { + pad.leds_on(); + wait(0.1); + pad.leds_off(); + wait(0.1); + } +} + + +void check(){ + Data data = bird.get_data(); + Data1 data1 = structure.get_data1(); + if ( data.y >= 48 ){ + death(); + }else if(data1.m >= 25 && data1.m <= 32 ){ if(data.y <= data1.n || data.y >= data1.n + 15){ + death(); }} + else if(data1.p >= 25 && data1.p <= 32){ if(data.y <= data1.q || data.y >= data1.q + 15){ + death(); }} + else if(data1.e >= 25 && data1.e <= 32){ if(data.y <= data1.o || data.y >= data1.o + 15){ + death(); }} + + } + + + +void check1(){ + Data data = bird.get_data(); + Data2 data2 = structure_2.get_data2(); + if ( data.y >= 48 ){ + death(); + }else if(data2.mm >= 25 && data2.mm <= 32 ){ if(data.y <= data2.nn || data.y >= data2.nn + 15){ + death(); }} + else if(data2.pp >= 25 && data2.pp <= 32){ if(data.y <= data2.qq || data.y >= data2.qq + 15){ + death(); }} + else if(data2.ee >= 25 && data2.ee <= 32){ if(data.y <= data2.oo || data.y >= data2.oo + 15){ + death(); }} + + } + +void death(){ + int fps = 2; + init(); + while (pad.check_event(Gamepad::START_PRESSED) == false) { + lcd.clear(); + lcd.drawRect(0,0,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(0,47,84,1,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.drawRect(83,1,1,48,FILL_BLACK);//该公式前两个点是坐标,后两个点是涂抹区域的长宽,先长后宽, + lcd.printString(" Dead ",1,1); + lcd.printString(" Press start",1,3); + lcd.printString("to play again",1,4); + lcd.refresh(); + wait(0.3); + + }//while(1) + + }//death + +@endcode */ class bird {