Custom Game Controllers assembled in lab sessions and mounted with Nokia N5110 LCD display and a FRDM-K64F mbed plus various buttons, a joystick, potentiometer and piezo. Designed a game called 'Fruit Basket' to be played on the game controller where the player controls a basket and moves it catch objects that fall from random points along the top of the display to collect score.

Dependencies:   Basket Catch_Model Fruit Gamepad N5110 Objects mbed

Project_Submission.cpp

Committer:
Nathanj94
Date:
2017-04-18
Revision:
11:a6a88a51dd57
Parent:
10:92a658c3c5a4
Child:
12:d87c9ae89472

File content as of revision 11:a6a88a51dd57:

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

#define BASKET_Y 41
#define BASKET_WIDTH 12
#define BALL_SPEED 3
#define LIVES 5

//OBJECTS//
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad; 
Catch_Model catchm;
Objects objects;

//FUNCTION PROTOTYPES//
void init();
void render();
void welcome();
void speed_select();

//MAIN//
int main()
{
    int fps = 8; 
    
    while(1) {

        init();
        welcome();
        //speed_select();
        render(); 
        wait(1.0f/fps);  
        int lives;

        do {
            catchm.input(pad);
            catchm.update(lcd, pad);
            
            catchm.check_a(lcd,pad);
            catchm.check_b(lcd,pad);
            catchm.check_x(lcd,pad);

            lives = catchm.get_lives();
            render();
            wait(1.0f/fps);
            
           } while(lives > 0);
    }
}

//FUNCTIONS//
void init()
{
    // initialise LCD and Gamepad 
    lcd.init();
    pad.init();
     
    // initialise game model
    catchm.init(BASKET_Y,BASKET_WIDTH,BALL_SPEED,LIVES);

}

void render()
{
    // re-draw screen each loop
    lcd.clear();  
    catchm.draw(lcd);
    lcd.refresh();
}

void welcome() 
{
     
    lcd.printString("  Press Start ",0,2);
    lcd.refresh();
     
    while (pad.check_event(Gamepad::START_PRESSED) == false) {
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
    pad.tone(500, 0.5);
}

void speed_select()
{
    lcd.clear();
    lcd.refresh();
    
    while (pad.check_event(Gamepad::START_PRESSED) == false) {
        
        objects.speed_select(pad);
        
        char buffer[14];
        float speed = objects.get_speed();
        int print_speed = sprintf(buffer, "%10.2f", speed);
        
        if (speed > 1) {
            lcd.printString("INSANE",0,0);
        } else if (speed != 0) {
            lcd.printString(buffer,0,0);
        }
        lcd.refresh();
    }
}