![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
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)
Revision 13:1472c1637bfc, committed 2020-05-27
- Comitter:
- helioslyons
- Date:
- Wed May 27 15:40:47 2020 +0000
- Parent:
- 12:5359c4a51dd3
- Commit message:
- Final Submission. I have read and agreed with Statement of Academic Integrity.
Changed in this revision
--- a/Battle/Battle.cpp Wed May 27 05:33:34 2020 +0000 +++ b/Battle/Battle.cpp Wed May 27 15:40:47 2020 +0000 @@ -53,14 +53,13 @@ lcd.refresh(); } -void Battle::clock(Gamepad &pad) // call invader fire at an interval of 2 +void Battle::clock(Gamepad &pad) // call invader fire at _interval passed into battle.h { t.attach(Callback<void()>(this, &Battle::invader_fire), _interval); } void Battle::update(Gamepad &pad) // update canon position and firing, { // and all projectile positions and collisions - //_army.move_army(); canon_fire(pad); _canon.update(_d,_mag);
--- a/Battle/Battle.h Wed May 27 05:33:34 2020 +0000 +++ b/Battle/Battle.h Wed May 27 15:40:47 2020 +0000 @@ -30,9 +30,7 @@ /** Destructor */ ~Battle(); - /** Creates a rectangle - * @param rectangle (struct) - */ + /** 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
--- a/main.cpp Wed May 27 05:33:34 2020 +0000 +++ b/main.cpp Wed May 27 15:40:47 2020 +0000 @@ -11,12 +11,21 @@ */ /** Main -* @brief Start screen, menu, and game loop +* @brief Start screen, menu, game loop, and time tracking. The start project Pong was used for the initial structuring and velocity systems it provided. * @author Helios A. Lyons * @date March, 2020 */ -///////// pre-processor directives //////// +// NOTE: the Battle.h API docs are not being recognised by Doxygen, though +// I have included the requisite code. Additionally, code was used from Mozilla +// to implement the rectangle based collision system in Battle.h (link below): +// https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection + +// KNOWN BUGS: On first play through, or when waves are played too quickly, the +// game recognises that the wave has ended, but does not load into the +// next. I am in the process of identifying the source of this. + +// pre-processor directives #include "mbed.h" #include "Gamepad.h" #include "N5110.h" @@ -42,9 +51,11 @@ void update_game(UserInput input); void render(); void welcome(); +void game(Gamepad &pad); void wave(int n); -void game(Gamepad &pad); +void waveState(int n, Gamepad &pad); void menu(Gamepad &pad); +void instructions(Gamepad &pad); // functions int main() @@ -66,85 +77,49 @@ switch(n) { case 1: // initialise entities for the wave battle.init(1,3,4,3,0,3); // row,column,speed,firing interval,boss,bossNum - battle.clock(pad); // start the invader firing pattern - wave(n); // print wave # - playTime.start(); // start timer before game starts - game(pad); // start the main game loop - playTime.stop(); // stop timer + waveState(n, pad); break; case 2: battle.init(3,3,4,3,0,3); // init function is used this way to provide - battle.clock(pad); // easy options to vary invader formation and number - wave(n); // in wave - playTime.start(); - game(pad); - playTime.stop(); - break; + waveState(n, pad); // easy options to vary invader formation and number + break; // in each wave, creating streamlined level design case 3: - battle.init(1,1,3,2,1,1); - battle.clock(pad); - wave(n); - playTime.start(); - game(pad); - playTime.stop(); - break; + battle.init(1,1,3,2,1,1); // in redesign, would likely implement a 2D vector + waveState(n, pad); // which stores each wave's information, and is run + break; // through using a for loop to fetch case 4: battle.init(2,3,3,3,0,1); - battle.clock(pad); - wave(n); - playTime.start(); - game(pad); - playTime.stop(); + waveState(n, pad); break; case 5: battle.init(3,3,3,3,0,1); - battle.clock(pad); - wave(n); - playTime.start(); - game(pad); - playTime.stop(); + waveState(n, pad); break; case 6: battle.init(1,1,2,1,1,2); - battle.clock(pad); - wave(n); - playTime.start(); - game(pad); - playTime.stop(); + waveState(n, pad); break; case 7: battle.init(3,4,2,3,0,2); - battle.clock(pad); - wave(n); - playTime.start(); - game(pad); - playTime.stop(); + waveState(n, pad); break; case 8: battle.init(3,6,3,2,0,2); - battle.clock(pad); - wave(n); - playTime.start(); - game(pad); - playTime.stop(); + waveState(n, pad); break; case 9: battle.init(1,1,1,1,1,3); - battle.clock(pad); - wave(n); - playTime.start(); - game(pad); - playTime.stop(); + waveState(n, pad); break; - } // end of switch statement + } } if (battle.life() < 1) { // if player failed display game over @@ -188,13 +163,14 @@ battle.update(pad); render(); wait(1.0f/fps); - if (battle.end() || battle.life() < 1 ) { break; } - } - lcd.clear(); + if (battle.end() || battle.life() < 1 ) { break; } // end condition based on + } // remaining invaders or number + lcd.clear(); // of lives left } void wave(int n) { // prints wave number and time taken so far lcd.clear(); + char buffer[14]; char buffer3[3]; int number = sprintf(buffer,"Wave%2d",n); @@ -205,6 +181,14 @@ lcd.refresh(); wait(3.0); } + +void waveState(int n, Gamepad &pad) { + battle.clock(pad); // start the invader firing pattern + wave(n); // print wave # + playTime.start(); // start timer before game starts + game(pad); // start the main game loop + playTime.stop(); // stop timer + } void welcome() { // bitmap logo and title for start screen static int logo[] = { @@ -252,35 +236,7 @@ lcd.refresh(); if (pad.X_pressed()) { - lcd.clear(); - lcd.printString("Press A",0,2); - lcd.printString("to shoot",0,3); - lcd.refresh(); - wait(5.0); - - lcd.clear(); - lcd.printString("Use the",0,1); - lcd.printString("joystick to",0,2); - lcd.printString("move left",0,3); - lcd.printString("or right",0,4); - lcd.refresh(); - wait(5.0); - - lcd.clear(); - lcd.printString("Remaining ",0,1); - lcd.printString("lives are on",0,2); - lcd.printString("the bottom",0,3); - lcd.printString("left",0,4); - lcd.refresh(); - wait(5.0); - - lcd.clear(); - lcd.printString("Elapsed time",0,1); - lcd.printString("is shown at",0,2); - lcd.printString("each wave",0,3); - lcd.printString("interval",0,4); - lcd.refresh(); - wait(5.0); + instructions(pad); } else if (pad.A_pressed()) { return; @@ -293,5 +249,36 @@ wait(5.0); } } - -} \ No newline at end of file +} + +void instructions(Gamepad &pad) { + lcd.clear(); + lcd.printString("Press A",0,2); + lcd.printString("to shoot",0,3); + lcd.refresh(); + wait(5.0); + + lcd.clear(); + lcd.printString("Use the",0,1); + lcd.printString("joystick to",0,2); + lcd.printString("move left",0,3); + lcd.printString("or right",0,4); + lcd.refresh(); + wait(5.0); + + lcd.clear(); + lcd.printString("Remaining ",0,1); + lcd.printString("lives are on",0,2); + lcd.printString("the bottom",0,3); + lcd.printString("left",0,4); + lcd.refresh(); + wait(5.0); + + lcd.clear(); + lcd.printString("Elapsed time",0,1); + lcd.printString("is shown at",0,2); + lcd.printString("each wave",0,3); + lcd.printString("interval",0,4); + lcd.refresh(); + wait(5.0); +} \ No newline at end of file