A simplified version of Galaga that can be run on an mbed
Dependencies: 4DGL-uLCD-SE DebounceIn mbed
Fork of AsteroidDefender by
game.h@2:13ba45ceb03f, 2015-10-21 (annotated)
- Committer:
- ndaniel7
- Date:
- Wed Oct 21 14:30:05 2015 +0000
- Revision:
- 2:13ba45ceb03f
- Parent:
- 1:34bb7c386b9f
- Child:
- 4:6fc77e25bbcf
Initial release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rquinn7 | 0:bbc2ad180020 | 1 | #include <vector> |
rquinn7 | 0:bbc2ad180020 | 2 | #include "mbed.h" |
rquinn7 | 0:bbc2ad180020 | 3 | |
ndaniel7 | 2:13ba45ceb03f | 4 | struct Pair { |
rquinn7 | 0:bbc2ad180020 | 5 | double x; |
rquinn7 | 0:bbc2ad180020 | 6 | double y; |
rquinn7 | 0:bbc2ad180020 | 7 | }; |
rquinn7 | 0:bbc2ad180020 | 8 | |
ndaniel7 | 2:13ba45ceb03f | 9 | class Enemy{ |
rquinn7 | 0:bbc2ad180020 | 10 | private: |
rquinn7 | 0:bbc2ad180020 | 11 | |
rquinn7 | 0:bbc2ad180020 | 12 | public: |
rquinn7 | 0:bbc2ad180020 | 13 | bool moved; |
ndaniel7 | 2:13ba45ceb03f | 14 | Pair spawn; |
ndaniel7 | 2:13ba45ceb03f | 15 | Pair speed; |
ndaniel7 | 2:13ba45ceb03f | 16 | Pair coord; |
ndaniel7 | 2:13ba45ceb03f | 17 | Pair old_coord; |
ndaniel7 | 2:13ba45ceb03f | 18 | Pair size; |
rquinn7 | 0:bbc2ad180020 | 19 | |
ndaniel7 | 2:13ba45ceb03f | 20 | Enemy(Pair tSpawn, Pair tSpeed) : moved(false) |
rquinn7 | 0:bbc2ad180020 | 21 | { |
rquinn7 | 0:bbc2ad180020 | 22 | |
ndaniel7 | 2:13ba45ceb03f | 23 | spawn = tSpawn; |
ndaniel7 | 2:13ba45ceb03f | 24 | speed = tSpeed; |
ndaniel7 | 2:13ba45ceb03f | 25 | coord = tSpawn; |
rquinn7 | 0:bbc2ad180020 | 26 | old_coord = coord; |
ndaniel7 | 2:13ba45ceb03f | 27 | size.x = 5; |
ndaniel7 | 2:13ba45ceb03f | 28 | size.y = 7; |
rquinn7 | 0:bbc2ad180020 | 29 | } |
rquinn7 | 0:bbc2ad180020 | 30 | |
rquinn7 | 0:bbc2ad180020 | 31 | void move(){ |
rquinn7 | 0:bbc2ad180020 | 32 | old_coord = coord; |
rquinn7 | 0:bbc2ad180020 | 33 | moved = true; |
ndaniel7 | 2:13ba45ceb03f | 34 | coord.x = coord.x + speed.x; |
ndaniel7 | 2:13ba45ceb03f | 35 | coord.y = coord.y + speed.y; |
ndaniel7 | 2:13ba45ceb03f | 36 | if (coord.x <= 0) { |
ndaniel7 | 2:13ba45ceb03f | 37 | coord.x = 0; |
ndaniel7 | 2:13ba45ceb03f | 38 | speed.x = -speed.x; |
ndaniel7 | 2:13ba45ceb03f | 39 | } |
ndaniel7 | 2:13ba45ceb03f | 40 | else if (coord.x >= 128-size.x) { |
ndaniel7 | 2:13ba45ceb03f | 41 | coord.x = 128-size.x; |
ndaniel7 | 2:13ba45ceb03f | 42 | speed.x = -speed.x; |
ndaniel7 | 2:13ba45ceb03f | 43 | } |
rquinn7 | 0:bbc2ad180020 | 44 | } |
rquinn7 | 0:bbc2ad180020 | 45 | }; |
rquinn7 | 0:bbc2ad180020 | 46 | |
ndaniel7 | 2:13ba45ceb03f | 47 | |
ndaniel7 | 2:13ba45ceb03f | 48 | class Bullet{ |
rquinn7 | 0:bbc2ad180020 | 49 | private: |
rquinn7 | 0:bbc2ad180020 | 50 | |
rquinn7 | 0:bbc2ad180020 | 51 | public: |
rquinn7 | 0:bbc2ad180020 | 52 | bool moved; |
ndaniel7 | 2:13ba45ceb03f | 53 | Pair old_coord; |
ndaniel7 | 2:13ba45ceb03f | 54 | Pair coord; |
ndaniel7 | 2:13ba45ceb03f | 55 | Pair size; |
rquinn7 | 0:bbc2ad180020 | 56 | |
ndaniel7 | 2:13ba45ceb03f | 57 | Bullet(Pair tCoord) : moved(false) |
rquinn7 | 0:bbc2ad180020 | 58 | { |
ndaniel7 | 2:13ba45ceb03f | 59 | coord = tCoord; |
ndaniel7 | 2:13ba45ceb03f | 60 | //old_coord = coord; |
rquinn7 | 0:bbc2ad180020 | 61 | size.x = 3; |
rquinn7 | 0:bbc2ad180020 | 62 | size.y = 3; |
rquinn7 | 0:bbc2ad180020 | 63 | } |
rquinn7 | 0:bbc2ad180020 | 64 | |
rquinn7 | 0:bbc2ad180020 | 65 | void move(){ |
rquinn7 | 0:bbc2ad180020 | 66 | old_coord = coord; |
rquinn7 | 0:bbc2ad180020 | 67 | moved = true; |
ndaniel7 | 2:13ba45ceb03f | 68 | coord.y = coord.y - 5; |
rquinn7 | 0:bbc2ad180020 | 69 | } |
rquinn7 | 0:bbc2ad180020 | 70 | }; |
rquinn7 | 0:bbc2ad180020 | 71 | |
ndaniel7 | 2:13ba45ceb03f | 72 | |
ndaniel7 | 2:13ba45ceb03f | 73 | class Ship{ |
rquinn7 | 0:bbc2ad180020 | 74 | private: |
rquinn7 | 0:bbc2ad180020 | 75 | public: |
rquinn7 | 0:bbc2ad180020 | 76 | bool moved; |
ndaniel7 | 2:13ba45ceb03f | 77 | Pair coord; |
ndaniel7 | 2:13ba45ceb03f | 78 | Pair old_coord; |
ndaniel7 | 2:13ba45ceb03f | 79 | Pair size; |
rquinn7 | 0:bbc2ad180020 | 80 | |
ndaniel7 | 2:13ba45ceb03f | 81 | Ship() : moved(false) |
rquinn7 | 0:bbc2ad180020 | 82 | { |
ndaniel7 | 2:13ba45ceb03f | 83 | size.x = 10; |
ndaniel7 | 2:13ba45ceb03f | 84 | size.y = 5; |
ndaniel7 | 2:13ba45ceb03f | 85 | coord.x = (128/2)-size.x; |
ndaniel7 | 2:13ba45ceb03f | 86 | coord.y = 128-size.y; |
rquinn7 | 0:bbc2ad180020 | 87 | old_coord = coord; |
rquinn7 | 0:bbc2ad180020 | 88 | } |
rquinn7 | 0:bbc2ad180020 | 89 | }; |