Kaif Kutchwala 201267448 ELEC2645 Project

Dependencies:   mbed

main.cpp

Committer:
KaifK
Date:
2020-05-16
Revision:
5:ed71996c0534
Parent:
4:08a0ff6668df
Child:
6:09a555c0d997

File content as of revision 5:ed71996c0534:

/*
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;
Splash splash;
Game game;
//functions
void display_menu();
//variables
int initial_pos = WIDTH / 2;
int dir = 1;
int dirr = 1;
int aim_line = WIDTH / 2;
int _user_input_x = 40;
int _user_input_y = 12;
int _ball_x = 35;
int _ball_y = 43;
int j = 0;
int k = 0;
int sizex = 11;
int sizey = 15;
char sprite = 'b';

int main()
{
    lcd.init();
    lcd.setContrast(0.5);
    pad.init();
    lcd.backLightOn();
    //splash.displayInfo(lcd);
    //splash.playIntro(lcd,ball);
    while (1)
    {
        display_menu();
        if (pad.A_pressed()) {
            while(!pad.B_pressed()) {
                game.init();
                game.updateLives(pad);
                game.updateScore(lcd);
                game.displayLevel(1,lcd);
                ball.init(lcd);
                wait_ms(100);
                lcd.refresh();
                lcd.clear();
            }
        }
        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();}
        /*
        ball.init(lcd);
        Vector2D joystick = pad.get_mapped_coord();
        float ballx = WIDTH / 2 - 7;
        float bally = 43;

        lcd.drawLine(0, 24, 84, 24, 1);
        lcd.drawLine(WIDTH / 2 - 5, 41, initial_pos, HEIGHT / 2 + 7, 1);
        lcd.drawLine(WIDTH / 2 + 5, 41, initial_pos, HEIGHT / 2 + 7, 1);
        lcd.drawLine(WIDTH / 2 + 5, 41, WIDTH / 2 - 5, 41, 1);
        lcd.printString("Score", 0, 5);

        aim_line += dir;
        initial_pos += dirr;
        if (initial_pos > 84)
        {
            dirr = -1;
        }

        if (initial_pos < 0)
        {
            dirr = 1;
        }

        if (aim_line > 84)
        {
            dir = -1;
        }

        if (aim_line < 0)
        {
            dir = 1;
        }

        if (pad.A_pressed())
        {
            wait(0.2);
            ball.set_status(0);
            ball.playShot(aim_line, 12, lcd);

        }
        */

        //printf("done");
        wait_ms(100);
        lcd.refresh();
        lcd.clear();
    }
}

void display_menu()
{
    splash.drawLogo(13, 0, lcd, ball);
    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);
}