| 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.PlayerCollisionWithObstacleEvent; | |
| 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.Player; | |
| 12 | import java.util.ArrayList; | |
| 13 | import java.util.List; | |
| 14 | ||
| 15 | public class PlayerToObstacleCollisionEventsController extends Controller<Game> { | |
| 16 | ||
| 17 | public PlayerToObstacleCollisionEventsController(Game model, IEventManager eventManager) { | |
| 18 | super(model, eventManager); | |
| 19 | } | |
| 20 | ||
| 21 | @Override | |
| 22 | public void tick(App app, double dt) { | |
| 23 | Bundle<BoundingBox> boundingBoxes = app.getBoundingBoxes(); | |
| 24 | Player player = getModel().getPlayer(); | |
| 25 | List<Obstacle> obstacles = getModel().getCurrentRoom().getObstacles(); | |
| 26 | ArrayList<PlayerCollisionWithObstacleEvent> eventsToDispatch = new ArrayList<>(); | |
| 27 | ||
| 28 | BoundingBox playerBox = boundingBoxes.get("shiba"); | |
| 29 | BoundingBox playerBoundingBox = playerBox.translate(player.getNextPosition(dt)); | |
| 30 | ||
| 31 | BoundingBox obstacleBox = boundingBoxes.get("rock"); | |
| 32 | for (Obstacle obstacle : obstacles) { | |
| 33 | BoundingBox obstacleBoundingBox = obstacleBox.translate(obstacle.getPosition()); | |
| 34 | ||
| 35 |
1
1. tick : negated conditional → KILLED |
if (playerBoundingBox.collides(obstacleBoundingBox)) |
| 36 | eventsToDispatch.add( | |
| 37 | new PlayerCollisionWithObstacleEvent(dt, app, player, obstacle)); | |
| 38 | } | |
| 39 | ||
| 40 | for (PlayerCollisionWithObstacleEvent event : eventsToDispatch) | |
| 41 |
1
1. tick : removed call to g0803/bindingofshiba/events/IEventManager::dispatchEvent → KILLED |
getEventManager().dispatchEvent(event); |
| 42 | } | |
| 43 | } | |
Mutations | ||
| 35 |
1.1 |
|
| 41 |
1.1 |