Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.
Dependencies: mbed
main.cpp@128:a3f581b8461c, 2019-05-06 (annotated)
- Committer:
- fy14lkaa
- Date:
- Mon May 06 00:11:06 2019 +0000
- Revision:
- 128:a3f581b8461c
- Parent:
- 127:8bd8cf136f19
- Child:
- 131:2084e4a8338f
include Bullet header file in Alien.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fy14lkaa | 3:985fab783b92 | 1 | ///////// pre-processor directives //////// |
fy14lkaa | 0:e2af4c8e462e | 2 | #include "mbed.h" |
fy14lkaa | 0:e2af4c8e462e | 3 | #include "Gamepad.h" |
fy14lkaa | 0:e2af4c8e462e | 4 | #include "N5110.h" |
fy14lkaa | 127:8bd8cf136f19 | 5 | #include "SpaceEngine.h" |
fy14lkaa | 8:eec0d7fc365f | 6 | |
fy14lkaa | 127:8bd8cf136f19 | 7 | /////////////// structs ///////////////// |
fy14lkaa | 0:e2af4c8e462e | 8 | struct UserInput { |
fy14lkaa | 0:e2af4c8e462e | 9 | Direction d; |
fy14lkaa | 0:e2af4c8e462e | 10 | float mag; |
fy14lkaa | 0:e2af4c8e462e | 11 | }; |
fy14lkaa | 127:8bd8cf136f19 | 12 | /////////////// objects /////////////// |
fy14lkaa | 50:f538885a788b | 13 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
fy14lkaa | 0:e2af4c8e462e | 14 | Gamepad pad; |
fy14lkaa | 127:8bd8cf136f19 | 15 | SpaceEngine space; |
fy14lkaa | 13:9d6ee753eca6 | 16 | |
fy14lkaa | 3:985fab783b92 | 17 | ///////////// prototypes /////////////// |
fy14lkaa | 0:e2af4c8e462e | 18 | void init(); |
fy14lkaa | 0:e2af4c8e462e | 19 | void update_game(UserInput input); |
fy14lkaa | 0:e2af4c8e462e | 20 | void render(); |
fy14lkaa | 0:e2af4c8e462e | 21 | void welcome(); |
fy14lkaa | 12:45b1249b3d9a | 22 | |
fy14lkaa | 13:9d6ee753eca6 | 23 | ///////////// functions //////////////// |
fy14lkaa | 54:095eae44895b | 24 | int main() |
fy14lkaa | 54:095eae44895b | 25 | { |
fy14lkaa | 12:45b1249b3d9a | 26 | |
fy14lkaa | 128:a3f581b8461c | 27 | int fps = 8; |
fy14lkaa | 54:095eae44895b | 28 | |
fy14lkaa | 128:a3f581b8461c | 29 | init(); |
fy14lkaa | 128:a3f581b8461c | 30 | welcome(); |
fy14lkaa | 127:8bd8cf136f19 | 31 | |
fy14lkaa | 128:a3f581b8461c | 32 | render(); |
fy14lkaa | 128:a3f581b8461c | 33 | wait(1.0f/fps); |
fy14lkaa | 54:095eae44895b | 34 | |
fy14lkaa | 54:095eae44895b | 35 | |
fy14lkaa | 128:a3f581b8461c | 36 | |
fy14lkaa | 0:e2af4c8e462e | 37 | while (1) { |
fy14lkaa | 54:095eae44895b | 38 | space.read_input(pad); |
fy14lkaa | 12:45b1249b3d9a | 39 | space.update(pad); |
fy14lkaa | 54:095eae44895b | 40 | render(); |
fy14lkaa | 127:8bd8cf136f19 | 41 | wait(1.0f/fps); |
fy14lkaa | 57:45c5de9cefdf | 42 | } |
fy14lkaa | 54:095eae44895b | 43 | } |
fy14lkaa | 54:095eae44895b | 44 | |
fy14lkaa | 54:095eae44895b | 45 | // initialies all classes and libraries |
fy14lkaa | 54:095eae44895b | 46 | void init() |
fy14lkaa | 54:095eae44895b | 47 | { |
fy14lkaa | 0:e2af4c8e462e | 48 | lcd.init(); |
fy14lkaa | 54:095eae44895b | 49 | pad.init(); |
fy14lkaa | 127:8bd8cf136f19 | 50 | |
fy14lkaa | 128:a3f581b8461c | 51 | |
fy14lkaa | 127:8bd8cf136f19 | 52 | space.init(0,10, 10, 10,0,70,10, 1, 1, 1); |
fy14lkaa | 54:095eae44895b | 53 | |
fy14lkaa | 3:985fab783b92 | 54 | } |
fy14lkaa | 54:095eae44895b | 55 | |
fy14lkaa | 54:095eae44895b | 56 | void render() |
fy14lkaa | 54:095eae44895b | 57 | { |
fy14lkaa | 128:a3f581b8461c | 58 | |
fy14lkaa | 127:8bd8cf136f19 | 59 | lcd.clear(); |
fy14lkaa | 12:45b1249b3d9a | 60 | space.draw(lcd); |
fy14lkaa | 0:e2af4c8e462e | 61 | lcd.refresh(); |
fy14lkaa | 0:e2af4c8e462e | 62 | } |
fy14lkaa | 3:985fab783b92 | 63 | |
fy14lkaa | 128:a3f581b8461c | 64 | |
fy14lkaa | 127:8bd8cf136f19 | 65 | void welcome() { |
fy14lkaa | 127:8bd8cf136f19 | 66 | |
fy14lkaa | 128:a3f581b8461c | 67 | lcd.printString(" Spaceship! ",0,1); |
fy14lkaa | 127:8bd8cf136f19 | 68 | lcd.printString(" Press Start ",0,4); |
fy14lkaa | 0:e2af4c8e462e | 69 | lcd.refresh(); |
fy14lkaa | 127:8bd8cf136f19 | 70 | |
fy14lkaa | 127:8bd8cf136f19 | 71 | // wait flashing LEDs until start button is pressed |
fy14lkaa | 0:e2af4c8e462e | 72 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
fy14lkaa | 0:e2af4c8e462e | 73 | pad.leds_on(); |
fy14lkaa | 127:8bd8cf136f19 | 74 | wait(0.1); |
fy14lkaa | 0:e2af4c8e462e | 75 | pad.leds_off(); |
fy14lkaa | 0:e2af4c8e462e | 76 | wait(0.1); |
fy14lkaa | 0:e2af4c8e462e | 77 | } |
fy14lkaa | 127:8bd8cf136f19 | 78 | |
fy14lkaa | 127:8bd8cf136f19 | 79 | } |
fy14lkaa | 54:095eae44895b | 80 | |
fy14lkaa | 54:095eae44895b | 81 | |
fy14lkaa | 54:095eae44895b | 82 |