Mortal Kombat Game ELEC2645

Dependencies:   mbed N5110 ShiftReg Joystick

Committer:
ozy
Date:
Sat Apr 17 11:38:39 2021 +0000
Revision:
1:3bdadf6f6dbd
Parent:
0:99b49fd71085
Child:
3:1d99b6ad4f9e
Code Before adding interrupts

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ozy 1:3bdadf6f6dbd 1 // This file includes abandoned code that was replaced because it did not work
ozy 0:99b49fd71085 2
ozy 0:99b49fd71085 3 /*
ozy 0:99b49fd71085 4 void abandoned_function() {
ozy 0:99b49fd71085 5 // getting joystick coordinates using Vector2D
ozy 0:99b49fd71085 6 // joystick centered at 0 with (1,0) being utmost right and (-1,0) being utmost left
ozy 0:99b49fd71085 7 Vector2D coord = joystick.get_coord();
ozy 0:99b49fd71085 8 printf("Coord = %f | %f\n", coord.x, coord.y);
ozy 0:99b49fd71085 9 float x = coord.x;
ozy 0:99b49fd71085 10 float y = coord.y;
ozy 0:99b49fd71085 11
ozy 0:99b49fd71085 12 loop idea:
ozy 0:99b49fd71085 13 while nothing pressed, display standsprite
ozy 0:99b49fd71085 14 while moving right, toggle between runright and midrunright
ozy 0:99b49fd71085 15 while moving left, toggle between runleft and midrunleft
ozy 0:99b49fd71085 16
ozy 0:99b49fd71085 17 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 18 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 19 printf("*Coord = %f | %f\n",x, y);
ozy 0:99b49fd71085 20 lcd.refresh();
ozy 0:99b49fd71085 21 }
ozy 0:99b49fd71085 22
ozy 0:99b49fd71085 23 while (x > 0.02) { // Joystick moved to the right
ozy 0:99b49fd71085 24 // toggle between the 2 move_right animations with a small delay in between to make it smooth
ozy 0:99b49fd71085 25 fighter.update_forward(x);
ozy 0:99b49fd71085 26 printf("**Coord = %f | %f\n", x, y);
ozy 0:99b49fd71085 27 fighter.move_right(lcd, x, 34);
ozy 0:99b49fd71085 28 wait(0.2);
ozy 0:99b49fd71085 29 fighter.update_forward(x);
ozy 0:99b49fd71085 30 fighter.move_right2(lcd, x, 34);
ozy 0:99b49fd71085 31 wait(0.2);
ozy 0:99b49fd71085 32 lcd.refresh();
ozy 0:99b49fd71085 33 }
ozy 0:99b49fd71085 34 while (x < -0.02) { // Joystick moved to the left
ozy 0:99b49fd71085 35 // toggle between the 2 move_left animations with a small delay in between to make it smooth
ozy 0:99b49fd71085 36 fighter.update_backward(x);
ozy 0:99b49fd71085 37 printf("***Coord = %f | %f\n", x, y);
ozy 0:99b49fd71085 38 fighter.move_left(lcd, x, 34);
ozy 0:99b49fd71085 39 wait(0.2);
ozy 0:99b49fd71085 40 fighter.update_backward(x);
ozy 0:99b49fd71085 41 fighter.move_left2(lcd, x, 34);
ozy 0:99b49fd71085 42 wait(0.2);
ozy 0:99b49fd71085 43 lcd.refresh();
ozy 0:99b49fd71085 44 }
ozy 0:99b49fd71085 45 }
ozy 0:99b49fd71085 46
ozy 0:99b49fd71085 47
ozy 0:99b49fd71085 48 const int logo[17][19] = {
ozy 0:99b49fd71085 49
ozy 0:99b49fd71085 50 { 1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1 },
ozy 0:99b49fd71085 51 { 0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0 },
ozy 0:99b49fd71085 52 { 0,0,0,0,0,1,0,1,1,1,0,0,0,0,1,0,0,0,0 },
ozy 0:99b49fd71085 53 { 0,0,0,0,1,0,1,1,1,1,1,0,0,0,0,1,0,0,0 },
ozy 0:99b49fd71085 54 { 0,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0 },
ozy 0:99b49fd71085 55 { 0,0,1,0,1,1,1,0,1,1,1,1,1,1,0,0,0,1,0 },
ozy 0:99b49fd71085 56 { 0,0,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,1,0 },
ozy 0:99b49fd71085 57 { 0,0,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,1,0 },
ozy 0:99b49fd71085 58 { 0,0,1,0,1,1,1,1,0,0,0,0,0,1,1,1,0,1,0 },
ozy 0:99b49fd71085 59 { 0,0,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,0 },
ozy 0:99b49fd71085 60 { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,0 },
ozy 0:99b49fd71085 61 { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0 },
ozy 0:99b49fd71085 62 { 0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0 },
ozy 0:99b49fd71085 63 { 0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0 },
ozy 0:99b49fd71085 64 { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0 },
ozy 0:99b49fd71085 65 { 0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0 },
ozy 0:99b49fd71085 66 { 1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1 },
ozy 0:99b49fd71085 67
ozy 0:99b49fd71085 68 };
ozy 0:99b49fd71085 69 */
ozy 1:3bdadf6f6dbd 70
ozy 1:3bdadf6f6dbd 71 /*
ozy 1:3bdadf6f6dbd 72 void menu_select() {
ozy 1:3bdadf6f6dbd 73 char button = get_user_input();
ozy 1:3bdadf6f6dbd 74 switch (button) {
ozy 1:3bdadf6f6dbd 75 case 'A':
ozy 1:3bdadf6f6dbd 76 menu.play(lcd);
ozy 1:3bdadf6f6dbd 77 break;
ozy 1:3bdadf6f6dbd 78 case 'B':
ozy 1:3bdadf6f6dbd 79 menu.tutorial(lcd);
ozy 1:3bdadf6f6dbd 80 break;
ozy 1:3bdadf6f6dbd 81 case 'C':
ozy 1:3bdadf6f6dbd 82 menu.options_menu(lcd);
ozy 1:3bdadf6f6dbd 83 break;
ozy 1:3bdadf6f6dbd 84 default:
ozy 1:3bdadf6f6dbd 85 menu.homescreen(lcd);
ozy 1:3bdadf6f6dbd 86 break;
ozy 1:3bdadf6f6dbd 87 }
ozy 1:3bdadf6f6dbd 88 }
ozy 1:3bdadf6f6dbd 89
ozy 1:3bdadf6f6dbd 90 char get_user_input() {
ozy 1:3bdadf6f6dbd 91 char button;
ozy 1:3bdadf6f6dbd 92 while (buttonA.read() == 1) {
ozy 1:3bdadf6f6dbd 93 button = 'A';
ozy 1:3bdadf6f6dbd 94 wait(0.2);
ozy 1:3bdadf6f6dbd 95 }
ozy 1:3bdadf6f6dbd 96 while (buttonB.read() == 1) {
ozy 1:3bdadf6f6dbd 97 button = 'B';
ozy 1:3bdadf6f6dbd 98 wait(0.2);
ozy 1:3bdadf6f6dbd 99 }
ozy 1:3bdadf6f6dbd 100 while (buttonC.read() == 1) {
ozy 1:3bdadf6f6dbd 101 button = 'C';
ozy 1:3bdadf6f6dbd 102 wait(0.2);
ozy 1:3bdadf6f6dbd 103 }
ozy 1:3bdadf6f6dbd 104 while (buttonD.read() == 1) {
ozy 1:3bdadf6f6dbd 105 button = 'D';
ozy 1:3bdadf6f6dbd 106 wait(0.2);
ozy 1:3bdadf6f6dbd 107 }
ozy 1:3bdadf6f6dbd 108 pc.printf("Value is %c", button);
ozy 1:3bdadf6f6dbd 109 return button;
ozy 1:3bdadf6f6dbd 110 }
ozy 1:3bdadf6f6dbd 111 */