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 16:50:00 2020 +0000
Revision:
3:2f4a7787beb3
Parent:
2:b936aa854de2
Child:
4:5cc1b81999a9
Basic collision 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 // initialise the game parameters
el18rg 2:b936aa854de2 12 width = paddle_width;
el18rg 2:b936aa854de2 13 height = paddle_height;
el18rg 2:b936aa854de2 14 //_ball_size = ball_size;
el18rg 2:b936aa854de2 15 _speed = speed;
el18rg 2:b936aa854de2 16 x = GAP;
el18rg 2:b936aa854de2 17 _cup.init(x,height,width);
el18rg 2:b936aa854de2 18 _ball.init(_speed);
el18rg 2:b936aa854de2 19 }
el18rg 2:b936aa854de2 20
el18rg 2:b936aa854de2 21 void Engine::read_input(Gamepad &pad)
el18rg 2:b936aa854de2 22 {
el18rg 2:b936aa854de2 23 _d = pad.get_direction();
el18rg 2:b936aa854de2 24 _mag = pad.get_mag();
el18rg 2:b936aa854de2 25 }
el18rg 2:b936aa854de2 26
el18rg 2:b936aa854de2 27 void Engine::draw(N5110 &lcd)
el18rg 2:b936aa854de2 28 {
el18rg 2:b936aa854de2 29 _ball.draw(lcd);
el18rg 2:b936aa854de2 30 _cup.draw(lcd);
el18rg 2:b936aa854de2 31 }
el18rg 2:b936aa854de2 32
el18rg 2:b936aa854de2 33 void Engine::update(Gamepad &pad)
el18rg 2:b936aa854de2 34 {
el18rg 2:b936aa854de2 35 _cup.update(_d,_mag);
el18rg 2:b936aa854de2 36 _ball.update();
el18rg 2:b936aa854de2 37 check_wall_collision(pad);
el18rg 2:b936aa854de2 38 check_paddle_collisions(pad);
el18rg 2:b936aa854de2 39 }
el18rg 2:b936aa854de2 40 void Engine::check_wall_collision(Gamepad &pad)
el18rg 2:b936aa854de2 41 {
el18rg 2:b936aa854de2 42 // read current ball attributes
el18rg 2:b936aa854de2 43 Vector2D ball_pos = _ball.get_pos();
el18rg 2:b936aa854de2 44 Vector2D ball_velocity = _ball.get_velocity();
el18rg 2:b936aa854de2 45
el18rg 2:b936aa854de2 46 // check if hit top wall
el18rg 2:b936aa854de2 47 if (ball_pos.y <= 1) { // 1 due to 1 pixel boundary
el18rg 2:b936aa854de2 48 ball_pos.y = 1; // bounce off ceiling without going off screen
el18rg 2:b936aa854de2 49 ball_velocity.y = -ball_velocity.y;
el18rg 2:b936aa854de2 50 // audio feedback
el18rg 2:b936aa854de2 51 pad.tone(750.0,0.1);
el18rg 2:b936aa854de2 52 }
el18rg 2:b936aa854de2 53 // check if hit bottom wall
el18rg 2:b936aa854de2 54 else if (ball_pos.y + 10 >= (HEIGHT-1) ) { // bottom pixel is 47
el18rg 2:b936aa854de2 55 // hit bottom
el18rg 2:b936aa854de2 56 ball_pos.y = (HEIGHT-1) - 10; // stops ball going off screen
el18rg 2:b936aa854de2 57 ball_velocity.y = -ball_velocity.y;
el18rg 2:b936aa854de2 58 // audio feedback
el18rg 2:b936aa854de2 59 pad.tone(750.0,0.1);
el18rg 2:b936aa854de2 60 }
el18rg 2:b936aa854de2 61
el18rg 2:b936aa854de2 62 // update ball parameters
el18rg 2:b936aa854de2 63 _ball.set_velocity(ball_velocity);
el18rg 2:b936aa854de2 64 _ball.set_pos(ball_pos);
el18rg 2:b936aa854de2 65 }
el18rg 2:b936aa854de2 66 void Engine::check_paddle_collisions(Gamepad &pad)
el18rg 2:b936aa854de2 67 {
el18rg 2:b936aa854de2 68 Vector2D ball_pos = _ball.get_pos();
el18rg 3:2f4a7787beb3 69 Vector2D p_pos = _cup.get_pos();
el18rg 2:b936aa854de2 70
el18rg 3:2f4a7787beb3 71 if (ball_pos.x == p_pos.x )
el18rg 3:2f4a7787beb3 72 {
el18rg 3:2f4a7787beb3 73 collisionX=true;
el18rg 3:2f4a7787beb3 74 }
el18rg 3:2f4a7787beb3 75 else
el18rg 3:2f4a7787beb3 76 {
el18rg 3:2f4a7787beb3 77 collisionX=false;
el18rg 3:2f4a7787beb3 78 }
el18rg 3:2f4a7787beb3 79
el18rg 3:2f4a7787beb3 80 if (ball_pos.y +10 == p_pos.y )
el18rg 3:2f4a7787beb3 81 {
el18rg 3:2f4a7787beb3 82 collisionY=true;
el18rg 3:2f4a7787beb3 83 }
el18rg 3:2f4a7787beb3 84 else
el18rg 3:2f4a7787beb3 85 {
el18rg 3:2f4a7787beb3 86 collisionY=false;
el18rg 2:b936aa854de2 87 }
el18rg 2:b936aa854de2 88
el18rg 3:2f4a7787beb3 89 if (collisionX && collisionY)
el18rg 3:2f4a7787beb3 90 {
el18rg 3:2f4a7787beb3 91 pad.leds_on();
el18rg 3:2f4a7787beb3 92 wait_ms(100);
el18rg 3:2f4a7787beb3 93 pad.leds_off();
el18rg 3:2f4a7787beb3 94 }
el18rg 2:b936aa854de2 95 }