JianWei Lee
/
project_game
Meteor defense project
main.cpp@4:4145abd09075, 2017-03-22 (annotated)
- Committer:
- jasper0712
- Date:
- Wed Mar 22 15:19:20 2017 +0000
- Revision:
- 4:4145abd09075
- Parent:
- 3:6b50fe9d3848
- Child:
- 5:c74bbdda06f4
GameEngine worked. but weapon.h is not included yet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jasper0712 | 0:5fbc0fbc9d30 | 1 | #include "mbed.h" |
jasper0712 | 0:5fbc0fbc9d30 | 2 | #include "N5110.h" |
jasper0712 | 0:5fbc0fbc9d30 | 3 | #include "Gamepad.h" |
jasper0712 | 0:5fbc0fbc9d30 | 4 | #include "Weapon.h" |
jasper0712 | 0:5fbc0fbc9d30 | 5 | #include "Spawn.h" |
jasper0712 | 4:4145abd09075 | 6 | #include "GameEngine.h" |
jasper0712 | 0:5fbc0fbc9d30 | 7 | |
jasper0712 | 0:5fbc0fbc9d30 | 8 | #define PI 3.14159265 |
jasper0712 | 0:5fbc0fbc9d30 | 9 | //Y rows and X columns |
jasper0712 | 1:f5cda0674f24 | 10 | #define Rows 48 |
jasper0712 | 1:f5cda0674f24 | 11 | #define Cols 84 |
jasper0712 | 0:5fbc0fbc9d30 | 12 | |
jasper0712 | 0:5fbc0fbc9d30 | 13 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
jasper0712 | 0:5fbc0fbc9d30 | 14 | Gamepad pad; |
jasper0712 | 4:4145abd09075 | 15 | GameEngine game; |
jasper0712 | 0:5fbc0fbc9d30 | 16 | Weapon weap; |
jasper0712 | 4:4145abd09075 | 17 | |
jasper0712 | 0:5fbc0fbc9d30 | 18 | |
jasper0712 | 4:4145abd09075 | 19 | int gamefps = 15; |
jasper0712 | 0:5fbc0fbc9d30 | 20 | void init(); |
jasper0712 | 0:5fbc0fbc9d30 | 21 | void render(); |
jasper0712 | 0:5fbc0fbc9d30 | 22 | |
jasper0712 | 0:5fbc0fbc9d30 | 23 | int main() |
jasper0712 | 0:5fbc0fbc9d30 | 24 | { |
jasper0712 | 0:5fbc0fbc9d30 | 25 | |
jasper0712 | 0:5fbc0fbc9d30 | 26 | init(); |
jasper0712 | 0:5fbc0fbc9d30 | 27 | while (true) { |
jasper0712 | 4:4145abd09075 | 28 | game.drawSpawn(lcd); |
jasper0712 | 0:5fbc0fbc9d30 | 29 | |
jasper0712 | 0:5fbc0fbc9d30 | 30 | weap.drawWeapon(pad, lcd); |
jasper0712 | 0:5fbc0fbc9d30 | 31 | |
jasper0712 | 0:5fbc0fbc9d30 | 32 | if (pad.buttonhold == 1) { |
jasper0712 | 0:5fbc0fbc9d30 | 33 | printf("hi im working \n"); |
jasper0712 | 0:5fbc0fbc9d30 | 34 | weap.fireWeapon(pad, lcd); |
jasper0712 | 0:5fbc0fbc9d30 | 35 | } |
jasper0712 | 0:5fbc0fbc9d30 | 36 | |
jasper0712 | 0:5fbc0fbc9d30 | 37 | render(); |
jasper0712 | 0:5fbc0fbc9d30 | 38 | } |
jasper0712 | 0:5fbc0fbc9d30 | 39 | } |
jasper0712 | 0:5fbc0fbc9d30 | 40 | |
jasper0712 | 0:5fbc0fbc9d30 | 41 | void init() |
jasper0712 | 0:5fbc0fbc9d30 | 42 | { |
jasper0712 | 0:5fbc0fbc9d30 | 43 | // need to initialise LCD and Gamepad |
jasper0712 | 0:5fbc0fbc9d30 | 44 | lcd.init(); |
jasper0712 | 0:5fbc0fbc9d30 | 45 | pad.init(); |
jasper0712 | 0:5fbc0fbc9d30 | 46 | |
jasper0712 | 0:5fbc0fbc9d30 | 47 | // initialise the game |
jasper0712 | 0:5fbc0fbc9d30 | 48 | } |
jasper0712 | 0:5fbc0fbc9d30 | 49 | |
jasper0712 | 0:5fbc0fbc9d30 | 50 | void render() |
jasper0712 | 0:5fbc0fbc9d30 | 51 | { |
jasper0712 | 0:5fbc0fbc9d30 | 52 | // clear screen, re-draw and refresh |
jasper0712 | 0:5fbc0fbc9d30 | 53 | lcd.refresh(); |
jasper0712 | 0:5fbc0fbc9d30 | 54 | wait(1.0/gamefps); |
jasper0712 | 0:5fbc0fbc9d30 | 55 | lcd.clear(); |
jasper0712 | 0:5fbc0fbc9d30 | 56 | } |