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:
Mon May 18 18:14:35 2020 +0000
Revision:
10:19b250c7de5e
Parent:
1:a3f43007030e
Child:
11:1fd8fca23375
Helios Lyons 201239214

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 0:b7f1f47bb26a 1 /*
eencae 0:b7f1f47bb26a 2 ELEC2645 Embedded Systems Project
eencae 0:b7f1f47bb26a 3 School of Electronic & Electrical Engineering
eencae 0:b7f1f47bb26a 4 University of Leeds
eencae 0:b7f1f47bb26a 5 2019/20
eencae 0:b7f1f47bb26a 6
helioslyons 1:a3f43007030e 7 Name: Helios Ael Lyons
helioslyons 1:a3f43007030e 8 Username: mc18hal
helioslyons 1:a3f43007030e 9 Student ID Number: 201239214
helioslyons 1:a3f43007030e 10 Date: 24th March 2020
helioslyons 1:a3f43007030e 11 */
helioslyons 1:a3f43007030e 12
helioslyons 1:a3f43007030e 13 /** Main
helioslyons 1:a3f43007030e 14 * @brief Main game functions and loop
helioslyons 1:a3f43007030e 15 * @author Helios A. Lyons
helioslyons 1:a3f43007030e 16 * @date March, 2020
eencae 0:b7f1f47bb26a 17 */
eencae 0:b7f1f47bb26a 18
helioslyons 10:19b250c7de5e 19 ///////// pre-processor directives ////////
eencae 0:b7f1f47bb26a 20 #include "mbed.h"
eencae 0:b7f1f47bb26a 21 #include "Gamepad.h"
eencae 0:b7f1f47bb26a 22 #include "N5110.h"
helioslyons 10:19b250c7de5e 23 #include "Battle.h"
helioslyons 10:19b250c7de5e 24
helioslyons 10:19b250c7de5e 25 #define PADDLE_WIDTH 2
helioslyons 10:19b250c7de5e 26 #define PADDLE_HEIGHT 8
helioslyons 10:19b250c7de5e 27 #define BALL_SIZE 2
helioslyons 10:19b250c7de5e 28 #define BALL_SPEED 3
helioslyons 10:19b250c7de5e 29
helioslyons 10:19b250c7de5e 30 // structs
helioslyons 10:19b250c7de5e 31 struct UserInput {
helioslyons 10:19b250c7de5e 32 Direction d;
helioslyons 10:19b250c7de5e 33 float mag;
helioslyons 10:19b250c7de5e 34 };
helioslyons 10:19b250c7de5e 35 // objects
helioslyons 10:19b250c7de5e 36 N5110 lcd;
helioslyons 10:19b250c7de5e 37 Gamepad pad;
helioslyons 10:19b250c7de5e 38 Battle battle;
helioslyons 10:19b250c7de5e 39
helioslyons 10:19b250c7de5e 40 // prototypes
helioslyons 10:19b250c7de5e 41 void init();
helioslyons 10:19b250c7de5e 42 void update_game(UserInput input);
helioslyons 10:19b250c7de5e 43 void render();
helioslyons 10:19b250c7de5e 44 void welcome();
helioslyons 10:19b250c7de5e 45
helioslyons 10:19b250c7de5e 46 // functions
helioslyons 10:19b250c7de5e 47 int main()
helioslyons 10:19b250c7de5e 48 {
helioslyons 10:19b250c7de5e 49 int fps = 6; // frames per second
helioslyons 10:19b250c7de5e 50
helioslyons 10:19b250c7de5e 51 init(); // initialise and then display welcome screen...
helioslyons 10:19b250c7de5e 52 welcome(); // waiting for the user to start
helioslyons 10:19b250c7de5e 53
helioslyons 10:19b250c7de5e 54 render(); // first draw the initial frame
helioslyons 10:19b250c7de5e 55 wait(1.0f/fps); // and wait for one frame period
eencae 0:b7f1f47bb26a 56
eencae 0:b7f1f47bb26a 57
helioslyons 10:19b250c7de5e 58 // game loop - read input, update the game state and render the display
helioslyons 10:19b250c7de5e 59 while (1) {
helioslyons 10:19b250c7de5e 60 //battle.read_input(pad);
helioslyons 10:19b250c7de5e 61 //battle.update(pad);
helioslyons 10:19b250c7de5e 62 render();
helioslyons 10:19b250c7de5e 63 wait(1.0f/fps);
helioslyons 10:19b250c7de5e 64 }
helioslyons 10:19b250c7de5e 65 }
eencae 0:b7f1f47bb26a 66
helioslyons 10:19b250c7de5e 67 // initialies all classes and libraries
helioslyons 10:19b250c7de5e 68 void init()
eencae 0:b7f1f47bb26a 69 {
helioslyons 10:19b250c7de5e 70 // need to initialise LCD and Gamepad
helioslyons 10:19b250c7de5e 71 lcd.init();
helioslyons 10:19b250c7de5e 72 pad.init();
helioslyons 10:19b250c7de5e 73
helioslyons 10:19b250c7de5e 74 // initialise the game
helioslyons 10:19b250c7de5e 75 //battle.init();
helioslyons 10:19b250c7de5e 76
eencae 0:b7f1f47bb26a 77 }
eencae 0:b7f1f47bb26a 78
helioslyons 10:19b250c7de5e 79 // this function draws each frame on the LCD
helioslyons 10:19b250c7de5e 80 void render()
helioslyons 10:19b250c7de5e 81 {
helioslyons 10:19b250c7de5e 82 // clear screen, re-draw and refresh
helioslyons 10:19b250c7de5e 83 lcd.clear();
helioslyons 10:19b250c7de5e 84 //battle.draw(lcd);
helioslyons 10:19b250c7de5e 85 lcd.refresh();
helioslyons 10:19b250c7de5e 86 }
helioslyons 10:19b250c7de5e 87
helioslyons 10:19b250c7de5e 88 // simple splash screen displayed on start-up
helioslyons 10:19b250c7de5e 89 void welcome() {
helioslyons 10:19b250c7de5e 90
helioslyons 10:19b250c7de5e 91 lcd.printString("Space Invaders",0,1);
helioslyons 10:19b250c7de5e 92 lcd.printString(" Press Start ",0,4);
helioslyons 10:19b250c7de5e 93 lcd.refresh();
helioslyons 10:19b250c7de5e 94
helioslyons 10:19b250c7de5e 95 // wait flashing LEDs until start button is pressed
helioslyons 10:19b250c7de5e 96 while ( pad.start_pressed() == false) {
helioslyons 10:19b250c7de5e 97 lcd.setContrast( pad.read_pot1());
helioslyons 10:19b250c7de5e 98 pad.leds_on();
helioslyons 10:19b250c7de5e 99 wait(0.1);
helioslyons 10:19b250c7de5e 100 pad.leds_off();
helioslyons 10:19b250c7de5e 101 wait(0.1);
helioslyons 10:19b250c7de5e 102 }
helioslyons 10:19b250c7de5e 103
helioslyons 10:19b250c7de5e 104 }