Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

MenuClasses/StartScreen/StartScreen.cpp

Committer:
AhmedPlaymaker
Date:
2019-05-05
Revision:
76:7fa91122907f
Parent:
68:b9cfd27987ac
Child:
80:51ca38c5dcdf

File content as of revision 76:7fa91122907f:

#include "StartScreen.h"

int titleSprite[48][84] = {
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0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,0,0,0,0,0,0,0,1},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},

};

int arrow[7][9] = {
    {0,0,0,0,1,0,0,0,0},
    {0,0,0,1,1,0,0,0,0},
    {0,0,1,1,1,0,0,0,0},
    {0,1,1,1,1,1,1,1,1},
    {0,0,1,1,1,0,0,0,0},
    {0,0,0,1,1,0,0,0,0},
    {0,0,0,0,1,0,0,0,0},
};

int motionControl[12][21] = {
    {0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
    {0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,0,0,0,0},
    {0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,0,0,0,0},
    {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
    {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
    {1,1,1,0,1,0,0,1,1,1,1,1,1,1,0,0,1,0,1,1,1},
    {1,1,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,1},
    {1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1},
    {0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0},
    {0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0},
    {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
};

int joystick[13][48] = {
    {0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0},
    {0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0},
    {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},
};

int navL[13][8] = {
    {0,0,0,0,0,0,1,1},
    {0,0,0,0,0,1,1,0},
    {0,0,0,0,1,1,0,0},
    {0,0,0,1,1,0,0,0},
    {0,0,1,1,0,0,0,0},
    {0,1,1,0,0,0,0,0},
    {1,1,1,1,1,1,1,1},
    {0,1,1,0,0,0,0,0},
    {0,0,1,1,0,0,0,0},
    {0,0,0,1,1,0,0,0},
    {0,0,0,0,1,1,0,0},
    {0,0,0,0,0,1,1,0},
    {0,0,0,0,0,0,1,1},
};

int navR[13][8] = {
    {1,1,0,0,0,0,0,0},
    {0,1,1,0,0,0,0,0},
    {0,0,1,1,0,0,0,0},
    {0,0,0,1,1,0,0,0},
    {0,0,0,0,1,1,0,0},
    {0,0,0,0,0,1,1,0},
    {1,1,1,1,1,1,1,1},
    {0,0,0,0,0,1,1,0},
    {0,0,0,0,1,1,0,0},
    {0,0,0,1,1,0,0,0},
    {0,0,1,1,0,0,0,0},
    {0,1,1,0,0,0,0,0},
    {1,1,0,0,0,0,0,0},
};

StartScreen::StartScreen()
{

}

StartScreen::~StartScreen()
{

}

void StartScreen::init()
{
    fps = 15; //sets the default frames per second to a certain value.
    menu_index = 16; //main menu selection arrow position
    g_mode = 1; //game mode selection (joystick/motion control).
    speed_index = 2; //game speed page selection index.
    showCredits = 1; //this helps in wether ot not to show credits to the user.
    controlSensitivity = 5; //sensitivity of control speed of menu options.
}

void StartScreen::titleScreen(N5110 &lcd, Gamepad &pad)
{
    //this saves the Theme song I want to play at the start.
    int song[18] = {441,494,439,372,392,370,330,246,329,331,370,555,555,495,440,392,392,370};
    pad.leds_on();

    for(int ani = -51; ani <= 0; ani+=3)  {
        lcd.clear();
        lcd.drawSprite(0,ani,48,84,(int *)titleSprite); //Function used to draw the sprite
        lcd.refresh();
        pad.tone(song[(ani+48)/3],0.1);

        //This Allows us to skip/play the animation before the menu screen
        _startPressed = false; //by default, animmation is not skipped, as StartScreen::instruct(lcd,pad) requires Start_Pressed to be 0 to be displayed
        if((pad.check_event(Gamepad::START_PRESSED) == true)||(pad.check_event(Gamepad::A_PRESSED) == true)) { //to allow the gamer to skip the long starting animation if they are not a fan.
            _startPressed = true;
            break;
        }
        wait(0.2);
    }
    if (_startPressed == false) {
        wait(0.3);    //dont wait anymore if start is pressed. (this is to allow for quick skip towards menu)
    }
    pad.leds_off();
    lcd.clear();

    StartScreen::instruct(lcd,pad); //after the screen_saver is displayed we need to send in instructions of how to preoceed to menu.
}

void StartScreen::instruct(N5110 &lcd, Gamepad &pad)
{
    //pad.init();
    wait(1/controlSensitivity); //to avoid race condition of the following while loop being skipped.
    while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)&&(_startPressed == false)) {
        //Start_Pressed is 1 if start is already pressed during animation in titleScreen();
        lcd.printString("Please Press",5,1); //Function used to promt the user to start.
        lcd.printString("Start",25,3);
        lcd.printString("to Begin",15,5);
        lcd.refresh();
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
    pad.tone(1000.0,0.1);
    lcd.clear();
    pad.leds_off();
}

void StartScreen::credits(N5110 &lcd)
{
    lcd.clear();
    if(showCredits)  {
        lcd.printString("Created BY",8,1);
        lcd.printString("Ahmed",24,3);
        lcd.printString("Adamjee",20,4);
        lcd.printString("201161436",15,5);
        lcd.refresh();
        wait(2);
    }
    lcd.clear();
}

void StartScreen::read_stats(SDFileSystem &sd) //to read the data from the SD card at the start of the game to be able to display before starting game.
{
    _stats.read(sd);
}

bool StartScreen::checkBackPressed(Gamepad &pad)
{
    //This is a very important process, this helps the code to not get stuck in  menu loop but also allow to toggle between diffrent menu screens.
    if (pad.check_event(Gamepad::BACK_PRESSED) == true) {
        pad.tone(1000.0,0.1);
        _backPressed = true;
    } else {
        _backPressed = false;
    }
    return _backPressed; //returns 1 if back is pressed, returns 0 otherwise.
}

void StartScreen::menu(N5110 &lcd, Gamepad &pad)
{
    lcd.clear();
    //StartScreen::init();
    //pad.init();
    while ((pad.check_event(Gamepad::A_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) {
        //This menu loop won't be skipped unless the player decides to press START/A.
        lcd.clear();
        StartScreen::mainMenu(lcd, pad);
        lcd.refresh();
        
    }
    pad.tone(1000.0,0.1);
    StartScreen::nextMenu(lcd, pad); //after all main menu operations have been completed, this function allows us to get to the next menu.
}

void StartScreen::mainMenu(N5110 &lcd, Gamepad &pad) //Displays the main menu contents, and then allows the user to select the next menu using the selection arrow.
{
    StartScreen::drawSelectionArrow(lcd, pad); //draws arrow to select menu option.

    lcd.printString("Snake vs Block",0,0);
    lcd.printString("Play",0,2);
    lcd.printString("Settings",0,3);
    lcd.printString("Stats",0,4);
    lcd.printString("Tutorial",0,5);
}

void StartScreen::drawSelectionArrow(N5110 &lcd, Gamepad &pad)
{
    wait(1/controlSensitivity);
    Direction d = pad.get_direction();
    if(((d==N)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(menu_index>16))  {
        menu_index=menu_index-8; // menu_index is the position of the selection arrow in menu and also the index of the case structure to select the next menu in StartScreen::NextMenu(lcd, pad).
    }
    if(((d==S)||(pad.check_event(Gamepad::R_PRESSED) == true))&&(menu_index<40))  {
        menu_index=menu_index+8; // menu_index is the position of the selection arrow in menu and also the index of the case structure to select the next menu in StartScreen::NextMenu(lcd, pad).
    }
    lcd.drawSprite(60,menu_index,7,9,(int *)arrow); // menu_index is the postion of where the arrow will be drawn and is determined by the above if command using joystick.
}

//////////////////////////////DECIDES THE NEXT MENU PAGE//////////////////////////////

void StartScreen::nextMenu(N5110 &lcd, Gamepad &pad)
{
    switch (menu_index) { //this menu_index saves the value from the coordinates of arrow in main menu, and allows us to select the next menu accordingly.
        case 16:
            game_mode(lcd, pad); //calls game mode after play has been pressed.
            game_speed(lcd, pad); //calls game speed after the game mode has been selected.
            return; //This forces us out of the menu class and back into int main().
        case 24:
            float *cs_sc;
            cs_sc = _settings.Implement(lcd, pad, controlSensitivity);
            controlSensitivity = cs_sc[0]; //saves the number in controlSensitivity which controls the control speed of the menu oftions (basically the wait time of between reading joystick input).
            showCredits = cs_sc[1]; //saves the logic in showCredits which decides weather or not to show credits when game starts.
            menu(lcd, pad); //to return to main_menu if back is pressed
            break;
        case 32:
            _stats.StatsDisplay(lcd, pad);
            menu(lcd, pad); //to return to main_menu if back is pressed
            break;
        case 40:
            _tutorial.Implement(lcd, pad);
            menu(lcd, pad); //to return to main_menu if back is pressed
            break;
    }
}


//////////////////////////////GAME MODE SELECTION//////////////////////////////

void StartScreen::game_mode(N5110 &lcd, Gamepad &pad)
{
    lcd.clear();
    //pad.init();
    while ((pad.check_event(Gamepad::A_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) {  //Change this to if button pressed.

        lcd.clear();
        StartScreen::selectMode(lcd, pad); //displays to the user what are the mode options
        lcd.refresh();

        if (StartScreen::checkBackPressed(pad)) {
            break;    //if back is pressed, the while loop is escaped.
        }

    }
    pad.tone(1000.0,0.1);

    if(_backPressed) { //if back was pressed in the while loop, the previous menu is called.
        menu(lcd, pad);
    }
}

void StartScreen::selectMode(N5110 &lcd, Gamepad &pad)
{
    StartScreen::scrollModeSelection(pad);  //the mode is selected by moving joystick in this function.
    switch (g_mode) {
        case 1:
            lcd.printString("Joystick",18,1);
            lcd.drawSprite(17,22,13,48,(int *)joystick); //Function used to draw the sprite.
            lcd.refresh();
            break;
        case 2:
            lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
            lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
            lcd.printString("Motion Control",1,1);
            lcd.drawSprite(32,22,12,21,(int *)motionControl); //Function used to draw the sprite.
            break;
    }

}

void StartScreen::scrollModeSelection(Gamepad &pad)
{
    Direction d = pad.get_direction();
    wait(1/controlSensitivity);//to make the joystick selection's speed inversely proportional to controlSensitivity.
    if(((d==E)||(d==W)||(pad.check_event(Gamepad::R_PRESSED) == true)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(g_mode==1))  {
        g_mode=2;
    }

    else if(((d==E)||(d==W)||(pad.check_event(Gamepad::R_PRESSED) == true)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(g_mode==2))  {
        g_mode=1;
    }
}

//////////////////////////////INSTRUCTIONS FOR MOTION CONTROL//////////////////////////////

void StartScreen::motionControlInstructions(N5110 &lcd)
{
    lcd.clear();
    lcd.printString("While playing the",5,0); //Function used to promt the user to start.
    lcd.printString("game, press",9,1);
    lcd.printString("A to centre",8,2);
    lcd.printString("the snake at",9,3);
    lcd.printString("prefered angle",0,4);
    lcd.refresh();
    wait(2);
}


//////////////////////////////GAME SPEED SELECTION//////////////////////////////

void StartScreen::game_speed(N5110 &lcd, Gamepad &pad)
{
    lcd.clear();
    //pad.init();
    while ((pad.check_event(Gamepad::A_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) {  //Change this to if button pressed.

        lcd.clear();
        StartScreen::selectSpeed(lcd, pad); //this displays all the speed options and saves the data obtained (fps) for use in main().
        lcd.refresh();

        if (StartScreen::checkBackPressed(pad)) {
            break;    //if back is pressed, the while loop is escaped.
        }
    }
    pad.tone(1000.0,0.1);

    if(_backPressed) { //if back was pressed in the while loop, the previous menu is called.
        menu(lcd, pad); //To go back to Menu if back is pressed.
    }

}

void StartScreen::selectSpeed(N5110 &lcd, Gamepad &pad) //decrease code size.
{
    StartScreen::scrollSpeedSelection(pad); //this swipes through the speed pages, dependent on the joystick input.
    lcd.drawSprite(10,22,13,8,(int *)navL); //Function used to draw the sprite.
    lcd.drawSprite(65,22,13,8,(int *)navR); //Function used to draw the sprite.
    lcd.printString("Game Speed",10,1);
    switch (speed_index) {
        case 1:
            lcd.printString("SNAKE",28,3);
            fps = 15;
            break;
        case 2:
            lcd.printString("HUMAN",28,3);
            fps = 22;
            break;
        case 3:
            lcd.printString("HORSE",28,3);
            fps = 26;
            break;
        case 4:
            lcd.printString("CHEETHA",21,3);
            fps = 30;
    }

}

void StartScreen::scrollSpeedSelection(Gamepad &pad)
{
    Direction d = pad.get_direction();
    wait(1/controlSensitivity);//to make the joystick selection's speed inversely proportional to controlSensitivity.
    if(((d==E)||(pad.check_event(Gamepad::R_PRESSED) == true))&&(speed_index==4))  {
        speed_index=1;
    } else if(((d==W)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(speed_index==1))  {
        speed_index=4;
    } else if(((d==E)||(pad.check_event(Gamepad::R_PRESSED) == true))&&(1<=speed_index<=3))  {
        speed_index=speed_index+1;
    } else if(((d==W)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(2<=speed_index<=4))  {
        speed_index=speed_index-1;
    }
}