Adam Baker 201166301

Dependencies:   mbed Gamepad N5110

Committer:
adambakerwa
Date:
Mon Apr 01 12:00:48 2019 +0000
Revision:
15:c4de6874aa19
Parent:
14:d8ced73dbb83
Child:
16:b0c0b1fc65d6
One moving platform succsess

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adambakerwa 1:a3cce487dffe 1 #include "mbed.h"
adambakerwa 1:a3cce487dffe 2 #include "Gamepad.h"
adambakerwa 1:a3cce487dffe 3 #include "N5110.h"
adambakerwa 1:a3cce487dffe 4 #include "Runner.h"
adambakerwa 6:cef9c2853315 5 #include "Levels.h"
adambakerwa 9:ddeafaadf984 6 #include "Animation.h"
adambakerwa 1:a3cce487dffe 7
adambakerwa 1:a3cce487dffe 8 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
adambakerwa 1:a3cce487dffe 9 Gamepad pad;
adambakerwa 1:a3cce487dffe 10 Runner runner;
adambakerwa 9:ddeafaadf984 11 Animation ani;
adambakerwa 15:c4de6874aa19 12 Levels lev;
adambakerwa 13:35a459a33bbd 13 Ticker ticker;
adambakerwa 13:35a459a33bbd 14
adambakerwa 13:35a459a33bbd 15
adambakerwa 13:35a459a33bbd 16 volatile int timer_flag = 0;
adambakerwa 13:35a459a33bbd 17
adambakerwa 13:35a459a33bbd 18 void timer_isr();
adambakerwa 1:a3cce487dffe 19
adambakerwa 6:cef9c2853315 20
adambakerwa 13:35a459a33bbd 21 int main()
adambakerwa 13:35a459a33bbd 22 {
adambakerwa 13:35a459a33bbd 23
adambakerwa 14:d8ced73dbb83 24 int fps = 10;
adambakerwa 13:35a459a33bbd 25
adambakerwa 1:a3cce487dffe 26 pad.init();
adambakerwa 1:a3cce487dffe 27 lcd.init();
adambakerwa 13:35a459a33bbd 28 lcd.setContrast(0.5);
adambakerwa 1:a3cce487dffe 29 Move move;
adambakerwa 15:c4de6874aa19 30 Pos pos;
adambakerwa 15:c4de6874aa19 31
adambakerwa 1:a3cce487dffe 32 move = runner.init(move);
adambakerwa 15:c4de6874aa19 33 pos = lev.init(pos);
adambakerwa 15:c4de6874aa19 34
adambakerwa 13:35a459a33bbd 35 ticker.attach(&timer_isr,1.0f/fps);
adambakerwa 13:35a459a33bbd 36
adambakerwa 13:35a459a33bbd 37
adambakerwa 1:a3cce487dffe 38 while(1) {
adambakerwa 1:a3cce487dffe 39
adambakerwa 14:d8ced73dbb83 40 if (timer_flag == true) {
adambakerwa 13:35a459a33bbd 41
adambakerwa 14:d8ced73dbb83 42 timer_flag = 0; // if it has, clear the flag
adambakerwa 13:35a459a33bbd 43
adambakerwa 14:d8ced73dbb83 44 lcd.clear();
adambakerwa 11:dcb38924d96b 45
adambakerwa 14:d8ced73dbb83 46 float speed = runner.getSpeed(pad);
adambakerwa 14:d8ced73dbb83 47
adambakerwa 14:d8ced73dbb83 48 move = runner.nextLevel(move); //must happen befofre 'fall' otherwise runner can fall out of screen
adambakerwa 13:35a459a33bbd 49
adambakerwa 15:c4de6874aa19 50 pos = runner.whatLevel(move, lcd, pos);
adambakerwa 13:35a459a33bbd 51
adambakerwa 14:d8ced73dbb83 52 move = runner.buttonPress(move, lcd, pad);
adambakerwa 13:35a459a33bbd 53
adambakerwa 14:d8ced73dbb83 54 move = runner.jump(move, lcd);
adambakerwa 14:d8ced73dbb83 55
adambakerwa 14:d8ced73dbb83 56 move = runner.wallJumpL(move, lcd, speed);
adambakerwa 13:35a459a33bbd 57
adambakerwa 14:d8ced73dbb83 58 move = runner.wallJumpR(move, lcd, speed);
adambakerwa 13:35a459a33bbd 59
adambakerwa 14:d8ced73dbb83 60 move = runner.runLeft(move, lcd, speed);
adambakerwa 13:35a459a33bbd 61
adambakerwa 14:d8ced73dbb83 62 move = runner.runRight(move, lcd, speed);
adambakerwa 13:35a459a33bbd 63
adambakerwa 14:d8ced73dbb83 64 move = runner.fall(move, lcd);
adambakerwa 13:35a459a33bbd 65
adambakerwa 14:d8ced73dbb83 66 move = runner.runnerState(move, lcd, speed); //what state runner is in (must come after next level
adambakerwa 13:35a459a33bbd 67
adambakerwa 15:c4de6874aa19 68 pos = runner.whatLevel(move, lcd, pos); // call level(why again)??
adambakerwa 13:35a459a33bbd 69
adambakerwa 13:35a459a33bbd 70
adambakerwa 13:35a459a33bbd 71
adambakerwa 14:d8ced73dbb83 72 char buffer[14];
adambakerwa 15:c4de6874aa19 73 sprintf(buffer,"%i",pos.d);
adambakerwa 14:d8ced73dbb83 74 lcd.printString(buffer,0,1);
adambakerwa 13:35a459a33bbd 75
adambakerwa 14:d8ced73dbb83 76 //sleep(); //sleep untill next refresh
adambakerwa 13:35a459a33bbd 77
adambakerwa 13:35a459a33bbd 78 lcd.refresh();
adambakerwa 13:35a459a33bbd 79
adambakerwa 14:d8ced73dbb83 80 } else {
adambakerwa 14:d8ced73dbb83 81
adambakerwa 14:d8ced73dbb83 82 sleep();
adambakerwa 14:d8ced73dbb83 83
adambakerwa 13:35a459a33bbd 84 }
adambakerwa 1:a3cce487dffe 85 }
adambakerwa 13:35a459a33bbd 86
adambakerwa 13:35a459a33bbd 87 }
adambakerwa 13:35a459a33bbd 88
adambakerwa 13:35a459a33bbd 89 void timer_isr()
adambakerwa 13:35a459a33bbd 90 {
adambakerwa 13:35a459a33bbd 91
adambakerwa 13:35a459a33bbd 92 timer_flag = 1; // set flag in ISR
adambakerwa 1:a3cce487dffe 93 }
adambakerwa 1:a3cce487dffe 94
adambakerwa 1:a3cce487dffe 95
adambakerwa 13:35a459a33bbd 96 //rtos
adambakerwa 2:1ad390d81d81 97
adambakerwa 13:35a459a33bbd 98