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.MonsterCollisionWithWallsEvent; | |
8 | import g0803.bindingofshiba.math.BoundingBox; | |
9 | import g0803.bindingofshiba.model.game.Game; | |
10 | import g0803.bindingofshiba.model.game.elements.Monster; | |
11 | import java.util.ArrayList; | |
12 | import java.util.List; | |
13 | ||
14 | public class MonsterToWallsCollisionEventsController extends Controller<Game> { | |
15 | ||
16 | public MonsterToWallsCollisionEventsController(Game model, IEventManager eventManager) { | |
17 | super(model, eventManager); | |
18 | } | |
19 | ||
20 | @Override | |
21 | public void tick(App app, double dt) { | |
22 | Bundle<BoundingBox> boundingBoxes = app.getBoundingBoxes(); | |
23 | List<Monster> monsters = getModel().getCurrentRoom().getMonsters(); | |
24 | ArrayList<MonsterCollisionWithWallsEvent> eventsToDispatch = new ArrayList<>(); | |
25 | ||
26 | BoundingBox monsterBox = boundingBoxes.get("monster"); | |
27 | BoundingBox roomBox = boundingBoxes.get("room"); | |
28 | for (Monster monster : monsters) { | |
29 | BoundingBox monsterBoundingBox = monsterBox.translate(monster.getNextPosition(dt)); | |
30 | ||
31 |
1
1. tick : negated conditional → KILLED |
if (!roomBox.contains(monsterBoundingBox)) |
32 | eventsToDispatch.add(new MonsterCollisionWithWallsEvent(dt, app, monster)); | |
33 | } | |
34 | ||
35 | for (MonsterCollisionWithWallsEvent event : eventsToDispatch) | |
36 |
1
1. tick : removed call to g0803/bindingofshiba/events/IEventManager::dispatchEvent → KILLED |
getEventManager().dispatchEvent(event); |
37 | } | |
38 | } | |
Mutations | ||
31 |
1.1 |
|
36 |
1.1 |