Mortal Kombat Game ELEC2645
Dependencies: mbed N5110 ShiftReg Joystick
Diff: Fighter.cpp
- Revision:
- 15:7fd2d34f3be5
- Parent:
- 11:b344a64b75bf
- Child:
- 17:928edcdd1058
diff -r 7f23841685ad -r 7fd2d34f3be5 Fighter.cpp --- a/Fighter.cpp Mon Apr 26 22:19:28 2021 +0000 +++ b/Fighter.cpp Mon Apr 26 23:58:35 2021 +0000 @@ -281,6 +281,12 @@ if (buttonC.read() == 1) { guard(lcd); // draw guard move frame } + if (buttonD.read() == 0) { // code to return fighter to ground when user uses the jump button whilst moving right/left + int y_pos = get_y(); + if (y_pos != 34) { + set_y(34); + } + } } else if(x < 0.48) { // joystick moved to the right // print the move_right animation, refresh, then print the 2nd move_right animation (toggling animations to create moving legs!) @@ -304,7 +310,24 @@ if (buttonC.read() == 1) { // we use while not if here because user would hold to guard guard(lcd); // draw kick on same coordinates as the sprite } - + if (buttonD.read() == 1) { // computing jump move + move_right(lcd); + add_y(-12); // add 12 to y position + add_x(5); + int y_pos = get_y(); + if (y_pos < 22) { // to avoid sprite jumping more than 12 everytime they click D + set_y(22); + } + if (x_pos >= 65) { // code to stop fighter moving out of lcd screen while jumping! + add_x(-5); + } + } + if (buttonD.read() == 0) { // code to return fighter to ground + int y_pos = get_y(); + if (y_pos != 34) { + set_y(34); + } + } } else if(x > 0.52) { // joystick moved to the left add_x(-4); // decrement left by 5 @@ -325,5 +348,24 @@ if (buttonC.read() == 1) { guard(lcd); } + // code to make fighter jump + if (buttonD.read() == 1) { // computing jump move for left movement + move_left(lcd); + add_y(-12); // add 12 to y position + add_x(-5); + int y_pos = get_y(); + if (y_pos < 22) { // to avoid sprite jumping more than 12 everytime they click D + set_y(22); + } + if (x_pos <= 8) { // code to stop fighter moving out of lcd screen while jumping! + add_x(5); + } + } + if (buttonD.read() == 0) { // code to return fighter to ground + int y_pos = get_y(); + if (y_pos != 34) { + set_y(34); + } + } } } \ No newline at end of file