![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Adam Baker 201166301
Dependencies: mbed Gamepad N5110
main.cpp@14:d8ced73dbb83, 2019-03-31 (annotated)
- Committer:
- adambakerwa
- Date:
- Sun Mar 31 19:07:25 2019 +0000
- Revision:
- 14:d8ced73dbb83
- Parent:
- 13:35a459a33bbd
- Child:
- 15:c4de6874aa19
Moving platform implemented
Who changed what in which revision?
User | Revision | Line number | New 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 | 13:35a459a33bbd | 12 | Ticker ticker; |
adambakerwa | 13:35a459a33bbd | 13 | |
adambakerwa | 13:35a459a33bbd | 14 | |
adambakerwa | 13:35a459a33bbd | 15 | volatile int timer_flag = 0; |
adambakerwa | 13:35a459a33bbd | 16 | |
adambakerwa | 13:35a459a33bbd | 17 | void timer_isr(); |
adambakerwa | 1:a3cce487dffe | 18 | |
adambakerwa | 6:cef9c2853315 | 19 | |
adambakerwa | 13:35a459a33bbd | 20 | int main() |
adambakerwa | 13:35a459a33bbd | 21 | { |
adambakerwa | 13:35a459a33bbd | 22 | |
adambakerwa | 14:d8ced73dbb83 | 23 | int fps = 10; |
adambakerwa | 13:35a459a33bbd | 24 | |
adambakerwa | 1:a3cce487dffe | 25 | pad.init(); |
adambakerwa | 1:a3cce487dffe | 26 | lcd.init(); |
adambakerwa | 13:35a459a33bbd | 27 | lcd.setContrast(0.5); |
adambakerwa | 1:a3cce487dffe | 28 | Move move; |
adambakerwa | 13:35a459a33bbd | 29 | |
adambakerwa | 1:a3cce487dffe | 30 | move = runner.init(move); |
adambakerwa | 13:35a459a33bbd | 31 | |
adambakerwa | 13:35a459a33bbd | 32 | ticker.attach(&timer_isr,1.0f/fps); |
adambakerwa | 13:35a459a33bbd | 33 | |
adambakerwa | 13:35a459a33bbd | 34 | |
adambakerwa | 1:a3cce487dffe | 35 | while(1) { |
adambakerwa | 1:a3cce487dffe | 36 | |
adambakerwa | 14:d8ced73dbb83 | 37 | if (timer_flag == true) { |
adambakerwa | 13:35a459a33bbd | 38 | |
adambakerwa | 14:d8ced73dbb83 | 39 | timer_flag = 0; // if it has, clear the flag |
adambakerwa | 13:35a459a33bbd | 40 | |
adambakerwa | 14:d8ced73dbb83 | 41 | lcd.clear(); |
adambakerwa | 11:dcb38924d96b | 42 | |
adambakerwa | 14:d8ced73dbb83 | 43 | float speed = runner.getSpeed(pad); |
adambakerwa | 14:d8ced73dbb83 | 44 | |
adambakerwa | 14:d8ced73dbb83 | 45 | move = runner.nextLevel(move); //must happen befofre 'fall' otherwise runner can fall out of screen |
adambakerwa | 13:35a459a33bbd | 46 | |
adambakerwa | 14:d8ced73dbb83 | 47 | runner.whatLevel(move, lcd); |
adambakerwa | 13:35a459a33bbd | 48 | |
adambakerwa | 14:d8ced73dbb83 | 49 | move = runner.buttonPress(move, lcd, pad); |
adambakerwa | 13:35a459a33bbd | 50 | |
adambakerwa | 14:d8ced73dbb83 | 51 | move = runner.jump(move, lcd); |
adambakerwa | 14:d8ced73dbb83 | 52 | |
adambakerwa | 14:d8ced73dbb83 | 53 | move = runner.wallJumpL(move, lcd, speed); |
adambakerwa | 13:35a459a33bbd | 54 | |
adambakerwa | 14:d8ced73dbb83 | 55 | move = runner.wallJumpR(move, lcd, speed); |
adambakerwa | 13:35a459a33bbd | 56 | |
adambakerwa | 14:d8ced73dbb83 | 57 | move = runner.runLeft(move, lcd, speed); |
adambakerwa | 13:35a459a33bbd | 58 | |
adambakerwa | 14:d8ced73dbb83 | 59 | move = runner.runRight(move, lcd, speed); |
adambakerwa | 13:35a459a33bbd | 60 | |
adambakerwa | 14:d8ced73dbb83 | 61 | move = runner.fall(move, lcd); |
adambakerwa | 13:35a459a33bbd | 62 | |
adambakerwa | 14:d8ced73dbb83 | 63 | move = runner.runnerState(move, lcd, speed); //what state runner is in (must come after next level |
adambakerwa | 13:35a459a33bbd | 64 | |
adambakerwa | 14:d8ced73dbb83 | 65 | runner.whatLevel(move, lcd); // call level |
adambakerwa | 13:35a459a33bbd | 66 | |
adambakerwa | 13:35a459a33bbd | 67 | |
adambakerwa | 13:35a459a33bbd | 68 | |
adambakerwa | 14:d8ced73dbb83 | 69 | char buffer[14]; |
adambakerwa | 14:d8ced73dbb83 | 70 | sprintf(buffer,"%i",move.cr); |
adambakerwa | 14:d8ced73dbb83 | 71 | lcd.printString(buffer,0,1); |
adambakerwa | 13:35a459a33bbd | 72 | |
adambakerwa | 14:d8ced73dbb83 | 73 | //sleep(); //sleep untill next refresh |
adambakerwa | 13:35a459a33bbd | 74 | |
adambakerwa | 13:35a459a33bbd | 75 | lcd.refresh(); |
adambakerwa | 13:35a459a33bbd | 76 | |
adambakerwa | 14:d8ced73dbb83 | 77 | } else { |
adambakerwa | 14:d8ced73dbb83 | 78 | |
adambakerwa | 14:d8ced73dbb83 | 79 | sleep(); |
adambakerwa | 14:d8ced73dbb83 | 80 | |
adambakerwa | 13:35a459a33bbd | 81 | } |
adambakerwa | 1:a3cce487dffe | 82 | } |
adambakerwa | 13:35a459a33bbd | 83 | |
adambakerwa | 13:35a459a33bbd | 84 | } |
adambakerwa | 13:35a459a33bbd | 85 | |
adambakerwa | 13:35a459a33bbd | 86 | void timer_isr() |
adambakerwa | 13:35a459a33bbd | 87 | { |
adambakerwa | 13:35a459a33bbd | 88 | |
adambakerwa | 13:35a459a33bbd | 89 | timer_flag = 1; // set flag in ISR |
adambakerwa | 1:a3cce487dffe | 90 | } |
adambakerwa | 1:a3cce487dffe | 91 | |
adambakerwa | 1:a3cce487dffe | 92 | |
adambakerwa | 13:35a459a33bbd | 93 | //rtos |
adambakerwa | 2:1ad390d81d81 | 94 | |
adambakerwa | 13:35a459a33bbd | 95 |