Kaif Kutchwala 201267448 ELEC2645 Project

Dependencies:   mbed

main.cpp

Committer:
KaifK
Date:
2020-05-18
Revision:
15:5bf3f951d337
Parent:
13:5133f00d2a2d
Child:
16:1f196a0e12be

File content as of revision 15:5bf3f951d337:

/*
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 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 display_menu();
//variables


int main()
{
    lcd.init();
    lcd.setContrast(0.5);
    pad.init();
    lcd.backLightOn();
    splash.displayInfo();
    splash.playIntro();
    while (1)
    {
        //ball.level_loop();
        display_menu();
        if (pad.A_pressed()) {
            wait(0.2); //debounce
            game.init();
            game.play();
            lcd.printString("GAME OVER",15,2);
            lcd.refresh();
            wait(2);
        }
        if (pad.B_pressed()) {
            wait(0.2); //debounce
            while(!pad.B_pressed()) {
                //Instructions Page
                wait_ms(100);
                lcd.refresh();
                lcd.clear();
            }
        }
        if (pad.X_pressed()) {
            while(!pad.B_pressed()) {
                //settings
                wait_ms(100);
                lcd.refresh();
                lcd.clear();
            }
        }
        if (pad.Y_pressed()) {
            lcd.turnOff();
            pad.leds(0.0);
        }
        
        wait_ms(100);
        lcd.refresh();
        lcd.clear();
    }
}

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);
    lcd.refresh();
    wait(0.1);
}