Introduce scatterTarget function and inline things that should be in the ghost

This commit is contained in:
Patricia Aas 2021-07-28 16:39:27 +02:00
parent f31d238bd4
commit 4d53ccce18
10 changed files with 56 additions and 35 deletions

View file

@ -16,16 +16,20 @@ double Blinky::speed(const GameState & gameState) const {
Position Blinky::target(const GameState & gameState) const {
if (state == State::Eyes)
return initialBlinkyPosition();
return initialPosition();
if (isInPen())
return penDoorPosition();
return blinkyScatterTarget();
return scatterTarget();
}
Position Blinky::initialPosition() const {
return initialBlinkyPosition();
return { 13.5, 11 };
}
Position Blinky::scatterTarget() const {
return { 25, -3 };
}
}

View file

@ -16,17 +16,20 @@ double Clyde::speed(const GameState & gameState) const {
Position Clyde::target(const GameState & gameState) const {
if (state == State::Eyes)
return initialClydePosition();
return initialPosition();
if (isInPen())
return penDoorPosition();
return clydeScatterTarget();
return scatterTarget();
}
Position Clyde::initialPosition() const {
return initialClydePosition();
return { 15.5, 14 };
}
Position Clyde::scatterTarget() const {
return { 0, 30 };
}
}

View file

@ -16,17 +16,20 @@ double Inky::speed(const GameState & gameState) const {
Position Inky::target(const GameState & gameState) const {
if (state == State::Eyes)
return initialInkyPosition();
return initialPosition();
if (isInPen())
return penDoorPosition();
return inkyScatterTarget();
return scatterTarget();
}
Position Inky::initialPosition() const {
return initialInkyPosition();
return { 13.5, 14 };
}
Position Inky::scatterTarget() const {
return { 27, 30 };
}
}

View file

@ -16,16 +16,20 @@ double Pinky::speed(const GameState & gameState) const {
Position Pinky::target(const GameState & gameState) const {
if (state == State::Eyes)
return initialPinkyPosition();
return initialPosition();
if (isInPen())
return penDoorPosition();
return pinkyScatterTarget();
return scatterTarget();
}
Position Pinky::initialPosition() const {
return initialPinkyPosition();
return { 11.5, 14 };
}
Position Pinky::scatterTarget() const {
return { 3, -2 };
}
}

View file

@ -6,10 +6,15 @@ namespace pacman {
class Blinky : public Ghost {
public:
explicit Blinky();
[[nodiscard]] double speed(const GameState & gameState) const override;
[[nodiscard]] Position target(const GameState & gameState) const override;
Blinky();
protected:
double speed(const GameState & gameState) const override;
Position target(const GameState & gameState) const override;
Position initialPosition() const override;
private:
Position scatterTarget() const;
};
} // namespace pacman

View file

@ -23,16 +23,4 @@ namespace pacman {
inline Position penDoorPosition() { return { 13, 11 }; }
inline Position initialPacManPosition() { return { 13.5, 23 }; }
inline Position initialBlinkyPosition() { return { 13.5, 11 }; }
inline Position blinkyScatterTarget() { return { 25, -3 }; }
inline Position initialPinkyPosition() { return { 11.5, 14 }; }
inline Position pinkyScatterTarget() { return { 3, -2 }; }
inline Position initialInkyPosition() { return { 13.5, 14 }; }
inline Position inkyScatterTarget() { return { 27, 30 }; }
inline Position initialClydePosition() { return { 15.5, 14 }; }
inline Position clydeScatterTarget() { return { 0, 30 }; }
} // namespace pacman
} // namespace pacman

View file

@ -7,9 +7,14 @@ namespace pacman {
class Clyde : public Ghost {
public:
explicit Clyde();
[[nodiscard]] double speed(const GameState & gameState) const override;
[[nodiscard]] Position target(const GameState & gameState) const override;
protected:
double speed(const GameState & gameState) const override;
Position target(const GameState & gameState) const override;
Position initialPosition() const override;
private:
Position scatterTarget() const;
};
} // namespace pacman

View file

@ -46,7 +46,6 @@ protected:
virtual Position target(const GameState & gameState) const = 0;
virtual Position initialPosition() const = 0;
Atlas::Ghost spritesSet;
Direction direction = Direction::NONE;
double timeForAnimation = 0;

View file

@ -7,9 +7,14 @@ namespace pacman {
class Inky : public Ghost {
public:
explicit Inky();
[[nodiscard]] double speed(const GameState & gameState) const override;
[[nodiscard]] Position target(const GameState & gameState) const override;
protected:
double speed(const GameState & gameState) const override;
Position target(const GameState & gameState) const override;
Position initialPosition() const override;
private:
Position scatterTarget() const;
};
} // namespace pacman

View file

@ -7,9 +7,14 @@ namespace pacman {
class Pinky : public Ghost {
public:
explicit Pinky();
[[nodiscard]] double speed(const GameState & gameState) const override;
[[nodiscard]] Position target(const GameState & gameState) const override;
protected:
double speed(const GameState & gameState) const override;
Position target(const GameState & gameState) const override;
Position initialPosition() const override;
private:
Position scatterTarget() const;
};
} // namespace pacman