ELEC2645 (2018/19) / Mbed 2 deprecated el17arm

Dependencies:   mbed

main.cpp

Committer:
el17arm
Date:
2019-03-20
Revision:
2:725c213b2396
Parent:
1:813ba5341985
Child:
3:d27ee2440829

File content as of revision 2:725c213b2396:

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

Levelengine level;
Minerengine engine;
Gamepad pad;
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
AnalogIn pot0(PTB2);

void contrast();
void init();
void start_screen();

int main()
{
    lcd.clear();
    init();
    start_screen();
    lcd.refresh();

    while (1) {

        contrast();
        level.test_level(lcd);
        engine.read_direction(pad);
        engine.miner_move();
        engine.miner_draw(lcd);
        engine.miner_jump(lcd, pad);
        wait(0.1);

    }

}

void init()
{
    lcd.init();
    lcd.normalMode();      // normal colour mode
    lcd.setBrightness(0.5); // put LED backlight on 50%
    lcd.refresh();
    pad.init();
    pad.leds_off();
    

}

void contrast()
{
    lcd.refresh();
    float con = pot0.read();
    lcd.setContrast(con);
    lcd.clear();

}

void start_screen()
{   

    lcd.printString("***MANIC MILNER!***",0,1);
    lcd.printString("  Press start to play! ",0,4);


    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        contrast();
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);

    }
}

/*void minermove()
{

    const int miner_right[13][5] =   {
        0,0,0,1,1,
        0,1,1,1,1,
        0,1,0,1,0,
        0,1,1,1,1,
        0,1,1,1,0,
        0,0,1,0,0,
        1,1,1,1,1,
        1,1,1,1,1,
        1,1,1,1,1,
        0,1,1,1,0,
        0,1,0,1,0,
        0,1,1,1,1,
    };

    const int miner_left[13][5] =   {
        1,1,0,0,0,
        1,1,1,1,0,
        0,1,0,1,0,
        1,1,1,1,0,
        0,1,1,1,0,
        0,0,1,0,0,
        1,1,1,1,1,
        1,1,1,1,1,
        1,1,1,1,1,
        0,1,1,1,0,
        0,1,0,1,0,
        1,1,1,1,0,
    };

    lcd.drawSprite(WIDTH/2 + x_direction,HEIGHT/2 + y_direction,13,5,(int *)miner_right);

    Direction d = pad.get_direction();
    printf("Direction = %i\n",d);

    if (d==3) {

        x_direction = x_direction + 1;
        lcd.clear();
        lcd.drawSprite(WIDTH/2 + x_direction,HEIGHT/2 + y_direction,13,5,(int *)miner_right);
        lcd.refresh();
        wait(0.05);

    }

    if (d == 7) {

        x_direction = x_direction - 1;
        lcd.clear();
        lcd.drawSprite(WIDTH/2 + x_direction,HEIGHT/2 + y_direction,13,5,(int *)miner_left);
        lcd.refresh();
        wait(0.05);
    }
    //lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner);
    //lcd.refresh();

    if(pad.check_event(Gamepad::A_PRESSED)) {


        printf("A pressed");
        y_direction = y_direction - 6;
        lcd.clear();
        lcd.drawSprite(WIDTH/2 + x_direction,HEIGHT/2 + y_direction,13,5,(int *)miner_right);
        lcd.refresh();
        wait(0.2);
        y_direction = y_direction + 6;
    }
}*/