| 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.ProjectileDestroyedEvent; | |
| 8 | import g0803.bindingofshiba.events.game.ProjectileSpawnedEvent; | |
| 9 | import g0803.bindingofshiba.gui.keyboard.Keyboard; | |
| 10 | import g0803.bindingofshiba.math.Vec2D; | |
| 11 | import g0803.bindingofshiba.model.game.Game; | |
| 12 | import g0803.bindingofshiba.model.game.elements.Projectile; | |
| 13 | ||
| 14 | public class ProjectileController extends Controller<Game> implements Observer { | |
| 15 | ||
| 16 | private double projectileCooldown = 0; | |
| 17 | ||
| 18 | public ProjectileController(Game model, IEventManager eventManager) { | |
| 19 | super(model, eventManager); | |
| 20 | ||
| 21 |
1
1. <init> : removed call to g0803/bindingofshiba/events/IEventManager::addObserver → SURVIVED |
getEventManager().addObserver(this); |
| 22 | } | |
| 23 | ||
| 24 | private void spawnProjectilesIfNeeded(App app, double dt) { | |
| 25 |
2
1. spawnProjectilesIfNeeded : changed conditional boundary → SURVIVED 2. spawnProjectilesIfNeeded : negated conditional → KILLED |
if (projectileCooldown > 0) return; |
| 26 | ||
| 27 | Keyboard keyboard = app.getKeyboard(); | |
| 28 | ||
| 29 | Vec2D direction = | |
| 30 | switch (keyboard.getPressedKey()) { | |
| 31 | case ARROW_UP -> Vec2D.up(); | |
| 32 | case ARROW_DOWN -> Vec2D.down(); | |
| 33 | case ARROW_LEFT -> Vec2D.left(); | |
| 34 | case ARROW_RIGHT -> Vec2D.right(); | |
| 35 | default -> null; | |
| 36 | }; | |
| 37 | ||
| 38 |
1
1. spawnProjectilesIfNeeded : negated conditional → KILLED |
if (direction == null) return; |
| 39 | ||
| 40 | Projectile projectile = | |
| 41 | new Projectile( | |
| 42 | getModel().getPlayer().getPosition().add(new Vec2D(0, -2)), | |
| 43 | getModel().getPlayer().getDamage()); | |
| 44 | Vec2D playerVelocity = getModel().getPlayer().getVelocity(); | |
| 45 | ||
| 46 |
2
1. spawnProjectilesIfNeeded : changed conditional boundary → SURVIVED 2. spawnProjectilesIfNeeded : negated conditional → KILLED |
if (playerVelocity.getLengthSquared() < 16) { |
| 47 | playerVelocity = Vec2D.zero(); | |
| 48 | } else { | |
| 49 | playerVelocity = playerVelocity.normalize(); | |
| 50 | } | |
| 51 | ||
| 52 |
1
1. spawnProjectilesIfNeeded : removed call to g0803/bindingofshiba/model/game/elements/Projectile::setVelocity → KILLED |
projectile.setVelocity(playerVelocity.add(direction.scale(4)).normalize().scale(20)); |
| 53 |
1
1. spawnProjectilesIfNeeded : removed call to g0803/bindingofshiba/model/game/room/Room::addProjectile → KILLED |
getModel().getCurrentRoom().addProjectile(projectile); |
| 54 | ||
| 55 | ProjectileSpawnedEvent event = | |
| 56 | new ProjectileSpawnedEvent(dt, app, projectile, getModel().getCurrentRoom()); | |
| 57 |
1
1. spawnProjectilesIfNeeded : removed call to g0803/bindingofshiba/events/IEventManager::dispatchEvent → SURVIVED |
getEventManager().dispatchEvent(event); |
| 58 | ||
| 59 | projectileCooldown = 0.8; | |
| 60 | } | |
| 61 | ||
| 62 | private void moveProjectiles(double dt) { | |
| 63 | for (Projectile projectile : getModel().getCurrentRoom().getProjectiles()) { | |
| 64 |
1
1. moveProjectiles : removed call to g0803/bindingofshiba/model/game/elements/Projectile::move → KILLED |
projectile.move(dt); |
| 65 | } | |
| 66 | } | |
| 67 | ||
| 68 | @Override | |
| 69 | public void tick(App app, double dt) { | |
| 70 | Keyboard keyboard = app.getKeyboard(); | |
| 71 |
1
1. tick : Replaced double subtraction with addition → KILLED |
projectileCooldown -= dt; |
| 72 | ||
| 73 |
1
1. tick : removed call to g0803/bindingofshiba/controller/game/ProjectileController::moveProjectiles → KILLED |
moveProjectiles(dt); |
| 74 |
1
1. tick : removed call to g0803/bindingofshiba/controller/game/ProjectileController::spawnProjectilesIfNeeded → KILLED |
spawnProjectilesIfNeeded(app, dt); |
| 75 | } | |
| 76 | ||
| 77 | @Override | |
| 78 | public void onProjectileDestroyed(ProjectileDestroyedEvent event) { | |
| 79 |
1
1. onProjectileDestroyed : removed call to g0803/bindingofshiba/model/game/room/Room::removeProjectile → NO_COVERAGE |
getModel().getCurrentRoom().removeProjectile(event.getProjectile()); |
| 80 | } | |
| 81 | } | |
Mutations | ||
| 21 |
1.1 |
|
| 25 |
1.1 2.2 |
|
| 38 |
1.1 |
|
| 46 |
1.1 2.2 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |
|
| 57 |
1.1 |
|
| 64 |
1.1 |
|
| 71 |
1.1 |
|
| 73 |
1.1 |
|
| 74 |
1.1 |
|
| 79 |
1.1 |