Mortal Kombat Game ELEC2645
Dependencies: mbed N5110 ShiftReg Joystick
Abandoned.cpp@18:22bda659c70a, 2021-04-29 (annotated)
- Committer:
- ozy
- Date:
- Thu Apr 29 22:40:08 2021 +0000
- Revision:
- 18:22bda659c70a
- Parent:
- 6:a1a7dc264fed
- Child:
- 20:4ca04fd0965a
GameEngine Update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ozy | 6:a1a7dc264fed | 1 | // This file includes abandoned code that was replaced |
ozy | 6:a1a7dc264fed | 2 | /* |
ozy | 18:22bda659c70a | 3 | Function works but better solutions available |
ozy | 18:22bda659c70a | 4 | void GameEngine::check_health(N5110 &lcd, DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC) { |
ozy | 18:22bda659c70a | 5 | int F = 40; |
ozy | 18:22bda659c70a | 6 | int E = 40; |
ozy | 18:22bda659c70a | 7 | int collision = check_collision(lcd, buttonA, buttonB, buttonC); |
ozy | 18:22bda659c70a | 8 | if (collision == 1) { |
ozy | 18:22bda659c70a | 9 | F -= 4; |
ozy | 18:22bda659c70a | 10 | printf("fighter take health bar \n"); |
ozy | 18:22bda659c70a | 11 | } |
ozy | 18:22bda659c70a | 12 | // enemy health bar |
ozy | 18:22bda659c70a | 13 | // x y w h, type |
ozy | 18:22bda659c70a | 14 | lcd.drawRect(0,0,E,8,FILL_BLACK); |
ozy | 18:22bda659c70a | 15 | lcd.drawRect(0,0,40,8,FILL_TRANSPARENT); |
ozy | 18:22bda659c70a | 16 | if (collision == 0) { |
ozy | 18:22bda659c70a | 17 | E -= 4; |
ozy | 18:22bda659c70a | 18 | printf("enemy take health bar \n"); |
ozy | 18:22bda659c70a | 19 | } |
ozy | 18:22bda659c70a | 20 | } |
ozy | 18:22bda659c70a | 21 | */ |
ozy | 18:22bda659c70a | 22 | |
ozy | 18:22bda659c70a | 23 | /* |
ozy | 18:22bda659c70a | 24 | int get_fighter_health() { |
ozy | 18:22bda659c70a | 25 | // check collision before reducing fighter's health |
ozy | 18:22bda659c70a | 26 | int collision = game.check_collision(lcd, buttonA, buttonB, buttonC); |
ozy | 18:22bda659c70a | 27 | int fighter_health = HEALTH; |
ozy | 18:22bda659c70a | 28 | int enemy_health = HEALTH; |
ozy | 18:22bda659c70a | 29 | int lost = 0; |
ozy | 18:22bda659c70a | 30 | if (collision == 0) { |
ozy | 18:22bda659c70a | 31 | fighter_health--; |
ozy | 18:22bda659c70a | 32 | printf("fighter health is = %i", enemy_health); |
ozy | 18:22bda659c70a | 33 | if (fighter_health == 0) { // if fighter has zero health, fighter is the loser |
ozy | 18:22bda659c70a | 34 | gameover(0); |
ozy | 18:22bda659c70a | 35 | lost = 0; |
ozy | 18:22bda659c70a | 36 | } |
ozy | 18:22bda659c70a | 37 | } |
ozy | 18:22bda659c70a | 38 | else if (collision == 1) { |
ozy | 18:22bda659c70a | 39 | enemy_health--; |
ozy | 18:22bda659c70a | 40 | printf("enemy health is = %i", enemy_health); |
ozy | 18:22bda659c70a | 41 | if (enemy_health == 0) { // if fighter has zero health, fighter is the loser |
ozy | 18:22bda659c70a | 42 | gameover(1); |
ozy | 18:22bda659c70a | 43 | lost = 1; |
ozy | 18:22bda659c70a | 44 | } |
ozy | 18:22bda659c70a | 45 | } |
ozy | 18:22bda659c70a | 46 | return lost; |
ozy | 18:22bda659c70a | 47 | } |
ozy | 18:22bda659c70a | 48 | |
ozy | 18:22bda659c70a | 49 | int GameEngine::get_fighter_health(int collision, int health) { |
ozy | 18:22bda659c70a | 50 | if (collision == 0) { |
ozy | 18:22bda659c70a | 51 | health--; |
ozy | 18:22bda659c70a | 52 | } |
ozy | 18:22bda659c70a | 53 | //printf("f health = %i\n", health); |
ozy | 18:22bda659c70a | 54 | return health; |
ozy | 18:22bda659c70a | 55 | } |
ozy | 18:22bda659c70a | 56 | |
ozy | 18:22bda659c70a | 57 | int GameEngine::get_enemy_health(int collision, int health) { |
ozy | 18:22bda659c70a | 58 | if (collision == 1) { |
ozy | 18:22bda659c70a | 59 | health--; |
ozy | 18:22bda659c70a | 60 | } |
ozy | 18:22bda659c70a | 61 | //printf("enemy health = %i\n", health); |
ozy | 18:22bda659c70a | 62 | return health; |
ozy | 18:22bda659c70a | 63 | } |
ozy | 18:22bda659c70a | 64 | |
ozy | 6:a1a7dc264fed | 65 | |
ozy | 6:a1a7dc264fed | 66 | void move_sprite() { |
ozy | 6:a1a7dc264fed | 67 | // getting joystick coordinates using read() function |
ozy | 6:a1a7dc264fed | 68 | // joystick centered at (0.50,0.50) with utmost left at (1.00,0.50) and utmost right being (0.00,0.50) |
ozy | 6:a1a7dc264fed | 69 | // read each of the pins |
ozy | 6:a1a7dc264fed | 70 | float x = joy_h.read(); |
ozy | 6:a1a7dc264fed | 71 | float y = joy_v.read(); |
ozy | 6:a1a7dc264fed | 72 | printf("x = %.2f | y = %.2f \n",x,y); |
ozy | 6:a1a7dc264fed | 73 | // get x position of fighter |
ozy | 6:a1a7dc264fed | 74 | int x_pos = fighter.get_x(); |
ozy | 6:a1a7dc264fed | 75 | printf("fighter x pos = %i \n", x_pos); |
ozy | 6:a1a7dc264fed | 76 | |
ozy | 6:a1a7dc264fed | 77 | / * |
ozy | 6:a1a7dc264fed | 78 | Code idea: |
ozy | 6:a1a7dc264fed | 79 | if joystick is not moved , display standing sprite |
ozy | 6:a1a7dc264fed | 80 | if joystick is moved right, toggle between runright and midrunright |
ozy | 6:a1a7dc264fed | 81 | if joystick is moved left, toggle between runleft and midrunleft |
ozy | 6:a1a7dc264fed | 82 | * / |
ozy | 6:a1a7dc264fed | 83 | if(x > 0.48 && x < 0.52) { // joystick not moved - we use ± 0.02 to take account of fluctuation in joystick tolerance and noice on ADC |
ozy | 6:a1a7dc264fed | 84 | fighter.draw(lcd); // draw standing fighter |
ozy | 6:a1a7dc264fed | 85 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 86 | wait(0.3); |
ozy | 6:a1a7dc264fed | 87 | |
ozy | 6:a1a7dc264fed | 88 | // Preform kick move if user presses button A |
ozy | 6:a1a7dc264fed | 89 | if (buttonA.read() == 1) { |
ozy | 6:a1a7dc264fed | 90 | fighter.kick_right(lcd); // draw kick on same coordinates as the standing sprite |
ozy | 6:a1a7dc264fed | 91 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 92 | wait(0.3); |
ozy | 6:a1a7dc264fed | 93 | } |
ozy | 6:a1a7dc264fed | 94 | // Preform punch move if user presses button B |
ozy | 6:a1a7dc264fed | 95 | if (buttonB.read() == 1) { |
ozy | 6:a1a7dc264fed | 96 | fighter.punch_right(lcd); // draw kick |
ozy | 6:a1a7dc264fed | 97 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 98 | wait(0.3); |
ozy | 6:a1a7dc264fed | 99 | } |
ozy | 6:a1a7dc264fed | 100 | // Guard if user presses button C |
ozy | 6:a1a7dc264fed | 101 | while (buttonC.read() == 1) { |
ozy | 6:a1a7dc264fed | 102 | fighter.guard(lcd); // draw guard move frame |
ozy | 6:a1a7dc264fed | 103 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 104 | wait(0.3); |
ozy | 6:a1a7dc264fed | 105 | } |
ozy | 6:a1a7dc264fed | 106 | } |
ozy | 6:a1a7dc264fed | 107 | else if(x < 0.48) { // joystick moved to the right |
ozy | 6:a1a7dc264fed | 108 | // print the move_right animation, refresh, then print the 2nd move_right animation (toggling animations to create moving legs!) |
ozy | 6:a1a7dc264fed | 109 | fighter.add_x(5); // increment by 5 |
ozy | 6:a1a7dc264fed | 110 | fighter.move_right(lcd); |
ozy | 6:a1a7dc264fed | 111 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 112 | wait(0.1); |
ozy | 6:a1a7dc264fed | 113 | fighter.move_right2(lcd); |
ozy | 6:a1a7dc264fed | 114 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 115 | wait(0.08); |
ozy | 6:a1a7dc264fed | 116 | |
ozy | 6:a1a7dc264fed | 117 | if (x_pos >= 65) { // code to stop fighter moving out of lcd screen |
ozy | 6:a1a7dc264fed | 118 | fighter.add_x(-5); |
ozy | 6:a1a7dc264fed | 119 | } |
ozy | 6:a1a7dc264fed | 120 | |
ozy | 6:a1a7dc264fed | 121 | |
ozy | 6:a1a7dc264fed | 122 | // kick if user presses button A |
ozy | 6:a1a7dc264fed | 123 | if (buttonA.read() == 1) { |
ozy | 6:a1a7dc264fed | 124 | fighter.kick_right(lcd); |
ozy | 6:a1a7dc264fed | 125 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 126 | wait(0.3); |
ozy | 6:a1a7dc264fed | 127 | } |
ozy | 6:a1a7dc264fed | 128 | // Preform punch move if user presses button B |
ozy | 6:a1a7dc264fed | 129 | if (buttonB.read() == 1) { |
ozy | 6:a1a7dc264fed | 130 | fighter.punch_right(lcd); // draw kick on same coordinates as the sprite |
ozy | 6:a1a7dc264fed | 131 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 132 | wait(0.3); |
ozy | 6:a1a7dc264fed | 133 | } |
ozy | 6:a1a7dc264fed | 134 | // Guard if user presses button C |
ozy | 6:a1a7dc264fed | 135 | while (buttonC.read() == 1) { // we use while not if here because user would hold to guard |
ozy | 6:a1a7dc264fed | 136 | fighter.guard(lcd); // draw kick on same coordinates as the sprite |
ozy | 6:a1a7dc264fed | 137 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 138 | wait(0.3); |
ozy | 6:a1a7dc264fed | 139 | } |
ozy | 6:a1a7dc264fed | 140 | } |
ozy | 6:a1a7dc264fed | 141 | |
ozy | 6:a1a7dc264fed | 142 | else if(x > 0.52) { // joystick moved to the left |
ozy | 6:a1a7dc264fed | 143 | fighter.add_x(-5); // decrement left by 5 |
ozy | 6:a1a7dc264fed | 144 | fighter.move_left(lcd); |
ozy | 6:a1a7dc264fed | 145 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 146 | wait(0.1); |
ozy | 6:a1a7dc264fed | 147 | fighter.move_left2(lcd); |
ozy | 6:a1a7dc264fed | 148 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 149 | wait(0.08); |
ozy | 6:a1a7dc264fed | 150 | |
ozy | 6:a1a7dc264fed | 151 | if (x_pos <= 6) { // code to stop fighter moving out of lcd screen |
ozy | 6:a1a7dc264fed | 152 | fighter.add_x(5); |
ozy | 6:a1a7dc264fed | 153 | } |
ozy | 6:a1a7dc264fed | 154 | |
ozy | 6:a1a7dc264fed | 155 | // kick if user presses button A |
ozy | 6:a1a7dc264fed | 156 | if (buttonA.read() == 1) { |
ozy | 6:a1a7dc264fed | 157 | fighter.kick_left(lcd); |
ozy | 6:a1a7dc264fed | 158 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 159 | wait(0.3); |
ozy | 6:a1a7dc264fed | 160 | } |
ozy | 6:a1a7dc264fed | 161 | if (buttonB.read() == 1) { |
ozy | 6:a1a7dc264fed | 162 | fighter.punch_left(lcd); // draw punch on same coordinates as the sprite |
ozy | 6:a1a7dc264fed | 163 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 164 | wait(0.3); |
ozy | 6:a1a7dc264fed | 165 | } |
ozy | 6:a1a7dc264fed | 166 | // Guard if user presses button C |
ozy | 6:a1a7dc264fed | 167 | if (buttonC.read() == 1) { |
ozy | 6:a1a7dc264fed | 168 | fighter.guard(lcd); // draw guard on same coordinates as the sprite |
ozy | 6:a1a7dc264fed | 169 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 170 | wait(0.3); |
ozy | 6:a1a7dc264fed | 171 | } |
ozy | 6:a1a7dc264fed | 172 | } |
ozy | 6:a1a7dc264fed | 173 | } |
ozy | 6:a1a7dc264fed | 174 | |
ozy | 6:a1a7dc264fed | 175 | void move_enemy() { |
ozy | 6:a1a7dc264fed | 176 | // read each of the pins |
ozy | 6:a1a7dc264fed | 177 | float x = joy_h.read(); |
ozy | 6:a1a7dc264fed | 178 | float y = joy_v.read(); |
ozy | 6:a1a7dc264fed | 179 | printf("x = %.2f | y = %.2f \n",x,y); |
ozy | 6:a1a7dc264fed | 180 | // get x position of enemy |
ozy | 6:a1a7dc264fed | 181 | int x_pos = enemy.get_x(); |
ozy | 6:a1a7dc264fed | 182 | printf("enemy x pos = %i \n", x_pos); |
ozy | 6:a1a7dc264fed | 183 | |
ozy | 6:a1a7dc264fed | 184 | if(x > 0.48 && x < 0.52) { // joystick not moved - we use ± 0.02 to take account of fluctuation in joystick tolerance and noice on ADC |
ozy | 6:a1a7dc264fed | 185 | enemy.draw(lcd); // draw enemy |
ozy | 6:a1a7dc264fed | 186 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 187 | wait(0.3); |
ozy | 6:a1a7dc264fed | 188 | // Preform kick move if user presses button A |
ozy | 6:a1a7dc264fed | 189 | if (buttonA.read() == 1) { |
ozy | 6:a1a7dc264fed | 190 | enemy.kick_right(lcd); // draw kick on same coordinates as the standing sprite |
ozy | 6:a1a7dc264fed | 191 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 192 | wait(0.3); |
ozy | 6:a1a7dc264fed | 193 | } |
ozy | 6:a1a7dc264fed | 194 | // Preform punch move if user presses button B |
ozy | 6:a1a7dc264fed | 195 | if (buttonB.read() == 1) { |
ozy | 6:a1a7dc264fed | 196 | enemy.sword_right(lcd); // draw sword move on same coordinates as the standing sprite |
ozy | 6:a1a7dc264fed | 197 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 198 | wait(0.3); |
ozy | 6:a1a7dc264fed | 199 | } |
ozy | 6:a1a7dc264fed | 200 | } |
ozy | 6:a1a7dc264fed | 201 | else if(x < 0.48) { // joystick moved to the right |
ozy | 6:a1a7dc264fed | 202 | enemy.add_x(5); // increment by 5 |
ozy | 6:a1a7dc264fed | 203 | // print the move_right animation, refresh, then print the 2nd move_right animation (toggling animations to create moving legs!) |
ozy | 6:a1a7dc264fed | 204 | enemy.move_right(lcd); // draw standing fighter, multiply by speed -69 (negative to correct for direction!) |
ozy | 6:a1a7dc264fed | 205 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 206 | wait(0.1); |
ozy | 6:a1a7dc264fed | 207 | enemy.move_right2(lcd); |
ozy | 6:a1a7dc264fed | 208 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 209 | wait(0.08); |
ozy | 6:a1a7dc264fed | 210 | |
ozy | 6:a1a7dc264fed | 211 | if (x_pos >= 65) { // code to stop enemy moving out of lcd screen |
ozy | 6:a1a7dc264fed | 212 | enemy.add_x(-5); |
ozy | 6:a1a7dc264fed | 213 | } |
ozy | 6:a1a7dc264fed | 214 | |
ozy | 6:a1a7dc264fed | 215 | // kick if user presses button A |
ozy | 6:a1a7dc264fed | 216 | if (buttonA.read() == 1) { |
ozy | 6:a1a7dc264fed | 217 | enemy.kick_right(lcd); |
ozy | 6:a1a7dc264fed | 218 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 219 | wait(0.3); |
ozy | 6:a1a7dc264fed | 220 | } |
ozy | 6:a1a7dc264fed | 221 | // Preform punch move if user presses button B |
ozy | 6:a1a7dc264fed | 222 | if (buttonB.read() == 1) { |
ozy | 6:a1a7dc264fed | 223 | enemy.sword_right(lcd); // draw kick on same coordinates as the sprite |
ozy | 6:a1a7dc264fed | 224 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 225 | wait(0.3); |
ozy | 6:a1a7dc264fed | 226 | } |
ozy | 6:a1a7dc264fed | 227 | } |
ozy | 6:a1a7dc264fed | 228 | else if(x > 0.52) { // joystick moved to the left |
ozy | 6:a1a7dc264fed | 229 | enemy.add_x(-5); // decrement by 5 |
ozy | 6:a1a7dc264fed | 230 | enemy.move_left(lcd); |
ozy | 6:a1a7dc264fed | 231 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 232 | wait(0.1); |
ozy | 6:a1a7dc264fed | 233 | enemy.move_left2(lcd); |
ozy | 6:a1a7dc264fed | 234 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 235 | wait(0.08); |
ozy | 6:a1a7dc264fed | 236 | |
ozy | 6:a1a7dc264fed | 237 | |
ozy | 6:a1a7dc264fed | 238 | if (x_pos <= 6) { // code to stop enemy moving out of lcd screen |
ozy | 6:a1a7dc264fed | 239 | enemy.add_x(5); |
ozy | 6:a1a7dc264fed | 240 | } |
ozy | 6:a1a7dc264fed | 241 | |
ozy | 6:a1a7dc264fed | 242 | // kick if user presses button A |
ozy | 6:a1a7dc264fed | 243 | if (buttonA.read() == 1) { |
ozy | 6:a1a7dc264fed | 244 | enemy.kick_left(lcd); |
ozy | 6:a1a7dc264fed | 245 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 246 | wait(0.3); |
ozy | 6:a1a7dc264fed | 247 | } |
ozy | 6:a1a7dc264fed | 248 | if (buttonB.read() == 1) { |
ozy | 6:a1a7dc264fed | 249 | enemy.sword_left(lcd); // draw kick on same coordinates as the sprite |
ozy | 6:a1a7dc264fed | 250 | lcd.refresh(); |
ozy | 6:a1a7dc264fed | 251 | wait(0.3); |
ozy | 6:a1a7dc264fed | 252 | } |
ozy | 6:a1a7dc264fed | 253 | } |
ozy | 6:a1a7dc264fed | 254 | } |
ozy | 0:99b49fd71085 | 255 | |
ozy | 0:99b49fd71085 | 256 | /* |
ozy | 6:a1a7dc264fed | 257 | |
ozy | 3:1d99b6ad4f9e | 258 | int get_user_input(int &input) { |
ozy | 3:1d99b6ad4f9e | 259 | while (1) { |
ozy | 3:1d99b6ad4f9e | 260 | if (buttonA.read() == 1) { |
ozy | 3:1d99b6ad4f9e | 261 | input = 1; |
ozy | 3:1d99b6ad4f9e | 262 | break; |
ozy | 3:1d99b6ad4f9e | 263 | } |
ozy | 3:1d99b6ad4f9e | 264 | if (buttonB.read() == 1) { |
ozy | 3:1d99b6ad4f9e | 265 | input = 2; |
ozy | 3:1d99b6ad4f9e | 266 | break; |
ozy | 3:1d99b6ad4f9e | 267 | } |
ozy | 3:1d99b6ad4f9e | 268 | if (buttonC.read() == 1) { |
ozy | 3:1d99b6ad4f9e | 269 | input = 3; |
ozy | 3:1d99b6ad4f9e | 270 | break; |
ozy | 3:1d99b6ad4f9e | 271 | } |
ozy | 3:1d99b6ad4f9e | 272 | if (buttonD.read() == 1) { |
ozy | 3:1d99b6ad4f9e | 273 | input = 4; |
ozy | 3:1d99b6ad4f9e | 274 | break; |
ozy | 3:1d99b6ad4f9e | 275 | } |
ozy | 3:1d99b6ad4f9e | 276 | } |
ozy | 3:1d99b6ad4f9e | 277 | return input; |
ozy | 3:1d99b6ad4f9e | 278 | } |
ozy | 3:1d99b6ad4f9e | 279 | |
ozy | 3:1d99b6ad4f9e | 280 | |
ozy | 3:1d99b6ad4f9e | 281 | |
ozy | 0:99b49fd71085 | 282 | void abandoned_function() { |
ozy | 0:99b49fd71085 | 283 | // getting joystick coordinates using Vector2D |
ozy | 0:99b49fd71085 | 284 | // joystick centered at 0 with (1,0) being utmost right and (-1,0) being utmost left |
ozy | 0:99b49fd71085 | 285 | Vector2D coord = joystick.get_coord(); |
ozy | 0:99b49fd71085 | 286 | printf("Coord = %f | %f\n", coord.x, coord.y); |
ozy | 0:99b49fd71085 | 287 | float x = coord.x; |
ozy | 0:99b49fd71085 | 288 | float y = coord.y; |
ozy | 0:99b49fd71085 | 289 | |
ozy | 0:99b49fd71085 | 290 | loop idea: |
ozy | 0:99b49fd71085 | 291 | while nothing pressed, display standsprite |
ozy | 0:99b49fd71085 | 292 | while moving right, toggle between runright and midrunright |
ozy | 0:99b49fd71085 | 293 | while moving left, toggle between runleft and midrunleft |
ozy | 0:99b49fd71085 | 294 | |
ozy | 0:99b49fd71085 | 295 | while (x > -0.02 && x < 0.02) { // joystick not moved - we use ± 0.02 to take account of fluctuation in joystick input |
ozy | 0:99b49fd71085 | 296 | fighter.draw(lcd, x, 34); // we write 34 as the y-coordinate to place sprite exactly on ground ( 46 - 12(height of sprite) = 34 ) |
ozy | 0:99b49fd71085 | 297 | printf("*Coord = %f | %f\n",x, y); |
ozy | 0:99b49fd71085 | 298 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 299 | } |
ozy | 0:99b49fd71085 | 300 | |
ozy | 0:99b49fd71085 | 301 | while (x > 0.02) { // Joystick moved to the right |
ozy | 0:99b49fd71085 | 302 | // toggle between the 2 move_right animations with a small delay in between to make it smooth |
ozy | 0:99b49fd71085 | 303 | fighter.update_forward(x); |
ozy | 0:99b49fd71085 | 304 | printf("**Coord = %f | %f\n", x, y); |
ozy | 0:99b49fd71085 | 305 | fighter.move_right(lcd, x, 34); |
ozy | 0:99b49fd71085 | 306 | wait(0.2); |
ozy | 0:99b49fd71085 | 307 | fighter.update_forward(x); |
ozy | 0:99b49fd71085 | 308 | fighter.move_right2(lcd, x, 34); |
ozy | 0:99b49fd71085 | 309 | wait(0.2); |
ozy | 0:99b49fd71085 | 310 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 311 | } |
ozy | 0:99b49fd71085 | 312 | while (x < -0.02) { // Joystick moved to the left |
ozy | 0:99b49fd71085 | 313 | // toggle between the 2 move_left animations with a small delay in between to make it smooth |
ozy | 0:99b49fd71085 | 314 | fighter.update_backward(x); |
ozy | 0:99b49fd71085 | 315 | printf("***Coord = %f | %f\n", x, y); |
ozy | 0:99b49fd71085 | 316 | fighter.move_left(lcd, x, 34); |
ozy | 0:99b49fd71085 | 317 | wait(0.2); |
ozy | 0:99b49fd71085 | 318 | fighter.update_backward(x); |
ozy | 0:99b49fd71085 | 319 | fighter.move_left2(lcd, x, 34); |
ozy | 0:99b49fd71085 | 320 | wait(0.2); |
ozy | 0:99b49fd71085 | 321 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 322 | } |
ozy | 0:99b49fd71085 | 323 | } |
ozy | 0:99b49fd71085 | 324 | |
ozy | 0:99b49fd71085 | 325 | |
ozy | 0:99b49fd71085 | 326 | const int logo[17][19] = { |
ozy | 0:99b49fd71085 | 327 | |
ozy | 0:99b49fd71085 | 328 | { 1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1 }, |
ozy | 0:99b49fd71085 | 329 | { 0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 330 | { 0,0,0,0,0,1,0,1,1,1,0,0,0,0,1,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 331 | { 0,0,0,0,1,0,1,1,1,1,1,0,0,0,0,1,0,0,0 }, |
ozy | 0:99b49fd71085 | 332 | { 0,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0 }, |
ozy | 0:99b49fd71085 | 333 | { 0,0,1,0,1,1,1,0,1,1,1,1,1,1,0,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 334 | { 0,0,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 335 | { 0,0,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 336 | { 0,0,1,0,1,1,1,1,0,0,0,0,0,1,1,1,0,1,0 }, |
ozy | 0:99b49fd71085 | 337 | { 0,0,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 338 | { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 339 | { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0 }, |
ozy | 0:99b49fd71085 | 340 | { 0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0 }, |
ozy | 0:99b49fd71085 | 341 | { 0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0 }, |
ozy | 0:99b49fd71085 | 342 | { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 343 | { 0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 344 | { 1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1 }, |
ozy | 0:99b49fd71085 | 345 | |
ozy | 0:99b49fd71085 | 346 | }; |
ozy | 0:99b49fd71085 | 347 | */ |
ozy | 1:3bdadf6f6dbd | 348 | |
ozy | 1:3bdadf6f6dbd | 349 | /* |
ozy | 1:3bdadf6f6dbd | 350 | void menu_select() { |
ozy | 1:3bdadf6f6dbd | 351 | char button = get_user_input(); |
ozy | 1:3bdadf6f6dbd | 352 | switch (button) { |
ozy | 1:3bdadf6f6dbd | 353 | case 'A': |
ozy | 1:3bdadf6f6dbd | 354 | menu.play(lcd); |
ozy | 1:3bdadf6f6dbd | 355 | break; |
ozy | 1:3bdadf6f6dbd | 356 | case 'B': |
ozy | 1:3bdadf6f6dbd | 357 | menu.tutorial(lcd); |
ozy | 1:3bdadf6f6dbd | 358 | break; |
ozy | 1:3bdadf6f6dbd | 359 | case 'C': |
ozy | 1:3bdadf6f6dbd | 360 | menu.options_menu(lcd); |
ozy | 1:3bdadf6f6dbd | 361 | break; |
ozy | 1:3bdadf6f6dbd | 362 | default: |
ozy | 1:3bdadf6f6dbd | 363 | menu.homescreen(lcd); |
ozy | 1:3bdadf6f6dbd | 364 | break; |
ozy | 1:3bdadf6f6dbd | 365 | } |
ozy | 1:3bdadf6f6dbd | 366 | } |
ozy | 1:3bdadf6f6dbd | 367 | |
ozy | 1:3bdadf6f6dbd | 368 | char get_user_input() { |
ozy | 1:3bdadf6f6dbd | 369 | char button; |
ozy | 1:3bdadf6f6dbd | 370 | while (buttonA.read() == 1) { |
ozy | 1:3bdadf6f6dbd | 371 | button = 'A'; |
ozy | 1:3bdadf6f6dbd | 372 | wait(0.2); |
ozy | 1:3bdadf6f6dbd | 373 | } |
ozy | 1:3bdadf6f6dbd | 374 | while (buttonB.read() == 1) { |
ozy | 1:3bdadf6f6dbd | 375 | button = 'B'; |
ozy | 1:3bdadf6f6dbd | 376 | wait(0.2); |
ozy | 1:3bdadf6f6dbd | 377 | } |
ozy | 1:3bdadf6f6dbd | 378 | while (buttonC.read() == 1) { |
ozy | 1:3bdadf6f6dbd | 379 | button = 'C'; |
ozy | 1:3bdadf6f6dbd | 380 | wait(0.2); |
ozy | 1:3bdadf6f6dbd | 381 | } |
ozy | 1:3bdadf6f6dbd | 382 | while (buttonD.read() == 1) { |
ozy | 1:3bdadf6f6dbd | 383 | button = 'D'; |
ozy | 1:3bdadf6f6dbd | 384 | wait(0.2); |
ozy | 1:3bdadf6f6dbd | 385 | } |
ozy | 1:3bdadf6f6dbd | 386 | pc.printf("Value is %c", button); |
ozy | 1:3bdadf6f6dbd | 387 | return button; |
ozy | 1:3bdadf6f6dbd | 388 | } |
ozy | 1:3bdadf6f6dbd | 389 | */ |