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:
Wed May 27 23:24:11 2020 +0000
Revision:
7:b5ef03efe784
Parent:
6:98e08a6b385b
Child:
8:c5a8576b2e8d
Got splat working

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 2:b936aa854de2 6 Engine::Engine(){}
el18rg 2:b936aa854de2 7 Engine::~Engine(){}
el18rg 2:b936aa854de2 8
el18rg 2:b936aa854de2 9 void Engine::init(int paddle_width,int paddle_height,int ball_size,int speed)
el18rg 2:b936aa854de2 10 {
el18rg 2:b936aa854de2 11 width = paddle_width;
el18rg 2:b936aa854de2 12 height = paddle_height;
el18rg 2:b936aa854de2 13 _speed = speed;
el18rg 2:b936aa854de2 14 x = GAP;
el18rg 2:b936aa854de2 15 _cup.init(x,height,width);
el18rg 2:b936aa854de2 16 _ball.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 2:b936aa854de2 27 _ball.draw(lcd);
el18rg 2:b936aa854de2 28 _cup.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 2:b936aa854de2 33 _cup.update(_d,_mag);
el18rg 2:b936aa854de2 34 _ball.update();
el18rg 2:b936aa854de2 35 check_wall_collision(pad);
el18rg 7:b5ef03efe784 36 check_paddle_collisions(lcd, pad);
el18rg 2:b936aa854de2 37 }
el18rg 2:b936aa854de2 38 void Engine::check_wall_collision(Gamepad &pad)
el18rg 2:b936aa854de2 39 {
el18rg 2:b936aa854de2 40 Vector2D ball_pos = _ball.get_pos();
el18rg 2:b936aa854de2 41 Vector2D ball_velocity = _ball.get_velocity();
el18rg 2:b936aa854de2 42
el18rg 4:5cc1b81999a9 43 if (ball_pos.y <= 1) {
el18rg 4:5cc1b81999a9 44 ball_pos.y = 1;
el18rg 2:b936aa854de2 45 ball_velocity.y = -ball_velocity.y;
el18rg 6:98e08a6b385b 46 ball_velocity.x = rand() % 5;
el18rg 4:5cc1b81999a9 47
el18rg 2:b936aa854de2 48 pad.tone(750.0,0.1);
el18rg 2:b936aa854de2 49 }
el18rg 4:5cc1b81999a9 50 else if (ball_pos.y + 10 >= (HEIGHT-1) ) {
el18rg 4:5cc1b81999a9 51 ball_pos.y = (HEIGHT-1) - 10;
el18rg 4:5cc1b81999a9 52 ball_velocity.y = -ball_velocity.y ;
el18rg 6:98e08a6b385b 53 ball_velocity.x = rand() % 5;
el18rg 4:5cc1b81999a9 54 pad.tone(750.0,0.1);
el18rg 4:5cc1b81999a9 55 }
el18rg 4:5cc1b81999a9 56 if (ball_pos.x <= 1) {
el18rg 4:5cc1b81999a9 57 ball_pos.x = 1;
el18rg 4:5cc1b81999a9 58 ball_velocity.x = -ball_velocity.x;
el18rg 6:98e08a6b385b 59 ball_velocity.y = rand() % 5;
el18rg 4:5cc1b81999a9 60 pad.tone(750.0,0.1);
el18rg 4:5cc1b81999a9 61 }
el18rg 4:5cc1b81999a9 62 else if (ball_pos.x + 10 >= (WIDTH-1) ) {
el18rg 4:5cc1b81999a9 63 ball_pos.x = (WIDTH-1) - 10;
el18rg 4:5cc1b81999a9 64 ball_velocity.x = -ball_velocity.x ;
el18rg 6:98e08a6b385b 65 ball_velocity.y = rand() % 5;
el18rg 2:b936aa854de2 66 pad.tone(750.0,0.1);
el18rg 2:b936aa854de2 67 }
el18rg 2:b936aa854de2 68
el18rg 2:b936aa854de2 69 _ball.set_velocity(ball_velocity);
el18rg 2:b936aa854de2 70 _ball.set_pos(ball_pos);
el18rg 2:b936aa854de2 71 }
el18rg 7:b5ef03efe784 72 void Engine::check_paddle_collisions(N5110 & lcd, Gamepad & pad)
el18rg 2:b936aa854de2 73 {
el18rg 2:b936aa854de2 74 Vector2D ball_pos = _ball.get_pos();
el18rg 3:2f4a7787beb3 75 Vector2D p_pos = _cup.get_pos();
el18rg 6:98e08a6b385b 76 Vector2D ball_velocity = _ball.get_velocity();
el18rg 2:b936aa854de2 77
el18rg 6:98e08a6b385b 78 if ((ball_pos.x <= (p_pos.x + 5)) && (ball_pos.x +5 >= p_pos.x))
el18rg 3:2f4a7787beb3 79 {
el18rg 3:2f4a7787beb3 80 collisionX=true;
el18rg 3:2f4a7787beb3 81 }
el18rg 3:2f4a7787beb3 82 else
el18rg 3:2f4a7787beb3 83 {
el18rg 3:2f4a7787beb3 84 collisionX=false;
el18rg 3:2f4a7787beb3 85 }
el18rg 3:2f4a7787beb3 86
el18rg 6:98e08a6b385b 87 if ((ball_pos.y <= (p_pos.y+5)) && (ball_pos.y+5 >= p_pos.y ))
el18rg 3:2f4a7787beb3 88 {
el18rg 3:2f4a7787beb3 89 collisionY=true;
el18rg 3:2f4a7787beb3 90 }
el18rg 3:2f4a7787beb3 91 else
el18rg 3:2f4a7787beb3 92 {
el18rg 3:2f4a7787beb3 93 collisionY=false;
el18rg 2:b936aa854de2 94 }
el18rg 2:b936aa854de2 95
el18rg 3:2f4a7787beb3 96 if (collisionX && collisionY)
el18rg 3:2f4a7787beb3 97 {
el18rg 7:b5ef03efe784 98 ending(lcd, pad);
el18rg 3:2f4a7787beb3 99 }
el18rg 2:b936aa854de2 100 }
el18rg 7:b5ef03efe784 101 void Engine::ending(N5110 & lcd, Gamepad & pad)
el18rg 7:b5ef03efe784 102 {
el18rg 7:b5ef03efe784 103 lcd.clear();
el18rg 7:b5ef03efe784 104 pad.leds_on();
el18rg 7:b5ef03efe784 105 for (double t = 0; t < 100000; t += 0.1)
el18rg 7:b5ef03efe784 106 {
el18rg 7:b5ef03efe784 107 lcd.refresh();
el18rg 7:b5ef03efe784 108 _splat.draw(lcd);
el18rg 7:b5ef03efe784 109 }
el18rg 7:b5ef03efe784 110 }