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 15:40:47 2020 +0000
Revision:
13:1472c1637bfc
Parent:
11:1fd8fca23375
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
helioslyons 2:ef7f9892ba4f 1 #include "Canon.h"
helioslyons 4:c644522ff9d9 2 #include "Bitmap.h"
helioslyons 4:c644522ff9d9 3 #include <vector>
helioslyons 4:c644522ff9d9 4
helioslyons 2:ef7f9892ba4f 5 Canon::Canon()
helioslyons 2:ef7f9892ba4f 6 {
helioslyons 2:ef7f9892ba4f 7
helioslyons 2:ef7f9892ba4f 8 }
helioslyons 2:ef7f9892ba4f 9
helioslyons 2:ef7f9892ba4f 10 Canon::~Canon()
helioslyons 2:ef7f9892ba4f 11 {
helioslyons 2:ef7f9892ba4f 12
helioslyons 2:ef7f9892ba4f 13 }
helioslyons 2:ef7f9892ba4f 14
helioslyons 11:1fd8fca23375 15 void Canon::init(int y) // initialise canon at a certain Y position
helioslyons 2:ef7f9892ba4f 16 {
helioslyons 10:19b250c7de5e 17 _y = y; // y value is fixed
helioslyons 11:1fd8fca23375 18 _x = WIDTH/2 - _width/2; // x depends on width of screen and width of canon
helioslyons 11:1fd8fca23375 19 _height = 3; // initialise all accessible variables
helioslyons 11:1fd8fca23375 20 _width = 5;
helioslyons 11:1fd8fca23375 21 _speed = 1;
helioslyons 2:ef7f9892ba4f 22 }
helioslyons 2:ef7f9892ba4f 23
helioslyons 11:1fd8fca23375 24 void Canon::draw(N5110 &lcd) // bitmap for canon sprite
helioslyons 2:ef7f9892ba4f 25 {
helioslyons 4:c644522ff9d9 26 static int sprite_data[] = {
helioslyons 11:1fd8fca23375 27 0,0,1,0,0,
helioslyons 11:1fd8fca23375 28 1,0,1,0,1,
helioslyons 11:1fd8fca23375 29 1,1,1,1,1
helioslyons 4:c644522ff9d9 30 };
helioslyons 11:1fd8fca23375 31 Bitmap canon_sprite(sprite_data, _height, _width);
helioslyons 4:c644522ff9d9 32 canon_sprite.render(lcd, _x,_y);
helioslyons 2:ef7f9892ba4f 33 }
helioslyons 10:19b250c7de5e 34
helioslyons 10:19b250c7de5e 35 Vector2D Canon::get_pos()
helioslyons 10:19b250c7de5e 36 {
helioslyons 2:ef7f9892ba4f 37 Vector2D p = {_x,_y};
helioslyons 3:13fd052f79c6 38 return p;
helioslyons 2:ef7f9892ba4f 39 }
helioslyons 2:ef7f9892ba4f 40
helioslyons 2:ef7f9892ba4f 41 int Canon::get_life()
helioslyons 2:ef7f9892ba4f 42 {
helioslyons 2:ef7f9892ba4f 43 return _life;
helioslyons 2:ef7f9892ba4f 44 }
helioslyons 2:ef7f9892ba4f 45
helioslyons 2:ef7f9892ba4f 46 int Canon::remove_life()
helioslyons 2:ef7f9892ba4f 47 {
helioslyons 2:ef7f9892ba4f 48 _life--;
helioslyons 4:c644522ff9d9 49 return _life;
helioslyons 2:ef7f9892ba4f 50 }
helioslyons 2:ef7f9892ba4f 51
helioslyons 2:ef7f9892ba4f 52 int Canon::reset_life()
helioslyons 2:ef7f9892ba4f 53 {
helioslyons 2:ef7f9892ba4f 54 _life = 3;
helioslyons 4:c644522ff9d9 55 return _life;
helioslyons 10:19b250c7de5e 56 }
helioslyons 10:19b250c7de5e 57
helioslyons 11:1fd8fca23375 58 void Canon::update(Direction d,float mag) // take input from the magnometer and pad direction
helioslyons 10:19b250c7de5e 59 {
helioslyons 11:1fd8fca23375 60 _speed = int(mag*10.0f);
helioslyons 10:19b250c7de5e 61
helioslyons 10:19b250c7de5e 62 if (d == E) {
helioslyons 11:1fd8fca23375 63 _x+=_speed;
helioslyons 10:19b250c7de5e 64 } else if (d == W) {
helioslyons 11:1fd8fca23375 65 _x-=_speed;
helioslyons 10:19b250c7de5e 66 }
helioslyons 10:19b250c7de5e 67
helioslyons 11:1fd8fca23375 68 // check the X origin to ensure that canon doesn't go off screen
helioslyons 10:19b250c7de5e 69 if (_x < 1) {
helioslyons 10:19b250c7de5e 70 _x = 1;
helioslyons 10:19b250c7de5e 71 }
helioslyons 11:1fd8fca23375 72 if (_x > WIDTH - _width - 1) {
helioslyons 11:1fd8fca23375 73 _x = WIDTH - _width - 1;
helioslyons 10:19b250c7de5e 74 }
helioslyons 11:1fd8fca23375 75 }
helioslyons 11:1fd8fca23375 76
helioslyons 11:1fd8fca23375 77 int Canon::get_width()
helioslyons 11:1fd8fca23375 78 {
helioslyons 11:1fd8fca23375 79 return _width;
helioslyons 11:1fd8fca23375 80 }
helioslyons 11:1fd8fca23375 81
helioslyons 11:1fd8fca23375 82 int Canon::get_height()
helioslyons 11:1fd8fca23375 83 {
helioslyons 11:1fd8fca23375 84 return _height;
helioslyons 2:ef7f9892ba4f 85 }