Adam Baker 201166301
Dependencies: mbed Gamepad N5110
main.cpp@6:cef9c2853315, 2019-03-22 (annotated)
- Committer:
- adambakerwa
- Date:
- Fri Mar 22 18:07:39 2019 +0000
- Revision:
- 6:cef9c2853315
- Parent:
- 5:37b37f48e8bf
- Child:
- 7:66ea4d394fea
levels class created
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 | 6:cef9c2853315 | 6 | |
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 | 1:a3cce487dffe | 11 | |
adambakerwa | 6:cef9c2853315 | 12 | |
adambakerwa | 1:a3cce487dffe | 13 | int main() { |
adambakerwa | 1:a3cce487dffe | 14 | |
adambakerwa | 2:1ad390d81d81 | 15 | int fps = 12; |
adambakerwa | 1:a3cce487dffe | 16 | |
adambakerwa | 1:a3cce487dffe | 17 | pad.init(); |
adambakerwa | 1:a3cce487dffe | 18 | lcd.init(); |
adambakerwa | 1:a3cce487dffe | 19 | |
adambakerwa | 1:a3cce487dffe | 20 | Move move; |
adambakerwa | 1:a3cce487dffe | 21 | |
adambakerwa | 1:a3cce487dffe | 22 | move = runner.init(move); |
adambakerwa | 1:a3cce487dffe | 23 | |
adambakerwa | 1:a3cce487dffe | 24 | while(1) { |
adambakerwa | 1:a3cce487dffe | 25 | |
adambakerwa | 1:a3cce487dffe | 26 | lcd.clear(); |
adambakerwa | 2:1ad390d81d81 | 27 | |
adambakerwa | 1:a3cce487dffe | 28 | lcd.drawCircle(move.x,move.y,3,FILL_BLACK); |
adambakerwa | 6:cef9c2853315 | 29 | |
adambakerwa | 6:cef9c2853315 | 30 | move = runner.nextLevel(move, lcd); //must happen befofre 'fall' otherwise runner can fall out of screen |
adambakerwa | 6:cef9c2853315 | 31 | |
adambakerwa | 1:a3cce487dffe | 32 | |
adambakerwa | 4:cf765fff4e0e | 33 | float speed = runner.getSpeed(pad); |
adambakerwa | 1:a3cce487dffe | 34 | |
adambakerwa | 4:cf765fff4e0e | 35 | move = runner.buttonPress(move, lcd, pad); |
adambakerwa | 4:cf765fff4e0e | 36 | |
adambakerwa | 4:cf765fff4e0e | 37 | move = runner.jump(move, lcd); |
adambakerwa | 4:cf765fff4e0e | 38 | |
adambakerwa | 5:37b37f48e8bf | 39 | move = runner.wallJumpL(move, lcd, speed); |
adambakerwa | 5:37b37f48e8bf | 40 | |
adambakerwa | 5:37b37f48e8bf | 41 | move = runner.wallJumpR(move, lcd, speed); |
adambakerwa | 4:cf765fff4e0e | 42 | |
adambakerwa | 3:c1f4968111d7 | 43 | move = runner.runLeft(move, lcd, speed); |
adambakerwa | 3:c1f4968111d7 | 44 | |
adambakerwa | 3:c1f4968111d7 | 45 | move = runner.runRight(move, lcd, speed); |
adambakerwa | 6:cef9c2853315 | 46 | |
adambakerwa | 6:cef9c2853315 | 47 | |
adambakerwa | 2:1ad390d81d81 | 48 | |
adambakerwa | 4:cf765fff4e0e | 49 | move = runner.fall(move, lcd); |
adambakerwa | 2:1ad390d81d81 | 50 | |
adambakerwa | 6:cef9c2853315 | 51 | |
adambakerwa | 6:cef9c2853315 | 52 | |
adambakerwa | 6:cef9c2853315 | 53 | char buffer[14]; |
adambakerwa | 6:cef9c2853315 | 54 | sprintf(buffer,"%i",move.wjl); |
adambakerwa | 2:1ad390d81d81 | 55 | lcd.printString(buffer,0,1); |
adambakerwa | 6:cef9c2853315 | 56 | |
adambakerwa | 3:c1f4968111d7 | 57 | char buffer1[14]; |
adambakerwa | 6:cef9c2853315 | 58 | sprintf(buffer1,"%i",move.wjr); |
adambakerwa | 3:c1f4968111d7 | 59 | lcd.printString(buffer1,0,0); |
adambakerwa | 2:1ad390d81d81 | 60 | |
adambakerwa | 5:37b37f48e8bf | 61 | |
adambakerwa | 1:a3cce487dffe | 62 | lcd.refresh(); |
adambakerwa | 1:a3cce487dffe | 63 | |
adambakerwa | 1:a3cce487dffe | 64 | wait(1.0f/fps); |
adambakerwa | 1:a3cce487dffe | 65 | |
adambakerwa | 1:a3cce487dffe | 66 | } |
adambakerwa | 1:a3cce487dffe | 67 | } |
adambakerwa | 1:a3cce487dffe | 68 | |
adambakerwa | 1:a3cce487dffe | 69 | |
adambakerwa | 2:1ad390d81d81 | 70 |