Adam Baker 201166301

Dependencies:   mbed Gamepad N5110

main.cpp

Committer:
adambakerwa
Date:
2019-04-08
Revision:
19:48d49a42037c
Parent:
18:0a0976faedfb
Child:
20:54724f686c14

File content as of revision 19:48d49a42037c:

#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Runner.h"
#include "Levels.h"
#include "Animation.h"

N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Runner runner;
Animation ani;
Levels lev;
Ticker ticker;


volatile int timer_flag = 0;

void timer_isr();


int main()
{

    int fps = 6; //6
    int d = 0 ; // direction of moving plats
    int l = 0;
    int r = 0;
    int d2 = 0;
    int l2 = 0;
    int r2 = 0;
    
    pad.init();
    lcd.init();
    lcd.setContrast(0.55);
    Move move;
    Pos pos;
    
    move = runner.init(move);
    pos = lev.init(pos);
    
    ticker.attach(&timer_isr,1.0f/fps);


    while(1) {

        if (timer_flag == true) {

            timer_flag = 0;  // if it has, clear the flag

            lcd.clear();

            float speed = runner.getSpeed(pad);

            move = runner.nextLevel(move); //must happen befofre 'fall' otherwise runner can fall out of screen

            pos = lev.whatLevel(lcd, move.l);

            move = runner.buttonPress(move, lcd, pad);

            move = runner.jump(move, lcd);

            move = runner.wallJumpL(move, lcd, speed);

            move = runner.wallJumpR(move, lcd, speed);

            move = runner.runLeft(move, lcd, speed);

            move = runner.runRight(move, lcd, speed);
            
            move = runner.cancelSprint(move, lcd, speed);

            move = runner.fall(move, lcd);

            move = runner.runnerState(move, lcd, speed); //what state runner is in (must come after next level

            //runner.whatLevel(move, lcd); // call level(why again)??
            d = runner.onPlatformCheck(move, pos);
            
            r = runner.byPlatformCheckRight(move, pos);
            
            l = runner.byPlatformCheckLeft(move, pos);
            
            d2 = runner.onPlatform2Check(move, pos);
                        
            r2 = runner.byPlatform2CheckRight(move, pos);
            
            l2 = runner.byPlatform2CheckLeft(move, pos);
            
            move = runner.onPlatform(lcd, move, d, r, l, d2, r2, l2);


            char buffer[14];
            sprintf(buffer,"%i %i %i %i %i" ,pos.x, pos.y, pos.d2, pos.c2, pos.l2);
            lcd.printString(buffer,0,0);
            char buffer1[14];
            sprintf(buffer1,"%i %i %i",d2, r2, l2);
            lcd.printString(buffer1,0,1);

            //sleep(); //sleep untill next refresh

            lcd.refresh();

        } else {

            sleep();

        }
    }

}

void timer_isr()
{

    timer_flag = 1;   // set flag in ISR
}


//rtos