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:
Fri Apr 10 14:28:25 2020 +0000
Revision:
4:c644522ff9d9
Parent:
3:13fd052f79c6
Child:
7:5fe9ac6522c5
Started implementing Army class and grouped movement

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 4:c644522ff9d9 15 void Canon::init(int y,int height,int width)
helioslyons 2:ef7f9892ba4f 16 {
helioslyons 2:ef7f9892ba4f 17 _y = y; // y value on screen is fixed
helioslyons 4:c644522ff9d9 18 _x = WIDTH/2 - width/2; // x depends on width of screen and width of canon
helioslyons 2:ef7f9892ba4f 19 _height = height;
helioslyons 2:ef7f9892ba4f 20 _width = width;
helioslyons 2:ef7f9892ba4f 21 _speed = 1; // init speed, add in options – accessible?
helioslyons 2:ef7f9892ba4f 22 _score = 0; // start all at 0
helioslyons 2:ef7f9892ba4f 23 _inv1_kill = 0;
helioslyons 2:ef7f9892ba4f 24 _inv2_kill = 0;
helioslyons 2:ef7f9892ba4f 25 _inv3_kill = 0;
helioslyons 2:ef7f9892ba4f 26 _total_kill = 0;
helioslyons 2:ef7f9892ba4f 27 _life = 3;
helioslyons 2:ef7f9892ba4f 28 }
helioslyons 2:ef7f9892ba4f 29
helioslyons 2:ef7f9892ba4f 30 void Canon::draw(N5110 &lcd)
helioslyons 2:ef7f9892ba4f 31 {
helioslyons 2:ef7f9892ba4f 32 // draw canon in screen buffer – need to replace with a different shape
helioslyons 4:c644522ff9d9 33 //lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
helioslyons 4:c644522ff9d9 34 static int sprite_data[] = {
helioslyons 4:c644522ff9d9 35 0,0,0,1,1,0,0,0,
helioslyons 4:c644522ff9d9 36 0,0,0,1,1,0,0,0,
helioslyons 4:c644522ff9d9 37 1,1,1,1,1,1,1,1,
helioslyons 4:c644522ff9d9 38 1,1,1,1,1,1,1,1
helioslyons 4:c644522ff9d9 39 };
helioslyons 4:c644522ff9d9 40 Bitmap canon_sprite(sprite_data, 8, 4);
helioslyons 4:c644522ff9d9 41 canon_sprite.render(lcd, _x,_y);
helioslyons 2:ef7f9892ba4f 42 }
helioslyons 2:ef7f9892ba4f 43
helioslyons 2:ef7f9892ba4f 44 void Canon::update(Direction d,float mag)
helioslyons 2:ef7f9892ba4f 45 {
helioslyons 2:ef7f9892ba4f 46 _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future – add in options menu
helioslyons 2:ef7f9892ba4f 47
helioslyons 2:ef7f9892ba4f 48 // update x value based on direction
helioslyons 2:ef7f9892ba4f 49 // North is decrement as origin is at the top-left so decreasing moves up
helioslyons 2:ef7f9892ba4f 50 if (d == W) {
helioslyons 2:ef7f9892ba4f 51 _x-=_speed;
helioslyons 2:ef7f9892ba4f 52 } else if (d == E) {
helioslyons 2:ef7f9892ba4f 53 _x+=_speed;
helioslyons 2:ef7f9892ba4f 54 }
helioslyons 2:ef7f9892ba4f 55
helioslyons 2:ef7f9892ba4f 56 // check the x origin to set boundaries
helioslyons 2:ef7f9892ba4f 57 if (_x < 1) {
helioslyons 2:ef7f9892ba4f 58 _x = 1;
helioslyons 2:ef7f9892ba4f 59 }
helioslyons 2:ef7f9892ba4f 60 if (_x > WIDTH - _width - 1) {
helioslyons 2:ef7f9892ba4f 61 _x = WIDTH - _width - 1;
helioslyons 2:ef7f9892ba4f 62 }
helioslyons 2:ef7f9892ba4f 63 }
helioslyons 2:ef7f9892ba4f 64
helioslyons 4:c644522ff9d9 65 int Canon::add_inv1_kill(int n)
helioslyons 2:ef7f9892ba4f 66 {
helioslyons 4:c644522ff9d9 67 _inv1_kill = _inv1_kill + n;
helioslyons 4:c644522ff9d9 68 return _inv1_kill;
helioslyons 2:ef7f9892ba4f 69 }
helioslyons 2:ef7f9892ba4f 70
helioslyons 4:c644522ff9d9 71 int Canon::add_inv2_kill(int n)
helioslyons 2:ef7f9892ba4f 72 {
helioslyons 4:c644522ff9d9 73 _inv2_kill = _inv2_kill + n;
helioslyons 4:c644522ff9d9 74 return _inv2_kill;
helioslyons 2:ef7f9892ba4f 75 }
helioslyons 2:ef7f9892ba4f 76
helioslyons 4:c644522ff9d9 77 int Canon::add_inv3_kill(int n)
helioslyons 2:ef7f9892ba4f 78 {
helioslyons 4:c644522ff9d9 79 _inv3_kill = _inv3_kill + n;
helioslyons 4:c644522ff9d9 80 return _inv3_kill;
helioslyons 2:ef7f9892ba4f 81 }
helioslyons 2:ef7f9892ba4f 82
helioslyons 4:c644522ff9d9 83 int Canon::add_boss_kill()
helioslyons 2:ef7f9892ba4f 84 {
helioslyons 2:ef7f9892ba4f 85 _boss_kill++;
helioslyons 4:c644522ff9d9 86 return _boss_kill;
helioslyons 2:ef7f9892ba4f 87 }
helioslyons 2:ef7f9892ba4f 88
helioslyons 2:ef7f9892ba4f 89 int Canon::get_total_kill()
helioslyons 2:ef7f9892ba4f 90 {
helioslyons 2:ef7f9892ba4f 91 _total_kill = _inv1_kill + _inv2_kill + _inv3_kill + _boss_kill;
helioslyons 2:ef7f9892ba4f 92 return _total_kill;
helioslyons 4:c644522ff9d9 93 }
helioslyons 2:ef7f9892ba4f 94
helioslyons 2:ef7f9892ba4f 95 int Canon::get_score()
helioslyons 2:ef7f9892ba4f 96 {
helioslyons 2:ef7f9892ba4f 97 _score = (_inv1_kill * 10) + (_inv2_kill * 20) + (_inv1_kill * 30) + (_boss_kill * 100);
helioslyons 2:ef7f9892ba4f 98 return _score;
helioslyons 2:ef7f9892ba4f 99 }
helioslyons 2:ef7f9892ba4f 100
helioslyons 2:ef7f9892ba4f 101 Vector2D Canon::get_pos() {
helioslyons 2:ef7f9892ba4f 102 Vector2D p = {_x,_y};
helioslyons 3:13fd052f79c6 103 return p;
helioslyons 2:ef7f9892ba4f 104 }
helioslyons 2:ef7f9892ba4f 105
helioslyons 2:ef7f9892ba4f 106 int Canon::get_life()
helioslyons 2:ef7f9892ba4f 107 {
helioslyons 2:ef7f9892ba4f 108 return _life;
helioslyons 2:ef7f9892ba4f 109 }
helioslyons 2:ef7f9892ba4f 110
helioslyons 2:ef7f9892ba4f 111 int Canon::remove_life()
helioslyons 2:ef7f9892ba4f 112 {
helioslyons 2:ef7f9892ba4f 113 _life--;
helioslyons 4:c644522ff9d9 114 return _life;
helioslyons 2:ef7f9892ba4f 115 }
helioslyons 2:ef7f9892ba4f 116
helioslyons 2:ef7f9892ba4f 117 int Canon::reset_life()
helioslyons 2:ef7f9892ba4f 118 {
helioslyons 2:ef7f9892ba4f 119 _life = 3;
helioslyons 4:c644522ff9d9 120 return _life;
helioslyons 2:ef7f9892ba4f 121 }