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 8:ec4199484adf 1 #ifndef BATTLE_H
helioslyons 8:ec4199484adf 2 #define BATTLE_H
helioslyons 8:ec4199484adf 3
helioslyons 8:ec4199484adf 4 #include "mbed.h"
helioslyons 8:ec4199484adf 5 #include "N5110.h"
helioslyons 8:ec4199484adf 6 #include "Gamepad.h"
helioslyons 11:1fd8fca23375 7
helioslyons 8:ec4199484adf 8 #include "Canon.h"
helioslyons 8:ec4199484adf 9 #include "Invader.h"
helioslyons 8:ec4199484adf 10 #include "Army.h"
helioslyons 10:19b250c7de5e 11 #include "Bullet.h"
helioslyons 10:19b250c7de5e 12
helioslyons 10:19b250c7de5e 13 #include <vector>
helioslyons 10:19b250c7de5e 14
helioslyons 11:1fd8fca23375 15 /** Battle.h
helioslyons 11:1fd8fca23375 16 * @brief Main engine for the game, instatiates canon and army objects
helioslyons 11:1fd8fca23375 17 * @author Helios A. Lyons
helioslyons 11:1fd8fca23375 18 * @date May, 2020
helioslyons 11:1fd8fca23375 19 */
helioslyons 11:1fd8fca23375 20
helioslyons 11:1fd8fca23375 21 using namespace std;
helioslyons 11:1fd8fca23375 22 extern std::vector<std::vector<Invader*> > invaders;
helioslyons 8:ec4199484adf 23
helioslyons 8:ec4199484adf 24 class Battle
helioslyons 8:ec4199484adf 25 {
helioslyons 8:ec4199484adf 26
helioslyons 8:ec4199484adf 27 public:
helioslyons 11:1fd8fca23375 28 /** Constructor */
helioslyons 8:ec4199484adf 29 Battle();
helioslyons 11:1fd8fca23375 30 /** Destructor */
helioslyons 8:ec4199484adf 31 ~Battle();
helioslyons 11:1fd8fca23375 32
helioslyons 13:1472c1637bfc 33 /** Rectangle struct */
helioslyons 11:1fd8fca23375 34 // Struct for bounding boxes – rectangles (canon, invaders, bullets)
helioslyons 11:1fd8fca23375 35 // Idea taken from https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection
helioslyons 11:1fd8fca23375 36 struct Rectangle
helioslyons 11:1fd8fca23375 37 {
helioslyons 11:1fd8fca23375 38 Rectangle(int x, int y, int w, int h) : x(x), y(y), width(w), height(h) {}
helioslyons 11:1fd8fca23375 39 int x;
helioslyons 11:1fd8fca23375 40 int y;
helioslyons 11:1fd8fca23375 41 int width;
helioslyons 11:1fd8fca23375 42 int height;
helioslyons 11:1fd8fca23375 43 };
helioslyons 11:1fd8fca23375 44 /** Initialises variables
helioslyons 11:1fd8fca23375 45 * @param value for invader vector (int), speed (int), interval (int), boss (bool), and boss number (int)
helioslyons 11:1fd8fca23375 46 */
helioslyons 11:1fd8fca23375 47 void init(int rows, int columns, int speed, int interval, bool boss, int bossNum);
helioslyons 11:1fd8fca23375 48
helioslyons 11:1fd8fca23375 49 /** Reads input
helioslyons 11:1fd8fca23375 50 * @param gamepad input (struct)
helioslyons 11:1fd8fca23375 51 */
helioslyons 11:1fd8fca23375 52 void read_input(Gamepad &pad);
helioslyons 11:1fd8fca23375 53
helioslyons 11:1fd8fca23375 54 /** Updates positions for canon and bullets
helioslyons 11:1fd8fca23375 55 * @param current positions (vector)
helioslyons 11:1fd8fca23375 56 */
helioslyons 11:1fd8fca23375 57 void update(Gamepad &pad);
helioslyons 11:1fd8fca23375 58
helioslyons 11:1fd8fca23375 59 /** Draws contents to LCD
helioslyons 11:1fd8fca23375 60 * @param bitmap and position values (bit, int)
helioslyons 11:1fd8fca23375 61 */
helioslyons 11:1fd8fca23375 62 void draw(N5110 &lcd);
helioslyons 11:1fd8fca23375 63
helioslyons 11:1fd8fca23375 64 /** Resets variables and vectors
helioslyons 11:1fd8fca23375 65 * @param vectors and variables to reset (int, bool, vector)
helioslyons 11:1fd8fca23375 66 */
helioslyons 11:1fd8fca23375 67 void reset(); // frees memory
helioslyons 11:1fd8fca23375 68
helioslyons 11:1fd8fca23375 69 /** Returns battle end condition
helioslyons 11:1fd8fca23375 70 * @return boolean end condition
helioslyons 11:1fd8fca23375 71 */
helioslyons 11:1fd8fca23375 72 bool end();
helioslyons 11:1fd8fca23375 73
helioslyons 11:1fd8fca23375 74 /** Returns lives
helioslyons 11:1fd8fca23375 75 * @return player lives remaining
helioslyons 11:1fd8fca23375 76 */
helioslyons 11:1fd8fca23375 77 int life();
helioslyons 11:1fd8fca23375 78
helioslyons 11:1fd8fca23375 79 /** Resets player lives
helioslyons 11:1fd8fca23375 80 * @param player life from canon.h
helioslyons 11:1fd8fca23375 81 */
helioslyons 11:1fd8fca23375 82 void reset_life();
helioslyons 11:1fd8fca23375 83
helioslyons 11:1fd8fca23375 84 /** Defines bullet vector 'bullets'
helioslyons 11:1fd8fca23375 85 * @param vector of bullet object pointers
helioslyons 11:1fd8fca23375 86 */
helioslyons 11:1fd8fca23375 87 vector<Bullet*> Bullets;
helioslyons 11:1fd8fca23375 88
helioslyons 11:1fd8fca23375 89 /** Defines bullet vector 'bombs'
helioslyons 11:1fd8fca23375 90 * @param vector of bullet object pointers
helioslyons 11:1fd8fca23375 91 */
helioslyons 11:1fd8fca23375 92 vector<Bullet*> Bombs;
helioslyons 11:1fd8fca23375 93
helioslyons 11:1fd8fca23375 94 Ticker t;
helioslyons 11:1fd8fca23375 95
helioslyons 11:1fd8fca23375 96 /** Starts invader firing
helioslyons 11:1fd8fca23375 97 * @param invader_fire() method to certain time interval
helioslyons 11:1fd8fca23375 98 */
helioslyons 11:1fd8fca23375 99 void clock(Gamepad &pad);
helioslyons 11:1fd8fca23375 100
helioslyons 11:1fd8fca23375 101 bool _boss;
helioslyons 11:1fd8fca23375 102 bool _end;
helioslyons 11:1fd8fca23375 103 bool _dead;
helioslyons 11:1fd8fca23375 104 int _speed;
helioslyons 11:1fd8fca23375 105
helioslyons 11:1fd8fca23375 106 private:
helioslyons 11:1fd8fca23375 107
helioslyons 9:6a245c8ce08e 108 void invader_fire();
helioslyons 10:19b250c7de5e 109 void canon_fire(Gamepad &pad);
helioslyons 11:1fd8fca23375 110 void projectile_edge();
helioslyons 8:ec4199484adf 111
helioslyons 11:1fd8fca23375 112 bool colTest(Rectangle r1, Rectangle r2);
helioslyons 11:1fd8fca23375 113 void bullet_collision(Gamepad &pad);
helioslyons 11:1fd8fca23375 114 void bomb_collision(Gamepad &pad);
helioslyons 11:1fd8fca23375 115 void canon_collision(Gamepad &pad);
helioslyons 11:1fd8fca23375 116
helioslyons 8:ec4199484adf 117 int _x;
helioslyons 9:6a245c8ce08e 118 int _interval;
helioslyons 11:1fd8fca23375 119 int _rows;
helioslyons 11:1fd8fca23375 120 int _columns;
helioslyons 8:ec4199484adf 121
helioslyons 8:ec4199484adf 122 Canon _canon;
helioslyons 10:19b250c7de5e 123 Army _army;
helioslyons 8:ec4199484adf 124
helioslyons 8:ec4199484adf 125 Direction _d;
helioslyons 8:ec4199484adf 126 float _mag;
helioslyons 8:ec4199484adf 127
helioslyons 8:ec4199484adf 128 };
helioslyons 8:ec4199484adf 129
helioslyons 8:ec4199484adf 130 #endif