Mortal Kombat Game ELEC2645
Dependencies: mbed N5110 ShiftReg Joystick
Abandoned.cpp@3:1d99b6ad4f9e, 2021-04-19 (annotated)
- Committer:
- ozy
- Date:
- Mon Apr 19 18:38:59 2021 +0000
- Revision:
- 3:1d99b6ad4f9e
- Parent:
- 1:3bdadf6f6dbd
- Child:
- 6:a1a7dc264fed
Code after new fighter class
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:1d99b6ad4f9e | 4 | int get_user_input(int &input) { |
ozy | 3:1d99b6ad4f9e | 5 | while (1) { |
ozy | 3:1d99b6ad4f9e | 6 | if (buttonA.read() == 1) { |
ozy | 3:1d99b6ad4f9e | 7 | input = 1; |
ozy | 3:1d99b6ad4f9e | 8 | break; |
ozy | 3:1d99b6ad4f9e | 9 | } |
ozy | 3:1d99b6ad4f9e | 10 | if (buttonB.read() == 1) { |
ozy | 3:1d99b6ad4f9e | 11 | input = 2; |
ozy | 3:1d99b6ad4f9e | 12 | break; |
ozy | 3:1d99b6ad4f9e | 13 | } |
ozy | 3:1d99b6ad4f9e | 14 | if (buttonC.read() == 1) { |
ozy | 3:1d99b6ad4f9e | 15 | input = 3; |
ozy | 3:1d99b6ad4f9e | 16 | break; |
ozy | 3:1d99b6ad4f9e | 17 | } |
ozy | 3:1d99b6ad4f9e | 18 | if (buttonD.read() == 1) { |
ozy | 3:1d99b6ad4f9e | 19 | input = 4; |
ozy | 3:1d99b6ad4f9e | 20 | break; |
ozy | 3:1d99b6ad4f9e | 21 | } |
ozy | 3:1d99b6ad4f9e | 22 | } |
ozy | 3:1d99b6ad4f9e | 23 | return input; |
ozy | 3:1d99b6ad4f9e | 24 | } |
ozy | 3:1d99b6ad4f9e | 25 | |
ozy | 3:1d99b6ad4f9e | 26 | |
ozy | 3:1d99b6ad4f9e | 27 | |
ozy | 0:99b49fd71085 | 28 | void abandoned_function() { |
ozy | 0:99b49fd71085 | 29 | // getting joystick coordinates using Vector2D |
ozy | 0:99b49fd71085 | 30 | // joystick centered at 0 with (1,0) being utmost right and (-1,0) being utmost left |
ozy | 0:99b49fd71085 | 31 | Vector2D coord = joystick.get_coord(); |
ozy | 0:99b49fd71085 | 32 | printf("Coord = %f | %f\n", coord.x, coord.y); |
ozy | 0:99b49fd71085 | 33 | float x = coord.x; |
ozy | 0:99b49fd71085 | 34 | float y = coord.y; |
ozy | 0:99b49fd71085 | 35 | |
ozy | 0:99b49fd71085 | 36 | loop idea: |
ozy | 0:99b49fd71085 | 37 | while nothing pressed, display standsprite |
ozy | 0:99b49fd71085 | 38 | while moving right, toggle between runright and midrunright |
ozy | 0:99b49fd71085 | 39 | while moving left, toggle between runleft and midrunleft |
ozy | 0:99b49fd71085 | 40 | |
ozy | 0:99b49fd71085 | 41 | 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 | 42 | 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 | 43 | printf("*Coord = %f | %f\n",x, y); |
ozy | 0:99b49fd71085 | 44 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 45 | } |
ozy | 0:99b49fd71085 | 46 | |
ozy | 0:99b49fd71085 | 47 | while (x > 0.02) { // Joystick moved to the right |
ozy | 0:99b49fd71085 | 48 | // toggle between the 2 move_right animations with a small delay in between to make it smooth |
ozy | 0:99b49fd71085 | 49 | fighter.update_forward(x); |
ozy | 0:99b49fd71085 | 50 | printf("**Coord = %f | %f\n", x, y); |
ozy | 0:99b49fd71085 | 51 | fighter.move_right(lcd, x, 34); |
ozy | 0:99b49fd71085 | 52 | wait(0.2); |
ozy | 0:99b49fd71085 | 53 | fighter.update_forward(x); |
ozy | 0:99b49fd71085 | 54 | fighter.move_right2(lcd, x, 34); |
ozy | 0:99b49fd71085 | 55 | wait(0.2); |
ozy | 0:99b49fd71085 | 56 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 57 | } |
ozy | 0:99b49fd71085 | 58 | while (x < -0.02) { // Joystick moved to the left |
ozy | 0:99b49fd71085 | 59 | // toggle between the 2 move_left animations with a small delay in between to make it smooth |
ozy | 0:99b49fd71085 | 60 | fighter.update_backward(x); |
ozy | 0:99b49fd71085 | 61 | printf("***Coord = %f | %f\n", x, y); |
ozy | 0:99b49fd71085 | 62 | fighter.move_left(lcd, x, 34); |
ozy | 0:99b49fd71085 | 63 | wait(0.2); |
ozy | 0:99b49fd71085 | 64 | fighter.update_backward(x); |
ozy | 0:99b49fd71085 | 65 | fighter.move_left2(lcd, x, 34); |
ozy | 0:99b49fd71085 | 66 | wait(0.2); |
ozy | 0:99b49fd71085 | 67 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 68 | } |
ozy | 0:99b49fd71085 | 69 | } |
ozy | 0:99b49fd71085 | 70 | |
ozy | 0:99b49fd71085 | 71 | |
ozy | 0:99b49fd71085 | 72 | const int logo[17][19] = { |
ozy | 0:99b49fd71085 | 73 | |
ozy | 0:99b49fd71085 | 74 | { 1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1 }, |
ozy | 0:99b49fd71085 | 75 | { 0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 76 | { 0,0,0,0,0,1,0,1,1,1,0,0,0,0,1,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 77 | { 0,0,0,0,1,0,1,1,1,1,1,0,0,0,0,1,0,0,0 }, |
ozy | 0:99b49fd71085 | 78 | { 0,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0 }, |
ozy | 0:99b49fd71085 | 79 | { 0,0,1,0,1,1,1,0,1,1,1,1,1,1,0,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 80 | { 0,0,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 81 | { 0,0,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 82 | { 0,0,1,0,1,1,1,1,0,0,0,0,0,1,1,1,0,1,0 }, |
ozy | 0:99b49fd71085 | 83 | { 0,0,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 84 | { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 85 | { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0 }, |
ozy | 0:99b49fd71085 | 86 | { 0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0 }, |
ozy | 0:99b49fd71085 | 87 | { 0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0 }, |
ozy | 0:99b49fd71085 | 88 | { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 89 | { 0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 90 | { 1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1 }, |
ozy | 0:99b49fd71085 | 91 | |
ozy | 0:99b49fd71085 | 92 | }; |
ozy | 0:99b49fd71085 | 93 | */ |
ozy | 1:3bdadf6f6dbd | 94 | |
ozy | 1:3bdadf6f6dbd | 95 | /* |
ozy | 1:3bdadf6f6dbd | 96 | void menu_select() { |
ozy | 1:3bdadf6f6dbd | 97 | char button = get_user_input(); |
ozy | 1:3bdadf6f6dbd | 98 | switch (button) { |
ozy | 1:3bdadf6f6dbd | 99 | case 'A': |
ozy | 1:3bdadf6f6dbd | 100 | menu.play(lcd); |
ozy | 1:3bdadf6f6dbd | 101 | break; |
ozy | 1:3bdadf6f6dbd | 102 | case 'B': |
ozy | 1:3bdadf6f6dbd | 103 | menu.tutorial(lcd); |
ozy | 1:3bdadf6f6dbd | 104 | break; |
ozy | 1:3bdadf6f6dbd | 105 | case 'C': |
ozy | 1:3bdadf6f6dbd | 106 | menu.options_menu(lcd); |
ozy | 1:3bdadf6f6dbd | 107 | break; |
ozy | 1:3bdadf6f6dbd | 108 | default: |
ozy | 1:3bdadf6f6dbd | 109 | menu.homescreen(lcd); |
ozy | 1:3bdadf6f6dbd | 110 | break; |
ozy | 1:3bdadf6f6dbd | 111 | } |
ozy | 1:3bdadf6f6dbd | 112 | } |
ozy | 1:3bdadf6f6dbd | 113 | |
ozy | 1:3bdadf6f6dbd | 114 | char get_user_input() { |
ozy | 1:3bdadf6f6dbd | 115 | char button; |
ozy | 1:3bdadf6f6dbd | 116 | while (buttonA.read() == 1) { |
ozy | 1:3bdadf6f6dbd | 117 | button = 'A'; |
ozy | 1:3bdadf6f6dbd | 118 | wait(0.2); |
ozy | 1:3bdadf6f6dbd | 119 | } |
ozy | 1:3bdadf6f6dbd | 120 | while (buttonB.read() == 1) { |
ozy | 1:3bdadf6f6dbd | 121 | button = 'B'; |
ozy | 1:3bdadf6f6dbd | 122 | wait(0.2); |
ozy | 1:3bdadf6f6dbd | 123 | } |
ozy | 1:3bdadf6f6dbd | 124 | while (buttonC.read() == 1) { |
ozy | 1:3bdadf6f6dbd | 125 | button = 'C'; |
ozy | 1:3bdadf6f6dbd | 126 | wait(0.2); |
ozy | 1:3bdadf6f6dbd | 127 | } |
ozy | 1:3bdadf6f6dbd | 128 | while (buttonD.read() == 1) { |
ozy | 1:3bdadf6f6dbd | 129 | button = 'D'; |
ozy | 1:3bdadf6f6dbd | 130 | wait(0.2); |
ozy | 1:3bdadf6f6dbd | 131 | } |
ozy | 1:3bdadf6f6dbd | 132 | pc.printf("Value is %c", button); |
ozy | 1:3bdadf6f6dbd | 133 | return button; |
ozy | 1:3bdadf6f6dbd | 134 | } |
ozy | 1:3bdadf6f6dbd | 135 | */ |