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