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.PlayerCollisionWithMonsterEvent; | |
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.Player; | |
12 | import java.util.ArrayList; | |
13 | import java.util.List; | |
14 | ||
15 | public class PlayerToMonsterCollisionEventsController extends Controller<Game> { | |
16 | ||
17 | public PlayerToMonsterCollisionEventsController(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<Monster> monsters = getModel().getCurrentRoom().getMonsters(); | |
26 | ArrayList<PlayerCollisionWithMonsterEvent> eventsToDispatch = new ArrayList<>(); | |
27 | ||
28 | BoundingBox playerBox = boundingBoxes.get("shiba"); | |
29 | BoundingBox playerBoundingBox = playerBox.translate(player.getNextPosition(dt)); | |
30 | ||
31 | BoundingBox monsterBox = boundingBoxes.get("monster"); | |
32 | for (Monster monster : monsters) { | |
33 | BoundingBox monsterBoundingBox = monsterBox.translate(monster.getNextPosition(dt)); | |
34 | ||
35 |
1
1. tick : negated conditional → KILLED |
if (playerBoundingBox.collides(monsterBoundingBox)) |
36 | eventsToDispatch.add(new PlayerCollisionWithMonsterEvent(dt, app, player, monster)); | |
37 | } | |
38 | ||
39 | for (PlayerCollisionWithMonsterEvent event : eventsToDispatch) | |
40 |
1
1. tick : removed call to g0803/bindingofshiba/events/IEventManager::dispatchEvent → KILLED |
getEventManager().dispatchEvent(event); |
41 | } | |
42 | } | |
Mutations | ||
35 |
1.1 |
|
40 |
1.1 |