summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/pacman/Clyde.java
blob: 40089db1373ca5092d98daa2f6767dc2ddd48e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package ch.epfl.maze.physical.pacman;

import ch.epfl.maze.physical.Animal;
import ch.epfl.maze.physical.Daedalus;
import ch.epfl.maze.physical.GhostPredator;
import ch.epfl.maze.util.Vector2D;

/**
 * Orange ghost from the Pac-Man game, alternates between direct chase if far
 * from its target and SCATTER if close.
 *
 * @author EPFL
 * @author Pacien TRAN-GIRARD
 */
public class Clyde extends GhostPredator {

    private static double PROXIMITY_THRESHOLD = 4.0d;

    /**
     * Constructs a Clyde with a starting position.
     *
     * @param position Starting position of Clyde in the labyrinth
     */
    public Clyde(Vector2D position) {
        super(position);
    }

    /**
     * Checks if Clyde is close to the targeted Prey.
     *
     * @param daedalus The Daedalus
     * @return T(the Prey is reckless)
     */
    private boolean closeToTarget(Daedalus daedalus) {
        double dist = this
                .getPosition()
                .sub(this.getPreyPosition(daedalus))
                .dist();

        return dist < Clyde.PROXIMITY_THRESHOLD;
    }

    /**
     * Returns the current Mode, forcing the SCATTER Mode if far from the target.
     *
     * @param daedalus The Daedalus
     * @return The current Mode
     */
    @Override
    protected Mode getMode(Daedalus daedalus) {
        return this.closeToTarget(daedalus) ? super.getMode(daedalus) : Mode.SCATTER;
    }

    /**
     * Targets directly the current position of the Prey.
     *
     * @param daedalus The Daedalus
     * @return The position of the Prey
     */
    @Override
    protected Vector2D getPreyTargetPosition(Daedalus daedalus) {
        return getPreyPosition(daedalus);
    }

    @Override
    public Animal copy() {
        return new Clyde(this.getPosition());
    }

}