| 1 | package g0803.bindingofshiba.controller.game; | |
| 2 | ||
| 3 | import g0803.bindingofshiba.App; | |
| 4 | import g0803.bindingofshiba.controller.Controller; | |
| 5 | import g0803.bindingofshiba.events.IEventManager; | |
| 6 | import g0803.bindingofshiba.events.Observer; | |
| 7 | import g0803.bindingofshiba.events.game.*; | |
| 8 | import g0803.bindingofshiba.gui.keyboard.Keyboard; | |
| 9 | import g0803.bindingofshiba.math.BoundingBox; | |
| 10 | import g0803.bindingofshiba.math.Vec2D; | |
| 11 | import g0803.bindingofshiba.model.game.Game; | |
| 12 | import g0803.bindingofshiba.model.game.elements.Player; | |
| 13 | import g0803.bindingofshiba.model.game.room.Door; | |
| 14 | import g0803.bindingofshiba.model.game.room.Room; | |
| 15 | import g0803.bindingofshiba.state.end.GameOverState; | |
| 16 | ||
| 17 | public class PlayerController extends Controller<Game> implements Observer { | |
| 18 | ||
| 19 | public PlayerController(Game model, IEventManager eventManager) { | |
| 20 | super(model, eventManager); | |
| 21 |
1
1. <init> : removed call to g0803/bindingofshiba/events/IEventManager::addObserver → KILLED |
eventManager.addObserver(this); |
| 22 | } | |
| 23 | ||
| 24 | private Vec2D getNextPlayerAcceleration(Keyboard keyboard, Vec2D currentVelocity) { | |
| 25 | Vec2D direction = | |
| 26 | switch (keyboard.getPressedKey()) { | |
| 27 | case W -> Vec2D.up(); | |
| 28 | case S -> Vec2D.down(); | |
| 29 | case A -> Vec2D.left(); | |
| 30 | case D -> Vec2D.right(); | |
| 31 | default -> Vec2D.zero(); | |
| 32 | }; | |
| 33 | ||
| 34 | Vec2D force = direction.scale(200); | |
| 35 | Vec2D drag = currentVelocity.scale(4); | |
| 36 | ||
| 37 |
1
1. getNextPlayerAcceleration : replaced return value with null for g0803/bindingofshiba/controller/game/PlayerController::getNextPlayerAcceleration → KILLED |
return force.subtract(drag); |
| 38 | } | |
| 39 | ||
| 40 | @Override | |
| 41 | public void tick(App app, double dt) { | |
| 42 |
1
1. tick : removed call to g0803/bindingofshiba/model/game/elements/Player::move → KILLED |
getModel().getPlayer().move(dt); |
| 43 | getModel() | |
| 44 | .getPlayer() | |
| 45 |
1
1. tick : removed call to g0803/bindingofshiba/model/game/elements/Player::setAcceleration → KILLED |
.setAcceleration( |
| 46 | getNextPlayerAcceleration( | |
| 47 | app.getKeyboard(), getModel().getPlayer().getVelocity())); | |
| 48 | } | |
| 49 | ||
| 50 | @Override | |
| 51 | public void onPlayerCollisionWithMonster(PlayerCollisionWithMonsterEvent event) { | |
| 52 | Player player = event.getPlayer(); | |
| 53 |
1
1. onPlayerCollisionWithMonster : removed call to g0803/bindingofshiba/model/game/elements/Player::setAcceleration → KILLED |
player.setAcceleration(Vec2D.zero()); |
| 54 |
1
1. onPlayerCollisionWithMonster : removed call to g0803/bindingofshiba/model/game/elements/Player::setVelocity → KILLED |
player.setVelocity(Vec2D.zero()); |
| 55 | ||
| 56 |
1
1. onPlayerCollisionWithMonster : removed call to g0803/bindingofshiba/model/game/elements/Player::decreaseHpByAmount → SURVIVED |
player.decreaseHpByAmount(5); |
| 57 |
1
1. onPlayerCollisionWithMonster : negated conditional → SURVIVED |
if (!player.isAlive()) { |
| 58 |
1
1. onPlayerCollisionWithMonster : removed call to g0803/bindingofshiba/App::setState → SURVIVED |
event.getApp().setState(new GameOverState(false)); |
| 59 | } | |
| 60 | } | |
| 61 | ||
| 62 | @Override | |
| 63 | public void onPlayerCollisionWithObstacle(PlayerCollisionWithObstacleEvent event) { | |
| 64 | Player player = event.getPlayer(); | |
| 65 |
1
1. onPlayerCollisionWithObstacle : removed call to g0803/bindingofshiba/model/game/elements/Player::setAcceleration → KILLED |
player.setAcceleration(Vec2D.zero()); |
| 66 |
1
1. onPlayerCollisionWithObstacle : removed call to g0803/bindingofshiba/model/game/elements/Player::setVelocity → KILLED |
player.setVelocity(Vec2D.zero()); |
| 67 | } | |
| 68 | ||
| 69 | @Override | |
| 70 | public void onPlayerCollisionWithWalls(PlayerCollisionWithWallsEvent event) { | |
| 71 | Player player = event.getPlayer(); | |
| 72 |
1
1. onPlayerCollisionWithWalls : removed call to g0803/bindingofshiba/model/game/elements/Player::setAcceleration → KILLED |
player.setAcceleration(Vec2D.zero()); |
| 73 |
1
1. onPlayerCollisionWithWalls : removed call to g0803/bindingofshiba/model/game/elements/Player::setVelocity → KILLED |
player.setVelocity(Vec2D.zero()); |
| 74 | } | |
| 75 | ||
| 76 | @Override | |
| 77 | public void onPlayerEnterDoor(PlayerEnterDoorEvent event) { | |
| 78 | Room destination = event.getDoor().getOtherRoom(getModel().getCurrentRoom()); | |
| 79 | Door door = event.getDoor(); | |
| 80 | ||
| 81 | Vec2D position = door.getPositionByWall(destination); | |
| 82 |
2
1. onPlayerEnterDoor : Replaced double division with multiplication → SURVIVED 2. onPlayerEnterDoor : Replaced double division with multiplication → SURVIVED |
Vec2D roomCenter = new Vec2D(destination.getWidth() / 2D, destination.getHeight() / 2D); |
| 83 | ||
| 84 | BoundingBox playerBoundingBox = event.getApp().getBoundingBoxes().get("shiba"); | |
| 85 | Vec2D playerMidpoint = | |
| 86 | playerBoundingBox | |
| 87 | .getTopLeftCorner() | |
| 88 | .add(playerBoundingBox.getBottomRightCorner()) | |
| 89 | .scale(0.5); | |
| 90 | ||
| 91 | Vec2D playerPos = | |
| 92 | roomCenter | |
| 93 | .subtract(position) | |
| 94 | .normalize() | |
| 95 | .scale(10) | |
| 96 | .add(position) | |
| 97 | .subtract(playerMidpoint); | |
| 98 |
1
1. onPlayerEnterDoor : removed call to g0803/bindingofshiba/model/game/elements/Player::setPosition → KILLED |
event.getPlayer().setPosition(playerPos); |
| 99 |
1
1. onPlayerEnterDoor : removed call to g0803/bindingofshiba/model/game/elements/Player::setVelocity → KILLED |
event.getPlayer().setVelocity(Vec2D.zero()); |
| 100 | } | |
| 101 | ||
| 102 | @Override | |
| 103 | public void onPlayerUnlockDoor(PlayerUnlockDoorEvent event) { | |
| 104 |
1
1. onPlayerUnlockDoor : negated conditional → KILLED |
if (event.isCancelled()) return; |
| 105 | ||
| 106 | Player player = event.getPlayer(); | |
| 107 | ||
| 108 |
2
1. onPlayerUnlockDoor : changed conditional boundary → KILLED 2. onPlayerUnlockDoor : negated conditional → KILLED |
if (player.getNumberOfKeys() <= 0) { |
| 109 |
1
1. onPlayerUnlockDoor : removed call to g0803/bindingofshiba/events/game/PlayerUnlockDoorEvent::setCancelled → KILLED |
event.setCancelled(true); |
| 110 | return; | |
| 111 | } | |
| 112 | ||
| 113 |
1
1. onPlayerUnlockDoor : removed call to g0803/bindingofshiba/model/game/elements/Player::dropKey → KILLED |
player.dropKey(); |
| 114 | } | |
| 115 | ||
| 116 | @Override | |
| 117 | public void onMonsterDamaged(MonsterDamagedEvent event) { | |
| 118 |
2
1. onMonsterDamaged : negated conditional → NO_COVERAGE 2. onMonsterDamaged : removed call to g0803/bindingofshiba/model/game/elements/Player::pickKey → NO_COVERAGE |
if (!event.getMonster().isAlive()) getModel().getPlayer().pickKey(); |
| 119 | } | |
| 120 | } | |
Mutations | ||
| 21 |
1.1 |
|
| 37 |
1.1 |
|
| 42 |
1.1 |
|
| 45 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 56 |
1.1 |
|
| 57 |
1.1 |
|
| 58 |
1.1 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 82 |
1.1 2.2 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 104 |
1.1 |
|
| 108 |
1.1 2.2 |
|
| 109 |
1.1 |
|
| 113 |
1.1 |
|
| 118 |
1.1 2.2 |