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:
Mon May 18 18:14:35 2020 +0000
Revision:
10:19b250c7de5e
Parent:
9:6a245c8ce08e
Child:
11:1fd8fca23375
Helios Lyons 201239214

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 8:ec4199484adf 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 9:6a245c8ce08e 28 if (_death == false) { // classic Space Invader sprites made into bitmap
helioslyons 4:c644522ff9d9 29 //lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
helioslyons 4:c644522ff9d9 30 static int invader1_data[] = {
helioslyons 4:c644522ff9d9 31 0,0,1,0,0,0,0,0,1,0,0, // ..#.....#..
helioslyons 4:c644522ff9d9 32 0,0,0,1,0,0,0,1,0,0,0, // ...#...#...
helioslyons 4:c644522ff9d9 33 0,0,1,1,1,1,1,1,1,0,0, // ..#######..
helioslyons 4:c644522ff9d9 34 0,1,1,0,1,1,1,0,1,1,0, // .##.###.##.
helioslyons 4:c644522ff9d9 35 1,1,1,1,1,1,1,1,1,1,1, // ###########
helioslyons 4:c644522ff9d9 36 1,0,1,1,1,1,1,1,1,0,1, // #.#######.#
helioslyons 4:c644522ff9d9 37 1,0,1,0,0,0,0,0,1,0,1, // #.#.....#.#
helioslyons 4:c644522ff9d9 38 0,0,0,1,1,0,1,1,0,0,0 // ...##.##...
helioslyons 4:c644522ff9d9 39 };
helioslyons 4:c644522ff9d9 40
helioslyons 4:c644522ff9d9 41 static int invader2_data[] = {
helioslyons 4:c644522ff9d9 42 0,0,1,0,0,0,0,0,1,0,0, // ..#.....#..
helioslyons 4:c644522ff9d9 43 1,0,0,1,0,0,0,1,0,0,1, // #..#...#..#
helioslyons 4:c644522ff9d9 44 1,0,1,1,1,1,1,1,1,0,1, // #.#######.#
helioslyons 4:c644522ff9d9 45 1,1,1,0,1,1,1,0,1,1,1, // ###.###.###
helioslyons 4:c644522ff9d9 46 1,1,1,1,1,1,1,1,1,1,1, // ###########
helioslyons 4:c644522ff9d9 47 0,1,1,1,1,1,1,1,1,1,0, // .#########.
helioslyons 4:c644522ff9d9 48 0,0,1,0,0,0,0,0,1,0,0, // ..#.....#..
helioslyons 4:c644522ff9d9 49 0,1,0,0,0,0,0,0,0,1,0 // .#.......#.
helioslyons 4:c644522ff9d9 50 };
helioslyons 4:c644522ff9d9 51
helioslyons 4:c644522ff9d9 52 static int invader3_data[] = {
helioslyons 4:c644522ff9d9 53 0,0,0,0,1,1,1,0,0,0,0, // ....###....
helioslyons 4:c644522ff9d9 54 0,0,0,1,1,1,1,1,0,0,0, // ...#####...
helioslyons 4:c644522ff9d9 55 0,0,1,1,1,1,1,1,1,0,0, // ..#######..
helioslyons 4:c644522ff9d9 56 1,1,0,0,1,1,1,0,0,1,1, // ##..###..##
helioslyons 4:c644522ff9d9 57 1,1,1,1,1,1,1,1,1,1,1, // ###########
helioslyons 4:c644522ff9d9 58 0,0,1,1,0,0,0,1,1,0,0, // ..##...##..
helioslyons 4:c644522ff9d9 59 0,1,0,0,1,1,1,0,0,1,0, // .#..###..#.
helioslyons 4:c644522ff9d9 60 1,0,1,1,0,0,0,1,1,0,1 // #.##...##.#
helioslyons 4:c644522ff9d9 61 };
helioslyons 4:c644522ff9d9 62
helioslyons 4:c644522ff9d9 63 if (_sprite == 1 && _death == false) {
helioslyons 4:c644522ff9d9 64 Bitmap invader1(invader1_data,11,8);
helioslyons 4:c644522ff9d9 65 invader1.render(lcd,_x,_y);
helioslyons 4:c644522ff9d9 66 }
helioslyons 4:c644522ff9d9 67 else if (_sprite == 2 && _death == false) {
helioslyons 4:c644522ff9d9 68 Bitmap invader2(invader2_data,11,8);
helioslyons 4:c644522ff9d9 69 invader2.render(lcd,_x,_y);
helioslyons 4:c644522ff9d9 70 }
helioslyons 4:c644522ff9d9 71 else if (_sprite == 3 && _death == false) {
helioslyons 4:c644522ff9d9 72 Bitmap invader3(invader3_data,11,8);
helioslyons 4:c644522ff9d9 73 invader3.render(lcd,_x,_y);
helioslyons 4:c644522ff9d9 74 }
helioslyons 4:c644522ff9d9 75 else if (_death == true) {printf("Alien is dead");}
helioslyons 4:c644522ff9d9 76 else {printf("Incorrect Sprite Value");}
helioslyons 7:5fe9ac6522c5 77 }
helioslyons 4:c644522ff9d9 78 }
helioslyons 4:c644522ff9d9 79
helioslyons 6:e3a1bfbb1627 80 int Invader::hit()
helioslyons 6:e3a1bfbb1627 81 {
helioslyons 4:c644522ff9d9 82 _hitpoints--;
helioslyons 10:19b250c7de5e 83 if (_hitpoints <= 0) {
helioslyons 10:19b250c7de5e 84 _death = true;
helioslyons 10:19b250c7de5e 85 }
helioslyons 4:c644522ff9d9 86 return _hitpoints;
helioslyons 6:e3a1bfbb1627 87 }
helioslyons 4:c644522ff9d9 88
helioslyons 6:e3a1bfbb1627 89 bool Invader::get_death()
helioslyons 6:e3a1bfbb1627 90 {
helioslyons 7:5fe9ac6522c5 91 if (_hitpoints <= 0) {
helioslyons 4:c644522ff9d9 92 _death = true;
helioslyons 4:c644522ff9d9 93 }
helioslyons 4:c644522ff9d9 94 return _death;
helioslyons 6:e3a1bfbb1627 95 }
helioslyons 4:c644522ff9d9 96
helioslyons 6:e3a1bfbb1627 97 Vector2D Invader::get_pos()
helioslyons 6:e3a1bfbb1627 98 {
helioslyons 4:c644522ff9d9 99 Vector2D p = {_x,_y};
helioslyons 4:c644522ff9d9 100 return p;
helioslyons 6:e3a1bfbb1627 101 }
helioslyons 6:e3a1bfbb1627 102
helioslyons 7:5fe9ac6522c5 103 int Invader::get_x_pos()
helioslyons 7:5fe9ac6522c5 104 {
helioslyons 7:5fe9ac6522c5 105 return _x;
helioslyons 7:5fe9ac6522c5 106 }
helioslyons 7:5fe9ac6522c5 107
helioslyons 10:19b250c7de5e 108 int Invader::get_sprite()
helioslyons 10:19b250c7de5e 109 {
helioslyons 10:19b250c7de5e 110 return _sprite;
helioslyons 10:19b250c7de5e 111 }
helioslyons 10:19b250c7de5e 112
helioslyons 7:5fe9ac6522c5 113 int Invader::get_y_pos()
helioslyons 7:5fe9ac6522c5 114 {
helioslyons 7:5fe9ac6522c5 115 return _y;
helioslyons 7:5fe9ac6522c5 116 }
helioslyons 7:5fe9ac6522c5 117
helioslyons 6:e3a1bfbb1627 118 void Invader::set_pos(int x, int y)
helioslyons 6:e3a1bfbb1627 119 {
helioslyons 6:e3a1bfbb1627 120 _x = x;
helioslyons 6:e3a1bfbb1627 121 _y = y;
helioslyons 4:c644522ff9d9 122 }