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