
Kaif Kutchwala 201267448 ELEC2645 Project
Dependencies: mbed
main.cpp
- Committer:
- KaifK
- Date:
- 2020-05-22
- Revision:
- 17:2fbe40177b9c
- Parent:
- 16:1f196a0e12be
- Child:
- 18:100e7d3509b5
File content as of revision 17:2fbe40177b9c:
/* Shoot ELEC2645 Project EL18KK 201267448 */ #include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "Ball.h" #include "Splash.h" #include "Game.h" const int highscore_icon [9][15] = { {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, {0,0,0,0,0,1,0,0,0,1,0,0,0,0,0}, {0,0,0,0,0,1,0,0,0,1,0,0,0,0,0}, {1,1,1,1,0,1,0,0,0,1,0,0,0,0,0}, {1,0,0,1,0,1,0,0,0,1,0,1,1,1,1}, {1,0,0,1,0,1,0,0,0,1,0,1,0,0,1}, {1,0,0,1,0,1,0,0,0,1,0,1,0,0,1}, {1,0,0,1,0,1,0,0,0,1,0,1,0,0,1}, {1,1,1,1,0,1,1,1,1,1,0,1,1,1,1}, }; const int a_button [9][9] = { {0,0,0,1,1,1,0,0,0}, {0,0,1,0,0,0,1,0,0}, {0,1,0,0,1,0,0,1,0}, {1,0,0,1,0,1,0,0,1}, {1,0,0,1,1,1,0,0,1}, {1,0,0,1,0,1,0,0,1}, {0,1,0,0,0,0,0,1,0}, {0,0,1,0,0,0,1,0,0}, {0,0,0,1,1,1,0,0,0} }; const int b_button [9][9] = { {0,0,0,1,1,1,0,0,0}, {0,0,1,0,0,0,1,0,0}, {0,1,0,1,1,1,0,1,0}, {1,0,0,1,0,0,1,0,1}, {1,0,0,1,1,1,0,0,1}, {1,0,0,1,0,0,1,0,1}, {0,1,0,1,1,1,0,1,0}, {0,0,1,0,0,0,1,0,0}, {0,0,0,1,1,1,0,0,0} }; const int x_button [9][9] = { {0,0,0,1,1,1,0,0,0}, {0,0,1,0,0,0,1,0,0}, {0,1,0,0,0,0,0,1,0}, {1,0,0,1,0,1,0,0,1}, {1,0,0,0,1,0,0,0,1}, {1,0,0,1,0,1,0,0,1}, {0,1,0,0,0,0,0,1,0}, {0,0,1,0,0,0,1,0,0}, {0,0,0,1,1,1,0,0,0} }; const int y_button [9][9] = { {0,0,0,1,1,1,0,0,0}, {0,0,1,0,0,0,1,0,0}, {0,1,0,0,0,0,0,1,0}, {1,0,0,1,0,1,0,0,1}, {1,0,0,0,1,0,0,0,1}, {1,0,0,0,1,0,0,0,1}, {0,1,0,0,1,0,0,1,0}, {0,0,1,0,0,0,1,0,0}, {0,0,0,1,1,1,0,0,0} }; //objects Gamepad pad; N5110 lcd; Ball ball(lcd); Splash splash(lcd, ball); Game game(lcd, pad, ball); //functions void init(); void display_menu(); void game_loop(); void how_to(); void display_settings(); //variables int main() { init(); while (1) { //ball.level_loop(); display_menu(); if (pad.A_pressed()) { game_loop(); } else if (pad.B_pressed()) { wait(0.2); //debounce while(!pad.B_pressed()) { //Instructions Page wait_ms(100); lcd.refresh(); lcd.clear(); } } else if (pad.X_pressed()) { while(!pad.B_pressed()) { display_settings(); } } else if (pad.Y_pressed()) { lcd.turnOff(); pad.leds(0.0); } } } void init() { lcd.init(); lcd.setContrast(0.5); pad.init(); lcd.backLightOn(); //splash.displayInfo(); //splash.playIntro(); } void display_menu() { splash.drawLogo(13, 0); lcd.printString("Play", 2, 2); lcd.printString("How-To?", 2, 3); lcd.printString("Settings", 2, 4); lcd.printString("Exit", 2, 5); lcd.drawSprite(28, 15, 9, 9, (int*) a_button); lcd.drawSprite(45, 23, 9, 9, (int*) b_button); lcd.drawSprite(52, 31, 9, 9, (int*) x_button); lcd.drawSprite(28, 39, 9, 9, (int*) y_button); //highscore lcd.drawSprite(65, 21, 9 , 15, (int *)highscore_icon); lcd.drawRect(65, 30, 15, 12, FILL_TRANSPARENT); int highscore = game.get_highscore(); char buffer[12]; sprintf(buffer,"%d",highscore); lcd.printString(buffer,67,4); lcd.refresh(); wait(0.1); lcd.clear(); } void game_loop() { wait(0.2); //debounce game.init(); game.play(); lcd.clear(); lcd.printString("GAME OVER",15,2); lcd.refresh(); wait(2); pad.reset_buttons(); //to ensure no accidental selection on menu } void how_to() { //page 1 - b to exit, buttons on gamepad //page 2 - a to stop pointer, b to set power //page 3- tips //page 4- tips //page 5- life after 5 points } void display_settings() { lcd.printString("Settings",20,0); lcd.printString("Set Contrast",0,1); lcd.printString("using Pot 1",0,2); lcd.printString("Hit B to Exit",0,5); lcd.drawRect(0, 24, 84, 8, FILL_TRANSPARENT); float pot_1_val = pad.read_pot1(); printf("POT 1 = %.2f \n",pot_1_val); lcd.drawRect(0, 24, (int)(84*pot_1_val), 8, FILL_BLACK); lcd.setContrast(pot_1_val); lcd.refresh(); wait_ms(100); lcd.clear(); }