Rosie Gillman

Dependencies:   mbed Gamepad2 ELEC2645_Project_el18rg

Dependents:   ELEC2645_Project_el18rg

https://os.mbed.com/media/uploads/el18rg/bug_splat_logo.png

Rosemary Gillman 201265952

Objective

The goal of the game is to splat the bug as fast as you can using the swatter.

Controls

1 - Joystick - left/right to control the swatter 2 - Start button - starts the game 3 - Reset - resets the game 4 - Volume pot - adjusts the volume https://os.mbed.com/media/uploads/el18rg/buttons.png

Instructions

  1. Turn the gamepad on
  2. Wait for start screen and press start
  3. Move the joystick to control the swatter
  4. Splat the bug as fast as you can
  5. Press reset to play again

Gameplay

Start Screen 1

  • Low pad tone plays for 0.5s
  • Pad lights flash (200ms on/200ms off)
  • Text saying "Bug Splat Leeds Edition" is displayed
  • After 5 flashes the screen changes to Start Screen 2

https://os.mbed.com/media/uploads/el18rg/intro_screen1.jpg

Start Screen 2

  • Pad lights stay on constantly
  • Text reads "Splat the bug as fast as you can! Press start"
  • When start is pressed the screen changes to Gamplay Screen

https://os.mbed.com/media/uploads/el18rg/intro_screen_2.jpg

Gameplay Screen

  • The timer begins
  • Bug appears in the top right corner
  • Swatter appears in the bottom left corner
  • The bug bounces (with random velocity/direction) off the sides
  • When the bug bounces off the wall a low pad tone is played each time for 0.1 seconds
  • Swatter is controlled left to right with the joystick
  • When the bug and swatter overlap the screen changes to the Ending Screen

https://os.mbed.com/media/uploads/el18rg/gameplay.jpg

Ending Screen

  • Low pad tone plays for 0.5s
  • The timer ends and its value is displayed
  • Text reads "SPLAT (time) secs"
  • Splats are drawn on the screen https://os.mbed.com/media/uploads/el18rg/end_screen.jpg
Committer:
el18rg
Date:
Fri May 29 21:49:53 2020 +0000
Revision:
24:6e6bcdd22159
Parent:
23:aa2a10451586
Final Submission. I have read and agreed with Statement of Academic Integrity

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18rg 0:77899648f88b 1 /*
el18rg 2:b936aa854de2 2 ELEC2645 Embedded Systems Project
el18rg 2:b936aa854de2 3 School of Electronic & Electrical Engineering
el18rg 2:b936aa854de2 4 University of Leeds
el18rg 2:b936aa854de2 5 2019/20
el18rg 2:b936aa854de2 6
el18rg 2:b936aa854de2 7 Name: Rosemary Gillman
el18rg 2:b936aa854de2 8 Username: EL18RG
el18rg 2:b936aa854de2 9 Student ID Number: 201265952
el18rg 14:9b4a219dd91e 10 Date:20/03/20
el18rg 0:77899648f88b 11 */
el18rg 1:8fdb6a804c74 12
el18rg 15:4ed54ff548cf 13 /** pre-processor directives */
el18rg 0:77899648f88b 14 #include "mbed.h"
el18rg 0:77899648f88b 15 #include "Gamepad.h"
el18rg 0:77899648f88b 16 #include "N5110.h"
el18rg 10:b6e45e4acde7 17 #include "Swatter.h"
el18rg 9:e7dce4de0910 18 #include "Bug.h"
el18rg 2:b936aa854de2 19 #include "Engine.h"
el18rg 0:77899648f88b 20
el18rg 14:9b4a219dd91e 21 #define SWATTER_WIDTH 10
el18rg 14:9b4a219dd91e 22 #define SWATTER_HEIGHT 9
el18rg 9:e7dce4de0910 23 #define BUG_SPEED 3
el18rg 2:b936aa854de2 24
el18rg 24:6e6bcdd22159 25 #ifdef TESTING
el18rg 24:6e6bcdd22159 26 # include "tests.h"
el18rg 24:6e6bcdd22159 27 #endif
el18rg 24:6e6bcdd22159 28
el18rg 15:4ed54ff548cf 29 /** objects */
el18rg 0:77899648f88b 30 Gamepad pad;
el18rg 0:77899648f88b 31 N5110 lcd;
el18rg 2:b936aa854de2 32 Engine engine;
el18rg 2:b936aa854de2 33
el18rg 15:4ed54ff548cf 34 /** prototypes */
el18rg 2:b936aa854de2 35 void first_init();
el18rg 2:b936aa854de2 36 void start();
el18rg 2:b936aa854de2 37 void play_game();
el18rg 0:77899648f88b 38
el18rg 15:4ed54ff548cf 39 /** functions */
el18rg 0:77899648f88b 40 int main()
el18rg 0:77899648f88b 41 {
el18rg 24:6e6bcdd22159 42 #ifdef TESTING //running tests
el18rg 23:aa2a10451586 43 int fails = run_all_tests();
el18rg 19:bdfab290446a 44
el18rg 23:aa2a10451586 45 if(fails > 0) return nfails;
el18rg 19:bdfab290446a 46 #endif
el18rg 19:bdfab290446a 47
el18rg 19:bdfab290446a 48 first_init(); //first initilisation
el18rg 19:bdfab290446a 49 engine.timer(); //starts the timer
el18rg 19:bdfab290446a 50 start(); //runs the start screen
el18rg 19:bdfab290446a 51 while (1) { //while start is pressed
el18rg 19:bdfab290446a 52 engine.read_input(pad); //engine reads inputs
el18rg 19:bdfab290446a 53 engine.update(lcd, pad); //engine updates
el18rg 19:bdfab290446a 54 pad.leds_off(); //turns the leds off
el18rg 19:bdfab290446a 55 play_game(); //starts the gameplay
el18rg 19:bdfab290446a 56 wait_ms(80); //sets the fps
el18rg 2:b936aa854de2 57 }
el18rg 2:b936aa854de2 58 }
el18rg 2:b936aa854de2 59
el18rg 15:4ed54ff548cf 60 void first_init() //initilises the gamepad and screen
el18rg 2:b936aa854de2 61 {
el18rg 19:bdfab290446a 62 lcd.init(); //initalises the lcd
el18rg 19:bdfab290446a 63 pad.init(); //initlaises the gamepad
el18rg 19:bdfab290446a 64 engine.init(SWATTER_WIDTH,SWATTER_HEIGHT,BUG_SPEED); //initalises the engine with the input values
el18rg 2:b936aa854de2 65 }
el18rg 0:77899648f88b 66
el18rg 15:4ed54ff548cf 67 void play_game() //starts the game and timer
el18rg 2:b936aa854de2 68 {
el18rg 19:bdfab290446a 69 lcd.clear(); //clears the lcd
el18rg 19:bdfab290446a 70 engine.draw(lcd); //engine draws the gameplay
el18rg 19:bdfab290446a 71 lcd.refresh(); //refreshs the lcd
el18rg 2:b936aa854de2 72 }
el18rg 2:b936aa854de2 73
el18rg 15:4ed54ff548cf 74 void start() //displays the start screen
el18rg 2:b936aa854de2 75 {
el18rg 19:bdfab290446a 76 lcd.printString("Bug Splat",15,2); //lcd prints text
el18rg 19:bdfab290446a 77 lcd.printString("Leeds Edition",1,3); //lcd prints text
el18rg 19:bdfab290446a 78 lcd.refresh(); //lcd refreshes
el18rg 19:bdfab290446a 79 pad.tone(500.0,0.5); //low pad tone plays
el18rg 19:bdfab290446a 80 for (int i = 0; i < 5; i++) { //for loop flashes the leds
el18rg 0:77899648f88b 81 pad.leds_on();
el18rg 0:77899648f88b 82 wait_ms(200);
el18rg 0:77899648f88b 83 pad.leds_off();
el18rg 0:77899648f88b 84 wait_ms(200);
el18rg 0:77899648f88b 85 }
el18rg 19:bdfab290446a 86 pad.leds_off(); //leds are turned off
el18rg 19:bdfab290446a 87 lcd.clear(); //lcd is cleared
el18rg 19:bdfab290446a 88 lcd.refresh(); //lcd is refreshed
el18rg 19:bdfab290446a 89 lcd.printString("Splat the bug",0,0); //lcd prints text
el18rg 19:bdfab290446a 90 lcd.printString("as fast",0,1); //lcd prints text
el18rg 19:bdfab290446a 91 lcd.printString("as you can!",0,2); //lcd prints text
el18rg 19:bdfab290446a 92 lcd.printString("Press start",0,5); //lcd prints text
el18rg 19:bdfab290446a 93 lcd.refresh(); //lcd refreshes
el18rg 19:bdfab290446a 94 while ( pad.start_pressed() == false) { //when start is pressed lights turn off
el18rg 2:b936aa854de2 95 pad.leds_on();
el18rg 0:77899648f88b 96 }
el18rg 2:b936aa854de2 97 }