| 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.MonsterCollisionWithObstacleEvent; | |
| 8 | import g0803.bindingofshiba.math.BoundingBox; | |
| 9 | import g0803.bindingofshiba.model.game.Game; | |
| 10 | import g0803.bindingofshiba.model.game.elements.Monster; | |
| 11 | import g0803.bindingofshiba.model.game.elements.Obstacle; | |
| 12 | import java.util.ArrayList; | |
| 13 | import java.util.List; | |
| 14 | ||
| 15 | public class MonsterToObstacleCollisionEventsController extends Controller<Game> { | |
| 16 | ||
| 17 | public MonsterToObstacleCollisionEventsController(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 | List<Monster> monsters = getModel().getCurrentRoom().getMonsters(); | |
| 25 | List<Obstacle> obstacles = getModel().getCurrentRoom().getObstacles(); | |
| 26 | ArrayList<MonsterCollisionWithObstacleEvent> eventsToDispatch = new ArrayList<>(); | |
| 27 | ||
| 28 | BoundingBox monsterBox = boundingBoxes.get("monster"); | |
| 29 | BoundingBox obstacleBox = boundingBoxes.get("rock"); | |
| 30 | for (Monster monster : monsters) { | |
| 31 | BoundingBox monsterBoundingBox = monsterBox.translate(monster.getNextPosition(dt)); | |
| 32 | ||
| 33 | for (Obstacle obstacle : obstacles) { | |
| 34 | BoundingBox obstacleBoundingBox = obstacleBox.translate(obstacle.getPosition()); | |
| 35 | ||
| 36 |
1
1. tick : negated conditional → KILLED |
if (monsterBoundingBox.collides(obstacleBoundingBox)) |
| 37 | eventsToDispatch.add( | |
| 38 | new MonsterCollisionWithObstacleEvent(dt, app, monster, obstacle)); | |
| 39 | } | |
| 40 | } | |
| 41 | ||
| 42 | for (MonsterCollisionWithObstacleEvent event : eventsToDispatch) | |
| 43 |
1
1. tick : removed call to g0803/bindingofshiba/events/IEventManager::dispatchEvent → KILLED |
getEventManager().dispatchEvent(event); |
| 44 | } | |
| 45 | } | |
Mutations | ||
| 36 |
1.1 |
|
| 43 |
1.1 |