Adam Baker 201166301

Dependencies:   mbed Gamepad N5110

Committer:
adambakerwa
Date:
Wed Apr 10 15:21:33 2019 +0000
Revision:
22:8218092c2e4b
Parent:
21:f82573f3e40e
Child:
23:4b1abf659467
worked on spikes

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 18:0a0976faedfb 24 int fps = 6; //6
adambakerwa 17:ecbafe932c19 25 int d = 0 ; // direction of moving plats
adambakerwa 21:f82573f3e40e 26 int l = 0; //length
adambakerwa 19:48d49a42037c 27 int r = 0;
adambakerwa 18:0a0976faedfb 28 int d2 = 0;
adambakerwa 19:48d49a42037c 29 int l2 = 0;
adambakerwa 19:48d49a42037c 30 int r2 = 0;
adambakerwa 21:f82573f3e40e 31 int d3 = 0;
adambakerwa 21:f82573f3e40e 32 int d4 = 0;
adambakerwa 22:8218092c2e4b 33 int g = 0;
adambakerwa 22:8218092c2e4b 34
adambakerwa 17:ecbafe932c19 35
adambakerwa 1:a3cce487dffe 36 pad.init();
adambakerwa 1:a3cce487dffe 37 lcd.init();
adambakerwa 17:ecbafe932c19 38 lcd.setContrast(0.55);
adambakerwa 1:a3cce487dffe 39 Move move;
adambakerwa 18:0a0976faedfb 40 Pos pos;
adambakerwa 15:c4de6874aa19 41
adambakerwa 1:a3cce487dffe 42 move = runner.init(move);
adambakerwa 18:0a0976faedfb 43 pos = lev.init(pos);
adambakerwa 15:c4de6874aa19 44
adambakerwa 13:35a459a33bbd 45 ticker.attach(&timer_isr,1.0f/fps);
adambakerwa 13:35a459a33bbd 46
adambakerwa 13:35a459a33bbd 47
adambakerwa 1:a3cce487dffe 48 while(1) {
adambakerwa 1:a3cce487dffe 49
adambakerwa 14:d8ced73dbb83 50 if (timer_flag == true) {
adambakerwa 13:35a459a33bbd 51
adambakerwa 14:d8ced73dbb83 52 timer_flag = 0; // if it has, clear the flag
adambakerwa 13:35a459a33bbd 53
adambakerwa 14:d8ced73dbb83 54 lcd.clear();
adambakerwa 11:dcb38924d96b 55
adambakerwa 14:d8ced73dbb83 56 float speed = runner.getSpeed(pad);
adambakerwa 14:d8ced73dbb83 57
adambakerwa 14:d8ced73dbb83 58 move = runner.nextLevel(move); //must happen befofre 'fall' otherwise runner can fall out of screen
adambakerwa 13:35a459a33bbd 59
adambakerwa 18:0a0976faedfb 60 pos = lev.whatLevel(lcd, move.l);
adambakerwa 13:35a459a33bbd 61
adambakerwa 21:f82573f3e40e 62 move = runner.buttonPress(move, lcd, pad, d3, d4);
adambakerwa 13:35a459a33bbd 63
adambakerwa 14:d8ced73dbb83 64 move = runner.jump(move, lcd);
adambakerwa 14:d8ced73dbb83 65
adambakerwa 14:d8ced73dbb83 66 move = runner.wallJumpL(move, lcd, speed);
adambakerwa 13:35a459a33bbd 67
adambakerwa 14:d8ced73dbb83 68 move = runner.wallJumpR(move, lcd, speed);
adambakerwa 13:35a459a33bbd 69
adambakerwa 14:d8ced73dbb83 70 move = runner.runLeft(move, lcd, speed);
adambakerwa 13:35a459a33bbd 71
adambakerwa 14:d8ced73dbb83 72 move = runner.runRight(move, lcd, speed);
adambakerwa 17:ecbafe932c19 73
adambakerwa 17:ecbafe932c19 74 move = runner.cancelSprint(move, lcd, speed);
adambakerwa 13:35a459a33bbd 75
adambakerwa 14:d8ced73dbb83 76 move = runner.fall(move, lcd);
adambakerwa 13:35a459a33bbd 77
adambakerwa 21:f82573f3e40e 78 move = runner.runnerState(move, lcd, speed, d3, d4); //what state runner is in (must come after next level
adambakerwa 13:35a459a33bbd 79
adambakerwa 18:0a0976faedfb 80 //runner.whatLevel(move, lcd); // call level(why again)??
adambakerwa 21:f82573f3e40e 81 d = runner.onHozCheck(move, pos);
adambakerwa 19:48d49a42037c 82
adambakerwa 21:f82573f3e40e 83 r = runner.byHozCheckRight(move, pos);
adambakerwa 19:48d49a42037c 84
adambakerwa 21:f82573f3e40e 85 l = runner.byHozCheckLeft(move, pos);
adambakerwa 19:48d49a42037c 86
adambakerwa 21:f82573f3e40e 87 d2 = runner.onHoz2Check(move, pos);
adambakerwa 19:48d49a42037c 88
adambakerwa 21:f82573f3e40e 89 r2 = runner.byHoz2CheckRight(move, pos);
adambakerwa 21:f82573f3e40e 90
adambakerwa 21:f82573f3e40e 91 l2 = runner.byHoz2CheckLeft(move, pos);
adambakerwa 19:48d49a42037c 92
adambakerwa 21:f82573f3e40e 93 d3 = runner.onVerCheck(move, pos);
adambakerwa 19:48d49a42037c 94
adambakerwa 21:f82573f3e40e 95 d4 = runner.onVer2Check(move, pos);
adambakerwa 21:f82573f3e40e 96
adambakerwa 22:8218092c2e4b 97 g = runner.spikeHit(lcd, pos);
adambakerwa 22:8218092c2e4b 98
adambakerwa 21:f82573f3e40e 99 move = runner.onPlatform(lcd, move, d, r, l, d2, r2, l2, d3, d4);
adambakerwa 13:35a459a33bbd 100
adambakerwa 13:35a459a33bbd 101
adambakerwa 17:ecbafe932c19 102 char buffer[14];
adambakerwa 22:8218092c2e4b 103 sprintf(buffer,"%i", g);
adambakerwa 18:0a0976faedfb 104 lcd.printString(buffer,0,0);
adambakerwa 22:8218092c2e4b 105 /** char buffer1[14];
adambakerwa 20:54724f686c14 106 sprintf(buffer1,"%i %i %i %i %i",pos.vx, pos. vy, pos.vd, pos.vc, pos.vl);
adambakerwa 18:0a0976faedfb 107 lcd.printString(buffer1,0,1);
adambakerwa 22:8218092c2e4b 108 */
adambakerwa 22:8218092c2e4b 109
adambakerwa 13:35a459a33bbd 110 lcd.refresh();
adambakerwa 13:35a459a33bbd 111
adambakerwa 14:d8ced73dbb83 112 } else {
adambakerwa 14:d8ced73dbb83 113
adambakerwa 14:d8ced73dbb83 114 sleep();
adambakerwa 14:d8ced73dbb83 115
adambakerwa 13:35a459a33bbd 116 }
adambakerwa 1:a3cce487dffe 117 }
adambakerwa 13:35a459a33bbd 118
adambakerwa 13:35a459a33bbd 119 }
adambakerwa 13:35a459a33bbd 120
adambakerwa 13:35a459a33bbd 121 void timer_isr()
adambakerwa 13:35a459a33bbd 122 {
adambakerwa 13:35a459a33bbd 123
adambakerwa 13:35a459a33bbd 124 timer_flag = 1; // set flag in ISR
adambakerwa 1:a3cce487dffe 125 }
adambakerwa 1:a3cce487dffe 126
adambakerwa 1:a3cce487dffe 127
adambakerwa 13:35a459a33bbd 128 //rtos
adambakerwa 2:1ad390d81d81 129
adambakerwa 13:35a459a33bbd 130