Rosie Gillman
Dependencies: mbed Gamepad2 ELEC2645_Project_el18rg
Dependents: ELEC2645_Project_el18rg
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
Instructions
- Turn the gamepad on
- Wait for start screen and press start
- Move the joystick to control the swatter
- Splat the bug as fast as you can
- 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
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
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
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
Engine/Engine.cpp@10:b6e45e4acde7, 2020-05-28 (annotated)
- Committer:
- el18rg
- Date:
- Thu May 28 20:56:57 2020 +0000
- Revision:
- 10:b6e45e4acde7
- Parent:
- 9:e7dce4de0910
- Child:
- 11:93da75c1849d
Changing cup(s) to swatter
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:e7dce4de0910 | 9 | void Engine::init(int paddle_width,int paddle_height,int bug_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 | 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 | 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 | 9:e7dce4de0910 | 40 | Vector2D bug_pos = _bug.get_pos(); |
el18rg | 9:e7dce4de0910 | 41 | Vector2D bug_velocity = _bug.get_velocity(); |
el18rg | 2:b936aa854de2 | 42 | |
el18rg | 9:e7dce4de0910 | 43 | if (bug_pos.y <= 1) { |
el18rg | 9:e7dce4de0910 | 44 | bug_pos.y = 1; |
el18rg | 9:e7dce4de0910 | 45 | bug_velocity.y = -bug_velocity.y; |
el18rg | 9:e7dce4de0910 | 46 | bug_velocity.x = rand() % 5; |
el18rg | 4:5cc1b81999a9 | 47 | |
el18rg | 2:b936aa854de2 | 48 | pad.tone(750.0,0.1); |
el18rg | 2:b936aa854de2 | 49 | } |
el18rg | 9:e7dce4de0910 | 50 | else if (bug_pos.y + 10 >= (HEIGHT-1) ) { |
el18rg | 9:e7dce4de0910 | 51 | bug_pos.y = (HEIGHT-1) - 10; |
el18rg | 9:e7dce4de0910 | 52 | bug_velocity.y = -bug_velocity.y ; |
el18rg | 9:e7dce4de0910 | 53 | bug_velocity.x = rand() % 5; |
el18rg | 4:5cc1b81999a9 | 54 | pad.tone(750.0,0.1); |
el18rg | 4:5cc1b81999a9 | 55 | } |
el18rg | 9:e7dce4de0910 | 56 | if (bug_pos.x <= 1) { |
el18rg | 9:e7dce4de0910 | 57 | bug_pos.x = 1; |
el18rg | 9:e7dce4de0910 | 58 | bug_velocity.x = -bug_velocity.x; |
el18rg | 9:e7dce4de0910 | 59 | bug_velocity.y = rand() % 5; |
el18rg | 4:5cc1b81999a9 | 60 | pad.tone(750.0,0.1); |
el18rg | 4:5cc1b81999a9 | 61 | } |
el18rg | 9:e7dce4de0910 | 62 | else if (bug_pos.x + 10 >= (WIDTH-1) ) { |
el18rg | 9:e7dce4de0910 | 63 | bug_pos.x = (WIDTH-1) - 10; |
el18rg | 9:e7dce4de0910 | 64 | bug_velocity.x = -bug_velocity.x ; |
el18rg | 9:e7dce4de0910 | 65 | bug_velocity.y = rand() % 5; |
el18rg | 2:b936aa854de2 | 66 | pad.tone(750.0,0.1); |
el18rg | 2:b936aa854de2 | 67 | } |
el18rg | 2:b936aa854de2 | 68 | |
el18rg | 9:e7dce4de0910 | 69 | _bug.set_velocity(bug_velocity); |
el18rg | 9:e7dce4de0910 | 70 | _bug.set_pos(bug_pos); |
el18rg | 2:b936aa854de2 | 71 | } |
el18rg | 7:b5ef03efe784 | 72 | void Engine::check_paddle_collisions(N5110 & lcd, Gamepad & pad) |
el18rg | 2:b936aa854de2 | 73 | { |
el18rg | 9:e7dce4de0910 | 74 | Vector2D bug_pos = _bug.get_pos(); |
el18rg | 10:b6e45e4acde7 | 75 | Vector2D p_pos = _swatter.get_pos(); |
el18rg | 9:e7dce4de0910 | 76 | Vector2D bug_velocity = _bug.get_velocity(); |
el18rg | 2:b936aa854de2 | 77 | |
el18rg | 9:e7dce4de0910 | 78 | if ((bug_pos.x <= (p_pos.x + 5)) && (bug_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 | 9:e7dce4de0910 | 87 | if ((bug_pos.y <= (p_pos.y+5)) && (bug_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 | 8:c5a8576b2e8d | 105 | for (double i = 0; i < 100000; i += 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 | } |