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.Event; | |
7 | import g0803.bindingofshiba.events.IEventManager; | |
8 | import g0803.bindingofshiba.events.game.ProjectileCollisionWithMonsterEvent; | |
9 | import g0803.bindingofshiba.events.game.ProjectileDestroyedEvent; | |
10 | import g0803.bindingofshiba.math.BoundingBox; | |
11 | import g0803.bindingofshiba.model.game.Game; | |
12 | import g0803.bindingofshiba.model.game.elements.Monster; | |
13 | import g0803.bindingofshiba.model.game.elements.Projectile; | |
14 | import java.util.ArrayList; | |
15 | import java.util.List; | |
16 | import java.util.Set; | |
17 | ||
18 | public class ProjectileToMonsterCollisionEventsController extends Controller<Game> { | |
19 | ||
20 | public ProjectileToMonsterCollisionEventsController(Game model, IEventManager eventManager) { | |
21 | super(model, eventManager); | |
22 | } | |
23 | ||
24 | @Override | |
25 | public void tick(App app, double dt) { | |
26 | Bundle<BoundingBox> boundingBoxes = app.getBoundingBoxes(); | |
27 | Set<Projectile> projectiles = getModel().getCurrentRoom().getProjectiles(); | |
28 | List<Monster> monsters = getModel().getCurrentRoom().getMonsters(); | |
29 | ||
30 | ArrayList<Event> eventsToDispatch = new ArrayList<>(); | |
31 | ||
32 | BoundingBox monsterBox = boundingBoxes.get("monster"); | |
33 | BoundingBox projectileBox = boundingBoxes.get("heart"); | |
34 | ||
35 | for (Projectile projectile : projectiles) { | |
36 | BoundingBox projectileBoundingBox = | |
37 | projectileBox.translate(projectile.getNextPosition(dt)); | |
38 | ||
39 | for (Monster monster : monsters) { | |
40 | BoundingBox monsterBoundingBox = monsterBox.translate(monster.getNextPosition(dt)); | |
41 | ||
42 |
1
1. tick : negated conditional → KILLED |
if (monsterBoundingBox.collides(projectileBoundingBox)) { |
43 | eventsToDispatch.add( | |
44 | new ProjectileCollisionWithMonsterEvent(dt, app, projectile, monster)); | |
45 | eventsToDispatch.add( | |
46 | new ProjectileDestroyedEvent( | |
47 | dt, app, projectile, getModel().getCurrentRoom())); | |
48 | } | |
49 | } | |
50 | } | |
51 | ||
52 |
1
1. tick : removed call to g0803/bindingofshiba/events/IEventManager::dispatchEvent → KILLED |
for (Event event : eventsToDispatch) getEventManager().dispatchEvent(event); |
53 | } | |
54 | } | |
Mutations | ||
42 |
1.1 |
|
52 |
1.1 |