Skip to content

Commit

Permalink
end round when no balls are present
Browse files Browse the repository at this point in the history
see #19
note that this will be different if balls respawn
  • Loading branch information
t3kt committed Dec 27, 2014
1 parent af05977 commit 8cc4596
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/core/LogicController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void LogicController::onBallHitWall(Ball& ball, Wall& wall) {
Player* player = ball.player();

ball.kill();
_state.decrementLiveBalls();
notifyBallDestroyed(_state, &ball);

if (player && _appParams.rules().playersCanLoseLives()) {
Expand All @@ -180,6 +181,10 @@ void LogicController::onBallHitWall(Ball& ball, Wall& wall) {
notifyPlayerLost(_state, player);
}
}

if (_state.liveBalls() <= 0) {
notifyTryEndRound(END_NO_BALLS);
}
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/game_objects/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RoundState::RoundState(const RoundConfig& config,
, _totalBricks(0)
, _liveBricks(0)
, _totalBalls(0)
, _liveBalls(0)
, endTime(-1) {
for (auto& player : players) {
addPlayer(player);
Expand Down Expand Up @@ -58,6 +59,8 @@ Wall& RoundState::addWall(const WallSpec& wallSpec) {
Ball& RoundState::addBall(const BallSpec& ballSpec) {
ofPtr<Ball> ball(new Ball(_config, ballSpec));
_balls.push_back(ball);
if (ball->alive())
_liveBalls++;
_totalBalls++;
return *ball;
}
Expand All @@ -69,12 +72,3 @@ void RoundState::addModifier(ofPtr<Modifier> modifier) {
void RoundState::addAnimation(ofPtr<AnimationObject> animation) {
_animations.push_back(animation);
}

int RoundState::liveBalls() const {
int count = 0;
for (const auto& ball : _balls) {
if (ball && ball->alive())
count++;
}
return count;
}
8 changes: 4 additions & 4 deletions src/game_objects/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ class RoundState {
void addModifier(ofPtr<Modifier> modifier);
void addAnimation(ofPtr<AnimationObject> animation);

void decrementLiveBricks() {
_liveBricks--;
}
void decrementLiveBricks() { _liveBricks--; }
void decrementLiveBalls() { _liveBalls--; }

int liveBricks() const { return _liveBricks; }
int totalBricks() const { return _totalBricks; }

int liveBalls() const;
int liveBalls() const { return _liveBalls; }
int totalBalls() const { return _totalBalls; }

void output(std::ostream& os) const;
Expand Down Expand Up @@ -93,6 +92,7 @@ class RoundState {
GameObjectCollection<AnimationObject> _animations;
int _liveBricks;
int _totalBricks;
int _liveBalls;
int _totalBalls;
};

Expand Down

0 comments on commit 8cc4596

Please sign in to comment.