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.

https://os.mbed.com/media/uploads/helioslyons/screenshot_2020-05-27_at_06.12.00.png

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)

https://os.mbed.com/media/uploads/helioslyons/screenshot_2020-05-27_at_06.20.18.png

Committer:
helioslyons
Date:
Fri Apr 10 14:28:25 2020 +0000
Revision:
4:c644522ff9d9
Child:
6:e3a1bfbb1627
Started implementing Army class and grouped movement

Who changed what in which revision?

UserRevisionLine numberNew 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 4:c644522ff9d9 78 /*void Invader::set_hitpoints(int hitpoints){
helioslyons 4:c644522ff9d9 79 _hitpoints = hitpoints;
helioslyons 4:c644522ff9d9 80 }
helioslyons 4:c644522ff9d9 81 */
helioslyons 4:c644522ff9d9 82 /* int Invader::get_hitpoints(){ // Shouldn't be necessary - use get_death method
helioslyons 4:c644522ff9d9 83
helioslyons 4:c644522ff9d9 84 return _hitpoints;
helioslyons 4:c644522ff9d9 85 }
helioslyons 4:c644522ff9d9 86 */
helioslyons 4:c644522ff9d9 87
helioslyons 4:c644522ff9d9 88 int Invader::hit(){
helioslyons 4:c644522ff9d9 89 _hitpoints--;
helioslyons 4:c644522ff9d9 90 return _hitpoints;
helioslyons 4:c644522ff9d9 91 }
helioslyons 4:c644522ff9d9 92
helioslyons 4:c644522ff9d9 93 /*void Invader::set_death(bool death){ // Likewise not necessary
helioslyons 4:c644522ff9d9 94 _death = death;
helioslyons 4:c644522ff9d9 95 }
helioslyons 4:c644522ff9d9 96 */
helioslyons 4:c644522ff9d9 97
helioslyons 4:c644522ff9d9 98 bool Invader::get_death(){
helioslyons 4:c644522ff9d9 99 if (_hitpoints == 0) {
helioslyons 4:c644522ff9d9 100 _death = true;
helioslyons 4:c644522ff9d9 101 }
helioslyons 4:c644522ff9d9 102 return _death;
helioslyons 4:c644522ff9d9 103 }
helioslyons 4:c644522ff9d9 104 /*
helioslyons 4:c644522ff9d9 105 void Invader::set_sprite(int sprite){
helioslyons 4:c644522ff9d9 106 _sprite = sprite;
helioslyons 4:c644522ff9d9 107 }
helioslyons 4:c644522ff9d9 108 */
helioslyons 4:c644522ff9d9 109
helioslyons 4:c644522ff9d9 110 Vector2D Invader::get_pos() {
helioslyons 4:c644522ff9d9 111 Vector2D p = {_x,_y};
helioslyons 4:c644522ff9d9 112 return p;
helioslyons 4:c644522ff9d9 113 }