Skip to content

Commit

Permalink
fix toybox-rs#13: no more extra balls
Browse files Browse the repository at this point in the history
The true issue was calling start_ball in new_game without setting
is_dead to false; this allowed the player to press the FIRE button and
get a second ball. Now the first ball requires FIRE to begin the game.
  • Loading branch information
jjfiv committed Jan 3, 2020
1 parent 349d7b8 commit f5ecf16
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tb_breakout/src/breakout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl toybox_core::Simulation for Breakout {
}
}

let mut state = State {
let state = State {
config: self.clone(),
state: StateCore {
lives: self.start_lives,
Expand All @@ -236,11 +236,10 @@ impl toybox_core::Simulation for Breakout {
paddle_speed: 4.0,
rand: random::Gen::new_child(&mut self.rand),
bricks,
reset: true,
reset: false,
},
};

state.start_ball();
Box::new(state)
}

Expand Down Expand Up @@ -484,6 +483,9 @@ impl toybox_core::State for State {

if self.state.is_dead {
if buttons.button1 {
// Delete old ball(s).
self.state.balls.clear();
// New ball.
self.start_ball();
self.state.is_dead = false;
}
Expand Down Expand Up @@ -660,6 +662,7 @@ impl toybox_core::State for State {
"num_columns" => serde_json::to_string(&screen::BRICKS_ACROSS)?,
"num_rows" => serde_json::to_string(&screen::ROW_SCORES.len())?,
"level" => serde_json::to_string(&state.level)?,
"is_dead" => serde_json::to_string(&state.is_dead)?,
"config.ball_start_positions" => serde_json::to_string(&config.ball_start_positions)?,
_ => Err(QueryError::NoSuchQuery)?,
})
Expand Down

0 comments on commit f5ecf16

Please sign in to comment.