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:
Wed May 27 05:07:34 2020 +0000
Revision:
11:1fd8fca23375
Parent:
10:19b250c7de5e
Helios A. 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 Invader::~Invader()
helioslyons 4:c644522ff9d9 10 {
helioslyons 4:c644522ff9d9 11 }
helioslyons 4:c644522ff9d9 12
helioslyons 11:1fd8fca23375 13 void Invader::init(int sprite, int hitpoints, int boss)
helioslyons 11:1fd8fca23375 14 {
helioslyons 11:1fd8fca23375 15 _height = 8; // set invader accessible variables
helioslyons 11:1fd8fca23375 16 _width = 8; // height is the same for normal invaders
helioslyons 11:1fd8fca23375 17 _death = false; // changed in drawn statement for bosses
helioslyons 4:c644522ff9d9 18 _sprite = sprite;
helioslyons 4:c644522ff9d9 19 _hitpoints = hitpoints;
helioslyons 4:c644522ff9d9 20 }
helioslyons 4:c644522ff9d9 21
helioslyons 4:c644522ff9d9 22 void Invader::draw(N5110 &lcd)
helioslyons 4:c644522ff9d9 23 {
helioslyons 11:1fd8fca23375 24 // classic Space Invader sprites made into a bitmap
helioslyons 11:1fd8fca23375 25 static int inv1_resize_data[] = {
helioslyons 11:1fd8fca23375 26 0,1,0,0,0,0,1,0, // shrunk from original design (used on start screen)
helioslyons 11:1fd8fca23375 27 0,0,1,0,0,1,0,0, // to fit better on LCD
helioslyons 11:1fd8fca23375 28 0,0,1,1,1,1,0,0,
helioslyons 11:1fd8fca23375 29 0,1,0,1,1,0,1,0,
helioslyons 11:1fd8fca23375 30 1,1,1,1,1,1,1,1,
helioslyons 11:1fd8fca23375 31 1,0,1,1,1,1,0,1,
helioslyons 11:1fd8fca23375 32 1,0,1,0,0,1,0,1,
helioslyons 11:1fd8fca23375 33 0,0,0,1,1,0,0,0
helioslyons 11:1fd8fca23375 34 };
helioslyons 11:1fd8fca23375 35
helioslyons 11:1fd8fca23375 36 static int inv2_resize_data[] = {
helioslyons 11:1fd8fca23375 37 0,1,0,0,0,0,1,0,
helioslyons 11:1fd8fca23375 38 0,0,1,0,0,1,0,0,
helioslyons 11:1fd8fca23375 39 1,0,1,1,1,1,0,1,
helioslyons 11:1fd8fca23375 40 1,1,0,1,1,0,1,1,
helioslyons 11:1fd8fca23375 41 0,1,1,1,1,1,1,0,
helioslyons 11:1fd8fca23375 42 0,0,1,0,0,1,0,0,
helioslyons 11:1fd8fca23375 43 0,1,0,0,0,0,1,0,
helioslyons 11:1fd8fca23375 44 1,0,0,0,0,0,0,1
helioslyons 11:1fd8fca23375 45 };
helioslyons 11:1fd8fca23375 46
helioslyons 11:1fd8fca23375 47 static int inv3_resize_data[] = {
helioslyons 11:1fd8fca23375 48 0,0,0,1,1,0,0,0,
helioslyons 11:1fd8fca23375 49 0,0,1,1,1,1,0,0,
helioslyons 11:1fd8fca23375 50 0,1,0,1,1,0,1,0,
helioslyons 11:1fd8fca23375 51 1,1,0,1,1,0,1,1,
helioslyons 11:1fd8fca23375 52 0,1,1,1,1,1,1,0,
helioslyons 11:1fd8fca23375 53 0,0,1,0,0,1,0,0,
helioslyons 11:1fd8fca23375 54 0,1,0,1,1,0,1,0,
helioslyons 11:1fd8fca23375 55 1,0,1,0,0,1,0,1
helioslyons 4:c644522ff9d9 56 };
helioslyons 4:c644522ff9d9 57
helioslyons 11:1fd8fca23375 58 static int boss1_data[] = {
helioslyons 11:1fd8fca23375 59 0,0,0,1,0,0,0,0,0,0,0, // Boss 1: Astro
helioslyons 11:1fd8fca23375 60 0,0,0,0,1,0,0,0,0,0,0,
helioslyons 11:1fd8fca23375 61 0,0,0,0,1,1,0,0,0,0,0,
helioslyons 11:1fd8fca23375 62 0,0,0,0,1,1,1,0,0,0,0,
helioslyons 11:1fd8fca23375 63 0,0,1,1,1,1,1,1,1,0,0,
helioslyons 11:1fd8fca23375 64 0,1,1,1,1,1,1,1,1,1,0,
helioslyons 11:1fd8fca23375 65 0,1,0,0,1,1,1,0,0,1,0,
helioslyons 11:1fd8fca23375 66 0,1,0,0,1,1,1,0,0,1,0,
helioslyons 11:1fd8fca23375 67 1,1,1,1,1,1,1,1,1,1,1,
helioslyons 11:1fd8fca23375 68 1,1,1,1,1,1,1,1,1,1,1,
helioslyons 11:1fd8fca23375 69 0,1,1,0,0,0,0,0,1,1,0,
helioslyons 11:1fd8fca23375 70 0,0,1,0,0,0,0,0,1,0,0,
helioslyons 11:1fd8fca23375 71 0,0,0,1,0,0,0,1,0,0,0,
helioslyons 11:1fd8fca23375 72 0,0,0,0,1,0,1,0,0,0,0
helioslyons 4:c644522ff9d9 73 };
helioslyons 4:c644522ff9d9 74
helioslyons 11:1fd8fca23375 75 static int boss2_data[] = {
helioslyons 11:1fd8fca23375 76 0,0,1,1,1,0,0,1,1,1,0,0, // Boss 2: Wormling
helioslyons 11:1fd8fca23375 77 0,1,0,0,0,0,0,0,0,0,1,0,
helioslyons 11:1fd8fca23375 78 0,1,0,0,1,1,1,1,0,0,1,0,
helioslyons 11:1fd8fca23375 79 0,1,0,1,1,1,1,1,1,0,1,0,
helioslyons 11:1fd8fca23375 80 0,0,1,0,0,1,1,0,0,1,0,0,
helioslyons 11:1fd8fca23375 81 0,0,1,0,0,1,1,0,0,1,0,0,
helioslyons 11:1fd8fca23375 82 1,1,1,1,1,1,1,1,1,1,1,1,
helioslyons 11:1fd8fca23375 83 1,0,0,0,1,1,1,1,0,0,0,1,
helioslyons 11:1fd8fca23375 84 1,0,0,0,0,1,1,0,0,0,0,1,
helioslyons 11:1fd8fca23375 85 0,1,1,1,0,0,0,0,1,1,1,0
helioslyons 4:c644522ff9d9 86 };
helioslyons 4:c644522ff9d9 87
helioslyons 11:1fd8fca23375 88 static int boss3_data[] = {
helioslyons 11:1fd8fca23375 89 0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0, // Boss 3: Eater of Worlds
helioslyons 11:1fd8fca23375 90 0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,
helioslyons 11:1fd8fca23375 91 0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,
helioslyons 11:1fd8fca23375 92 0,0,0,1,0,0,1,1,1,1,1,0,0,1,0,0,0,
helioslyons 11:1fd8fca23375 93 0,0,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,
helioslyons 11:1fd8fca23375 94 1,1,1,1,0,0,0,1,0,1,0,0,0,1,1,1,1,
helioslyons 11:1fd8fca23375 95 0,0,0,1,1,1,1,1,0,1,1,1,1,1,0,0,0,
helioslyons 11:1fd8fca23375 96 0,0,0,1,0,1,1,1,1,1,1,1,0,1,0,0,0,
helioslyons 11:1fd8fca23375 97 0,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0,0,
helioslyons 11:1fd8fca23375 98 0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
helioslyons 11:1fd8fca23375 99 0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0
helioslyons 11:1fd8fca23375 100 };
helioslyons 11:1fd8fca23375 101
helioslyons 11:1fd8fca23375 102 if (_sprite == 1 && _death == false) { // set conditions for draw function
helioslyons 11:1fd8fca23375 103 Bitmap invader1(inv1_resize_data,8,8); // only alive invaders are rendered
helioslyons 4:c644522ff9d9 104 invader1.render(lcd,_x,_y);
helioslyons 4:c644522ff9d9 105 }
helioslyons 4:c644522ff9d9 106 else if (_sprite == 2 && _death == false) {
helioslyons 11:1fd8fca23375 107 Bitmap invader2(inv2_resize_data,8,8);
helioslyons 4:c644522ff9d9 108 invader2.render(lcd,_x,_y);
helioslyons 4:c644522ff9d9 109 }
helioslyons 4:c644522ff9d9 110 else if (_sprite == 3 && _death == false) {
helioslyons 11:1fd8fca23375 111 Bitmap invader3(inv3_resize_data,8,8);
helioslyons 4:c644522ff9d9 112 invader3.render(lcd,_x,_y);
helioslyons 4:c644522ff9d9 113 }
helioslyons 11:1fd8fca23375 114 else if (_sprite == 4 && _death == false) {
helioslyons 11:1fd8fca23375 115 Bitmap boss1(boss1_data,14,11);
helioslyons 11:1fd8fca23375 116 boss1.render(lcd,_x,_y);
helioslyons 11:1fd8fca23375 117 _width = 11;
helioslyons 11:1fd8fca23375 118 _height = 14;
helioslyons 11:1fd8fca23375 119 }
helioslyons 11:1fd8fca23375 120 else if (_sprite == 5 && _death == false) {
helioslyons 11:1fd8fca23375 121 Bitmap boss2(boss2_data,10,12);
helioslyons 11:1fd8fca23375 122 boss2.render(lcd,_x,_y);
helioslyons 11:1fd8fca23375 123 _width = 10;
helioslyons 11:1fd8fca23375 124 _height = 12;
helioslyons 11:1fd8fca23375 125 }
helioslyons 11:1fd8fca23375 126 else if (_sprite == 6 && _death == false) {
helioslyons 11:1fd8fca23375 127 Bitmap boss3(boss3_data,11,17);
helioslyons 11:1fd8fca23375 128 boss3.render(lcd,_x,_y);
helioslyons 11:1fd8fca23375 129 _width = 17;
helioslyons 11:1fd8fca23375 130 _height = 11;
helioslyons 11:1fd8fca23375 131 }
helioslyons 4:c644522ff9d9 132 else if (_death == true) {printf("Alien is dead");}
helioslyons 4:c644522ff9d9 133 else {printf("Incorrect Sprite Value");}
helioslyons 4:c644522ff9d9 134 }
helioslyons 4:c644522ff9d9 135
helioslyons 11:1fd8fca23375 136 int Invader::hit() // decrement invader hitpoints, and set death if at 0
helioslyons 6:e3a1bfbb1627 137 {
helioslyons 4:c644522ff9d9 138 _hitpoints--;
helioslyons 10:19b250c7de5e 139 if (_hitpoints <= 0) {
helioslyons 10:19b250c7de5e 140 _death = true;
helioslyons 10:19b250c7de5e 141 }
helioslyons 4:c644522ff9d9 142 return _hitpoints;
helioslyons 6:e3a1bfbb1627 143 }
helioslyons 4:c644522ff9d9 144
helioslyons 11:1fd8fca23375 145 bool Invader::get_death() // retrieve death state
helioslyons 6:e3a1bfbb1627 146 {
helioslyons 7:5fe9ac6522c5 147 if (_hitpoints <= 0) {
helioslyons 4:c644522ff9d9 148 _death = true;
helioslyons 4:c644522ff9d9 149 }
helioslyons 4:c644522ff9d9 150 return _death;
helioslyons 6:e3a1bfbb1627 151 }
helioslyons 4:c644522ff9d9 152
helioslyons 6:e3a1bfbb1627 153 Vector2D Invader::get_pos()
helioslyons 6:e3a1bfbb1627 154 {
helioslyons 11:1fd8fca23375 155 Vector2D pos = {_x,_y};
helioslyons 11:1fd8fca23375 156 return pos;
helioslyons 7:5fe9ac6522c5 157 }
helioslyons 7:5fe9ac6522c5 158
helioslyons 10:19b250c7de5e 159 int Invader::get_sprite()
helioslyons 10:19b250c7de5e 160 {
helioslyons 10:19b250c7de5e 161 return _sprite;
helioslyons 10:19b250c7de5e 162 }
helioslyons 10:19b250c7de5e 163
helioslyons 6:e3a1bfbb1627 164 void Invader::set_pos(int x, int y)
helioslyons 6:e3a1bfbb1627 165 {
helioslyons 6:e3a1bfbb1627 166 _x = x;
helioslyons 6:e3a1bfbb1627 167 _y = y;
helioslyons 11:1fd8fca23375 168 }
helioslyons 11:1fd8fca23375 169
helioslyons 11:1fd8fca23375 170 int Invader::get_width()
helioslyons 11:1fd8fca23375 171 {
helioslyons 11:1fd8fca23375 172 return _width;
helioslyons 11:1fd8fca23375 173 }
helioslyons 11:1fd8fca23375 174
helioslyons 11:1fd8fca23375 175 int Invader::get_height()
helioslyons 11:1fd8fca23375 176 {
helioslyons 11:1fd8fca23375 177 return _height;
helioslyons 4:c644522ff9d9 178 }