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.
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)
Canon/Canon.cpp@3:13fd052f79c6, 2020-04-02 (annotated)
- Committer:
- helioslyons
- Date:
- Thu Apr 02 14:30:31 2020 +0000
- Revision:
- 3:13fd052f79c6
- Parent:
- 2:ef7f9892ba4f
- Child:
- 4:c644522ff9d9
Helios A. Lyons; 201239214
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
helioslyons | 2:ef7f9892ba4f | 1 | #include "Canon.h" |
helioslyons | 2:ef7f9892ba4f | 2 | |
helioslyons | 2:ef7f9892ba4f | 3 | Canon::Canon() |
helioslyons | 2:ef7f9892ba4f | 4 | { |
helioslyons | 2:ef7f9892ba4f | 5 | |
helioslyons | 2:ef7f9892ba4f | 6 | } |
helioslyons | 2:ef7f9892ba4f | 7 | |
helioslyons | 2:ef7f9892ba4f | 8 | Canon::~Canon() |
helioslyons | 2:ef7f9892ba4f | 9 | { |
helioslyons | 2:ef7f9892ba4f | 10 | |
helioslyons | 2:ef7f9892ba4f | 11 | } |
helioslyons | 2:ef7f9892ba4f | 12 | |
helioslyons | 2:ef7f9892ba4f | 13 | void Canon::init(int x,int height,int width) |
helioslyons | 2:ef7f9892ba4f | 14 | { |
helioslyons | 2:ef7f9892ba4f | 15 | _y = y; // y value on screen is fixed |
helioslyons | 2:ef7f9892ba4f | 16 | _x = WIDTH/2 - width/2; // x depends on height of screen and width of paddle |
helioslyons | 2:ef7f9892ba4f | 17 | _y = HEIGHT/2 - height/2; |
helioslyons | 2:ef7f9892ba4f | 18 | _height = height; |
helioslyons | 2:ef7f9892ba4f | 19 | _width = width; |
helioslyons | 2:ef7f9892ba4f | 20 | _speed = 1; // init speed, add in options – accessible? |
helioslyons | 2:ef7f9892ba4f | 21 | _score = 0; // start all at 0 |
helioslyons | 2:ef7f9892ba4f | 22 | _inv1_kill = 0; |
helioslyons | 2:ef7f9892ba4f | 23 | _inv2_kill = 0; |
helioslyons | 2:ef7f9892ba4f | 24 | _inv3_kill = 0; |
helioslyons | 2:ef7f9892ba4f | 25 | _total_kill = 0; |
helioslyons | 2:ef7f9892ba4f | 26 | _life = 3; |
helioslyons | 2:ef7f9892ba4f | 27 | } |
helioslyons | 2:ef7f9892ba4f | 28 | |
helioslyons | 2:ef7f9892ba4f | 29 | void Canon::draw(N5110 &lcd) |
helioslyons | 2:ef7f9892ba4f | 30 | { |
helioslyons | 2:ef7f9892ba4f | 31 | // draw canon in screen buffer – need to replace with a different shape |
helioslyons | 2:ef7f9892ba4f | 32 | lcd.drawRect(_x,_y,_width,_height,FILL_BLACK); |
helioslyons | 2:ef7f9892ba4f | 33 | } |
helioslyons | 2:ef7f9892ba4f | 34 | |
helioslyons | 2:ef7f9892ba4f | 35 | void Canon::update(Direction d,float mag) |
helioslyons | 2:ef7f9892ba4f | 36 | { |
helioslyons | 2:ef7f9892ba4f | 37 | _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future – add in options menu |
helioslyons | 2:ef7f9892ba4f | 38 | |
helioslyons | 2:ef7f9892ba4f | 39 | // update x value based on direction |
helioslyons | 2:ef7f9892ba4f | 40 | // North is decrement as origin is at the top-left so decreasing moves up |
helioslyons | 2:ef7f9892ba4f | 41 | if (d == W) { |
helioslyons | 2:ef7f9892ba4f | 42 | _x-=_speed; |
helioslyons | 2:ef7f9892ba4f | 43 | } else if (d == E) { |
helioslyons | 2:ef7f9892ba4f | 44 | _x+=_speed; |
helioslyons | 2:ef7f9892ba4f | 45 | } |
helioslyons | 2:ef7f9892ba4f | 46 | |
helioslyons | 2:ef7f9892ba4f | 47 | // check the x origin to set boundaries |
helioslyons | 2:ef7f9892ba4f | 48 | if (_x < 1) { |
helioslyons | 2:ef7f9892ba4f | 49 | _x = 1; |
helioslyons | 2:ef7f9892ba4f | 50 | } |
helioslyons | 2:ef7f9892ba4f | 51 | if (_x > WIDTH - _width - 1) { |
helioslyons | 2:ef7f9892ba4f | 52 | _x = WIDTH - _width - 1; |
helioslyons | 2:ef7f9892ba4f | 53 | } |
helioslyons | 2:ef7f9892ba4f | 54 | } |
helioslyons | 2:ef7f9892ba4f | 55 | |
helioslyons | 2:ef7f9892ba4f | 56 | void Canon::add_inv1_kill() |
helioslyons | 2:ef7f9892ba4f | 57 | { |
helioslyons | 2:ef7f9892ba4f | 58 | _inv1_kill++; |
helioslyons | 2:ef7f9892ba4f | 59 | } |
helioslyons | 2:ef7f9892ba4f | 60 | |
helioslyons | 2:ef7f9892ba4f | 61 | void Canon::add_inv2_kill() |
helioslyons | 2:ef7f9892ba4f | 62 | { |
helioslyons | 2:ef7f9892ba4f | 63 | _inv2_kill++; |
helioslyons | 2:ef7f9892ba4f | 64 | } |
helioslyons | 2:ef7f9892ba4f | 65 | |
helioslyons | 2:ef7f9892ba4f | 66 | void Canon::add_inv3_kill() |
helioslyons | 2:ef7f9892ba4f | 67 | { |
helioslyons | 2:ef7f9892ba4f | 68 | _inv3_kill++; |
helioslyons | 2:ef7f9892ba4f | 69 | } |
helioslyons | 2:ef7f9892ba4f | 70 | |
helioslyons | 2:ef7f9892ba4f | 71 | void Canon::add_boss_kill() |
helioslyons | 2:ef7f9892ba4f | 72 | { |
helioslyons | 2:ef7f9892ba4f | 73 | _boss_kill++; |
helioslyons | 2:ef7f9892ba4f | 74 | } |
helioslyons | 2:ef7f9892ba4f | 75 | |
helioslyons | 2:ef7f9892ba4f | 76 | int Canon::get_total_kill() |
helioslyons | 2:ef7f9892ba4f | 77 | { |
helioslyons | 2:ef7f9892ba4f | 78 | _total_kill = _inv1_kill + _inv2_kill + _inv3_kill + _boss_kill; |
helioslyons | 2:ef7f9892ba4f | 79 | return _total_kill; |
helioslyons | 2:ef7f9892ba4f | 80 | |
helioslyons | 2:ef7f9892ba4f | 81 | int Canon::get_score() |
helioslyons | 2:ef7f9892ba4f | 82 | { |
helioslyons | 2:ef7f9892ba4f | 83 | _score = (_inv1_kill * 10) + (_inv2_kill * 20) + (_inv1_kill * 30) + (_boss_kill * 100); |
helioslyons | 2:ef7f9892ba4f | 84 | return _score; |
helioslyons | 2:ef7f9892ba4f | 85 | } |
helioslyons | 2:ef7f9892ba4f | 86 | |
helioslyons | 2:ef7f9892ba4f | 87 | Vector2D Canon::get_pos() { |
helioslyons | 2:ef7f9892ba4f | 88 | Vector2D p = {_x,_y}; |
helioslyons | 3:13fd052f79c6 | 89 | return p; |
helioslyons | 2:ef7f9892ba4f | 90 | } |
helioslyons | 2:ef7f9892ba4f | 91 | |
helioslyons | 2:ef7f9892ba4f | 92 | int Canon::get_life() |
helioslyons | 2:ef7f9892ba4f | 93 | { |
helioslyons | 2:ef7f9892ba4f | 94 | return _life; |
helioslyons | 2:ef7f9892ba4f | 95 | } |
helioslyons | 2:ef7f9892ba4f | 96 | |
helioslyons | 2:ef7f9892ba4f | 97 | int Canon::remove_life() |
helioslyons | 2:ef7f9892ba4f | 98 | { |
helioslyons | 2:ef7f9892ba4f | 99 | _life--; |
helioslyons | 2:ef7f9892ba4f | 100 | } |
helioslyons | 2:ef7f9892ba4f | 101 | |
helioslyons | 2:ef7f9892ba4f | 102 | int Canon::reset_life() |
helioslyons | 2:ef7f9892ba4f | 103 | { |
helioslyons | 2:ef7f9892ba4f | 104 | _life = 3; |
helioslyons | 2:ef7f9892ba4f | 105 | } |