Introduce scatterTarget function and inline things that should be in the ghost
This commit is contained in:
parent
f31d238bd4
commit
4d53ccce18
10 changed files with 56 additions and 35 deletions
|
@ -16,16 +16,20 @@ double Blinky::speed(const GameState & gameState) const {
|
||||||
|
|
||||||
Position Blinky::target(const GameState & gameState) const {
|
Position Blinky::target(const GameState & gameState) const {
|
||||||
if (state == State::Eyes)
|
if (state == State::Eyes)
|
||||||
return initialBlinkyPosition();
|
return initialPosition();
|
||||||
|
|
||||||
if (isInPen())
|
if (isInPen())
|
||||||
return penDoorPosition();
|
return penDoorPosition();
|
||||||
|
|
||||||
return blinkyScatterTarget();
|
return scatterTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
Position Blinky::initialPosition() const {
|
Position Blinky::initialPosition() const {
|
||||||
return initialBlinkyPosition();
|
return { 13.5, 11 };
|
||||||
|
}
|
||||||
|
|
||||||
|
Position Blinky::scatterTarget() const {
|
||||||
|
return { 25, -3 };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,20 @@ double Clyde::speed(const GameState & gameState) const {
|
||||||
|
|
||||||
Position Clyde::target(const GameState & gameState) const {
|
Position Clyde::target(const GameState & gameState) const {
|
||||||
if (state == State::Eyes)
|
if (state == State::Eyes)
|
||||||
return initialClydePosition();
|
return initialPosition();
|
||||||
|
|
||||||
if (isInPen())
|
if (isInPen())
|
||||||
return penDoorPosition();
|
return penDoorPosition();
|
||||||
|
|
||||||
return clydeScatterTarget();
|
return scatterTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
Position Clyde::initialPosition() const {
|
Position Clyde::initialPosition() const {
|
||||||
return initialClydePosition();
|
return { 15.5, 14 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Position Clyde::scatterTarget() const {
|
||||||
|
return { 0, 30 };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,20 @@ double Inky::speed(const GameState & gameState) const {
|
||||||
|
|
||||||
Position Inky::target(const GameState & gameState) const {
|
Position Inky::target(const GameState & gameState) const {
|
||||||
if (state == State::Eyes)
|
if (state == State::Eyes)
|
||||||
return initialInkyPosition();
|
return initialPosition();
|
||||||
|
|
||||||
if (isInPen())
|
if (isInPen())
|
||||||
return penDoorPosition();
|
return penDoorPosition();
|
||||||
|
|
||||||
return inkyScatterTarget();
|
return scatterTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
Position Inky::initialPosition() const {
|
Position Inky::initialPosition() const {
|
||||||
return initialInkyPosition();
|
return { 13.5, 14 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Position Inky::scatterTarget() const {
|
||||||
|
return { 27, 30 };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,20 @@ double Pinky::speed(const GameState & gameState) const {
|
||||||
|
|
||||||
Position Pinky::target(const GameState & gameState) const {
|
Position Pinky::target(const GameState & gameState) const {
|
||||||
if (state == State::Eyes)
|
if (state == State::Eyes)
|
||||||
return initialPinkyPosition();
|
return initialPosition();
|
||||||
|
|
||||||
if (isInPen())
|
if (isInPen())
|
||||||
return penDoorPosition();
|
return penDoorPosition();
|
||||||
|
|
||||||
return pinkyScatterTarget();
|
return scatterTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
Position Pinky::initialPosition() const {
|
Position Pinky::initialPosition() const {
|
||||||
return initialPinkyPosition();
|
return { 11.5, 14 };
|
||||||
|
}
|
||||||
|
|
||||||
|
Position Pinky::scatterTarget() const {
|
||||||
|
return { 3, -2 };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,15 @@ namespace pacman {
|
||||||
|
|
||||||
class Blinky : public Ghost {
|
class Blinky : public Ghost {
|
||||||
public:
|
public:
|
||||||
explicit Blinky();
|
Blinky();
|
||||||
[[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;
|
Position initialPosition() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Position scatterTarget() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pacman
|
} // namespace pacman
|
||||||
|
|
|
@ -23,16 +23,4 @@ namespace pacman {
|
||||||
inline Position penDoorPosition() { return { 13, 11 }; }
|
inline Position penDoorPosition() { return { 13, 11 }; }
|
||||||
inline Position initialPacManPosition() { return { 13.5, 23 }; }
|
inline Position initialPacManPosition() { return { 13.5, 23 }; }
|
||||||
|
|
||||||
inline Position initialBlinkyPosition() { return { 13.5, 11 }; }
|
} // namespace pacman
|
||||||
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
|
|
||||||
|
|
|
@ -7,9 +7,14 @@ namespace pacman {
|
||||||
class Clyde : public Ghost {
|
class Clyde : public Ghost {
|
||||||
public:
|
public:
|
||||||
explicit Clyde();
|
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;
|
Position initialPosition() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Position scatterTarget() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pacman
|
} // namespace pacman
|
||||||
|
|
|
@ -46,7 +46,6 @@ protected:
|
||||||
virtual Position target(const GameState & gameState) const = 0;
|
virtual Position target(const GameState & gameState) const = 0;
|
||||||
virtual Position initialPosition() const = 0;
|
virtual Position initialPosition() const = 0;
|
||||||
|
|
||||||
|
|
||||||
Atlas::Ghost spritesSet;
|
Atlas::Ghost spritesSet;
|
||||||
Direction direction = Direction::NONE;
|
Direction direction = Direction::NONE;
|
||||||
double timeForAnimation = 0;
|
double timeForAnimation = 0;
|
||||||
|
|
|
@ -7,9 +7,14 @@ namespace pacman {
|
||||||
class Inky : public Ghost {
|
class Inky : public Ghost {
|
||||||
public:
|
public:
|
||||||
explicit Inky();
|
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;
|
Position initialPosition() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Position scatterTarget() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pacman
|
} // namespace pacman
|
||||||
|
|
|
@ -7,9 +7,14 @@ namespace pacman {
|
||||||
class Pinky : public Ghost {
|
class Pinky : public Ghost {
|
||||||
public:
|
public:
|
||||||
explicit Pinky();
|
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;
|
Position initialPosition() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Position scatterTarget() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pacman
|
} // namespace pacman
|
||||||
|
|
Loading…
Reference in a new issue