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

Canon/Canon.cpp

Committer:
helioslyons
Date:
2020-05-27
Revision:
13:1472c1637bfc
Parent:
11:1fd8fca23375

File content as of revision 13:1472c1637bfc:

#include "Canon.h"
#include "Bitmap.h"
#include <vector>

Canon::Canon()
{
 
}
 
Canon::~Canon()
{
 
}
 
void Canon::init(int y) // initialise canon at a certain Y position
{
    _y = y;  // y value is fixed
    _x = WIDTH/2 - _width/2; // x depends on width of screen and width of canon
    _height = 3; // initialise all accessible variables
    _width = 5;
    _speed = 1;
}
 
void Canon::draw(N5110 &lcd) // bitmap for canon sprite
{
    static int sprite_data[] = {
    0,0,1,0,0,
    1,0,1,0,1,
    1,1,1,1,1
    };
    Bitmap canon_sprite(sprite_data, _height, _width);
    canon_sprite.render(lcd, _x,_y);
}

Vector2D Canon::get_pos()
{
    Vector2D p = {_x,_y};
    return p;
}

int Canon::get_life()
{
    return _life;
}

int Canon::remove_life()
{
    _life--;
    return _life;
}

int Canon::reset_life()
{
    _life = 3;
    return _life;
}

void Canon::update(Direction d,float mag) // take input from the magnometer and pad direction
{
    _speed = int(mag*10.0f);

    if (d == E) {
        _x+=_speed;
    } else if (d == W) {
        _x-=_speed;
    }

    // check the X origin to ensure that canon doesn't go off screen
    if (_x < 1) {
        _x = 1;
    }
    if (_x > WIDTH - _width - 1) {
        _x = WIDTH - _width - 1;
    }
}

int Canon::get_width()
{
    return _width;
}

int Canon::get_height()
{
    return _height;
}