summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/pacman/Pinky.java
blob: 344f55a231534916a3787d377716d22f21494553 (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
package ch.epfl.maze.physical.pacman;

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

/**
 * Pink ghost from the Pac-Man game, targets 4 squares in front of its target.
 *
 * @author EPFL
 * @author Pacien TRAN-GIRARD
 */
public class Pinky extends Ghost {

    private static final int TARGET_OFFSET = 4;

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

    /**
     * Targets the position the Prey is heading toward.
     *
     * @param daedalus The Daedalus
     * @return The projected position
     */
    @Override
    protected Vector2D getPreyTargetPosition(Daedalus daedalus) {
        Vector2D offsetVector = this.getTargetOffsetVector(this.getPreyDirection(daedalus));
        return this
                .getPreyPosition(daedalus)
                .add(offsetVector);
    }

    /**
     * Returns the offset vector directed to the given Direction.
     *
     * @param direction The Direction
     * @return The offset Vector2D
     */
    private Vector2D getTargetOffsetVector(Direction direction) {
        return (new Vector2D())
                .addDirectionTo(direction)
                .mul(TARGET_OFFSET);
    }

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

}