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:
Mon May 18 18:14:35 2020 +0000
Revision:
10:19b250c7de5e
Parent:
8:ec4199484adf
Child:
11:1fd8fca23375
Helios Lyons 201239214

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 10:19b250c7de5e 15 void Canon::init(int y)
helioslyons 2:ef7f9892ba4f 16 {
helioslyons 10:19b250c7de5e 17 _y = y; // y value is fixed
helioslyons 10:19b250c7de5e 18 _x = 42; // x depends on width of screen and width of canon
helioslyons 10:19b250c7de5e 19 _height = 4;
helioslyons 10:19b250c7de5e 20 _width = 8;
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 4:c644522ff9d9 32 static int sprite_data[] = {
helioslyons 4:c644522ff9d9 33 0,0,0,1,1,0,0,0,
helioslyons 7:5fe9ac6522c5 34 0,0,1,1,1,1,0,0,
helioslyons 4:c644522ff9d9 35 1,1,1,1,1,1,1,1,
helioslyons 4:c644522ff9d9 36 1,1,1,1,1,1,1,1
helioslyons 4:c644522ff9d9 37 };
helioslyons 4:c644522ff9d9 38 Bitmap canon_sprite(sprite_data, 8, 4);
helioslyons 4:c644522ff9d9 39 canon_sprite.render(lcd, _x,_y);
helioslyons 2:ef7f9892ba4f 40 }
helioslyons 10:19b250c7de5e 41
helioslyons 10:19b250c7de5e 42 int Canon::kill(int sprite)
helioslyons 2:ef7f9892ba4f 43 {
helioslyons 10:19b250c7de5e 44 if (sprite == 1){
helioslyons 10:19b250c7de5e 45 _inv1_kill++;
helioslyons 10:19b250c7de5e 46 }
helioslyons 10:19b250c7de5e 47 else if (sprite == 2) {
helioslyons 10:19b250c7de5e 48 _inv2_kill++;
helioslyons 10:19b250c7de5e 49 }
helioslyons 10:19b250c7de5e 50 else if (sprite == 3) {
helioslyons 10:19b250c7de5e 51 _inv3_kill++;
helioslyons 10:19b250c7de5e 52 }
helioslyons 10:19b250c7de5e 53 else if (sprite == 4) {
helioslyons 10:19b250c7de5e 54 _boss_kill++;
helioslyons 10:19b250c7de5e 55 }
helioslyons 10:19b250c7de5e 56
helioslyons 10:19b250c7de5e 57 int kill = _inv1_kill + _inv2_kill + _inv3_kill + _boss_kill;
helioslyons 10:19b250c7de5e 58 return kill;
helioslyons 4:c644522ff9d9 59 }
helioslyons 2:ef7f9892ba4f 60
helioslyons 2:ef7f9892ba4f 61 int Canon::get_score()
helioslyons 2:ef7f9892ba4f 62 {
helioslyons 2:ef7f9892ba4f 63 _score = (_inv1_kill * 10) + (_inv2_kill * 20) + (_inv1_kill * 30) + (_boss_kill * 100);
helioslyons 2:ef7f9892ba4f 64 return _score;
helioslyons 2:ef7f9892ba4f 65 }
helioslyons 10:19b250c7de5e 66
helioslyons 10:19b250c7de5e 67 Vector2D Canon::get_pos()
helioslyons 10:19b250c7de5e 68 {
helioslyons 2:ef7f9892ba4f 69 Vector2D p = {_x,_y};
helioslyons 3:13fd052f79c6 70 return p;
helioslyons 2:ef7f9892ba4f 71 }
helioslyons 2:ef7f9892ba4f 72
helioslyons 10:19b250c7de5e 73 int Canon::get_x_pos()
helioslyons 10:19b250c7de5e 74 {
helioslyons 10:19b250c7de5e 75 return _x;
helioslyons 10:19b250c7de5e 76 }
helioslyons 10:19b250c7de5e 77
helioslyons 2:ef7f9892ba4f 78 int Canon::get_life()
helioslyons 2:ef7f9892ba4f 79 {
helioslyons 2:ef7f9892ba4f 80 return _life;
helioslyons 2:ef7f9892ba4f 81 }
helioslyons 2:ef7f9892ba4f 82
helioslyons 2:ef7f9892ba4f 83 int Canon::remove_life()
helioslyons 2:ef7f9892ba4f 84 {
helioslyons 2:ef7f9892ba4f 85 _life--;
helioslyons 4:c644522ff9d9 86 return _life;
helioslyons 2:ef7f9892ba4f 87 }
helioslyons 2:ef7f9892ba4f 88
helioslyons 2:ef7f9892ba4f 89 int Canon::reset_life()
helioslyons 2:ef7f9892ba4f 90 {
helioslyons 2:ef7f9892ba4f 91 _life = 3;
helioslyons 4:c644522ff9d9 92 return _life;
helioslyons 10:19b250c7de5e 93 }
helioslyons 10:19b250c7de5e 94
helioslyons 10:19b250c7de5e 95 void Canon::update(Direction d,float mag)
helioslyons 10:19b250c7de5e 96 {
helioslyons 10:19b250c7de5e 97 _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
helioslyons 10:19b250c7de5e 98
helioslyons 10:19b250c7de5e 99 // update X value depending on direction of movement
helioslyons 10:19b250c7de5e 100 // East is decrement as origin is at the top-left so decreasing moves left
helioslyons 10:19b250c7de5e 101 if (d == E) {
helioslyons 10:19b250c7de5e 102 _x-=_speed;
helioslyons 10:19b250c7de5e 103 } else if (d == W) {
helioslyons 10:19b250c7de5e 104 _x+=_speed;
helioslyons 10:19b250c7de5e 105 }
helioslyons 10:19b250c7de5e 106
helioslyons 10:19b250c7de5e 107 // check the X origin to ensure that the canon doesn't go off screen
helioslyons 10:19b250c7de5e 108 if (_x < 1) {
helioslyons 10:19b250c7de5e 109 _x = 1;
helioslyons 10:19b250c7de5e 110 }
helioslyons 10:19b250c7de5e 111 if (_x > 83) {
helioslyons 10:19b250c7de5e 112 _x = 83;
helioslyons 10:19b250c7de5e 113 }
helioslyons 2:ef7f9892ba4f 114 }