![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Adam Baker 201166301
Dependencies: mbed Gamepad N5110
Diff: main.cpp
- Revision:
- 13:35a459a33bbd
- Parent:
- 12:1253afc5d536
- Child:
- 14:d8ced73dbb83
--- a/main.cpp Sun Mar 24 22:47:33 2019 +0000 +++ b/main.cpp Mon Mar 25 11:01:43 2019 +0000 @@ -9,72 +9,85 @@ Gamepad pad; Runner runner; Animation ani; +Ticker ticker; + + +volatile int timer_flag = 0; + +void timer_isr(); -int main() { - - int fps = 8; - +int main() +{ + + int fps = 2; + pad.init(); lcd.init(); - + lcd.setContrast(0.5); Move move; - + move = runner.init(move); - + + ticker.attach(&timer_isr,1.0f/fps); + + while(1) { lcd.clear(); - + float speed = runner.getSpeed(pad); - - //runner.runnerState(move, lcd, speed); + + move = runner.nextLevel(move); //must happen befofre 'fall' otherwise runner can fall out of screen - move = runner.nextLevel(move); //must happen befofre 'fall' otherwise runner can fall out of screen - runner.whatLevel(move, lcd); - + 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.wallJumpL(move, lcd, speed); + + move = runner.wallJumpR(move, lcd, speed); + move = runner.runLeft(move, lcd, speed); - + move = runner.runRight(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 + + + + char buffer[14]; + sprintf(buffer,"%i",move.cr); + lcd.printString(buffer,0,1); + + //sleep(); //sleep untill next refresh + + if (timer_flag == true) { + timer_flag = 0; // if it has, clear the flag + + lcd.refresh(); + + } - runner.runnerState(move, lcd, speed); //what state runner is in (must come after next level - - runner.whatLevel(move, lcd); // call level - - /**char buffer[14]; - sprintf(buffer,"%i",move.l); - lcd.printString(buffer,0,1); - */ - int test; - if (ani.pixelsLeft(move.x, move.y, lcd) == true) { - test = 1; - } else { - test = 0; - } - - char buffer1[14]; - sprintf(buffer1,"%i",test); - lcd.printString(buffer1,0,0); - - - lcd.refresh(); - - wait(1.0f/fps); - + sleep(); + } + +} + +void timer_isr() +{ + + timer_flag = 1; // set flag in ISR } +//rtos +