| 1 | package io.github.some_example_name; | |
| 2 | ||
| 3 | import com.badlogic.gdx.math.Vector2; | |
| 4 | ||
| 5 | /** | |
| 6 | * Handles movement and interaction logic for Goose. | |
| 7 | */ | |
| 8 | public class GooseLogic { | |
| 9 | ||
| 10 | private Vector2 position; | |
| 11 | private float speed; | |
| 12 | private float stopDistance; | |
| 13 | private boolean fed; | |
| 14 | ||
| 15 | public GooseLogic(float x, float y, float speed, float stopDistance) { | |
| 16 | this.position = new Vector2(x, y); | |
| 17 | this.speed = speed; | |
| 18 | this.stopDistance = stopDistance; | |
| 19 | this.fed = false; | |
| 20 | } | |
| 21 | ||
| 22 | public void update(Vector2 playerPos, float delta, CellBlockChecker checker) { | |
| 23 |
1
1. update : negated conditional → KILLED |
if (fed) return; |
| 24 | ||
| 25 | float distance = position.dst(playerPos); | |
| 26 |
2
1. update : changed conditional boundary → SURVIVED 2. update : negated conditional → KILLED |
if (distance <= stopDistance) return; |
| 27 | ||
| 28 | Vector2 direction = new Vector2(playerPos).sub(position).nor(); | |
| 29 | ||
| 30 |
3
1. update : Replaced float multiplication with division → SURVIVED 2. update : Replaced float multiplication with division → SURVIVED 3. update : Replaced float addition with subtraction → KILLED |
float newX = position.x + direction.x * speed * delta; |
| 31 |
3
1. update : Replaced float multiplication with division → SURVIVED 2. update : Replaced float addition with subtraction → SURVIVED 3. update : Replaced float multiplication with division → SURVIVED |
float newY = position.y + direction.y * speed * delta; |
| 32 | ||
| 33 |
1
1. update : negated conditional → KILLED |
if (!checker.isCellBlocked(newX, newY)) { |
| 34 | position.set(newX, newY); | |
| 35 | } | |
| 36 | } | |
| 37 | ||
| 38 | public boolean caughtPlayer(Vector2 playerPos) { | |
| 39 |
3
1. caughtPlayer : changed conditional boundary → SURVIVED 2. caughtPlayer : negated conditional → KILLED 3. caughtPlayer : replaced boolean return with true for io/github/some_example_name/GooseLogic::caughtPlayer → KILLED |
return position.dst(playerPos) <= stopDistance; |
| 40 | } | |
| 41 | ||
| 42 | public void feed() { | |
| 43 | fed = true; | |
| 44 | } | |
| 45 | ||
| 46 | public void reduceStopDistance() { | |
| 47 | stopDistance = 5f; | |
| 48 | } | |
| 49 | ||
| 50 | public Vector2 getPosition() { | |
| 51 |
1
1. getPosition : replaced return value with null for io/github/some_example_name/GooseLogic::getPosition → KILLED |
return position; |
| 52 | } | |
| 53 | ||
| 54 | public boolean isFed() { | |
| 55 |
2
1. isFed : replaced boolean return with true for io/github/some_example_name/GooseLogic::isFed → KILLED 2. isFed : replaced boolean return with false for io/github/some_example_name/GooseLogic::isFed → KILLED |
return fed; |
| 56 | } | |
| 57 | } | |
Mutations | ||
| 23 |
1.1 |
|
| 26 |
1.1 2.2 |
|
| 30 |
1.1 2.2 3.3 |
|
| 31 |
1.1 2.2 3.3 |
|
| 33 |
1.1 |
|
| 39 |
1.1 2.2 3.3 |
|
| 51 |
1.1 |
|
| 55 |
1.1 2.2 |