Li Saiwen 201089052

Dependencies:   mbed Gamepad N5110

main.cpp

Committer:
1012754868
Date:
2019-05-05
Revision:
10:7cb79dbb351a
Parent:
7:cafa0b96e8d3

File content as of revision 10:7cb79dbb351a:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Li Saiwen
Username: Li Saiwen
Student ID Number: LEEDS ID: 201089052    SWJTU ID:2016110325
Date:
*/
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"

#include "Snake.h"


struct UserInput {
    Direction d;
   
};


N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Snake snake;
Direction d;
int SNAKY[15][48] = {
    {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,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,0,1,1,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,1,0,1,0,0,0,0,0,0,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,0,0,1,1,1,0,0,0,1,0,1,0,0,1,1,0,1,0,0,0,0,0,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,1,0,1,0,0,0,1,0,0,1,0,0,0,1,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},
    {1,0,1,1,0,1,0,1,0,0,0,0,1,0,0,1,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,1,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,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,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}
    };

char _Buffer[200];

void start_game();
void game_setting();
int game_music_2();


int main()
{   snake.Highest_score = 0;
    while(1){
            int _Flag = 1;
            lcd.init();
            pad.init();
            start_game();
            game_setting();
            snake.init(25,25,5,3);

    while (_Flag) {
            snake.drawsnake(lcd,pad);
            snake.snakemov(pad);
            if(snake.live <= 0) {
                _Flag = 0;
                }
            } 
        }       
}

int game_music_2(){
    pad.tone(1047.0,0.125); //gap
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1175.0,0.125); //1_
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1319.0,0.25); //2_
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1047.0,0.125); //3_
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(880.0,0.125); //1_
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(880.0,0.25); //5 3/4
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1175.0,0.25); //3_
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(988.0,0.25); //2
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(784.0,0.125); //5
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(659.0,0.125); //2
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(659.0,0.25); //1.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(988.0,0.25); //l6.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
     pad.tone(880.0,0.25); //3 3/4
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
     pad.tone(784.0,0.125); //1.
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
     pad.tone(523.0,0.125); //l7
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(523.0,0.25); //gap
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(784.0,0.25); //l7
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(659.0,0.25); //l6
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(0.0,0.25); //l7
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(0.0,0.25); //1.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(587.0,0.125); //2.
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(659.0,0.125); //l5
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(698.0,0.25); //1
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(0.0,0.25); //2.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1047.0,0.25); //3.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(988.0,0.0833); //4
    wait(0.0833);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(988.0,0.0833); //4.
    wait(0.0833);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1047.0,0.0833); //3.
    wait(0.0833);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(784.0,0.25); //2.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(0.0,0.25); //1.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(698.0,0.25); //2
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(659.0,0.1875); //gap
    wait(0.1875);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(698.0,0.0625); //1.
    wait(0.0625);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(740.0,0.25); //2.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(0.0,0.25); //3.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1047.0,0.25); //1.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(988.0,0.0833); //5 3/4
    wait(0.0833);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(988.0,0.0833); //3.
    wait(0.0833);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(880.0,0.0833); //2
    wait(0.0833);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(831.0,0.25); //5
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(0.0,0.25); //2
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(0.0,0.25); //1.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1047.0,0.125); //l6.
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1175.0,0.125); //l6
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1319.0,0.25); //l7.
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1047.0,0.125); //1.
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(880.0,0.125); //l5
    ////////////////////////////////////////////////////
    wait(0.125);
    pad.tone(880.0,0.25); //6
    wait(0.25);
    pad.tone(1175.0,0.25); //H2
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(988.0,0.25); //7
    wait(0.25);
    pad.tone(784.0,0.125); //5_
    wait(0.125);
    pad.tone(659.0,0.125); //3_
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(659.0,0.25); //3
    wait(0.25);
    pad.tone(988.0,0.25); //7
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
     pad.tone(880.0,0.25); //6
    wait(0.25);
     pad.tone(784.0,0.125); //5_
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
     pad.tone(523.0,0.125); //1_
    wait(0.125);
    pad.tone(523.0,0.25); //1
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(784.0,0.25); //5
    wait(0.25);
    pad.tone(659.0,0.25); //3
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(0.0,0.25); //gap
    wait(0.25);
    pad.tone(0.0,0.25); //gap
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(587.0,0.125); //2_
    wait(0.125);
    pad.tone(659.0,0.125); //3_
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(698.0,0.25); //4
    wait(0.25);
    pad.tone(0.0,0.25); //gap
    wait(0.25);
    pad.tone(784.0,0.25); //5
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(698.0,0.08333); //4_3
    wait(0.08333);
    pad.tone(698.0,0.08333); //4_3
    wait(0.08333);
    pad.tone(784.0,0.08333); //5_3
    wait(0.08333);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(659.0,0.25); //3
    wait(0.25);
    pad.tone(784.0,0.25); //5
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1046.0,0.25); //H1
    wait(0.25);
    pad.tone(1318.0,0.25); //H3
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1175.0,0.1875); //H2 3/4
    wait(0.1875);
    pad.tone(1175.0,0.125); //H2_
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1175.0,0.125); //H2_
    wait(0.125);
    pad.tone(1046.0,0.25); //H1
    wait(0.25);
    pad.tone(1046.0,0.125); //H1_
    wait(0.125);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(1046.0,0.25); //H1
    wait(0.25);
    pad.tone(0.0,0.25); //GAP
    wait(0.25);
    if(pad.check_event(Gamepad::A_PRESSED) == true){
        return 0;
        }
    pad.tone(0.0,0.25); //GAP
    wait(0.25);
    pad.tone(0.0,0.25); //GAP
    wait(0.25);
    return 0;
    }


void start_game(){
    lcd.printString("   LI Saiwen",0,3);  
    lcd.printString("Press twice A",0,5);
    lcd.refresh();
    
    lcd.drawSprite(60,5,15,48,(int *)SNAKY);
    lcd.refresh();
    wait(0.2);
    lcd.drawSprite(60,5,15,48,(int *)_SNAKY);
    lcd.refresh();
    
    lcd.drawSprite(55,5,15,48,(int *)SNAKY);
    lcd.refresh();
    wait(0.2);
    lcd.drawSprite(55,5,15,48,(int *)_SNAKY);
    lcd.refresh();
    
    lcd.drawSprite(50,5,15,48,(int *)SNAKY);
    lcd.refresh();
    wait(0.2);
    lcd.drawSprite(50,5,15,48,(int *)_SNAKY);
    lcd.refresh();
    
    lcd.drawSprite(45,5,15,48,(int *)SNAKY);
    lcd.refresh();
    wait(0.2);
    lcd.drawSprite(45,5,15,48,(int *)_SNAKY);
    lcd.refresh();
    
    lcd.drawSprite(40,5,15,48,(int *)SNAKY);
    lcd.refresh();
    wait(0.2);
    lcd.drawSprite(40,5,15,48,(int *)_SNAKY);
    lcd.refresh();
    
    lcd.drawSprite(35,5,15,48,(int *)SNAKY);
    lcd.refresh();
    wait(0.2);
    lcd.drawSprite(35,5,15,48,(int *)_SNAKY);
    lcd.refresh();
    
    lcd.drawSprite(30,5,15,48,(int *)SNAKY);
    lcd.refresh();
    wait(0.2);
    lcd.drawSprite(30,5,15,48,(int *)_SNAKY);
    lcd.refresh();
    
    lcd.drawSprite(25,5,15,48,(int *)SNAKY);
    lcd.refresh();
    wait(0.2);
    lcd.drawSprite(25,5,15,48,(int *)_SNAKY);
    
    lcd.drawSprite(20,5,15,48,(int *)SNAKY);
    lcd.refresh();
    
    while ( pad.check_event(Gamepad::A_PRESSED) == false) {
        game_music_2();
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
    lcd.clear();
}
   
void game_setting() {
    lcd.printString("     Menu",0,0);
    lcd.printString("   A to set",0,1);  
    lcd.printString("set speed   <",0,2);
    lcd.printString("history ",0,3);
    lcd.printString("  press start",0,5);
    lcd.refresh();
    int q = 1;
    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        d = pad.get_direction();
    if(d == N || q == 1){
    lcd.clear();
    lcd.printString("     Menu",0,0);
    lcd.printString("   A to set",0,1);  
    lcd.printString("set speed   <",0,2);
    lcd.printString("history ",0,3);
    lcd.printString("  press start",0,5);
    lcd.refresh();
        if(pad.check_event(Gamepad::A_PRESSED) == true) {
            bool IsCheck = false;
            int c = 1;
            lcd.clear();
            lcd.printString("   Speed set",0,0);
            lcd.printString("   B to set",0,1); 
            lcd.printString(" Normal    <",0,2);
            lcd.printString(" Difficult",0,3);
            lcd.printString(" Hell",0,4);
            lcd.printString(" Press back ",0,5);
            lcd.refresh();
            while(IsCheck == false){
            d = pad.get_direction();
            if(d == N && c == 1){
            lcd.clear();
            lcd.printString("   Speed set",0,0);
            lcd.printString("   B to set",0,1);
            lcd.printString(" Normal    <",0,2);
            lcd.printString(" Difficult",0,3);
            lcd.printString(" Hell",0,4);
            lcd.printString(" Press back ",0,5);
            c = 1;
            lcd.refresh();
                }
            else if(d == S && c == 1 ){
            lcd.clear();
            lcd.printString("   Speed set",0,0);
            lcd.printString("   B to set",0,1);
            lcd.printString(" Normal",0,2);
            lcd.printString(" Difficult <",0,3);
            lcd.printString(" Hell",0,4);
            lcd.printString(" Press back ",0,5);
            c = 2;
            lcd.refresh();
                }
            else if(d == N && c == 2){
            lcd.clear();
            lcd.printString("   Speed set",0,0);
            lcd.printString("   B to set",0,1);
            lcd.printString(" Normal",0,2);
            lcd.printString(" Difficult <",0,3);
            lcd.printString(" Hell",0,4);
            lcd.printString(" Press back ",0,5);
            c = 1;
            lcd.refresh();
                }
            else if(d == S && c == 2){
            lcd.clear();
            lcd.printString("   Speed set",0,0);
            lcd.printString("   B to set",0,1);
            lcd.printString(" Normal",0,2);
            lcd.printString(" Difficult",0,3);
            lcd.printString(" Hell      <",0,4);
            lcd.printString(" Press back ",0,5);
            c = 3; 
            lcd.refresh();  
                }
            else if(d == S && c == 3){
            lcd.clear();
            lcd.printString("   Speed set",0,0);
            lcd.printString("   B to set",0,1);
            lcd.printString(" Normal",0,2);
            lcd.printString(" Difficult",0,3);
            lcd.printString(" Hell      <",0,4);
            lcd.printString(" Press back ",0,5);
            c = 3; 
            lcd.refresh();  
                }
            else if(d == N && c == 3){
            lcd.clear();
            lcd.printString("   Speed set",0,0);
            lcd.printString("   B to set",0,1);
            lcd.printString(" Normal",0,2);
            lcd.printString(" Difficult <",0,3);
            lcd.printString(" Hell",0,4);
            lcd.printString(" Press back ",0,5);
            c = 2;
            lcd.refresh();   
                }
            wait(0.3);
            if(c == 1 && pad.check_event(Gamepad::B_PRESSED) == true) {
                snake._speed = 0;
                lcd.clear();
                lcd.printString(" set success!",0,2);
                lcd.printString(" Press Back!",0,4);
                lcd.refresh();
                }
            else if(c == 2 && pad.check_event(Gamepad::B_PRESSED) == true) {
                snake._speed = 10;
                lcd.clear();
                lcd.printString(" set success!",0,2);
                lcd.printString(" Press Back!",0,4);
                lcd.refresh();
                }
            else if(c == 3 && pad.check_event(Gamepad::B_PRESSED) == true) {
                snake._speed = 50;
                lcd.clear();
                lcd.printString(" set success",0,2);
                lcd.printString(" Press Back!",0,4);
                lcd.refresh();
                }
            if(pad.check_event(Gamepad::BACK_PRESSED) == true){
                IsCheck = true;
                }
            }
            
        if(pad.check_event(Gamepad::BACK_PRESSED) == true){
            break;
            }
        }
    
    }
        if(d == S && q == 1){
    lcd.clear();
    lcd.printString("     Menu",0,0);
    lcd.printString("   A to set",0,1);  
    lcd.printString("set speed",0,2);
    lcd.printString("history     <",0,3);
    lcd.printString("  press start",0,5);
    lcd.refresh();
    q = 2;
        }
        if(d == S && q == 2){
    lcd.clear();
    lcd.printString("     Menu",0,0);
    lcd.printString("   A to set",0,1);  
    lcd.printString("set speed",0,2);
    lcd.printString("history     <",0,3);
    lcd.printString("  press start",0,5);
    lcd.refresh();
    q = 2;    
            }
        if(d == N && q == 2) {
    lcd.clear();
    lcd.printString("     Menu",0,0);
    lcd.printString("   A to set",0,1);  
    lcd.printString("set speed   <",0,2);
    lcd.printString("history ",0,3);
    lcd.printString("  press start",0,5);
    lcd.refresh(); 
    q = 1;      
            }

    if(q == 2 && pad.check_event(Gamepad::A_PRESSED) == true) {
          lcd.clear();
          sprintf(_Buffer,"%2d",snake.Highest_score);
          lcd.printString(_Buffer,34,3);
          lcd.printString("Highest score",0,1);
          lcd.printString(" Press Back",0,5);
          lcd.refresh();  
          while(pad.check_event(Gamepad::BACK_PRESSED) == false){
            
            }
            lcd.clear();
            lcd.printString("MOVE joystick",0,1);
            lcd.refresh();   
        }    
        
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
        }
        
        
        
        lcd.clear();
        lcd.printString("    start!!!",0,1);
        lcd.printString("Enjoy yourself",0,3);
        lcd.refresh();
        wait(2);
}