fix(input): start games with the plus key
Match the recovered Win16 registration flow: the first plus press creates Player 1 and additional presses add Players 2 through 4 until the initial launch. Down now belongs only to charging and releasing the plunger. Test Plan: - cargo fmt --check - cargo test - cargo clippy --all-targets --all-features -- -D warnings - live: verify Down cannot leave attract mode - live: start with plus, add Player 2, hold Down through partial/full plunger frames, and release onto the table - git diff --check
This commit is contained in:
@@ -92,6 +92,12 @@ pub struct Ball {
|
||||
pub in_launcher: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum PlayerEntry {
|
||||
Open,
|
||||
Closed,
|
||||
}
|
||||
|
||||
impl Default for Ball {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -128,6 +134,7 @@ pub struct Game {
|
||||
nudge_meter: f32,
|
||||
stalled_for: f32,
|
||||
launcher_was_down: bool,
|
||||
player_entry: PlayerEntry,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
@@ -157,6 +164,7 @@ impl Game {
|
||||
nudge_meter: 0.0,
|
||||
stalled_for: 0.0,
|
||||
launcher_was_down: false,
|
||||
player_entry: PlayerEntry::Open,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,12 +176,21 @@ impl Game {
|
||||
LAUNCHER_FRAME_THRESHOLDS.partition_point(|threshold| self.launcher_charge >= *threshold)
|
||||
}
|
||||
|
||||
pub fn add_player_before_launch(&mut self) -> bool {
|
||||
if self.player_entry == PlayerEntry::Closed || self.players.len() >= 4 {
|
||||
return false;
|
||||
}
|
||||
self.players.push(Player::default());
|
||||
true
|
||||
}
|
||||
|
||||
fn fire_launcher(&mut self) {
|
||||
let launch_speed = LAUNCH_SPEED_MIN + self.launcher_charge * LAUNCH_SPEED_RANGE;
|
||||
self.ball.in_launcher = false;
|
||||
self.ball.velocity = vec2(0.0, -launch_speed);
|
||||
self.launcher_charge = 0.0;
|
||||
self.launcher_was_down = false;
|
||||
self.player_entry = PlayerEntry::Closed;
|
||||
self.stalled_for = 0.0;
|
||||
}
|
||||
|
||||
@@ -626,6 +643,22 @@ mod tests {
|
||||
assert_eq!(Game::new(99).players.len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plus_adds_players_only_before_the_first_launch() {
|
||||
let mut game = Game::new(1);
|
||||
|
||||
assert!(game.add_player_before_launch());
|
||||
assert!(game.add_player_before_launch());
|
||||
assert!(game.add_player_before_launch());
|
||||
assert!(!game.add_player_before_launch());
|
||||
assert_eq!(game.players.len(), 4);
|
||||
|
||||
let mut game = Game::new(1);
|
||||
launch_ball(&mut game, 1);
|
||||
assert!(!game.add_player_before_launch());
|
||||
assert_eq!(game.players.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ball_starts_in_the_recovered_shooter_lane() {
|
||||
let game = Game::new(1);
|
||||
|
||||
Reference in New Issue
Block a user