Rename speedy, remove starting position
This commit is contained in:
parent
59484babef
commit
f31d238bd4
12 changed files with 54 additions and 29 deletions
|
@ -3,7 +3,7 @@
|
|||
namespace pacman {
|
||||
|
||||
Blinky::Blinky()
|
||||
: Ghost(Atlas::Ghost::blinky, initialBlinkyPosition()) {
|
||||
: Ghost(Atlas::Ghost::blinky) {
|
||||
}
|
||||
|
||||
double Blinky::speed(const GameState & gameState) const {
|
||||
|
@ -16,7 +16,7 @@ double Blinky::speed(const GameState & gameState) const {
|
|||
|
||||
Position Blinky::target(const GameState & gameState) const {
|
||||
if (state == State::Eyes)
|
||||
return startingPosition;
|
||||
return initialBlinkyPosition();
|
||||
|
||||
if (isInPen())
|
||||
return penDoorPosition();
|
||||
|
@ -24,4 +24,8 @@ Position Blinky::target(const GameState & gameState) const {
|
|||
return blinkyScatterTarget();
|
||||
}
|
||||
|
||||
Position Blinky::initialPosition() const {
|
||||
return initialBlinkyPosition();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
namespace pacman {
|
||||
|
||||
Clyde::Clyde()
|
||||
: Ghost(Atlas::Ghost::clyde, initialClydePosition()) {
|
||||
: Ghost(Atlas::Ghost::clyde) {
|
||||
}
|
||||
|
||||
double Clyde::speed(const GameState & gameState) const {
|
||||
|
@ -16,7 +16,7 @@ double Clyde::speed(const GameState & gameState) const {
|
|||
|
||||
Position Clyde::target(const GameState & gameState) const {
|
||||
if (state == State::Eyes)
|
||||
return startingPosition;
|
||||
return initialClydePosition();
|
||||
|
||||
if (isInPen())
|
||||
return penDoorPosition();
|
||||
|
@ -24,4 +24,9 @@ Position Clyde::target(const GameState & gameState) const {
|
|||
return clydeScatterTarget();
|
||||
}
|
||||
|
||||
Position Clyde::initialPosition() const {
|
||||
return initialClydePosition();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -4,10 +4,8 @@
|
|||
|
||||
namespace pacman {
|
||||
|
||||
Ghost::Ghost(Atlas::Ghost spritesSet, Position startingPosition)
|
||||
: spritesSet(spritesSet),
|
||||
pos(startingPosition),
|
||||
startingPosition(startingPosition) {
|
||||
Ghost::Ghost(Atlas::Ghost spritesSet)
|
||||
: spritesSet(spritesSet) {
|
||||
}
|
||||
|
||||
void Ghost::frighten() {
|
||||
|
@ -36,7 +34,10 @@ void Ghost::die() {
|
|||
}
|
||||
|
||||
void Ghost::reset() {
|
||||
pos = startingPosition;
|
||||
pos = initialPosition();
|
||||
state = State::Scatter;
|
||||
timeFrighten = 0;
|
||||
timeChase = 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] GridPosition Ghost::currentSprite() const {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace pacman {
|
||||
|
||||
Inky::Inky()
|
||||
: Ghost(Atlas::Ghost::inky, initialInkyPosition()) {
|
||||
: Ghost(Atlas::Ghost::inky) {
|
||||
}
|
||||
|
||||
double Inky::speed(const GameState & gameState) const {
|
||||
|
@ -16,7 +16,7 @@ double Inky::speed(const GameState & gameState) const {
|
|||
|
||||
Position Inky::target(const GameState & gameState) const {
|
||||
if (state == State::Eyes)
|
||||
return startingPosition;
|
||||
return initialInkyPosition();
|
||||
|
||||
if (isInPen())
|
||||
return penDoorPosition();
|
||||
|
@ -24,4 +24,9 @@ Position Inky::target(const GameState & gameState) const {
|
|||
return inkyScatterTarget();
|
||||
}
|
||||
|
||||
Position Inky::initialPosition() const {
|
||||
return initialInkyPosition();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
namespace pacman {
|
||||
|
||||
Pinky::Pinky()
|
||||
: Ghost(Atlas::Ghost::speedy, initialSpeedyPosition()) {
|
||||
: Ghost(Atlas::Ghost::pinky) {
|
||||
}
|
||||
|
||||
double Pinky::speed(const GameState & gameState) const {
|
||||
|
@ -16,12 +16,16 @@ double Pinky::speed(const GameState & gameState) const {
|
|||
|
||||
Position Pinky::target(const GameState & gameState) const {
|
||||
if (state == State::Eyes)
|
||||
return startingPosition;
|
||||
return initialPinkyPosition();
|
||||
|
||||
if (isInPen())
|
||||
return penDoorPosition();
|
||||
|
||||
return speedyScatterTarget();
|
||||
return pinkyScatterTarget();
|
||||
}
|
||||
|
||||
Position Pinky::initialPosition() const {
|
||||
return initialPinkyPosition();
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@ namespace pacman::Atlas {
|
|||
|
||||
enum class Ghost : unsigned int {
|
||||
blinky = 2,
|
||||
speedy = 3,
|
||||
pinky = 3,
|
||||
inky = 4,
|
||||
clyde = 5,
|
||||
};
|
||||
|
|
|
@ -9,6 +9,7 @@ public:
|
|||
explicit Blinky();
|
||||
[[nodiscard]] double speed(const GameState & gameState) const override;
|
||||
[[nodiscard]] Position target(const GameState & gameState) const override;
|
||||
Position initialPosition() const override;
|
||||
};
|
||||
|
||||
} // namespace pacman
|
|
@ -26,8 +26,8 @@ namespace pacman {
|
|||
inline Position initialBlinkyPosition() { return { 13.5, 11 }; }
|
||||
inline Position blinkyScatterTarget() { return { 25, -3 }; }
|
||||
|
||||
inline Position initialSpeedyPosition() { return { 11.5, 14 }; }
|
||||
inline Position speedyScatterTarget() { return { 3, -2 }; }
|
||||
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 }; }
|
||||
|
|
|
@ -9,6 +9,7 @@ public:
|
|||
explicit Clyde();
|
||||
[[nodiscard]] double speed(const GameState & gameState) const override;
|
||||
[[nodiscard]] Position target(const GameState & gameState) const override;
|
||||
Position initialPosition() const override;
|
||||
};
|
||||
|
||||
} // namespace pacman
|
|
@ -19,7 +19,8 @@ public:
|
|||
Eyes,
|
||||
};
|
||||
|
||||
explicit Ghost(Atlas::Ghost spritesSet, Position startingPosition);
|
||||
explicit Ghost(Atlas::Ghost spritesSet);
|
||||
virtual ~Ghost() = default;
|
||||
|
||||
[[nodiscard]] GridPosition currentSprite() const;
|
||||
|
||||
|
@ -41,8 +42,10 @@ private:
|
|||
|
||||
protected:
|
||||
|
||||
[[nodiscard]] virtual double speed(const GameState & gameState) const = 0;
|
||||
[[nodiscard]] virtual Position target(const GameState & gameState) const = 0;
|
||||
virtual double speed(const GameState & gameState) const = 0;
|
||||
virtual Position target(const GameState & gameState) const = 0;
|
||||
virtual Position initialPosition() const = 0;
|
||||
|
||||
|
||||
Atlas::Ghost spritesSet;
|
||||
Direction direction = Direction::NONE;
|
||||
|
@ -52,7 +55,6 @@ protected:
|
|||
int timeFrighten = 0;
|
||||
int timeChase = 0;
|
||||
Position pos;
|
||||
Position startingPosition;
|
||||
GridPosition last_grid_position = { 0, 0 };
|
||||
[[nodiscard]] bool isInPen() const;
|
||||
};
|
||||
|
|
|
@ -9,6 +9,7 @@ public:
|
|||
explicit Inky();
|
||||
[[nodiscard]] double speed(const GameState & gameState) const override;
|
||||
[[nodiscard]] Position target(const GameState & gameState) const override;
|
||||
Position initialPosition() const override;
|
||||
};
|
||||
|
||||
} // namespace pacman
|
|
@ -9,6 +9,7 @@ public:
|
|||
explicit Pinky();
|
||||
[[nodiscard]] double speed(const GameState & gameState) const override;
|
||||
[[nodiscard]] Position target(const GameState & gameState) const override;
|
||||
Position initialPosition() const override;
|
||||
};
|
||||
|
||||
} // namespace pacman
|
Loading…
Reference in a new issue