Adam Baker 201166301

Dependencies:   mbed Gamepad N5110

main.cpp

Committer:
adambakerwa
Date:
2019-04-17
Revision:
23:4b1abf659467
Parent:
22:8218092c2e4b
Child:
24:f5dd1f3db693

File content as of revision 23:4b1abf659467:

#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;  //length
    int r = 0;
    int d2 = 0;
    int l2 = 0;
    int r2 = 0;
    int d3 = 0;
    int d4 = 0;
    int g = 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, d3, d4);

            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, d3, d4); //what state runner is in (must come after next level

            //runner.whatLevel(move, lcd); // call level(why again)??
            d = runner.onHozCheck(move, pos);
            
            r = runner.byHozCheckRight(move, pos);
            
            l = runner.byHozCheckLeft(move, pos);
            
            d2 = runner.onHoz2Check(move, pos);
                        
            r2 = runner.byHoz2CheckRight(move, pos);
            
            l2 = runner.byHoz2CheckLeft(move, pos);
            
            d3 = runner.onVerCheck(move, pos);
            
            d4 = runner.onVer2Check(move, pos);
            
            g = runner.crushedByVer(move, pos);
            
            g = g + runner.crushedByVer2(move, pos);
            
            g = g + runner.spikeHit(lcd, pos);
            
        
            
            move = runner.onPlatform(lcd, move, d, r, l, d2, r2, l2, d3, d4);


            char buffer[14];
            sprintf(buffer,"%i",  g);
            lcd.printString(buffer,0,0);
           /** char buffer1[14];
            sprintf(buffer1,"%i %i %i %i %i",pos.vx, pos. vy, pos.vd, pos.vc, pos.vl);
            lcd.printString(buffer1,0,1);
            */
            
            lcd.refresh();

        } else {

            sleep();

        }
    }

}

void timer_isr()
{

    timer_flag = 1;   // set flag in ISR
}


//rtos