Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
ModeA/ModeA.cpp@11:e29b173ccb27, 2019-05-09 (annotated)
- Committer:
- el17mtu
- Date:
- Thu May 09 01:06:23 2019 +0000
- Revision:
- 11:e29b173ccb27
- Parent:
- 10:1c3bdbf2fe9f
- Child:
- 12:343704be6401
score
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17mtu | 0:15b74f0f8c7f | 1 | #include "ModeA.h" |
| el17mtu | 0:15b74f0f8c7f | 2 | |
| el17mtu | 0:15b74f0f8c7f | 3 | ModeA::ModeA() |
| el17mtu | 0:15b74f0f8c7f | 4 | { |
| el17mtu | 0:15b74f0f8c7f | 5 | |
| el17mtu | 0:15b74f0f8c7f | 6 | } |
| el17mtu | 0:15b74f0f8c7f | 7 | |
| el17mtu | 0:15b74f0f8c7f | 8 | ModeA::~ModeA() |
| el17mtu | 0:15b74f0f8c7f | 9 | { |
| el17mtu | 0:15b74f0f8c7f | 10 | |
| el17mtu | 0:15b74f0f8c7f | 11 | } |
| el17mtu | 0:15b74f0f8c7f | 12 | |
| el17mtu | 0:15b74f0f8c7f | 13 | void ModeA::screen(N5110 &lcd) |
| el17mtu | 0:15b74f0f8c7f | 14 | { |
| el17mtu | 0:15b74f0f8c7f | 15 | |
| el17mtu | 0:15b74f0f8c7f | 16 | lcd.clear(); |
| el17mtu | 0:15b74f0f8c7f | 17 | lcd.printString("GAME",0,0); |
| el17mtu | 0:15b74f0f8c7f | 18 | lcd.printString("Back:Rules",0,2); |
| el17mtu | 0:15b74f0f8c7f | 19 | |
| el17mtu | 0:15b74f0f8c7f | 20 | }; |
| el17mtu | 0:15b74f0f8c7f | 21 | |
| el17mtu | 0:15b74f0f8c7f | 22 | void ModeA::initialise(N5110 &lcd) |
| el17mtu | 0:15b74f0f8c7f | 23 | { |
| el17mtu | 10:1c3bdbf2fe9f | 24 | //variables for the square |
| el17mtu | 10:1c3bdbf2fe9f | 25 | x_position = 12; |
| el17mtu | 10:1c3bdbf2fe9f | 26 | y_position = 18; |
| el17mtu | 10:1c3bdbf2fe9f | 27 | speed = 0; |
| el17mtu | 0:15b74f0f8c7f | 28 | gravity = 1; |
| el17mtu | 10:1c3bdbf2fe9f | 29 | //variables for the bar |
| el17mtu | 11:e29b173ccb27 | 30 | screen_width = 65; |
| el17mtu | 1:44f4594eacac | 31 | bar_width = 10; |
| el17mtu | 4:a81f05c8806a | 32 | bar_speed = 2; |
| el17mtu | 3:8e6950aeec8a | 33 | |
| el17mtu | 11:e29b173ccb27 | 34 | score = 0; |
| el17mtu | 10:1c3bdbf2fe9f | 35 | |
| el17mtu | 10:1c3bdbf2fe9f | 36 | //generating random sizes of the bar |
| el17mtu | 10:1c3bdbf2fe9f | 37 | srand(time(NULL)); |
| el17mtu | 10:1c3bdbf2fe9f | 38 | size_top = rand() % 15; |
| el17mtu | 10:1c3bdbf2fe9f | 39 | srand(time(NULL)); |
| el17mtu | 10:1c3bdbf2fe9f | 40 | size_bottom = rand() % 15; |
| el17mtu | 3:8e6950aeec8a | 41 | |
| el17mtu | 9:571f92b0211b | 42 | |
| el17mtu | 9:571f92b0211b | 43 | } |
| el17mtu | 0:15b74f0f8c7f | 44 | |
| el17mtu | 9:571f92b0211b | 45 | void ModeA::Bird(N5110 &lcd) |
| el17mtu | 0:15b74f0f8c7f | 46 | |
| el17mtu | 0:15b74f0f8c7f | 47 | { |
| el17mtu | 11:e29b173ccb27 | 48 | char buffer[14]; |
| el17mtu | 11:e29b173ccb27 | 49 | sprintf(buffer,"%2d",score); |
| el17mtu | 11:e29b173ccb27 | 50 | lcd.printString(buffer,70,0); |
| el17mtu | 0:15b74f0f8c7f | 51 | lcd.drawRect(x_position, y_position,6,6,FILL_BLACK); |
| el17mtu | 3:8e6950aeec8a | 52 | //lcd.drawRect(screen_width,0,bar_width,size_top,FILL_BLACK); |
| el17mtu | 3:8e6950aeec8a | 53 | //lcd.drawRect(screen_width,48-size_bottom,bar_width,size_bottom,FILL_BLACK); |
| el17mtu | 0:15b74f0f8c7f | 54 | lcd.refresh(); |
| el17mtu | 0:15b74f0f8c7f | 55 | |
| el17mtu | 0:15b74f0f8c7f | 56 | |
| el17mtu | 0:15b74f0f8c7f | 57 | |
| el17mtu | 0:15b74f0f8c7f | 58 | if ( pad.check_event(Gamepad::Y_PRESSED) == true) { |
| el17mtu | 8:d9b602e58126 | 59 | |
| el17mtu | 0:15b74f0f8c7f | 60 | speed = speed - gravity*5; |
| el17mtu | 0:15b74f0f8c7f | 61 | |
| el17mtu | 0:15b74f0f8c7f | 62 | } |
| el17mtu | 0:15b74f0f8c7f | 63 | |
| el17mtu | 10:1c3bdbf2fe9f | 64 | if (y_position > 48) { |
| el17mtu | 6:f7484a2f32fd | 65 | |
| el17mtu | 6:f7484a2f32fd | 66 | lcd.clear(); |
| el17mtu | 6:f7484a2f32fd | 67 | lcd.printString("GAME OVER",6,2); |
| el17mtu | 6:f7484a2f32fd | 68 | lcd.printString("Press BACK",6,4); |
| el17mtu | 6:f7484a2f32fd | 69 | pad.tone(2000.0,0.3); |
| el17mtu | 6:f7484a2f32fd | 70 | lcd.refresh(); |
| el17mtu | 6:f7484a2f32fd | 71 | bar_speed = 0; |
| el17mtu | 6:f7484a2f32fd | 72 | speed = 0; |
| el17mtu | 6:f7484a2f32fd | 73 | gravity = 0; |
| el17mtu | 6:f7484a2f32fd | 74 | y_position = 48; |
| el17mtu | 6:f7484a2f32fd | 75 | bar_width = 0; |
| el17mtu | 6:f7484a2f32fd | 76 | size_top = 0; |
| el17mtu | 6:f7484a2f32fd | 77 | size_bottom = 0; |
| el17mtu | 6:f7484a2f32fd | 78 | |
| el17mtu | 6:f7484a2f32fd | 79 | wait(0.5); |
| el17mtu | 6:f7484a2f32fd | 80 | |
| el17mtu | 0:15b74f0f8c7f | 81 | } |
| el17mtu | 9:571f92b0211b | 82 | |
| el17mtu | 11:e29b173ccb27 | 83 | |
| el17mtu | 11:e29b173ccb27 | 84 | |
| el17mtu | 9:571f92b0211b | 85 | |
| el17mtu | 0:15b74f0f8c7f | 86 | |
| el17mtu | 0:15b74f0f8c7f | 87 | if (y_position < 0) { |
| el17mtu | 0:15b74f0f8c7f | 88 | y_position = 0; |
| el17mtu | 0:15b74f0f8c7f | 89 | speed = 0; |
| el17mtu | 0:15b74f0f8c7f | 90 | } |
| el17mtu | 0:15b74f0f8c7f | 91 | |
| el17mtu | 0:15b74f0f8c7f | 92 | speed = speed + gravity; |
| el17mtu | 0:15b74f0f8c7f | 93 | y_position = y_position + speed; |
| el17mtu | 0:15b74f0f8c7f | 94 | wait(0.1); |
| el17mtu | 2:6ee8616695d1 | 95 | |
| el17mtu | 3:8e6950aeec8a | 96 | |
| el17mtu | 3:8e6950aeec8a | 97 | lcd.drawRect(screen_width,0,bar_width,size_top,FILL_BLACK); |
| el17mtu | 3:8e6950aeec8a | 98 | lcd.drawRect(screen_width,48-size_bottom,bar_width,size_bottom,FILL_BLACK); |
| el17mtu | 3:8e6950aeec8a | 99 | lcd.refresh(); |
| el17mtu | 3:8e6950aeec8a | 100 | |
| el17mtu | 9:571f92b0211b | 101 | // if (screen_width > 50) { |
| el17mtu | 9:571f92b0211b | 102 | // srand(time(NULL)); |
| el17mtu | 9:571f92b0211b | 103 | // size_top = rand() % 48; |
| el17mtu | 9:571f92b0211b | 104 | // srand(time(NULL)); |
| el17mtu | 9:571f92b0211b | 105 | // size_bottom = rand() % 48; |
| el17mtu | 3:8e6950aeec8a | 106 | // bar_width = 50; |
| el17mtu | 3:8e6950aeec8a | 107 | // bar_speed = 0; |
| el17mtu | 9:571f92b0211b | 108 | // } |
| el17mtu | 2:6ee8616695d1 | 109 | |
| el17mtu | 9:571f92b0211b | 110 | // if (screen_width == 5) { |
| el17mtu | 9:571f92b0211b | 111 | // srand(time(NULL)); |
| el17mtu | 9:571f92b0211b | 112 | // size_top = rand() % 15; |
| el17mtu | 9:571f92b0211b | 113 | // srand(time(NULL)); |
| el17mtu | 9:571f92b0211b | 114 | // size_bottom = rand() % 15; |
| el17mtu | 9:571f92b0211b | 115 | // } |
| el17mtu | 9:571f92b0211b | 116 | // if (screen_width == 11) { |
| el17mtu | 9:571f92b0211b | 117 | // lcd.clear(); |
| el17mtu | 9:571f92b0211b | 118 | // lcd.printString("GAME OVER",6,2); |
| el17mtu | 9:571f92b0211b | 119 | // lcd.printString("Press BACK",6,4); |
| el17mtu | 9:571f92b0211b | 120 | // pad.tone(2000.0,0.3); |
| el17mtu | 9:571f92b0211b | 121 | // lcd.refresh(); |
| el17mtu | 9:571f92b0211b | 122 | // bar_speed = 0; |
| el17mtu | 9:571f92b0211b | 123 | // speed = 0; |
| el17mtu | 9:571f92b0211b | 124 | // gravity = 0; |
| el17mtu | 9:571f92b0211b | 125 | // y_position = 48; |
| el17mtu | 9:571f92b0211b | 126 | // bar_width = 0; |
| el17mtu | 9:571f92b0211b | 127 | // size_top = 0; |
| el17mtu | 9:571f92b0211b | 128 | // size_bottom = 0; |
| el17mtu | 9:571f92b0211b | 129 | |
| el17mtu | 9:571f92b0211b | 130 | |
| el17mtu | 9:571f92b0211b | 131 | |
| el17mtu | 11:e29b173ccb27 | 132 | // wait(0.5); |
| el17mtu | 11:e29b173ccb27 | 133 | // } |
| el17mtu | 11:e29b173ccb27 | 134 | |
| el17mtu | 11:e29b173ccb27 | 135 | |
| el17mtu | 11:e29b173ccb27 | 136 | |
| el17mtu | 11:e29b173ccb27 | 137 | |
| el17mtu | 11:e29b173ccb27 | 138 | if ((screen_width == x_position)&& (size_top > y_position)) { |
| el17mtu | 9:571f92b0211b | 139 | // size_top > y_position |
| el17mtu | 9:571f92b0211b | 140 | // screen_width == x_position |
| el17mtu | 9:571f92b0211b | 141 | lcd.clear(); |
| el17mtu | 9:571f92b0211b | 142 | lcd.printString("GAME OVER",6,2); |
| el17mtu | 9:571f92b0211b | 143 | lcd.printString("Press BACK",6,4); |
| el17mtu | 4:a81f05c8806a | 144 | pad.tone(2000.0,0.3); |
| el17mtu | 9:571f92b0211b | 145 | lcd.refresh(); |
| el17mtu | 9:571f92b0211b | 146 | bar_speed = 0; |
| el17mtu | 9:571f92b0211b | 147 | speed = 0; |
| el17mtu | 9:571f92b0211b | 148 | gravity = 0; |
| el17mtu | 9:571f92b0211b | 149 | y_position = 48; |
| el17mtu | 9:571f92b0211b | 150 | bar_width = 0; |
| el17mtu | 9:571f92b0211b | 151 | size_top = 0; |
| el17mtu | 9:571f92b0211b | 152 | size_bottom = 0; |
| el17mtu | 11:e29b173ccb27 | 153 | |
| el17mtu | 10:1c3bdbf2fe9f | 154 | |
| el17mtu | 4:a81f05c8806a | 155 | |
| el17mtu | 9:571f92b0211b | 156 | |
| el17mtu | 9:571f92b0211b | 157 | |
| el17mtu | 9:571f92b0211b | 158 | wait(0.5); |
| el17mtu | 11:e29b173ccb27 | 159 | } |
| el17mtu | 11:e29b173ccb27 | 160 | |
| el17mtu | 11:e29b173ccb27 | 161 | |
| el17mtu | 11:e29b173ccb27 | 162 | if ((screen_width == x_position)&& (size_top < y_position)) { |
| el17mtu | 11:e29b173ccb27 | 163 | |
| el17mtu | 11:e29b173ccb27 | 164 | score = score + 1; |
| el17mtu | 11:e29b173ccb27 | 165 | lcd.clear(); |
| el17mtu | 11:e29b173ccb27 | 166 | sprintf(buffer,"%2d",score); |
| el17mtu | 11:e29b173ccb27 | 167 | |
| el17mtu | 11:e29b173ccb27 | 168 | } |
| el17mtu | 11:e29b173ccb27 | 169 | |
| el17mtu | 9:571f92b0211b | 170 | |
| el17mtu | 11:e29b173ccb27 | 171 | if ( pad.check_event(Gamepad::X_PRESSED) == true) { |
| el17mtu | 11:e29b173ccb27 | 172 | |
| el17mtu | 11:e29b173ccb27 | 173 | srand(time(NULL)); |
| el17mtu | 11:e29b173ccb27 | 174 | size_top = rand() % 15; |
| el17mtu | 11:e29b173ccb27 | 175 | srand(time(NULL)); |
| el17mtu | 11:e29b173ccb27 | 176 | size_bottom = rand() % 15; |
| el17mtu | 11:e29b173ccb27 | 177 | |
| el17mtu | 11:e29b173ccb27 | 178 | } |
| el17mtu | 11:e29b173ccb27 | 179 | |
| el17mtu | 11:e29b173ccb27 | 180 | |
| el17mtu | 10:1c3bdbf2fe9f | 181 | |
| el17mtu | 11:e29b173ccb27 | 182 | // if ((screen_width == x_position)&& (size_top < y_position)) { |
| el17mtu | 11:e29b173ccb27 | 183 | |
| el17mtu | 11:e29b173ccb27 | 184 | // score = score + 1; |
| el17mtu | 11:e29b173ccb27 | 185 | |
| el17mtu | 11:e29b173ccb27 | 186 | |
| el17mtu | 11:e29b173ccb27 | 187 | // } |
| el17mtu | 10:1c3bdbf2fe9f | 188 | |
| el17mtu | 10:1c3bdbf2fe9f | 189 | |
| el17mtu | 10:1c3bdbf2fe9f | 190 | |
| el17mtu | 9:571f92b0211b | 191 | |
| el17mtu | 10:1c3bdbf2fe9f | 192 | // if ((screen_width == x_position)&& (size_bottom < (y_position - 6))) { |
| el17mtu | 10:1c3bdbf2fe9f | 193 | // |
| el17mtu | 10:1c3bdbf2fe9f | 194 | // lcd.printString("GAME OVER",6,2); |
| el17mtu | 10:1c3bdbf2fe9f | 195 | // lcd.printString("Press BACK",6,4); |
| el17mtu | 10:1c3bdbf2fe9f | 196 | // pad.tone(2000.0,0.3); |
| el17mtu | 10:1c3bdbf2fe9f | 197 | // lcd.refresh(); |
| el17mtu | 10:1c3bdbf2fe9f | 198 | // bar_speed = 0; |
| el17mtu | 10:1c3bdbf2fe9f | 199 | // speed = 0; |
| el17mtu | 10:1c3bdbf2fe9f | 200 | // gravity = 0; |
| el17mtu | 10:1c3bdbf2fe9f | 201 | // y_position = 48; |
| el17mtu | 10:1c3bdbf2fe9f | 202 | // bar_width = 0; |
| el17mtu | 10:1c3bdbf2fe9f | 203 | // size_top = 0; |
| el17mtu | 10:1c3bdbf2fe9f | 204 | // size_bottom = 0; |
| el17mtu | 10:1c3bdbf2fe9f | 205 | |
| el17mtu | 10:1c3bdbf2fe9f | 206 | |
| el17mtu | 10:1c3bdbf2fe9f | 207 | |
| el17mtu | 10:1c3bdbf2fe9f | 208 | // |
| el17mtu | 10:1c3bdbf2fe9f | 209 | // wait(0.5); |
| el17mtu | 10:1c3bdbf2fe9f | 210 | |
| el17mtu | 10:1c3bdbf2fe9f | 211 | // } |
| el17mtu | 10:1c3bdbf2fe9f | 212 | |
| el17mtu | 11:e29b173ccb27 | 213 | // if ((screen_width == x_position)&& (size_top < y_position)) { |
| el17mtu | 11:e29b173ccb27 | 214 | |
| el17mtu | 11:e29b173ccb27 | 215 | |
| el17mtu | 11:e29b173ccb27 | 216 | // score = score + 1; |
| el17mtu | 11:e29b173ccb27 | 217 | // } |
| el17mtu | 10:1c3bdbf2fe9f | 218 | // if ((screen_width == x_position)&& (size_bottom < (y_position - 6))) { |
| el17mtu | 10:1c3bdbf2fe9f | 219 | |
| el17mtu | 10:1c3bdbf2fe9f | 220 | // } |
| el17mtu | 0:15b74f0f8c7f | 221 | |
| el17mtu | 1:44f4594eacac | 222 | screen_width = screen_width - bar_speed; |
| el17mtu | 10:1c3bdbf2fe9f | 223 | |
| el17mtu | 3:8e6950aeec8a | 224 | wait(0.1); |
| el17mtu | 4:a81f05c8806a | 225 | |
| el17mtu | 4:a81f05c8806a | 226 | |
| el17mtu | 0:15b74f0f8c7f | 227 | |
| el17mtu | 0:15b74f0f8c7f | 228 | } |
| el17mtu | 0:15b74f0f8c7f | 229 | |
| el17mtu | 0:15b74f0f8c7f | 230 | |
| el17mtu | 0:15b74f0f8c7f | 231 | |
| el17mtu | 0:15b74f0f8c7f | 232 | |
| el17mtu | 0:15b74f0f8c7f | 233 | |
| el17mtu | 0:15b74f0f8c7f | 234 |