Adam Baker 201166301

Dependencies:   mbed Gamepad N5110

Committer:
adambakerwa
Date:
Mon Apr 01 17:25:59 2019 +0000
Revision:
17:ecbafe932c19
Parent:
16:b0c0b1fc65d6
Child:
18:0a0976faedfb
Runner now moves on moving platform

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 17:ecbafe932c19 24 int fps = 6;
adambakerwa 17:ecbafe932c19 25 int d = 0 ; // direction of moving plats
adambakerwa 17:ecbafe932c19 26
adambakerwa 1:a3cce487dffe 27 pad.init();
adambakerwa 1:a3cce487dffe 28 lcd.init();
adambakerwa 17:ecbafe932c19 29 lcd.setContrast(0.55);
adambakerwa 1:a3cce487dffe 30 Move move;
adambakerwa 16:b0c0b1fc65d6 31 //Pos pos;
adambakerwa 15:c4de6874aa19 32
adambakerwa 1:a3cce487dffe 33 move = runner.init(move);
adambakerwa 16:b0c0b1fc65d6 34 //pos = lev.init(pos);
adambakerwa 15:c4de6874aa19 35
adambakerwa 13:35a459a33bbd 36 ticker.attach(&timer_isr,1.0f/fps);
adambakerwa 13:35a459a33bbd 37
adambakerwa 13:35a459a33bbd 38
adambakerwa 1:a3cce487dffe 39 while(1) {
adambakerwa 1:a3cce487dffe 40
adambakerwa 14:d8ced73dbb83 41 if (timer_flag == true) {
adambakerwa 13:35a459a33bbd 42
adambakerwa 14:d8ced73dbb83 43 timer_flag = 0; // if it has, clear the flag
adambakerwa 13:35a459a33bbd 44
adambakerwa 14:d8ced73dbb83 45 lcd.clear();
adambakerwa 11:dcb38924d96b 46
adambakerwa 14:d8ced73dbb83 47 float speed = runner.getSpeed(pad);
adambakerwa 14:d8ced73dbb83 48
adambakerwa 14:d8ced73dbb83 49 move = runner.nextLevel(move); //must happen befofre 'fall' otherwise runner can fall out of screen
adambakerwa 13:35a459a33bbd 50
adambakerwa 17:ecbafe932c19 51 d = runner.whatLevel(move, lcd);
adambakerwa 13:35a459a33bbd 52
adambakerwa 14:d8ced73dbb83 53 move = runner.buttonPress(move, lcd, pad);
adambakerwa 13:35a459a33bbd 54
adambakerwa 14:d8ced73dbb83 55 move = runner.jump(move, lcd);
adambakerwa 14:d8ced73dbb83 56
adambakerwa 14:d8ced73dbb83 57 move = runner.wallJumpL(move, lcd, speed);
adambakerwa 13:35a459a33bbd 58
adambakerwa 14:d8ced73dbb83 59 move = runner.wallJumpR(move, lcd, speed);
adambakerwa 13:35a459a33bbd 60
adambakerwa 14:d8ced73dbb83 61 move = runner.runLeft(move, lcd, speed);
adambakerwa 13:35a459a33bbd 62
adambakerwa 14:d8ced73dbb83 63 move = runner.runRight(move, lcd, speed);
adambakerwa 17:ecbafe932c19 64
adambakerwa 17:ecbafe932c19 65 move = runner.cancelSprint(move, lcd, speed);
adambakerwa 13:35a459a33bbd 66
adambakerwa 14:d8ced73dbb83 67 move = runner.fall(move, lcd);
adambakerwa 13:35a459a33bbd 68
adambakerwa 14:d8ced73dbb83 69 move = runner.runnerState(move, lcd, speed); //what state runner is in (must come after next level
adambakerwa 13:35a459a33bbd 70
adambakerwa 17:ecbafe932c19 71 d = runner.whatLevel(move, lcd); // call level(why again)??
adambakerwa 13:35a459a33bbd 72
adambakerwa 17:ecbafe932c19 73 move = runner.onPlatform(move, d);
adambakerwa 13:35a459a33bbd 74
adambakerwa 13:35a459a33bbd 75
adambakerwa 17:ecbafe932c19 76 char buffer[14];
adambakerwa 17:ecbafe932c19 77 sprintf(buffer,"%i",d);
adambakerwa 17:ecbafe932c19 78 lcd.printString(buffer,0,1);
adambakerwa 13:35a459a33bbd 79
adambakerwa 14:d8ced73dbb83 80 //sleep(); //sleep untill next refresh
adambakerwa 13:35a459a33bbd 81
adambakerwa 13:35a459a33bbd 82 lcd.refresh();
adambakerwa 13:35a459a33bbd 83
adambakerwa 14:d8ced73dbb83 84 } else {
adambakerwa 14:d8ced73dbb83 85
adambakerwa 14:d8ced73dbb83 86 sleep();
adambakerwa 14:d8ced73dbb83 87
adambakerwa 13:35a459a33bbd 88 }
adambakerwa 1:a3cce487dffe 89 }
adambakerwa 13:35a459a33bbd 90
adambakerwa 13:35a459a33bbd 91 }
adambakerwa 13:35a459a33bbd 92
adambakerwa 13:35a459a33bbd 93 void timer_isr()
adambakerwa 13:35a459a33bbd 94 {
adambakerwa 13:35a459a33bbd 95
adambakerwa 13:35a459a33bbd 96 timer_flag = 1; // set flag in ISR
adambakerwa 1:a3cce487dffe 97 }
adambakerwa 1:a3cce487dffe 98
adambakerwa 1:a3cce487dffe 99
adambakerwa 13:35a459a33bbd 100 //rtos
adambakerwa 2:1ad390d81d81 101
adambakerwa 13:35a459a33bbd 102