1 | package g0803.bindingofshiba.controller.game; | |
2 | ||
3 | import g0803.bindingofshiba.App; | |
4 | import g0803.bindingofshiba.Constants; | |
5 | import g0803.bindingofshiba.controller.Controller; | |
6 | import g0803.bindingofshiba.events.IEventManager; | |
7 | import g0803.bindingofshiba.events.Observer; | |
8 | import g0803.bindingofshiba.events.game.*; | |
9 | import g0803.bindingofshiba.math.Vec2D; | |
10 | import g0803.bindingofshiba.model.game.Game; | |
11 | import g0803.bindingofshiba.model.game.elements.Monster; | |
12 | ||
13 | public class MonsterController extends Controller<Game> implements Observer { | |
14 | ||
15 | public MonsterController(Game model, IEventManager eventManager) { | |
16 | super(model, eventManager); | |
17 |
1
1. <init> : removed call to g0803/bindingofshiba/events/IEventManager::addObserver → KILLED |
eventManager.addObserver(this); |
18 | } | |
19 | ||
20 | private Vec2D getNextMonsterAcceleration(Monster monster) { | |
21 | Vec2D playerPosition = getModel().getPlayer().getPosition(); | |
22 | Vec2D seekVector = playerPosition.subtract(monster.getPosition()); | |
23 | Vec2D direction = seekVector.normalize(); | |
24 | ||
25 |
2
1. getNextMonsterAcceleration : changed conditional boundary → SURVIVED 2. getNextMonsterAcceleration : negated conditional → KILLED |
if (seekVector.getLengthSquared() < 225) direction = direction.scale(-1); |
26 | ||
27 | Vec2D force = direction.scale(4); | |
28 | Vec2D drag = monster.getVelocity().scale(0.25); | |
29 | ||
30 |
1
1. getNextMonsterAcceleration : replaced return value with null for g0803/bindingofshiba/controller/game/MonsterController::getNextMonsterAcceleration → KILLED |
return force.subtract(drag); |
31 | } | |
32 | ||
33 | @Override | |
34 | public void tick(App app, double dt) { | |
35 | for (Monster monster : getModel().getCurrentRoom().getMonsters()) { | |
36 |
1
1. tick : removed call to g0803/bindingofshiba/model/game/elements/Monster::move → KILLED |
monster.move(dt); |
37 |
1
1. tick : removed call to g0803/bindingofshiba/model/game/elements/Monster::setAcceleration → KILLED |
monster.setAcceleration(getNextMonsterAcceleration(monster)); |
38 | } | |
39 | } | |
40 | ||
41 | @Override | |
42 | public void onMonsterCollisionWithMonster(MonsterCollisionWithMonsterEvent event) { | |
43 | Monster monster = event.getFirstMonster(); | |
44 | Monster other = event.getSecondMonster(); | |
45 | double dt = event.getTickTime(); | |
46 | ||
47 | Vec2D monsterVelocity = monster.getNextVelocity(dt); | |
48 | Vec2D otherVelocity = other.getNextVelocity(dt); | |
49 | ||
50 | Vec2D tangent = other.getNextPosition(dt).subtract(monster.getNextPosition(dt)).normalize(); | |
51 | Vec2D normal = tangent.rotate(Math.PI / 2); | |
52 | ||
53 | double monsterTangent = monsterVelocity.scalarProduct(tangent); | |
54 | double monsterNormal = monsterVelocity.scalarProduct(normal); | |
55 | double otherTangent = otherVelocity.scalarProduct(tangent); | |
56 | double otherNormal = otherVelocity.scalarProduct(normal); | |
57 | ||
58 | Vec2D monsterResultingNormal = normal.scale(monsterNormal); | |
59 |
1
1. onMonsterCollisionWithMonster : Replaced double multiplication with division → SURVIVED |
Vec2D monsterResultingTangent = |
60 | tangent.scale(otherTangent * Constants.MONSTER_COLLISION_ELASTICITY); | |
61 | Vec2D otherResultingNormal = normal.scale(otherNormal); | |
62 |
1
1. onMonsterCollisionWithMonster : Replaced double multiplication with division → SURVIVED |
Vec2D otherResultingTangent = |
63 | tangent.scale(monsterTangent * Constants.MONSTER_COLLISION_ELASTICITY); | |
64 | ||
65 |
1
1. onMonsterCollisionWithMonster : removed call to g0803/bindingofshiba/model/game/elements/Monster::setVelocity → KILLED |
monster.setVelocity(monsterResultingNormal.add(monsterResultingTangent)); |
66 |
1
1. onMonsterCollisionWithMonster : removed call to g0803/bindingofshiba/model/game/elements/Monster::setVelocity → KILLED |
other.setVelocity(otherResultingNormal.add(otherResultingTangent)); |
67 | } | |
68 | ||
69 | @Override | |
70 | public void onPlayerCollisionWithMonster(PlayerCollisionWithMonsterEvent event) { | |
71 | Monster monster = event.getMonster(); | |
72 |
1
1. onPlayerCollisionWithMonster : removed call to g0803/bindingofshiba/model/game/elements/Monster::setAcceleration → KILLED |
monster.setAcceleration(Vec2D.zero()); |
73 |
1
1. onPlayerCollisionWithMonster : removed call to g0803/bindingofshiba/model/game/elements/Monster::setVelocity → KILLED |
monster.setVelocity(Vec2D.zero()); |
74 | } | |
75 | ||
76 | @Override | |
77 | public void onMonsterCollisionWithObstacle(MonsterCollisionWithObstacleEvent event) { | |
78 | Monster monster = event.getMonster(); | |
79 |
1
1. onMonsterCollisionWithObstacle : removed call to g0803/bindingofshiba/model/game/elements/Monster::setAcceleration → KILLED |
monster.setAcceleration(Vec2D.zero()); |
80 |
1
1. onMonsterCollisionWithObstacle : removed call to g0803/bindingofshiba/model/game/elements/Monster::setVelocity → KILLED |
monster.setVelocity(Vec2D.zero()); |
81 | } | |
82 | ||
83 | @Override | |
84 | public void onMonsterCollisionWithWalls(MonsterCollisionWithWallsEvent event) { | |
85 | Monster monster = event.getMonster(); | |
86 |
1
1. onMonsterCollisionWithWalls : removed call to g0803/bindingofshiba/model/game/elements/Monster::setAcceleration → KILLED |
monster.setAcceleration(Vec2D.zero()); |
87 |
1
1. onMonsterCollisionWithWalls : removed call to g0803/bindingofshiba/model/game/elements/Monster::setVelocity → KILLED |
monster.setVelocity(Vec2D.zero()); |
88 | } | |
89 | ||
90 | @Override | |
91 | public void onProjectileCollisionWithMonster(ProjectileCollisionWithMonsterEvent event) { | |
92 | Monster monster = event.getMonster(); | |
93 | ||
94 | double startingHp = monster.getHp(); | |
95 |
1
1. onProjectileCollisionWithMonster : removed call to g0803/bindingofshiba/model/game/elements/Monster::decreaseHpByAmount → KILLED |
monster.decreaseHpByAmount(event.getProjectile().getDamage()); |
96 | double endingHp = monster.getHp(); | |
97 | ||
98 |
1
1. onProjectileCollisionWithMonster : negated conditional → KILLED |
if (startingHp != endingHp) { |
99 | MonsterDamagedEvent newEvent = | |
100 | new MonsterDamagedEvent( | |
101 | event.getTickTime(), | |
102 | event.getApp(), | |
103 | monster, | |
104 |
1
1. onProjectileCollisionWithMonster : Replaced double subtraction with addition → KILLED |
getModel().getCurrentRoom(), |
105 | startingHp - endingHp); | |
106 | ||
107 |
1
1. onProjectileCollisionWithMonster : removed call to g0803/bindingofshiba/events/IEventManager::dispatchEvent → KILLED |
getEventManager().dispatchEvent(newEvent); |
108 | } | |
109 | } | |
110 | } | |
Mutations | ||
17 |
1.1 |
|
25 |
1.1 2.2 |
|
30 |
1.1 |
|
36 |
1.1 |
|
37 |
1.1 |
|
59 |
1.1 |
|
62 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
72 |
1.1 |
|
73 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
95 |
1.1 |
|
98 |
1.1 |
|
104 |
1.1 |
|
107 |
1.1 |