
Kaif Kutchwala 201267448 ELEC2645 Project
Dependencies: mbed
main.cpp@15:5bf3f951d337, 2020-05-18 (annotated)
- Committer:
- KaifK
- Date:
- Mon May 18 18:03:43 2020 +0000
- Revision:
- 15:5bf3f951d337
- Parent:
- 13:5133f00d2a2d
- Child:
- 16:1f196a0e12be
Game v1 complete (still some debounce errors)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KaifK | 0:e47aa16004e6 | 1 | /* |
KaifK | 4:08a0ff6668df | 2 | Shoot |
KaifK | 0:e47aa16004e6 | 3 | ELEC2645 Project |
KaifK | 0:e47aa16004e6 | 4 | EL18KK |
KaifK | 0:e47aa16004e6 | 5 | 201267448 |
KaifK | 0:e47aa16004e6 | 6 | */ |
KaifK | 0:e47aa16004e6 | 7 | |
KaifK | 0:e47aa16004e6 | 8 | #include "mbed.h" |
KaifK | 0:e47aa16004e6 | 9 | #include "Gamepad.h" |
KaifK | 0:e47aa16004e6 | 10 | #include "N5110.h" |
KaifK | 3:f86c1cf90d0d | 11 | #include "Ball.h" |
KaifK | 3:f86c1cf90d0d | 12 | #include "Splash.h" |
KaifK | 4:08a0ff6668df | 13 | #include "Game.h" |
KaifK | 0:e47aa16004e6 | 14 | |
KaifK | 4:08a0ff6668df | 15 | const int a_button [9][9] = { |
KaifK | 4:08a0ff6668df | 16 | {0,0,0,1,1,1,0,0,0}, |
KaifK | 4:08a0ff6668df | 17 | {0,0,1,0,0,0,1,0,0}, |
KaifK | 4:08a0ff6668df | 18 | {0,1,0,0,1,0,0,1,0}, |
KaifK | 4:08a0ff6668df | 19 | {1,0,0,1,0,1,0,0,1}, |
KaifK | 4:08a0ff6668df | 20 | {1,0,0,1,1,1,0,0,1}, |
KaifK | 4:08a0ff6668df | 21 | {1,0,0,1,0,1,0,0,1}, |
KaifK | 4:08a0ff6668df | 22 | {0,1,0,0,0,0,0,1,0}, |
KaifK | 4:08a0ff6668df | 23 | {0,0,1,0,0,0,1,0,0}, |
KaifK | 4:08a0ff6668df | 24 | {0,0,0,1,1,1,0,0,0} |
KaifK | 4:08a0ff6668df | 25 | }; |
KaifK | 4:08a0ff6668df | 26 | const int b_button [9][9] = { |
KaifK | 4:08a0ff6668df | 27 | {0,0,0,1,1,1,0,0,0}, |
KaifK | 4:08a0ff6668df | 28 | {0,0,1,0,0,0,1,0,0}, |
KaifK | 4:08a0ff6668df | 29 | {0,1,0,1,1,1,0,1,0}, |
KaifK | 4:08a0ff6668df | 30 | {1,0,0,1,0,0,1,0,1}, |
KaifK | 4:08a0ff6668df | 31 | {1,0,0,1,1,1,0,0,1}, |
KaifK | 4:08a0ff6668df | 32 | {1,0,0,1,0,0,1,0,1}, |
KaifK | 4:08a0ff6668df | 33 | {0,1,0,1,1,1,0,1,0}, |
KaifK | 4:08a0ff6668df | 34 | {0,0,1,0,0,0,1,0,0}, |
KaifK | 4:08a0ff6668df | 35 | {0,0,0,1,1,1,0,0,0} |
KaifK | 4:08a0ff6668df | 36 | }; |
KaifK | 4:08a0ff6668df | 37 | const int x_button [9][9] = { |
KaifK | 4:08a0ff6668df | 38 | {0,0,0,1,1,1,0,0,0}, |
KaifK | 4:08a0ff6668df | 39 | {0,0,1,0,0,0,1,0,0}, |
KaifK | 4:08a0ff6668df | 40 | {0,1,0,0,0,0,0,1,0}, |
KaifK | 4:08a0ff6668df | 41 | {1,0,0,1,0,1,0,0,1}, |
KaifK | 4:08a0ff6668df | 42 | {1,0,0,0,1,0,0,0,1}, |
KaifK | 4:08a0ff6668df | 43 | {1,0,0,1,0,1,0,0,1}, |
KaifK | 4:08a0ff6668df | 44 | {0,1,0,0,0,0,0,1,0}, |
KaifK | 4:08a0ff6668df | 45 | {0,0,1,0,0,0,1,0,0}, |
KaifK | 4:08a0ff6668df | 46 | {0,0,0,1,1,1,0,0,0} |
KaifK | 4:08a0ff6668df | 47 | }; |
KaifK | 4:08a0ff6668df | 48 | const int y_button [9][9] = { |
KaifK | 4:08a0ff6668df | 49 | {0,0,0,1,1,1,0,0,0}, |
KaifK | 4:08a0ff6668df | 50 | {0,0,1,0,0,0,1,0,0}, |
KaifK | 4:08a0ff6668df | 51 | {0,1,0,0,0,0,0,1,0}, |
KaifK | 4:08a0ff6668df | 52 | {1,0,0,1,0,1,0,0,1}, |
KaifK | 4:08a0ff6668df | 53 | {1,0,0,0,1,0,0,0,1}, |
KaifK | 4:08a0ff6668df | 54 | {1,0,0,0,1,0,0,0,1}, |
KaifK | 4:08a0ff6668df | 55 | {0,1,0,0,1,0,0,1,0}, |
KaifK | 4:08a0ff6668df | 56 | {0,0,1,0,0,0,1,0,0}, |
KaifK | 4:08a0ff6668df | 57 | {0,0,0,1,1,1,0,0,0} |
KaifK | 4:08a0ff6668df | 58 | }; |
KaifK | 4:08a0ff6668df | 59 | //objects |
KaifK | 0:e47aa16004e6 | 60 | Gamepad pad; |
KaifK | 0:e47aa16004e6 | 61 | N5110 lcd; |
KaifK | 9:e6566d09f087 | 62 | Ball ball(lcd); |
KaifK | 9:e6566d09f087 | 63 | Splash splash(lcd, ball); |
KaifK | 9:e6566d09f087 | 64 | Game game(lcd, pad, ball); |
KaifK | 5:ed71996c0534 | 65 | //functions |
KaifK | 5:ed71996c0534 | 66 | void display_menu(); |
KaifK | 4:08a0ff6668df | 67 | //variables |
KaifK | 9:e6566d09f087 | 68 | |
KaifK | 2:21973e665a32 | 69 | |
KaifK | 4:08a0ff6668df | 70 | int main() |
KaifK | 4:08a0ff6668df | 71 | { |
KaifK | 4:08a0ff6668df | 72 | lcd.init(); |
KaifK | 4:08a0ff6668df | 73 | lcd.setContrast(0.5); |
KaifK | 4:08a0ff6668df | 74 | pad.init(); |
KaifK | 4:08a0ff6668df | 75 | lcd.backLightOn(); |
KaifK | 15:5bf3f951d337 | 76 | splash.displayInfo(); |
KaifK | 15:5bf3f951d337 | 77 | splash.playIntro(); |
KaifK | 4:08a0ff6668df | 78 | while (1) |
KaifK | 4:08a0ff6668df | 79 | { |
KaifK | 11:59119247dd68 | 80 | //ball.level_loop(); |
KaifK | 4:08a0ff6668df | 81 | display_menu(); |
KaifK | 4:08a0ff6668df | 82 | if (pad.A_pressed()) { |
KaifK | 15:5bf3f951d337 | 83 | wait(0.2); //debounce |
KaifK | 9:e6566d09f087 | 84 | game.init(); |
KaifK | 12:ca7329a41fc5 | 85 | game.play(); |
KaifK | 15:5bf3f951d337 | 86 | lcd.printString("GAME OVER",15,2); |
KaifK | 12:ca7329a41fc5 | 87 | lcd.refresh(); |
KaifK | 13:5133f00d2a2d | 88 | wait(2); |
KaifK | 4:08a0ff6668df | 89 | } |
KaifK | 5:ed71996c0534 | 90 | if (pad.B_pressed()) { |
KaifK | 5:ed71996c0534 | 91 | wait(0.2); //debounce |
KaifK | 5:ed71996c0534 | 92 | while(!pad.B_pressed()) { |
KaifK | 5:ed71996c0534 | 93 | //Instructions Page |
KaifK | 5:ed71996c0534 | 94 | wait_ms(100); |
KaifK | 5:ed71996c0534 | 95 | lcd.refresh(); |
KaifK | 5:ed71996c0534 | 96 | lcd.clear(); |
KaifK | 5:ed71996c0534 | 97 | } |
KaifK | 5:ed71996c0534 | 98 | } |
KaifK | 5:ed71996c0534 | 99 | if (pad.X_pressed()) { |
KaifK | 5:ed71996c0534 | 100 | while(!pad.B_pressed()) { |
KaifK | 5:ed71996c0534 | 101 | //settings |
KaifK | 5:ed71996c0534 | 102 | wait_ms(100); |
KaifK | 5:ed71996c0534 | 103 | lcd.refresh(); |
KaifK | 5:ed71996c0534 | 104 | lcd.clear(); |
KaifK | 5:ed71996c0534 | 105 | } |
KaifK | 5:ed71996c0534 | 106 | } |
KaifK | 6:09a555c0d997 | 107 | if (pad.Y_pressed()) { |
KaifK | 6:09a555c0d997 | 108 | lcd.turnOff(); |
KaifK | 6:09a555c0d997 | 109 | pad.leds(0.0); |
KaifK | 6:09a555c0d997 | 110 | } |
KaifK | 6:09a555c0d997 | 111 | |
KaifK | 4:08a0ff6668df | 112 | wait_ms(100); |
KaifK | 4:08a0ff6668df | 113 | lcd.refresh(); |
KaifK | 4:08a0ff6668df | 114 | lcd.clear(); |
KaifK | 4:08a0ff6668df | 115 | } |
KaifK | 4:08a0ff6668df | 116 | } |
KaifK | 4:08a0ff6668df | 117 | |
KaifK | 4:08a0ff6668df | 118 | void display_menu() |
KaifK | 4:08a0ff6668df | 119 | { |
KaifK | 9:e6566d09f087 | 120 | splash.drawLogo(13, 0); |
KaifK | 4:08a0ff6668df | 121 | lcd.printString("Play", 2, 2); |
KaifK | 4:08a0ff6668df | 122 | lcd.printString("How-To?", 2, 3); |
KaifK | 4:08a0ff6668df | 123 | lcd.printString("Settings", 2, 4); |
KaifK | 4:08a0ff6668df | 124 | lcd.printString("Exit", 2, 5); |
KaifK | 4:08a0ff6668df | 125 | lcd.drawSprite(28, 15, 9, 9, (int*) a_button); |
KaifK | 4:08a0ff6668df | 126 | lcd.drawSprite(45, 23, 9, 9, (int*) b_button); |
KaifK | 4:08a0ff6668df | 127 | lcd.drawSprite(52, 31, 9, 9, (int*) x_button); |
KaifK | 4:08a0ff6668df | 128 | lcd.drawSprite(28, 39, 9, 9, (int*) y_button); |
KaifK | 15:5bf3f951d337 | 129 | lcd.refresh(); |
KaifK | 15:5bf3f951d337 | 130 | wait(0.1); |
KaifK | 4:08a0ff6668df | 131 | } |