| 1 | package g0803.bindingofshiba.controller.game.events; | |
| 2 | ||
| 3 | import g0803.bindingofshiba.App; | |
| 4 | import g0803.bindingofshiba.bundles.Bundle; | |
| 5 | import g0803.bindingofshiba.controller.Controller; | |
| 6 | import g0803.bindingofshiba.events.IEventManager; | |
| 7 | import g0803.bindingofshiba.events.game.ProjectileDestroyedEvent; | |
| 8 | import g0803.bindingofshiba.math.BoundingBox; | |
| 9 | import g0803.bindingofshiba.model.game.Game; | |
| 10 | import g0803.bindingofshiba.model.game.elements.Obstacle; | |
| 11 | import g0803.bindingofshiba.model.game.elements.Projectile; | |
| 12 | import java.util.ArrayList; | |
| 13 | import java.util.List; | |
| 14 | import java.util.Set; | |
| 15 | ||
| 16 | public class ProjectileToStaticElementsCollisionEventsController extends Controller<Game> { | |
| 17 | ||
| 18 | public ProjectileToStaticElementsCollisionEventsController( | |
| 19 | Game model, IEventManager eventManager) { | |
| 20 | super(model, eventManager); | |
| 21 | } | |
| 22 | ||
| 23 | private void handleCollisionsWithRoom(App app, double dt) { | |
| 24 | Bundle<BoundingBox> boundingBoxes = app.getBoundingBoxes(); | |
| 25 | Set<Projectile> projectiles = getModel().getCurrentRoom().getProjectiles(); | |
| 26 | ArrayList<ProjectileDestroyedEvent> eventsToDispatch = new ArrayList<>(); | |
| 27 | ||
| 28 | BoundingBox projectileBox = boundingBoxes.get("heart"); | |
| 29 | BoundingBox roomBox = boundingBoxes.get("room"); | |
| 30 | ||
| 31 | for (Projectile projectile : projectiles) { | |
| 32 | BoundingBox projectileBoundingBox = | |
| 33 | projectileBox.translate(projectile.getNextPosition(dt)); | |
| 34 | ||
| 35 |
1
1. handleCollisionsWithRoom : negated conditional → KILLED |
if (!roomBox.contains(projectileBoundingBox)) |
| 36 | eventsToDispatch.add( | |
| 37 | new ProjectileDestroyedEvent( | |
| 38 | dt, app, projectile, getModel().getCurrentRoom())); | |
| 39 | } | |
| 40 | ||
| 41 | for (ProjectileDestroyedEvent event : eventsToDispatch) | |
| 42 |
1
1. handleCollisionsWithRoom : removed call to g0803/bindingofshiba/events/IEventManager::dispatchEvent → KILLED |
getEventManager().dispatchEvent(event); |
| 43 | } | |
| 44 | ||
| 45 | private void handleCollisionsWithObstacles(App app, double dt) { | |
| 46 | Bundle<BoundingBox> boundingBoxes = app.getBoundingBoxes(); | |
| 47 | ||
| 48 | Set<Projectile> projectiles = getModel().getCurrentRoom().getProjectiles(); | |
| 49 | List<Obstacle> obstacles = getModel().getCurrentRoom().getObstacles(); | |
| 50 | ||
| 51 | ArrayList<ProjectileDestroyedEvent> eventsToDispatch = new ArrayList<>(); | |
| 52 | ||
| 53 | BoundingBox projectileBox = boundingBoxes.get("heart"); | |
| 54 | BoundingBox obstacleBox = boundingBoxes.get("rock"); | |
| 55 | ||
| 56 | for (Projectile projectile : projectiles) { | |
| 57 | BoundingBox projectileBoundingBox = | |
| 58 | projectileBox.translate(projectile.getNextPosition(dt)); | |
| 59 | ||
| 60 | for (Obstacle obstacle : obstacles) { | |
| 61 | BoundingBox obstacleBoundingBox = obstacleBox.translate(obstacle.getPosition()); | |
| 62 | ||
| 63 |
1
1. handleCollisionsWithObstacles : negated conditional → KILLED |
if (obstacleBoundingBox.collides(projectileBoundingBox)) |
| 64 | eventsToDispatch.add( | |
| 65 | new ProjectileDestroyedEvent( | |
| 66 | dt, app, projectile, getModel().getCurrentRoom())); | |
| 67 | } | |
| 68 | } | |
| 69 | ||
| 70 | for (ProjectileDestroyedEvent event : eventsToDispatch) | |
| 71 |
1
1. handleCollisionsWithObstacles : removed call to g0803/bindingofshiba/events/IEventManager::dispatchEvent → KILLED |
getEventManager().dispatchEvent(event); |
| 72 | } | |
| 73 | ||
| 74 | @Override | |
| 75 | public void tick(App app, double dt) { | |
| 76 |
1
1. tick : removed call to g0803/bindingofshiba/controller/game/events/ProjectileToStaticElementsCollisionEventsController::handleCollisionsWithRoom → KILLED |
handleCollisionsWithRoom(app, dt); |
| 77 |
1
1. tick : removed call to g0803/bindingofshiba/controller/game/events/ProjectileToStaticElementsCollisionEventsController::handleCollisionsWithObstacles → KILLED |
handleCollisionsWithObstacles(app, dt); |
| 78 | } | |
| 79 | } | |
Mutations | ||
| 35 |
1.1 |
|
| 42 |
1.1 |
|
| 63 |
1.1 |
|
| 71 |
1.1 |
|
| 76 |
1.1 |
|
| 77 |
1.1 |