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 9:6a245c8ce08e 1 #include "mbed.h"
helioslyons 9:6a245c8ce08e 2 #include "N5110.h"
helioslyons 9:6a245c8ce08e 3 #include "Gamepad.h"
helioslyons 11:1fd8fca23375 4
helioslyons 11:1fd8fca23375 5 #include "Bullet.h"
helioslyons 9:6a245c8ce08e 6 #include "Canon.h"
helioslyons 8:ec4199484adf 7
helioslyons 8:ec4199484adf 8 Bullet::Bullet()
helioslyons 8:ec4199484adf 9 {
helioslyons 8:ec4199484adf 10
helioslyons 8:ec4199484adf 11 }
helioslyons 8:ec4199484adf 12
helioslyons 8:ec4199484adf 13 Bullet::~Bullet()
helioslyons 8:ec4199484adf 14 {
helioslyons 8:ec4199484adf 15
helioslyons 8:ec4199484adf 16 }
helioslyons 8:ec4199484adf 17
helioslyons 11:1fd8fca23375 18 void Bullet::init(bool canon, int x, int y, int speed)
helioslyons 8:ec4199484adf 19 {
helioslyons 11:1fd8fca23375 20 _canon = canon; // define ownership – canon, or invaders
helioslyons 8:ec4199484adf 21 _x = x;
helioslyons 8:ec4199484adf 22 _y = y;
helioslyons 11:1fd8fca23375 23 _speed = speed; // speed – using to update velocity
helioslyons 8:ec4199484adf 24
helioslyons 11:1fd8fca23375 25 Direction d;
helioslyons 8:ec4199484adf 26
helioslyons 11:1fd8fca23375 27 if (_canon == true) { // set direction based on ownership
helioslyons 8:ec4199484adf 28 d = N;
helioslyons 10:19b250c7de5e 29 _width = 1;
helioslyons 10:19b250c7de5e 30 _height = 2;
helioslyons 11:1fd8fca23375 31 _velocity.x = 0; // only moves on y axis for both canon and invader
helioslyons 11:1fd8fca23375 32 _velocity.y = -speed;
helioslyons 8:ec4199484adf 33 }
helioslyons 8:ec4199484adf 34 else {
helioslyons 8:ec4199484adf 35 d = S;
helioslyons 10:19b250c7de5e 36 _width = 1;
helioslyons 10:19b250c7de5e 37 _height = 1;
helioslyons 11:1fd8fca23375 38 _velocity.x = 0;
helioslyons 11:1fd8fca23375 39 _velocity.y = speed;
helioslyons 8:ec4199484adf 40 }
helioslyons 8:ec4199484adf 41 }
helioslyons 8:ec4199484adf 42
helioslyons 8:ec4199484adf 43 void Bullet::draw(N5110 &lcd)
helioslyons 8:ec4199484adf 44 {
helioslyons 10:19b250c7de5e 45 if (_canon == true) { // square bullets for canon
helioslyons 8:ec4199484adf 46 lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
helioslyons 8:ec4199484adf 47 }
helioslyons 11:1fd8fca23375 48 else { // 'round' bombs for invaders –– didn't turn out round
helioslyons 11:1fd8fca23375 49 lcd.drawCircle(_x,_y,_width,FILL_BLACK); // but I like the aesthetic
helioslyons 8:ec4199484adf 50 }
helioslyons 8:ec4199484adf 51 }
helioslyons 8:ec4199484adf 52
helioslyons 11:1fd8fca23375 53 void Bullet::update() // update positions using velocity
helioslyons 8:ec4199484adf 54 {
helioslyons 8:ec4199484adf 55 _x += _velocity.x;
helioslyons 8:ec4199484adf 56 _y += _velocity.y;
helioslyons 8:ec4199484adf 57 }
helioslyons 8:ec4199484adf 58
helioslyons 11:1fd8fca23375 59 Vector2D Bullet::get_velocity() // retrieve velocities
helioslyons 8:ec4199484adf 60 {
helioslyons 8:ec4199484adf 61 Vector2D v = {_velocity.x,_velocity.y};
helioslyons 8:ec4199484adf 62 return v;
helioslyons 8:ec4199484adf 63 }
helioslyons 8:ec4199484adf 64
helioslyons 11:1fd8fca23375 65 Vector2D Bullet::get_pos() // get x and y positions (for collision testing)
helioslyons 8:ec4199484adf 66 {
helioslyons 10:19b250c7de5e 67 Vector2D p = {_x,_y};
helioslyons 10:19b250c7de5e 68 return p;
helioslyons 11:1fd8fca23375 69 }
helioslyons 11:1fd8fca23375 70
helioslyons 11:1fd8fca23375 71 bool Bullet::get_canon() // return ownership
helioslyons 11:1fd8fca23375 72 {
helioslyons 11:1fd8fca23375 73 return _canon;
helioslyons 10:19b250c7de5e 74 }