Li Ruofan 201199450
Dependencies: mbed Gamepad Joystick
homepage/homepage.cpp@6:cbd9e1f26a10, 2020-05-15 (annotated)
- Committer:
- DannyLee
- Date:
- Fri May 15 21:16:14 2020 +0000
- Revision:
- 6:cbd9e1f26a10
- Parent:
- 5:e3a9f0548922
- Child:
- 8:b4a2954dd74f
still debuging
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DannyLee | 5:e3a9f0548922 | 1 | #include "homepage.h" |
DannyLee | 5:e3a9f0548922 | 2 | |
DannyLee | 5:e3a9f0548922 | 3 | Homepage::homepage(){ |
DannyLee | 6:cbd9e1f26a10 | 4 | |
DannyLee | 5:e3a9f0548922 | 5 | } |
DannyLee | 5:e3a9f0548922 | 6 | |
DannyLee | 5:e3a9f0548922 | 7 | Homepage::~homepage() |
DannyLee | 5:e3a9f0548922 | 8 | {} |
DannyLee | 5:e3a9f0548922 | 9 | |
DannyLee | 6:cbd9e1f26a10 | 10 | void Homepage::welcome(N5110 &lcd,BusOut &output,Bgm &bgm) |
DannyLee | 5:e3a9f0548922 | 11 | { |
DannyLee | 5:e3a9f0548922 | 12 | //show "Spaceship" |
DannyLee | 5:e3a9f0548922 | 13 | lcd.printString(" Spaceship ",0,1); |
DannyLee | 5:e3a9f0548922 | 14 | lcd.refresh(); |
DannyLee | 5:e3a9f0548922 | 15 | drawEverything(lcd); |
DannyLee | 5:e3a9f0548922 | 16 | lcd.refresh(); |
DannyLee | 5:e3a9f0548922 | 17 | output=0b000000; |
DannyLee | 5:e3a9f0548922 | 18 | |
DannyLee | 5:e3a9f0548922 | 19 | //welcome bgm |
DannyLee | 5:e3a9f0548922 | 20 | bgm.welcome(); |
DannyLee | 5:e3a9f0548922 | 21 | output=0b111111; |
DannyLee | 5:e3a9f0548922 | 22 | lcd.clear(); |
DannyLee | 5:e3a9f0548922 | 23 | } |
DannyLee | 5:e3a9f0548922 | 24 | void Homepage::over(N5110 &lcd,BusOut &output) |
DannyLee | 5:e3a9f0548922 | 25 | { |
DannyLee | 5:e3a9f0548922 | 26 | //show game over |
DannyLee | 6:cbd9e1f26a10 | 27 | lcd.printString(" You are failed ",0,1); |
DannyLee | 5:e3a9f0548922 | 28 | lcd.printString(" Press Start ",0,4); |
DannyLee | 5:e3a9f0548922 | 29 | lcd.refresh(); |
DannyLee | 5:e3a9f0548922 | 30 | wait(1.0f); |
DannyLee | 5:e3a9f0548922 | 31 | output=0b000000; |
DannyLee | 5:e3a9f0548922 | 32 | wait(1.0f); |
DannyLee | 5:e3a9f0548922 | 33 | output=0b111111; |
DannyLee | 5:e3a9f0548922 | 34 | lcd.clear(); |
DannyLee | 5:e3a9f0548922 | 35 | } |
DannyLee | 5:e3a9f0548922 | 36 | void Homepage::homepage(N5110 &lcd,InterruptIn &buttonA, InterruptIn &start,int *score,int n) |
DannyLee | 5:e3a9f0548922 | 37 | { |
DannyLee | 5:e3a9f0548922 | 38 | //show Homepage and check the pressed button |
DannyLee | 5:e3a9f0548922 | 39 | lcd.refresh(); |
DannyLee | 5:e3a9f0548922 | 40 | while(1){ |
DannyLee | 5:e3a9f0548922 | 41 | |
DannyLee | 5:e3a9f0548922 | 42 | lcd.printString(" Press Start to start ",0,0); |
DannyLee | 6:cbd9e1f26a10 | 43 | lcd.printString(" A Rules",0,2); |
DannyLee | 5:e3a9f0548922 | 44 | lcd.refresh(); |
DannyLee | 5:e3a9f0548922 | 45 | |
DannyLee | 5:e3a9f0548922 | 46 | if(buttonA){ |
DannyLee | 6:cbd9e1f26a10 | 47 | wait(0.5f); |
DannyLee | 5:e3a9f0548922 | 48 | lcd.clear(); |
DannyLee | 5:e3a9f0548922 | 49 | //show the game rule |
DannyLee | 5:e3a9f0548922 | 50 | rules(lcd,buttonA); |
DannyLee | 5:e3a9f0548922 | 51 | }else if(start){ |
DannyLee | 5:e3a9f0548922 | 52 | lcd.clear(); //start the game |
DannyLee | 5:e3a9f0548922 | 53 | break; |
DannyLee | 5:e3a9f0548922 | 54 | } |
DannyLee | 5:e3a9f0548922 | 55 | } |
DannyLee | 5:e3a9f0548922 | 56 | |
DannyLee | 5:e3a9f0548922 | 57 | } |
DannyLee | 5:e3a9f0548922 | 58 | |
DannyLee | 5:e3a9f0548922 | 59 | |
DannyLee | 6:cbd9e1f26a10 | 60 | void Homepage::displayCurScore(N5110 &lcd,int score){ |
DannyLee | 5:e3a9f0548922 | 61 | char buffer[4]; |
DannyLee | 5:e3a9f0548922 | 62 | sprintf(buffer,"%d",score); |
DannyLee | 5:e3a9f0548922 | 63 | lcd.printString(buffer,0,0); |
DannyLee | 5:e3a9f0548922 | 64 | } |
DannyLee | 6:cbd9e1f26a10 | 65 | void Homepage::drawEverything(N5110 &lcd){ |
DannyLee | 5:e3a9f0548922 | 66 | |
DannyLee | 5:e3a9f0548922 | 67 | int Spaceship[15][10] = { |
DannyLee | 5:e3a9f0548922 | 68 | 0,0,0,0,0,0,0,0,0,0, |
DannyLee | 5:e3a9f0548922 | 69 | 0,0,0,0,1,1,0,0,0,0, |
DannyLee | 5:e3a9f0548922 | 70 | 0,0,0,0,1,1,0,0,0,0, |
DannyLee | 5:e3a9f0548922 | 71 | 0,0,1,1,0,0,1,1,0,0, |
DannyLee | 5:e3a9f0548922 | 72 | 0,1,1,1,1,1,1,1,1,0, |
DannyLee | 5:e3a9f0548922 | 73 | 0,1,1,1,1,1,1,1,1,0, |
DannyLee | 5:e3a9f0548922 | 74 | 1,1,1,1,1,1,1,1,1,1, |
DannyLee | 5:e3a9f0548922 | 75 | 1,1,1,1,1,1,1,1,1,1, |
DannyLee | 5:e3a9f0548922 | 76 | 1,1,1,1,1,1,1,1,1,1, |
DannyLee | 5:e3a9f0548922 | 77 | 1,1,1,1,1,1,1,1,1,1, |
DannyLee | 5:e3a9f0548922 | 78 | 1,1,1,1,1,1,1,1,1,1, |
DannyLee | 5:e3a9f0548922 | 79 | 1,1,1,1,0,0,1,1,1,1, |
DannyLee | 5:e3a9f0548922 | 80 | 0,1,1,1,0,0,1,1,1,0, |
DannyLee | 5:e3a9f0548922 | 81 | 0,0,1,1,0,0,1,1,0,0, |
DannyLee | 5:e3a9f0548922 | 82 | 0,0,0,1,1,1,1,0,0,0, |
DannyLee | 5:e3a9f0548922 | 83 | 0,0,0,0,0,0,0,0,0,0, |
DannyLee | 5:e3a9f0548922 | 84 | //draw spaceship |
DannyLee | 6:cbd9e1f26a10 | 85 | Bitmap sprite2(_Spaceship, 16, 10); |
DannyLee | 6:cbd9e1f26a10 | 86 | sprite2.render(lcd, 28, 28); |
DannyLee | 5:e3a9f0548922 | 87 | } |
DannyLee | 6:cbd9e1f26a10 | 88 | void Homepage::rules(N5110 &lcd,InterruptIn &buttonA) { |
DannyLee | 5:e3a9f0548922 | 89 | //show game rules |
DannyLee | 5:e3a9f0548922 | 90 | while(1) { |
DannyLee | 5:e3a9f0548922 | 91 | lcd.clear(); |
DannyLee | 5:e3a9f0548922 | 92 | lcd.printString("press X to fire",0,0); |
DannyLee | 5:e3a9f0548922 | 93 | lcd.printString("use Joystick to move",0,1); |
DannyLee | 5:e3a9f0548922 | 94 | lcd.printString("You need to destroy UFO",0,2); |
DannyLee | 5:e3a9f0548922 | 95 | lcd.printString("Don't let a UFO come near you",0,3); |
DannyLee | 5:e3a9f0548922 | 96 | lcd.printString("Press B to go back",0,5); |
DannyLee | 5:e3a9f0548922 | 97 | lcd.refresh(); |
DannyLee | 5:e3a9f0548922 | 98 | if(buttonB) { |
DannyLee | 5:e3a9f0548922 | 99 | lcd.clear(); |
DannyLee | 5:e3a9f0548922 | 100 | wait(0.5f); |
DannyLee | 5:e3a9f0548922 | 101 | return; |
DannyLee | 5:e3a9f0548922 | 102 | } |
DannyLee | 5:e3a9f0548922 | 103 | } |
DannyLee | 5:e3a9f0548922 | 104 | } |
DannyLee | 5:e3a9f0548922 | 105 | int homepage::again(N5110 &lcd,int score,InterruptIn &buttonX,InterruptIn &buttonY){ |
DannyLee | 5:e3a9f0548922 | 106 | |
DannyLee | 5:e3a9f0548922 | 107 | lcd.clear(); |
DannyLee | 5:e3a9f0548922 | 108 | while(1){ |
DannyLee | 5:e3a9f0548922 | 109 | if(score>10){ |
DannyLee | 6:cbd9e1f26a10 | 110 | //if score > 10, player have enough POINTS to replay when he is defeated. |
DannyLee | 5:e3a9f0548922 | 111 | lcd.printString("Play Again?",0,0); |
DannyLee | 5:e3a9f0548922 | 112 | lcd.printString("Price: 10",0,2); |
DannyLee | 5:e3a9f0548922 | 113 | lcd.printString("X Yes",0,3); |
DannyLee | 5:e3a9f0548922 | 114 | lcd.printString("Y No",0,4); |
DannyLee | 5:e3a9f0548922 | 115 | lcd.refresh(); |
DannyLee | 5:e3a9f0548922 | 116 | if(buttonX){ |
DannyLee | 5:e3a9f0548922 | 117 | wait(0.5f); |
DannyLee | 5:e3a9f0548922 | 118 | lcd.clear(); |
DannyLee | 5:e3a9f0548922 | 119 | return -10; |
DannyLee | 5:e3a9f0548922 | 120 | }else if(buttonY){ |
DannyLee | 5:e3a9f0548922 | 121 | wait(0.5f); |
DannyLee | 5:e3a9f0548922 | 122 | lcd.clear(); |
DannyLee | 5:e3a9f0548922 | 123 | return 0; |
DannyLee | 5:e3a9f0548922 | 124 | } |
DannyLee | 5:e3a9f0548922 | 125 | }else{ |
DannyLee | 5:e3a9f0548922 | 126 | // player doesn't have enough scores , so game over directly |
DannyLee | 6:cbd9e1f26a10 | 127 | lcd.printString("Fail",0,1); |
DannyLee | 5:e3a9f0548922 | 128 | lcd.printString("Press Y return",0,2); |
DannyLee | 5:e3a9f0548922 | 129 | lcd.refresh(); |
DannyLee | 5:e3a9f0548922 | 130 | if(buttonY){ |
DannyLee | 5:e3a9f0548922 | 131 | wait(0.5f); |
DannyLee | 5:e3a9f0548922 | 132 | lcd.clear(); |
DannyLee | 5:e3a9f0548922 | 133 | return 0; |
DannyLee | 5:e3a9f0548922 | 134 | } |
DannyLee | 5:e3a9f0548922 | 135 | } |
DannyLee | 5:e3a9f0548922 | 136 | } |
DannyLee | 5:e3a9f0548922 | 137 | |
DannyLee | 5:e3a9f0548922 | 138 | } |