Mortal Kombat Game ELEC2645

Dependencies:   mbed N5110 ShiftReg Joystick

Committer:
ozy
Date:
Thu Apr 22 01:24:12 2021 +0000
Revision:
7:737fb0c3dbef
Parent:
6:a1a7dc264fed
Child:
8:e2e2eb4ea0ca
Code with Refresh problem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ozy 0:99b49fd71085 1 #include "Fighter.h"
ozy 0:99b49fd71085 2 #include "mbed.h"
ozy 0:99b49fd71085 3
ozy 0:99b49fd71085 4
ozy 0:99b49fd71085 5 Fighter::Fighter() {}
ozy 0:99b49fd71085 6
ozy 3:1d99b6ad4f9e 7 int Fighter::get_x() {
ozy 3:1d99b6ad4f9e 8 return _x;
ozy 3:1d99b6ad4f9e 9 }
ozy 3:1d99b6ad4f9e 10
ozy 3:1d99b6ad4f9e 11 int Fighter::get_y() {
ozy 3:1d99b6ad4f9e 12 return _y;
ozy 3:1d99b6ad4f9e 13 }
ozy 3:1d99b6ad4f9e 14
ozy 7:737fb0c3dbef 15 void Fighter::init() {
ozy 7:737fb0c3dbef 16 // initialize fighter position
ozy 7:737fb0c3dbef 17 set_x(15);
ozy 7:737fb0c3dbef 18 set_y(34);
ozy 7:737fb0c3dbef 19 }
ozy 7:737fb0c3dbef 20
ozy 3:1d99b6ad4f9e 21 void Fighter::set_x(int x) {
ozy 3:1d99b6ad4f9e 22 _x = x;
ozy 3:1d99b6ad4f9e 23 }
ozy 3:1d99b6ad4f9e 24
ozy 3:1d99b6ad4f9e 25 void Fighter::set_y(int y) {
ozy 3:1d99b6ad4f9e 26 _y = y;
ozy 3:1d99b6ad4f9e 27 }
ozy 3:1d99b6ad4f9e 28
ozy 7:737fb0c3dbef 29 void Fighter::add_x(int x) {
ozy 3:1d99b6ad4f9e 30 _x += x;
ozy 3:1d99b6ad4f9e 31 }
ozy 3:1d99b6ad4f9e 32
ozy 7:737fb0c3dbef 33 void Fighter::add_y(int y) {
ozy 3:1d99b6ad4f9e 34 _y += y;
ozy 3:1d99b6ad4f9e 35 }
ozy 3:1d99b6ad4f9e 36
ozy 7:737fb0c3dbef 37 void Fighter::draw(N5110 &lcd) { // drawing standing Fighter
ozy 0:99b49fd71085 38
ozy 0:99b49fd71085 39 const int standsprite[12][10] = {
ozy 0:99b49fd71085 40 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 41 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 42 { 0,0,1,1,1,1,1,1,0,0 },
ozy 0:99b49fd71085 43 { 0,0,1,0,1,1,0,1,0,0 },
ozy 0:99b49fd71085 44 { 0,1,1,0,1,1,0,1,1,0 },
ozy 0:99b49fd71085 45 { 0,1,0,0,1,1,0,0,1,0 },
ozy 0:99b49fd71085 46 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 47 { 0,0,1,1,0,0,1,1,0,0 },
ozy 0:99b49fd71085 48 { 0,0,1,0,0,0,0,1,0,0 },
ozy 0:99b49fd71085 49 { 0,1,1,0,0,0,0,1,1,0 },
ozy 0:99b49fd71085 50 { 0,1,0,0,0,0,0,0,1,0 },
ozy 0:99b49fd71085 51 { 0,1,0,0,0,0,0,0,1,0 },
ozy 0:99b49fd71085 52 };
ozy 7:737fb0c3dbef 53
ozy 7:737fb0c3dbef 54 lcd.drawSprite(_x,_y,12,10,(int *)standsprite);
ozy 7:737fb0c3dbef 55 }
ozy 7:737fb0c3dbef 56
ozy 7:737fb0c3dbef 57 // ************************************************************************
ozy 7:737fb0c3dbef 58
ozy 7:737fb0c3dbef 59 void Fighter::move_left(N5110 &lcd){
ozy 0:99b49fd71085 60 const int run_left[12][10] = {
ozy 0:99b49fd71085 61 { 0,0,1,1,1,0,0,0,0,0 },
ozy 0:99b49fd71085 62 { 0,0,1,1,1,0,0,0,0,0 },
ozy 0:99b49fd71085 63 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 64 { 0,0,1,0,1,1,1,1,0,0 },
ozy 0:99b49fd71085 65 { 1,1,1,0,1,1,0,1,1,0 },
ozy 0:99b49fd71085 66 { 0,0,0,0,1,1,0,0,0,1 },
ozy 0:99b49fd71085 67 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 68 { 0,0,1,1,0,0,1,1,0,0 },
ozy 0:99b49fd71085 69 { 0,1,1,0,0,0,1,1,1,1 },
ozy 0:99b49fd71085 70 { 0,0,1,1,0,0,0,0,0,0 },
ozy 0:99b49fd71085 71 { 0,0,0,1,1,0,0,0,0,0 },
ozy 0:99b49fd71085 72 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 73 };
ozy 7:737fb0c3dbef 74 lcd.drawSprite(_x,_y,12,10,(int *)run_left);
ozy 7:737fb0c3dbef 75 }
ozy 7:737fb0c3dbef 76
ozy 7:737fb0c3dbef 77 // ************************************************************************
ozy 7:737fb0c3dbef 78
ozy 7:737fb0c3dbef 79 void Fighter::move_left2(N5110 &lcd){
ozy 7:737fb0c3dbef 80 const int midrun_left[12][10] = {
ozy 0:99b49fd71085 81 { 0,0,1,1,1,0,0,0,0,0 },
ozy 0:99b49fd71085 82 { 0,0,1,1,1,0,0,0,0,0 },
ozy 0:99b49fd71085 83 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 84 { 0,0,1,0,1,1,1,1,0,0 },
ozy 0:99b49fd71085 85 { 1,1,1,0,1,1,0,1,1,0 },
ozy 0:99b49fd71085 86 { 0,0,0,0,1,1,0,0,0,1 },
ozy 0:99b49fd71085 87 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 88 { 0,0,1,1,0,0,1,1,0,0 },
ozy 1:3bdadf6f6dbd 89 { 0,0,0,1,1,1,1,0,0,0 },
ozy 1:3bdadf6f6dbd 90 { 0,0,0,0,1,1,0,0,0,0 },
ozy 1:3bdadf6f6dbd 91 { 0,0,0,0,1,0,1,0,0,0 },
ozy 1:3bdadf6f6dbd 92 { 0,0,0,1,0,0,0,1,0,0 },
ozy 0:99b49fd71085 93 };
ozy 7:737fb0c3dbef 94 lcd.drawSprite(_x,_y,12,10,(int *)midrun_left);
ozy 7:737fb0c3dbef 95 }
ozy 7:737fb0c3dbef 96
ozy 7:737fb0c3dbef 97 // ************************************************************************
ozy 7:737fb0c3dbef 98
ozy 7:737fb0c3dbef 99 void Fighter::move_right(N5110 &lcd) {
ozy 7:737fb0c3dbef 100
ozy 0:99b49fd71085 101 const int run_right[12][10] = {
ozy 0:99b49fd71085 102 { 0,0,0,0,0,1,1,1,0,0 },
ozy 0:99b49fd71085 103 { 0,0,0,0,0,1,1,1,0,0 },
ozy 0:99b49fd71085 104 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 105 { 0,0,1,1,1,1,0,1,0,0 },
ozy 0:99b49fd71085 106 { 0,1,1,0,1,1,0,1,1,1 },
ozy 0:99b49fd71085 107 { 1,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 108 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 109 { 0,0,1,1,0,0,1,1,0,0 },
ozy 0:99b49fd71085 110 { 1,1,1,1,0,0,0,1,1,0 },
ozy 0:99b49fd71085 111 { 0,0,0,0,0,0,1,1,0,0 },
ozy 0:99b49fd71085 112 { 0,0,0,0,0,1,1,0,0,0 },
ozy 0:99b49fd71085 113 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 114 };
ozy 7:737fb0c3dbef 115 lcd.drawSprite(_x,_y,12,10,(int *)run_right);
ozy 7:737fb0c3dbef 116 }
ozy 0:99b49fd71085 117
ozy 7:737fb0c3dbef 118 // ************************************************************************
ozy 7:737fb0c3dbef 119
ozy 7:737fb0c3dbef 120 void Fighter::move_right2(N5110 &lcd) {
ozy 7:737fb0c3dbef 121 const int midrun_right[12][10] = {
ozy 0:99b49fd71085 122 { 0,0,0,0,0,1,1,1,0,0 },
ozy 0:99b49fd71085 123 { 0,0,0,0,0,1,1,1,0,0 },
ozy 0:99b49fd71085 124 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 125 { 0,0,1,1,1,1,0,1,0,0 },
ozy 0:99b49fd71085 126 { 0,1,1,0,1,1,0,1,1,1 },
ozy 0:99b49fd71085 127 { 1,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 128 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 129 { 0,0,1,1,0,0,1,1,0,0 },
ozy 0:99b49fd71085 130 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 131 { 0,0,0,0,1,1,0,0,0,0 },
ozy 1:3bdadf6f6dbd 132 { 0,0,0,1,0,1,0,0,0,0 },
ozy 0:99b49fd71085 133 { 0,0,1,0,0,0,1,0,0,0 },
ozy 0:99b49fd71085 134 };
ozy 7:737fb0c3dbef 135
ozy 7:737fb0c3dbef 136 lcd.drawSprite(_x,_y,12,10,(int *)midrun_right);
ozy 7:737fb0c3dbef 137 }
ozy 7:737fb0c3dbef 138
ozy 7:737fb0c3dbef 139 // ************************************************************************
ozy 7:737fb0c3dbef 140
ozy 7:737fb0c3dbef 141 void Fighter::kick_right(N5110 &lcd) {
ozy 7:737fb0c3dbef 142 const int kick[12][10] = {
ozy 0:99b49fd71085 143 { 0,1,1,0,0,0,0,0,0,0 },
ozy 0:99b49fd71085 144 { 0,1,1,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 145 { 0,0,0,1,1,1,1,0,0,1 },
ozy 0:99b49fd71085 146 { 0,0,1,1,1,0,0,0,1,1 },
ozy 0:99b49fd71085 147 { 0,1,1,1,1,1,1,1,0,0 },
ozy 0:99b49fd71085 148 { 0,1,0,0,1,1,1,0,0,0 },
ozy 0:99b49fd71085 149 { 1,1,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 150 { 0,0,0,0,1,0,0,0,0,0 },
ozy 0:99b49fd71085 151 { 0,0,0,1,1,0,0,0,0,0 },
ozy 0:99b49fd71085 152 { 0,0,0,1,0,0,0,0,0,0 },
ozy 0:99b49fd71085 153 { 0,0,1,1,0,0,0,0,0,0 },
ozy 0:99b49fd71085 154 { 0,0,1,1,0,0,0,0,0,0 },
ozy 0:99b49fd71085 155 };
ozy 7:737fb0c3dbef 156 lcd.drawSprite(_x,_y,12,10,(int *)kick);
ozy 7:737fb0c3dbef 157 }
ozy 7:737fb0c3dbef 158
ozy 7:737fb0c3dbef 159 // ************************************************************************
ozy 7:737fb0c3dbef 160
ozy 7:737fb0c3dbef 161 void Fighter::kick_left(N5110 &lcd) {
ozy 7:737fb0c3dbef 162 const int kick[12][10] = {
ozy 0:99b49fd71085 163 { 0,0,0,0,0,0,0,1,1,0 },
ozy 0:99b49fd71085 164 { 0,0,0,0,1,1,0,1,1,0 },
ozy 0:99b49fd71085 165 { 1,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 166 { 1,1,0,0,0,1,1,1,0,0 },
ozy 0:99b49fd71085 167 { 0,0,1,1,1,1,1,1,1,0 },
ozy 0:99b49fd71085 168 { 0,0,0,1,1,1,0,0,1,0 },
ozy 0:99b49fd71085 169 { 0,0,0,0,1,1,0,0,1,1 },
ozy 0:99b49fd71085 170 { 0,0,0,0,0,1,0,0,0,0 },
ozy 0:99b49fd71085 171 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 172 { 0,0,0,0,1,0,0,0,0,0 },
ozy 0:99b49fd71085 173 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 174 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 175 };
ozy 7:737fb0c3dbef 176 lcd.drawSprite(_x,_y,12,10,(int *)kick);
ozy 7:737fb0c3dbef 177 }
ozy 7:737fb0c3dbef 178
ozy 7:737fb0c3dbef 179 // ************************************************************************
ozy 7:737fb0c3dbef 180
ozy 7:737fb0c3dbef 181 void Fighter::punch_right(N5110 &lcd) {
ozy 7:737fb0c3dbef 182 const int punch[12][10] = {
ozy 0:99b49fd71085 183 { 0,0,0,0,1,1,0,0,0,1 },
ozy 0:99b49fd71085 184 { 0,0,0,0,1,1,0,0,1,1 },
ozy 0:99b49fd71085 185 { 0,0,1,1,1,1,0,1,1,0 },
ozy 0:99b49fd71085 186 { 0,1,0,0,1,1,1,1,0,0 },
ozy 0:99b49fd71085 187 { 0,1,1,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 188 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 189 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 190 { 0,0,0,1,0,0,1,1,0,0 },
ozy 0:99b49fd71085 191 { 0,0,1,1,0,0,1,1,0,0 },
ozy 0:99b49fd71085 192 { 0,0,1,0,0,0,1,0,0,0 },
ozy 0:99b49fd71085 193 { 0,1,1,0,0,0,1,0,0,0 },
ozy 0:99b49fd71085 194 { 1,1,0,0,0,1,1,0,0,0 },
ozy 0:99b49fd71085 195 };
ozy 7:737fb0c3dbef 196 lcd.drawSprite(_x,_y,12,10,(int *)punch);
ozy 7:737fb0c3dbef 197 }
ozy 7:737fb0c3dbef 198
ozy 7:737fb0c3dbef 199 // ************************************************************************
ozy 7:737fb0c3dbef 200
ozy 7:737fb0c3dbef 201 void Fighter::punch_left(N5110 &lcd) {
ozy 7:737fb0c3dbef 202 const int punch[12][10] = {
ozy 0:99b49fd71085 203 { 1,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 204 { 1,1,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 205 { 0,1,1,0,1,1,1,1,0,0 },
ozy 0:99b49fd71085 206 { 0,0,1,1,1,1,0,0,1,0 },
ozy 0:99b49fd71085 207 { 0,0,0,0,1,1,0,1,1,0 },
ozy 0:99b49fd71085 208 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 209 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 210 { 0,0,1,1,0,0,1,0,0,0 },
ozy 0:99b49fd71085 211 { 0,0,1,1,0,0,1,1,0,0 },
ozy 0:99b49fd71085 212 { 0,0,0,1,0,0,0,1,0,0 },
ozy 0:99b49fd71085 213 { 0,0,0,1,0,0,0,1,1,0 },
ozy 0:99b49fd71085 214 { 0,0,0,1,1,0,0,0,1,1 },
ozy 0:99b49fd71085 215 };
ozy 7:737fb0c3dbef 216 lcd.drawSprite(_x,_y,12,10,(int *)punch);
ozy 7:737fb0c3dbef 217 }
ozy 7:737fb0c3dbef 218
ozy 7:737fb0c3dbef 219 // ************************************************************************
ozy 7:737fb0c3dbef 220
ozy 7:737fb0c3dbef 221 void Fighter::guard(N5110 &lcd) {
ozy 0:99b49fd71085 222 const int guard[12][10] = {
ozy 0:99b49fd71085 223 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 224 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 225 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 226 { 0,0,1,0,1,1,0,1,0,0 },
ozy 0:99b49fd71085 227 { 0,0,1,0,1,1,0,1,0,0 },
ozy 0:99b49fd71085 228 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 229 { 0,0,0,0,1,1,0,0,0,0 },
ozy 0:99b49fd71085 230 { 0,0,0,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 231 { 0,0,1,1,1,1,1,1,0,0 },
ozy 0:99b49fd71085 232 { 0,1,0,0,0,0,0,0,1,0 },
ozy 0:99b49fd71085 233 { 0,1,0,0,0,0,0,0,1,0 },
ozy 0:99b49fd71085 234 { 0,1,0,0,0,0,0,0,1,0 },
ozy 0:99b49fd71085 235 };
ozy 7:737fb0c3dbef 236 lcd.drawSprite(_x,_y,12,10,(int *)guard);
ozy 7:737fb0c3dbef 237 }
ozy 6:a1a7dc264fed 238
ozy 7:737fb0c3dbef 239 void Fighter::move_fighter(N5110 &lcd, DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC, DigitalIn &buttonD, AnalogIn &joy_v, AnalogIn &joy_h) {
ozy 6:a1a7dc264fed 240 // getting joystick coordinates using read() function
ozy 6:a1a7dc264fed 241 // 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 242 // read each of the pins
ozy 7:737fb0c3dbef 243 float x = joy_h.read();
ozy 7:737fb0c3dbef 244 float y = joy_v.read();
ozy 7:737fb0c3dbef 245 printf("x = %.2f | y = %.2f \n",x,y);
ozy 7:737fb0c3dbef 246
ozy 7:737fb0c3dbef 247 int x_pos = get_x();
ozy 7:737fb0c3dbef 248 printf("fighter x pos = %i \n", x_pos);
ozy 7:737fb0c3dbef 249
ozy 6:a1a7dc264fed 250 /*
ozy 6:a1a7dc264fed 251 Code idea:
ozy 6:a1a7dc264fed 252 if joystick is not moved , display standing sprite
ozy 6:a1a7dc264fed 253 if joystick is moved right, toggle between runright and midrunright
ozy 6:a1a7dc264fed 254 if joystick is moved left, toggle between runleft and midrunleft
ozy 6:a1a7dc264fed 255 */
ozy 7:737fb0c3dbef 256 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 7:737fb0c3dbef 257 draw(lcd); // draw standing fighter
ozy 6:a1a7dc264fed 258 lcd.refresh();
ozy 6:a1a7dc264fed 259 wait(0.3);
ozy 6:a1a7dc264fed 260
ozy 6:a1a7dc264fed 261 // Preform kick move if user presses button A
ozy 6:a1a7dc264fed 262 if (buttonA.read() == 1) {
ozy 7:737fb0c3dbef 263 kick_right(lcd); // draw kick on same coordinates as the standing sprite
ozy 6:a1a7dc264fed 264 lcd.refresh();
ozy 6:a1a7dc264fed 265 wait(0.3);
ozy 6:a1a7dc264fed 266 }
ozy 6:a1a7dc264fed 267 // Preform punch move if user presses button B
ozy 6:a1a7dc264fed 268 if (buttonB.read() == 1) {
ozy 7:737fb0c3dbef 269 punch_right(lcd); // draw kick
ozy 6:a1a7dc264fed 270 lcd.refresh();
ozy 6:a1a7dc264fed 271 wait(0.3);
ozy 6:a1a7dc264fed 272 }
ozy 6:a1a7dc264fed 273 // Guard if user presses button C
ozy 6:a1a7dc264fed 274 while (buttonC.read() == 1) {
ozy 7:737fb0c3dbef 275 guard(lcd); // draw guard move frame
ozy 6:a1a7dc264fed 276 lcd.refresh();
ozy 6:a1a7dc264fed 277 wait(0.3);
ozy 6:a1a7dc264fed 278 }
ozy 7:737fb0c3dbef 279 }
ozy 7:737fb0c3dbef 280 else if(x < 0.48) { // joystick moved to the right
ozy 6:a1a7dc264fed 281 // print the move_right animation, refresh, then print the 2nd move_right animation (toggling animations to create moving legs!)
ozy 7:737fb0c3dbef 282 add_x(5); // increment by 5
ozy 7:737fb0c3dbef 283 move_right(lcd);
ozy 6:a1a7dc264fed 284 lcd.refresh();
ozy 6:a1a7dc264fed 285 wait(0.1);
ozy 7:737fb0c3dbef 286 move_right2(lcd);
ozy 6:a1a7dc264fed 287 lcd.refresh();
ozy 6:a1a7dc264fed 288 wait(0.08);
ozy 7:737fb0c3dbef 289
ozy 7:737fb0c3dbef 290 if (x_pos >= 65) { // code to stop fighter moving out of lcd screen
ozy 7:737fb0c3dbef 291 add_x(-5);
ozy 6:a1a7dc264fed 292 }
ozy 7:737fb0c3dbef 293
ozy 7:737fb0c3dbef 294
ozy 6:a1a7dc264fed 295 // kick if user presses button A
ozy 6:a1a7dc264fed 296 if (buttonA.read() == 1) {
ozy 7:737fb0c3dbef 297 kick_right(lcd);
ozy 6:a1a7dc264fed 298 lcd.refresh();
ozy 6:a1a7dc264fed 299 wait(0.3);
ozy 7:737fb0c3dbef 300 }
ozy 6:a1a7dc264fed 301 // Preform punch move if user presses button B
ozy 6:a1a7dc264fed 302 if (buttonB.read() == 1) {
ozy 7:737fb0c3dbef 303 punch_right(lcd); // draw kick on same coordinates as the sprite
ozy 6:a1a7dc264fed 304 lcd.refresh();
ozy 6:a1a7dc264fed 305 wait(0.3);
ozy 6:a1a7dc264fed 306 }
ozy 6:a1a7dc264fed 307 // Guard if user presses button C
ozy 7:737fb0c3dbef 308 while (buttonC.read() == 1) { // we use while not if here because user would hold to guard
ozy 7:737fb0c3dbef 309 guard(lcd); // draw kick on same coordinates as the sprite
ozy 6:a1a7dc264fed 310 lcd.refresh();
ozy 6:a1a7dc264fed 311 wait(0.3);
ozy 6:a1a7dc264fed 312 }
ozy 6:a1a7dc264fed 313 }
ozy 6:a1a7dc264fed 314
ozy 7:737fb0c3dbef 315 else if(x > 0.52) { // joystick moved to the left
ozy 7:737fb0c3dbef 316 add_x(-5); // decrement left by 5
ozy 7:737fb0c3dbef 317 move_left(lcd);
ozy 7:737fb0c3dbef 318 lcd.refresh();
ozy 7:737fb0c3dbef 319 wait(0.1);
ozy 7:737fb0c3dbef 320 move_left2(lcd);
ozy 7:737fb0c3dbef 321 lcd.refresh();
ozy 7:737fb0c3dbef 322 wait(0.08);
ozy 0:99b49fd71085 323
ozy 7:737fb0c3dbef 324 if (x_pos <= 6) { // code to stop fighter moving out of lcd screen
ozy 7:737fb0c3dbef 325 add_x(5);
ozy 7:737fb0c3dbef 326 }
ozy 0:99b49fd71085 327
ozy 7:737fb0c3dbef 328 // kick if user presses button A
ozy 7:737fb0c3dbef 329 if (buttonA.read() == 1) {
ozy 7:737fb0c3dbef 330 kick_left(lcd);
ozy 7:737fb0c3dbef 331 lcd.refresh();
ozy 7:737fb0c3dbef 332 wait(0.3);
ozy 7:737fb0c3dbef 333 }
ozy 7:737fb0c3dbef 334 if (buttonB.read() == 1) {
ozy 7:737fb0c3dbef 335 punch_left(lcd); // draw punch on same coordinates as the sprite
ozy 7:737fb0c3dbef 336 lcd.refresh();
ozy 7:737fb0c3dbef 337 wait(0.3);
ozy 7:737fb0c3dbef 338 }
ozy 7:737fb0c3dbef 339 // Guard if user presses button C
ozy 7:737fb0c3dbef 340 while (buttonC.read() == 1) {
ozy 7:737fb0c3dbef 341 guard(lcd); // draw guard on same coordinates as the sprite
ozy 7:737fb0c3dbef 342 lcd.refresh();
ozy 7:737fb0c3dbef 343 wait(0.3);
ozy 7:737fb0c3dbef 344 }
ozy 7:737fb0c3dbef 345 }
ozy 7:737fb0c3dbef 346 }