el15mh 200929957

Dependencies:   mbed

main.cpp

Committer:
el15mh
Date:
2017-03-30
Revision:
1:8ce2586b5965
Parent:
0:d7701c5c20e6
Child:
2:a488caea1601

File content as of revision 1:8ce2586b5965:

#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"

// CREATE OBJECTS //
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;

// FUNCTION PROTOTYPES //
void init();

int main()
{
    init(); // initialise devices
    
    while(1){
        
        int selected = 0;
        int exit = 0;
        
        while(exit == 0){
            
            int back = 0;
            
            switch (selected) {
                    
                case 1:
                    
                    lcd.clear();
                    // displays options page with indicator on first
                    lcd.printString("Game Options:", 0, 0);
                    lcd.printString(">Difficulty", 0, 2);
                    lcd.printString(" Ball Colour", 0, 3);
                    lcd.refresh();
                    
                    while (back == 0){
                        
                        // if first option selected
                        if (pad.check_event(Gamepad::A_PRESSED) ||
                            pad.check_event(Gamepad::JOY_PRESSED)){
                            
                            switch(selected){
                                    
                                case 1:
                                    
                                    lcd.clear();
                                    lcd.printString("Difficulty: ", 0, 0);
                                    lcd.printString(">Easy", 0, 2);
                                    lcd.printString(" Hard", 0, 3);
                                    lcd.refresh();
                                    
                                    if (pad.check_event(Gamepad::A_PRESSED) ||
                                        pad.check_event(Gamepad::JOY_PRESSED)){
                                        
                                        // maze.mazeIndex = 0;
                                    }
                                    
                                    wait_ms(250);
                                    
                                    break;
                                    
                                case 2:
                                    
                                    lcd.clear();
                                    lcd.printString("Difficulty: ", 0, 0);
                                    lcd.printString(" Easy", 0, 2);
                                    lcd.printString(">Hard", 0, 3);
                                    lcd.refresh();
                                    
                                    if (pad.check_event(Gamepad::A_PRESSED) ||
                                        pad.check_event(Gamepad::JOY_PRESSED)){
                                        
                                        // maze.mazeIndex = 1;
                                        lcd.printString("Hard selected", 0, 1);
                                        lcd.refresh();
                                    }
                                    
                                    wait_ms(250);
                                    
                                    break;
                                    
                                default:
                                    
                                    selected = 0;
                                    
                                    break;
                                    
                            }
                        }
                        
                        if (pad.check_event(Gamepad::BACK_PRESSED)){
                            
                            back = 1;
                        }
                    }
                    
                    wait(1);    // 1s propogation delay
                    
                case 2:
                    
                    lcd.clear();
                    // displays options page with indicator on second
                    lcd.printString("Game Options:", 0, 0);
                    lcd.printString(" Difficulty", 0, 2);
                    lcd.printString(">Ball Colour", 0, 3);
                    lcd.refresh();
                    
                    while (back == 0){
                        
                        // if second option selected
                        if (pad.check_event(Gamepad::A_PRESSED) ||
                            pad.check_event(Gamepad::JOY_PRESSED)){
                            
                            switch (selected){
                                    
                                case 1:
                                    
                                    lcd.clear();
                                    lcd.printString("Ball colour: ", 0, 0);
                                    lcd.printString(">Transparent", 0, 2);
                                    lcd.printString(" Solid", 0, 3);
                                    lcd.refresh();
                                    
                                    if (pad.check_event(Gamepad::A_PRESSED) ||
                                        pad.check_event(Gamepad::JOY_PRESSED)){
                                        
                                        // ball.ballColour = 0;
                                        lcd.clear();
                                        lcd.printString("Transparent", 0, 1);
                                        lcd.refresh();
                                        
                                        wait(2);
                                    }
                                    
                                    break;
                                    
                                case 2:
                                    
                                    lcd.printString("Ball colour: ", 0, 0);
                                    lcd.printString(" Transparent", 0, 2);
                                    lcd.printString(">Solid", 0, 3);
                                    lcd.refresh();
                                    
                                    if (pad.check_event(Gamepad::A_PRESSED) ||
                                        pad.check_event(Gamepad::JOY_PRESSED)){
                                        
                                        // ball.ballColour = 1;
                                        lcd.clear();
                                        lcd.printString("Solid", 0, 1);
                                        lcd.refresh();
                                        
                                        wait(2);
                                    }
                                    
                                    break;
                                    
                                default:
                                    
                                    selected = 0;
                                    break;
                            }
                            
                            if (pad.check_event(Gamepad::BACK_PRESSED)){
                                
                                back = 1;
                            }
                        }
                        
                        wait(1);    // 1s propogation delay
                        
                    }
                    
                    if (pad.check_event(Gamepad::BACK_PRESSED)){
                        
                        exit = 1;
                    }
            }
        }
        
    }
}

void init()
{
    lcd.init();
    pad.init();
}