Helios Lyons 201239214
Dependencies: mbed
Brief
My aim for this project was to create a FRDM K64F adapted version of the classic Space Invaders by Tomohiro Nishikado. The game itself has a number of clear features to implement;
- Left to right movement for the player 'canon'
- A fixed amount of player lives
- Firing mechanics for both canon and invaders (hence collision systems)
- Random firing from remaining invaders
- Wave based combat
My own addition to these established ideas was Boss waves, featuring a single, larger sprite which fires at a faster interval than previous waves. The addition of a movement system using a basic for loop, as opposed to a velocity based system, will enhance the nostalgic feel of the game.
Gameplay
Movement is controlled with the joystick, moving the canon left or right. Fire by pressing A. Invaders spawn at set positions, but randomly fire at a set interval, which is higher for boss waves. Time is taken during each wave, and displayed at wave intervals, and if the play wins.
Controls are shown on the Gamepad below: (attribution: Craig A. Evans, ELEC2645 University of Leeds)
Invaders/Invader.cpp@6:e3a1bfbb1627, 2020-04-14 (annotated)
- Committer:
- helioslyons
- Date:
- Tue Apr 14 14:09:33 2020 +0000
- Revision:
- 6:e3a1bfbb1627
- Parent:
- 4:c644522ff9d9
- Child:
- 7:5fe9ac6522c5
Set army starting positions and simplified attributes. Use FSM for invader movement.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
helioslyons | 4:c644522ff9d9 | 1 | #include "Invader.h" |
helioslyons | 4:c644522ff9d9 | 2 | #include "Bitmap.h" |
helioslyons | 4:c644522ff9d9 | 3 | #include <vector> |
helioslyons | 4:c644522ff9d9 | 4 | |
helioslyons | 4:c644522ff9d9 | 5 | Invader::Invader() |
helioslyons | 4:c644522ff9d9 | 6 | { |
helioslyons | 4:c644522ff9d9 | 7 | |
helioslyons | 4:c644522ff9d9 | 8 | } |
helioslyons | 4:c644522ff9d9 | 9 | |
helioslyons | 4:c644522ff9d9 | 10 | Invader::~Invader() |
helioslyons | 4:c644522ff9d9 | 11 | { |
helioslyons | 4:c644522ff9d9 | 12 | |
helioslyons | 4:c644522ff9d9 | 13 | } |
helioslyons | 4:c644522ff9d9 | 14 | |
helioslyons | 4:c644522ff9d9 | 15 | void Invader::init(int sprite, int hitpoints) |
helioslyons | 4:c644522ff9d9 | 16 | { |
helioslyons | 4:c644522ff9d9 | 17 | //_y = y; |
helioslyons | 4:c644522ff9d9 | 18 | // _x = x; |
helioslyons | 4:c644522ff9d9 | 19 | _height = 8; |
helioslyons | 4:c644522ff9d9 | 20 | _width = 11; |
helioslyons | 4:c644522ff9d9 | 21 | _death = false; |
helioslyons | 4:c644522ff9d9 | 22 | _sprite = sprite; |
helioslyons | 4:c644522ff9d9 | 23 | _hitpoints = hitpoints; |
helioslyons | 4:c644522ff9d9 | 24 | } |
helioslyons | 4:c644522ff9d9 | 25 | |
helioslyons | 4:c644522ff9d9 | 26 | void Invader::draw(N5110 &lcd) |
helioslyons | 4:c644522ff9d9 | 27 | { |
helioslyons | 4:c644522ff9d9 | 28 | //lcd.drawRect(_x,_y,_width,_height,FILL_BLACK); |
helioslyons | 4:c644522ff9d9 | 29 | static int invader1_data[] = { |
helioslyons | 4:c644522ff9d9 | 30 | 0,0,1,0,0,0,0,0,1,0,0, // ..#.....#.. |
helioslyons | 4:c644522ff9d9 | 31 | 0,0,0,1,0,0,0,1,0,0,0, // ...#...#... |
helioslyons | 4:c644522ff9d9 | 32 | 0,0,1,1,1,1,1,1,1,0,0, // ..#######.. |
helioslyons | 4:c644522ff9d9 | 33 | 0,1,1,0,1,1,1,0,1,1,0, // .##.###.##. |
helioslyons | 4:c644522ff9d9 | 34 | 1,1,1,1,1,1,1,1,1,1,1, // ########### |
helioslyons | 4:c644522ff9d9 | 35 | 1,0,1,1,1,1,1,1,1,0,1, // #.#######.# |
helioslyons | 4:c644522ff9d9 | 36 | 1,0,1,0,0,0,0,0,1,0,1, // #.#.....#.# |
helioslyons | 4:c644522ff9d9 | 37 | 0,0,0,1,1,0,1,1,0,0,0 // ...##.##... |
helioslyons | 4:c644522ff9d9 | 38 | }; |
helioslyons | 4:c644522ff9d9 | 39 | |
helioslyons | 4:c644522ff9d9 | 40 | static int invader2_data[] = { |
helioslyons | 4:c644522ff9d9 | 41 | 0,0,1,0,0,0,0,0,1,0,0, // ..#.....#.. |
helioslyons | 4:c644522ff9d9 | 42 | 1,0,0,1,0,0,0,1,0,0,1, // #..#...#..# |
helioslyons | 4:c644522ff9d9 | 43 | 1,0,1,1,1,1,1,1,1,0,1, // #.#######.# |
helioslyons | 4:c644522ff9d9 | 44 | 1,1,1,0,1,1,1,0,1,1,1, // ###.###.### |
helioslyons | 4:c644522ff9d9 | 45 | 1,1,1,1,1,1,1,1,1,1,1, // ########### |
helioslyons | 4:c644522ff9d9 | 46 | 0,1,1,1,1,1,1,1,1,1,0, // .#########. |
helioslyons | 4:c644522ff9d9 | 47 | 0,0,1,0,0,0,0,0,1,0,0, // ..#.....#.. |
helioslyons | 4:c644522ff9d9 | 48 | 0,1,0,0,0,0,0,0,0,1,0 // .#.......#. |
helioslyons | 4:c644522ff9d9 | 49 | }; |
helioslyons | 4:c644522ff9d9 | 50 | |
helioslyons | 4:c644522ff9d9 | 51 | static int invader3_data[] = { |
helioslyons | 4:c644522ff9d9 | 52 | 0,0,0,0,1,1,1,0,0,0,0, // ....###.... |
helioslyons | 4:c644522ff9d9 | 53 | 0,0,0,1,1,1,1,1,0,0,0, // ...#####... |
helioslyons | 4:c644522ff9d9 | 54 | 0,0,1,1,1,1,1,1,1,0,0, // ..#######.. |
helioslyons | 4:c644522ff9d9 | 55 | 1,1,0,0,1,1,1,0,0,1,1, // ##..###..## |
helioslyons | 4:c644522ff9d9 | 56 | 1,1,1,1,1,1,1,1,1,1,1, // ########### |
helioslyons | 4:c644522ff9d9 | 57 | 0,0,1,1,0,0,0,1,1,0,0, // ..##...##.. |
helioslyons | 4:c644522ff9d9 | 58 | 0,1,0,0,1,1,1,0,0,1,0, // .#..###..#. |
helioslyons | 4:c644522ff9d9 | 59 | 1,0,1,1,0,0,0,1,1,0,1 // #.##...##.# |
helioslyons | 4:c644522ff9d9 | 60 | }; |
helioslyons | 4:c644522ff9d9 | 61 | |
helioslyons | 4:c644522ff9d9 | 62 | if (_sprite == 1 && _death == false) { |
helioslyons | 4:c644522ff9d9 | 63 | Bitmap invader1(invader1_data,11,8); |
helioslyons | 4:c644522ff9d9 | 64 | invader1.render(lcd,_x,_y); |
helioslyons | 4:c644522ff9d9 | 65 | } |
helioslyons | 4:c644522ff9d9 | 66 | else if (_sprite == 2 && _death == false) { |
helioslyons | 4:c644522ff9d9 | 67 | Bitmap invader2(invader2_data,11,8); |
helioslyons | 4:c644522ff9d9 | 68 | invader2.render(lcd,_x,_y); |
helioslyons | 4:c644522ff9d9 | 69 | } |
helioslyons | 4:c644522ff9d9 | 70 | else if (_sprite == 3 && _death == false) { |
helioslyons | 4:c644522ff9d9 | 71 | Bitmap invader3(invader3_data,11,8); |
helioslyons | 4:c644522ff9d9 | 72 | invader3.render(lcd,_x,_y); |
helioslyons | 4:c644522ff9d9 | 73 | } |
helioslyons | 4:c644522ff9d9 | 74 | else if (_death == true) {printf("Alien is dead");} |
helioslyons | 4:c644522ff9d9 | 75 | else {printf("Incorrect Sprite Value");} |
helioslyons | 4:c644522ff9d9 | 76 | } |
helioslyons | 4:c644522ff9d9 | 77 | |
helioslyons | 6:e3a1bfbb1627 | 78 | int Invader::hit() |
helioslyons | 6:e3a1bfbb1627 | 79 | { |
helioslyons | 4:c644522ff9d9 | 80 | _hitpoints--; |
helioslyons | 4:c644522ff9d9 | 81 | return _hitpoints; |
helioslyons | 6:e3a1bfbb1627 | 82 | } |
helioslyons | 4:c644522ff9d9 | 83 | |
helioslyons | 6:e3a1bfbb1627 | 84 | bool Invader::get_death() |
helioslyons | 6:e3a1bfbb1627 | 85 | { |
helioslyons | 4:c644522ff9d9 | 86 | if (_hitpoints == 0) { |
helioslyons | 4:c644522ff9d9 | 87 | _death = true; |
helioslyons | 4:c644522ff9d9 | 88 | } |
helioslyons | 4:c644522ff9d9 | 89 | return _death; |
helioslyons | 6:e3a1bfbb1627 | 90 | } |
helioslyons | 4:c644522ff9d9 | 91 | |
helioslyons | 6:e3a1bfbb1627 | 92 | Vector2D Invader::get_pos() |
helioslyons | 6:e3a1bfbb1627 | 93 | { |
helioslyons | 4:c644522ff9d9 | 94 | Vector2D p = {_x,_y}; |
helioslyons | 4:c644522ff9d9 | 95 | return p; |
helioslyons | 6:e3a1bfbb1627 | 96 | } |
helioslyons | 6:e3a1bfbb1627 | 97 | |
helioslyons | 6:e3a1bfbb1627 | 98 | void Invader::set_pos(int x, int y) |
helioslyons | 6:e3a1bfbb1627 | 99 | { |
helioslyons | 6:e3a1bfbb1627 | 100 | _x = x; |
helioslyons | 6:e3a1bfbb1627 | 101 | _y = y; |
helioslyons | 4:c644522ff9d9 | 102 | } |