Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

MenuClasses/StartScreen/StartScreen.cpp

Committer:
AhmedPlaymaker
Date:
2019-05-03
Revision:
65:2872ca289b49
Parent:
64:540aa1602372
Child:
66:e47333ffc6ca

File content as of revision 65:2872ca289b49:

#include "StartScreen.h"

int sprite[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,1},
    {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,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,0,0,0,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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.
    i = 16; //main menu selection arrow position
    g_mode = 1; //game mode selection (joystick/motion control).
    gameSpeedIndex = 2; //game speed page selection.
    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::screen_saver(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 *)sprite); //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
        Start_Pressed = 0; //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.
            Start_Pressed = 1;
            break;
        }
        wait(0.2);
    }
    if (Start_Pressed == 0) {
        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)&&(Start_Pressed == 0)) {
        //Start_Pressed is 1 if start is already pressed during animation
        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);
}

void StartScreen::main_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)) {  //Change this to if button pressed.
        StartScreen::ImplementMenu(lcd, pad);
    }
    pad.tone(1000.0,0.1);
    wait(1/controlSensitivity);
    StartScreen::NextMenu(lcd, pad); //after all main menu operations have been completed, this function allows us to get to the next menu.
}

void StartScreen::ImplementMenu(N5110 &lcd, Gamepad &pad)
{
    Direction d = pad.get_direction();
    if(((d==N)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(i>16))  {
        i=i-8; // i 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))&&(i<40))  {
        i=i+8; // i 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.printString("SnakeVSBlock",5,0);
    lcd.printString("Play",0,2);
    lcd.printString("Settings",0,3);
    lcd.printString("Stats",0,4);
    lcd.printString("Tutorial",0,5);
    lcd.drawSprite(50,i,7,9,(int *)arrow); // i is the postion of where the arrow will be drawn and is determined by the above if command using joystick.
    lcd.refresh();
    wait(1/controlSensitivity);
    lcd.clear();
}

void StartScreen::NextMenu(N5110 &lcd, Gamepad &pad)
{
    switch (i) { //this i 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
            break;
        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 number in sc which decides weather or not to show credits when game starts.
            main_menu(lcd, pad); //to return to main_menu if back is pressed
            break;
        case 32:
            _stats.StatsDisplay(lcd, pad);
            main_menu(lcd, pad); //to return to main_menu if back is pressed
            break;
        case 40:
            _tutorial.Implement(lcd, pad);
            main_menu(lcd, pad); //to return to main_menu if back is pressed
            break;
    }
}

void StartScreen::game_mode(N5110 &lcd, Gamepad &pad)
{
    lcd.clear();
    wait(2/controlSensitivity);
    //pad.init();
    while ((pad.check_event(Gamepad::A_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) {  //Change this to if button pressed.
        StartScreen::ModeOptions(lcd); //displays to the user what are the mode options
        StartScreen::SelectMode(pad);  //the mode is selected by moving joystick in this function.

        //This is a very important process, this helps the code to not get stuck in  menu loop.
        if (pad.check_event(Gamepad::BACK_PRESSED) == true) {
            pad.tone(1000.0,0.1);
            back_pressed = 1;
            break; //if back is pressed, the while loop is escaped.
        } else {
            back_pressed = 0;
        }
    }
    pad.tone(1000.0,0.1);
    if(back_pressed) { //if back was pressed in the while loop, the previous menu is called.
        main_menu(lcd, pad);
    }

    else {
        if (g_mode == 2) {  //show instructions to handle motion control.
            StartScreen::motionControlInstructions(lcd);    //this only comes up on the screen is the user selects motion control from menu options.
        }
        //Condition to go to next menu page.
        lcd.clear();
        game_speed(lcd, pad);
    }
}

void StartScreen::ModeOptions(N5110 &lcd)
{
    lcd.clear();
    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;
    }

    lcd.refresh();
}

void StartScreen::SelectMode(Gamepad &pad)
{
    Direction d = pad.get_direction();
    wait(1/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;
    }
}

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);
}

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

        //This is a very important process, this helps the code to not get stuck in  menu loop.
        if (pad.check_event(Gamepad::BACK_PRESSED) == true) {
            pad.tone(1000.0,0.1);
            back_pressed = 1;
            break; //if back is pressed, the while loop is escaped.
        } else {
            back_pressed = 0;
        }
    }

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

    else {
        pad.tone(1000.0,0.1);
        lcd.clear();
        wait(1/controlSensitivity);
    }
}

void StartScreen::selectSpeedPage(Gamepad &pad)
{
    Direction d = pad.get_direction();
    wait(1/controlSensitivity);
    if(((d==E)||(pad.check_event(Gamepad::R_PRESSED) == true))&&(gameSpeedIndex==4))  {
        gameSpeedIndex=1;
    } else if(((d==W)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(gameSpeedIndex==1))  {
        gameSpeedIndex=4;
    } else if(((d==E)||(pad.check_event(Gamepad::R_PRESSED) == true))&&(1<=gameSpeedIndex<=3))  {
        gameSpeedIndex=gameSpeedIndex+1;
    } else if(((d==W)||(pad.check_event(Gamepad::L_PRESSED) == true))&&(2<=gameSpeedIndex<=4))  {
        gameSpeedIndex=gameSpeedIndex-1;
    }
}

void StartScreen::showSpeedOptions(N5110 &lcd) //decrease code size.
{
    lcd.clear();
    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 (gameSpeedIndex) {
        case 1:
            lcd.printString("SNAKE",28,3);
            fps = 12;
            break;
        case 2:
            lcd.printString("HUMAN",28,3);
            fps = 18;
            break;
        case 3:
            lcd.printString("HORSE",28,3);
            fps = 22;
            break;
        case 4:
            lcd.printString("CHEETHA",21,3);
            fps = 27;
    }

    lcd.refresh();
}