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

Revision:
11:1fd8fca23375
Parent:
10:19b250c7de5e
Child:
13:1472c1637bfc
--- a/Battle/Battle.h	Mon May 18 18:14:35 2020 +0000
+++ b/Battle/Battle.h	Wed May 27 05:07:34 2020 +0000
@@ -4,6 +4,7 @@
 #include "mbed.h"
 #include "N5110.h"
 #include "Gamepad.h"
+
 #include "Canon.h"
 #include "Invader.h"
 #include "Army.h"
@@ -11,40 +12,117 @@
 
 #include <vector>
 
-#define SPACE 2
+/** Battle.h
+* @brief Main engine for the game, instatiates canon and army objects
+* @author Helios A. Lyons
+* @date May, 2020
+*/
+
+using namespace std;
+extern std::vector<std::vector<Invader*> > invaders;
  
 class Battle
 {
  
 public:
+    /** Constructor */
     Battle();
+    /** Destructor */
     ~Battle();
- 
-    void init(int invaders, int speed, int interval);
+    
+    /** Creates a rectangle
+    * @param rectangle (struct)
+    */
+    // Struct for bounding boxes – rectangles (canon, invaders, bullets)
+    // Idea taken from https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection
+    struct Rectangle
+    { 
+        Rectangle(int x, int y, int w, int h) : x(x), y(y), width(w), height(h) {}
+        int x;
+        int y;
+        int width;
+        int height;
+    };
+    /** Initialises variables
+    * @param value for invader vector (int), speed (int), interval (int), boss (bool), and boss number (int)
+    */
+    void init(int rows, int columns, int speed, int interval, bool boss, int bossNum);
+    
+    /** Reads input
+    * @param gamepad input (struct)
+    */
+    void read_input(Gamepad &pad);
+    
+    /** Updates positions for canon and bullets
+    * @param current positions (vector)
+    */
+    void update(Gamepad &pad);
+    
+    /** Draws contents to LCD
+    * @param bitmap and position values (bit, int)
+    */
+    void draw(N5110 &lcd);
+    
+    /** Resets variables and vectors
+    * @param vectors and variables to reset (int, bool, vector)
+    */
+    void reset(); // frees memory
+    
+    /** Returns battle end condition
+    * @return boolean end condition
+    */
+    bool end();
+    
+    /** Returns lives
+    * @return player lives remaining
+    */
+    int life();
+    
+    /** Resets player lives
+    * @param player life from canon.h
+    */
+    void reset_life();
+
+    /** Defines bullet vector 'bullets'
+    * @param vector of bullet object pointers
+    */
+    vector<Bullet*> Bullets;
+    
+    /** Defines bullet vector 'bombs'
+    * @param vector of bullet object pointers
+    */
+    vector<Bullet*> Bombs;
+    
+    Ticker t;
+    
+    /** Starts invader firing
+    * @param invader_fire() method to certain time interval
+    */
+    void clock(Gamepad &pad);
+    
+    bool _boss;
+    bool _end;
+    bool _dead;
+    int _speed;
+    
+private:
+
     void invader_fire();
     void canon_fire(Gamepad &pad);
-    void read_input(Gamepad &pad);
-    void update(Gamepad &pad);
-    void draw(N5110 &lcd);
-    void bullet_collisions();
-    
-    vector<Bullet> invBomb;
-    vector<Bullet> playBul;
+    void projectile_edge();
     
-private:
- 
-    void check_invader_hit(Gamepad &pad); 
-    void check_canon_hit(Gamepad &pad);
-    void print_score(N5110 &lcd);
-
-    int _speed;
+    bool colTest(Rectangle r1, Rectangle r2);
+    void bullet_collision(Gamepad &pad);
+    void bomb_collision(Gamepad &pad); 
+    void canon_collision(Gamepad &pad);
+    
     int _x;
     int _interval;
-    int _invaders;
+    int _rows;
+    int _columns;
     
     Canon _canon;
     Army _army;
-    Bullet _bullet;
     
     Direction _d;
     float _mag;