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:
Thu May 28 21:11:27 2020 +0000
Revision:
11:93da75c1849d
Parent:
10:b6e45e4acde7
Child:
13:09bc615e6665
Neaten 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18rg 2:b936aa854de2 1 #include "Engine.h"
el18rg 2:b936aa854de2 2 #include "mbed.h"
el18rg 2:b936aa854de2 3 #include "Gamepad.h"
el18rg 2:b936aa854de2 4 #include "N5110.h"
el18rg 2:b936aa854de2 5
el18rg 11:93da75c1849d 6 Engine::Engine() {}
el18rg 11:93da75c1849d 7 Engine::~Engine() {}
el18rg 2:b936aa854de2 8
el18rg 11:93da75c1849d 9 void Engine::init(int swatter_width,int swatter_height,int speed)
el18rg 2:b936aa854de2 10 {
el18rg 11:93da75c1849d 11 width = swatter_width;
el18rg 11:93da75c1849d 12 height = swatter_height;
el18rg 2:b936aa854de2 13 _speed = speed;
el18rg 2:b936aa854de2 14 x = GAP;
el18rg 10:b6e45e4acde7 15 _swatter.init(x,height,width);
el18rg 9:e7dce4de0910 16 _bug.init(_speed);
el18rg 2:b936aa854de2 17 }
el18rg 2:b936aa854de2 18
el18rg 2:b936aa854de2 19 void Engine::read_input(Gamepad &pad)
el18rg 2:b936aa854de2 20 {
el18rg 2:b936aa854de2 21 _d = pad.get_direction();
el18rg 2:b936aa854de2 22 _mag = pad.get_mag();
el18rg 2:b936aa854de2 23 }
el18rg 2:b936aa854de2 24
el18rg 2:b936aa854de2 25 void Engine::draw(N5110 &lcd)
el18rg 2:b936aa854de2 26 {
el18rg 9:e7dce4de0910 27 _bug.draw(lcd);
el18rg 10:b6e45e4acde7 28 _swatter.draw(lcd);
el18rg 2:b936aa854de2 29 }
el18rg 2:b936aa854de2 30
el18rg 7:b5ef03efe784 31 void Engine::update(N5110 & lcd, Gamepad & pad)
el18rg 2:b936aa854de2 32 {
el18rg 10:b6e45e4acde7 33 _swatter.update(_d,_mag);
el18rg 9:e7dce4de0910 34 _bug.update();
el18rg 2:b936aa854de2 35 check_wall_collision(pad);
el18rg 11:93da75c1849d 36 check_swatter_collisions(lcd, pad);
el18rg 2:b936aa854de2 37 }
el18rg 2:b936aa854de2 38 void Engine::check_wall_collision(Gamepad &pad)
el18rg 2:b936aa854de2 39 {
el18rg 9:e7dce4de0910 40 Vector2D bug_pos = _bug.get_pos();
el18rg 9:e7dce4de0910 41 Vector2D bug_velocity = _bug.get_velocity();
el18rg 2:b936aa854de2 42
el18rg 11:93da75c1849d 43 if (bug_pos.y <= 1) {
el18rg 11:93da75c1849d 44 bug_pos.y = 1;
el18rg 9:e7dce4de0910 45 bug_velocity.y = -bug_velocity.y;
el18rg 11:93da75c1849d 46 bug_velocity.x = rand() % 5;
el18rg 11:93da75c1849d 47
el18rg 2:b936aa854de2 48 pad.tone(750.0,0.1);
el18rg 11:93da75c1849d 49 } else if (bug_pos.y + 10 >= (HEIGHT-1) ) {
el18rg 9:e7dce4de0910 50 bug_pos.y = (HEIGHT-1) - 10;
el18rg 9:e7dce4de0910 51 bug_velocity.y = -bug_velocity.y ;
el18rg 11:93da75c1849d 52 bug_velocity.x = rand() % 5;
el18rg 4:5cc1b81999a9 53 pad.tone(750.0,0.1);
el18rg 4:5cc1b81999a9 54 }
el18rg 11:93da75c1849d 55 if (bug_pos.x <= 1) {
el18rg 11:93da75c1849d 56 bug_pos.x = 1;
el18rg 9:e7dce4de0910 57 bug_velocity.x = -bug_velocity.x;
el18rg 11:93da75c1849d 58 bug_velocity.y = rand() % 5;
el18rg 4:5cc1b81999a9 59 pad.tone(750.0,0.1);
el18rg 11:93da75c1849d 60 } else if (bug_pos.x + 10 >= (WIDTH-1) ) {
el18rg 9:e7dce4de0910 61 bug_pos.x = (WIDTH-1) - 10;
el18rg 9:e7dce4de0910 62 bug_velocity.x = -bug_velocity.x ;
el18rg 11:93da75c1849d 63 bug_velocity.y = rand() % 5;
el18rg 2:b936aa854de2 64 pad.tone(750.0,0.1);
el18rg 2:b936aa854de2 65 }
el18rg 2:b936aa854de2 66
el18rg 9:e7dce4de0910 67 _bug.set_velocity(bug_velocity);
el18rg 9:e7dce4de0910 68 _bug.set_pos(bug_pos);
el18rg 2:b936aa854de2 69 }
el18rg 11:93da75c1849d 70 void Engine::check_swatter_collisions(N5110 & lcd, Gamepad & pad)
el18rg 2:b936aa854de2 71 {
el18rg 9:e7dce4de0910 72 Vector2D bug_pos = _bug.get_pos();
el18rg 10:b6e45e4acde7 73 Vector2D p_pos = _swatter.get_pos();
el18rg 9:e7dce4de0910 74 Vector2D bug_velocity = _bug.get_velocity();
el18rg 11:93da75c1849d 75
el18rg 11:93da75c1849d 76 if ((bug_pos.x <= (p_pos.x + 5)) && (bug_pos.x +5 >= p_pos.x)) {
el18rg 3:2f4a7787beb3 77 collisionX=true;
el18rg 11:93da75c1849d 78 } else {
el18rg 3:2f4a7787beb3 79 collisionX=false;
el18rg 3:2f4a7787beb3 80 }
el18rg 11:93da75c1849d 81
el18rg 11:93da75c1849d 82 if ((bug_pos.y <= (p_pos.y+5)) && (bug_pos.y+5 >= p_pos.y )) {
el18rg 3:2f4a7787beb3 83 collisionY=true;
el18rg 11:93da75c1849d 84 } else {
el18rg 3:2f4a7787beb3 85 collisionY=false;
el18rg 2:b936aa854de2 86 }
el18rg 11:93da75c1849d 87
el18rg 11:93da75c1849d 88 if (collisionX && collisionY) {
el18rg 7:b5ef03efe784 89 ending(lcd, pad);
el18rg 11:93da75c1849d 90 }
el18rg 2:b936aa854de2 91 }
el18rg 7:b5ef03efe784 92 void Engine::ending(N5110 & lcd, Gamepad & pad)
el18rg 7:b5ef03efe784 93 {
el18rg 7:b5ef03efe784 94 lcd.clear();
el18rg 7:b5ef03efe784 95 pad.leds_on();
el18rg 11:93da75c1849d 96 for (double i = 0; i < 100000; i += 0.1) {
el18rg 11:93da75c1849d 97 lcd.refresh();
el18rg 11:93da75c1849d 98 _splat.draw(lcd);
el18rg 7:b5ef03efe784 99 }
el18rg 7:b5ef03efe784 100 }