Skip to content

Commit

Permalink
actually use NextGameConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsairobo committed Dec 9, 2023
1 parent 0f9bde7 commit e61acef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Ball {
ball_assets: &BallAssets,
bounds: &Boundaries,
aabb: Aabb2,
n_balls: usize,
n_balls: u32,
) {
let mut rng = rand::thread_rng();
for _ in 0..n_balls {
Expand Down
2 changes: 1 addition & 1 deletion src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub const OCCUPANCY_CELL_SIZE: Vec2 = Vec2::splat(AVOID_RADIUS);
pub const SQUAD_AI_COLLIDER_HEIGHT: f32 = 0.1;
pub const SQUAD_AI_COLLIDER_RADIUS: f32 = 2.0;
/// Players per square meter.
pub const SQUAD_CLUSTER_DENSITY: f32 = 1.0;
pub const SQUAD_CLUSTER_DENSITY: f32 = 4.0;
/// How far a thrown ball travels upwards on its trajectory.
///
/// This should be nonzero to avoid friendly fire.
Expand Down
32 changes: 21 additions & 11 deletions src/restart_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
ball::{Ball, BallAssets},
boundaries::Boundaries,
gym::{Gym, GymAssets, GymParams},
settings::GameSettings,
settings::{GameSettings, NextGameConfig},
squad::{AllSquadAssets, Squad, SquadBehaviors, SquadStates},
team::AllTeamAssets,
};
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn start_game(
mouse_rotate_sensitivity: Vec2::splat(settings.rotate_sensitivity),
..default()
},
Vec3::new(50.0, 50.0, 0.0),
Vec3::new(100.0, 100.0, 0.0),
Vec3::ZERO,
Vec3::Y,
),
Expand Down Expand Up @@ -90,8 +90,13 @@ pub fn start_game(
});
}

let NextGameConfig {
squads_per_team,
players_per_squad,
n_balls,
} = settings.next_game;

let ball_assets = BallAssets::new(&mut meshes, &mut materials);
let n_balls = 1000;
Ball::spawn_multiple_in_aabb(
&mut commands,
&ball_assets,
Expand All @@ -101,11 +106,16 @@ pub fn start_game(
);

let team_colors = [Color::GREEN, Color::BLUE];
let squad_teams = [0, 0, 0, 0, 1, 1, 1, 1];
let squad_teams: Vec<_> = std::iter::repeat(0u8)
.take(usize::from(squads_per_team))
.chain(std::iter::repeat(1).take(usize::from(squads_per_team)))
.collect();
let n_squads = squad_teams.len();
let squad_size = 750;

let squad_colors = squad_teams.map(|t| team_colors[t as usize]);
let squad_colors: Vec<_> = squad_teams
.iter()
.map(|&t| team_colors[t as usize])
.collect();
let team_assets = AllTeamAssets::new(team_colors, &mut meshes, &mut materials);
let squad_assets = AllSquadAssets::new(squad_colors, &mut materials);

Expand All @@ -115,24 +125,24 @@ pub fn start_game(
&team_assets.teams[0],
&squad_assets,
0,
0..4,
0..squads_per_team,
player_spawn_aabbs[0],
squad_size,
players_per_squad,
&mut squad_ai_entities,
);
Squad::spawn_in_line(
&mut commands,
&team_assets.teams[1],
&squad_assets,
1,
4..8,
squads_per_team..2 * squads_per_team,
player_spawn_aabbs[1],
squad_size,
players_per_squad,
&mut squad_ai_entities,
);

let squad_behaviors = SquadBehaviors::new(squad_ai_entities);
let squad_states = SquadStates::new(vec![squad_size; n_squads]);
let squad_states = SquadStates::new(vec![players_per_squad; n_squads]);

commands.insert_resource(ball_assets);
commands.insert_resource(bounds);
Expand Down

0 comments on commit e61acef

Please sign in to comment.