1
Fork 0

pull render into own section

This commit is contained in:
Andy Killorin 2026-11-09 18:05:05 -05:00
parent 0f831acf45
commit ada386fb30
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -172,6 +172,7 @@ async fn run_simulation() -> (i32, i32) {
let mut robots = Vec::new();
let mut craters: Vec<(f32, f32, f32, Color)> = Vec::new();
let mut new_craters: Vec<(f32, f32, f32, Color)> = Vec::new();
let mut score = HashMap::new();
@ -199,17 +200,9 @@ async fn run_simulation() -> (i32, i32) {
}
let mut loo = 0;
let mut loo = 1;
loop {
let rendered = loo %90 == 0;
//let rendered = false;
clear_background(LIGHTGRAY);
if rendered {
for crater in &craters {
draw_circle(crater.0, crater.1, crater.2, Color::new(0.75, 0.75, 0.75, 1.0));
}
}
let rendered = loo %490 == 0;
for food in &mut food{
if let Some(team) = food.detect(robots.iter()) {
@ -219,7 +212,6 @@ async fn run_simulation() -> (i32, i32) {
watchdog = 0;
}
}
if rendered { food.draw(); }
}
food = food.into_iter().filter(Mortal::living).collect(); // remove dead food
@ -261,13 +253,27 @@ async fn run_simulation() -> (i32, i32) {
death = false; // pacifists
}
if death {
if rendered {robot.draw_weapon();}
craters.push(robot.crater());
new_craters.push(robot.crater());
robot.weapon(peers);
}
if rendered { robot.draw();}
}
if rendered {
clear_background(LIGHTGRAY);
for crater in &new_craters {
draw_circle(crater.0, crater.1, crater.2, crater.3);
}
craters.append(&mut new_craters);
for crater in &craters {
draw_circle(crater.0, crater.1, crater.2, Color::new(0.75, 0.75, 0.75, 1.0));
}
for food in &food {
food.draw();
}
for robot in &robots {
robot.draw();
}
draw_text(format!("RED: {}", score.get(&color_hash(RED)).unwrap_or(&0)), 20.0, 20.0, 30.0, DARKGRAY);
draw_text(format!("BLUE: {}", score.get(&color_hash(BLUE)).unwrap_or(&0)), 20.0, 40.0, 30.0, DARKGRAY);
}