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 05:07:34 2020 +0000
Revision:
11:1fd8fca23375
Parent:
10:19b250c7de5e
Child:
13:1472c1637bfc
Helios A. Lyons 201239214;

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