aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/satellite_map.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 22:07:30 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 22:07:30 +0300
commit90ea3afec48e2bac7016db08987e5c94878b1993 (patch)
tree7949a1206922e684926ba476286972a9a64bcfba /apps/fparkan-game/src/satellite_map.rs
parentff0a199a9162f08e60bcd3bd645d8c2c9199776f (diff)
downloadfparkan-90ea3afec48e2bac7016db08987e5c94878b1993.tar.xz
fparkan-90ea3afec48e2bac7016db08987e5c94878b1993.zip
feat(ui): show player heading on the satellite map
Diffstat (limited to 'apps/fparkan-game/src/satellite_map.rs')
-rw-r--r--apps/fparkan-game/src/satellite_map.rs58
1 files changed, 49 insertions, 9 deletions
diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs
index f5dabd6f..37d60fa9 100644
--- a/apps/fparkan-game/src/satellite_map.rs
+++ b/apps/fparkan-game/src/satellite_map.rs
@@ -175,19 +175,59 @@ fn empty_layer() -> RgbaImage {
fn paint_unit(layer: &mut RgbaImage, unit: satellite_contacts::UnitContact) {
let radius = if unit.cross { 2 } else { 1 };
for dy in -radius..=radius {
- let y = unit.pixel[1].saturating_add(dy);
- if !(0..MAP_SIZE as i32).contains(&y) {
- continue;
- }
for dx in -radius..=radius {
- let x = unit.pixel[0].saturating_add(dx);
- if !(0..MAP_SIZE as i32).contains(&x) || (unit.cross && dx != 0 && dy != 0) {
- continue;
+ if !unit.cross || dx == 0 || dy == 0 {
+ paint_unit_pixel(layer, unit.pixel, [dx, dy], [128, 128, 255, 255]);
}
- let dst = (y as usize * MAP_SIZE + x as usize) * 4;
- layer.rgba8[dst..dst + 4].copy_from_slice(&[128, 128, 255, 255]);
}
}
+
+ let Some(heading) = unit.heading else {
+ return;
+ };
+ let color = if heading.selected {
+ [255; 4]
+ } else {
+ [0, 255, 0, 255]
+ };
+ let border = radius + 2;
+ for offset in -border..=border {
+ for point in [
+ [offset, -border],
+ [offset, border],
+ [-border, offset],
+ [border, offset],
+ ] {
+ paint_unit_pixel(layer, unit.pixel, point, color);
+ }
+ }
+ let [end_x, end_y] = heading.tip_offset;
+ let [mut x, mut y] = [0, 0];
+ let [dx, dy] = [end_x.abs(), -end_y.abs()];
+ let mut error = dx + dy;
+ loop {
+ paint_unit_pixel(layer, unit.pixel, [x, y], color);
+ if [x, y] == [end_x, end_y] {
+ break;
+ }
+ let twice = 2 * error;
+ if twice >= dy {
+ error += dy;
+ x += end_x.signum();
+ }
+ if twice <= dx {
+ error += dx;
+ y += end_y.signum();
+ }
+ }
+}
+
+fn paint_unit_pixel(layer: &mut RgbaImage, center: [i32; 2], offset: [i32; 2], color: [u8; 4]) {
+ let [x, y] = std::array::from_fn(|axis| center[axis].saturating_add(offset[axis]));
+ if (0..MAP_SIZE as i32).contains(&x) && (0..MAP_SIZE as i32).contains(&y) {
+ let dst = (y as usize * MAP_SIZE + x as usize) * 4;
+ layer.rgba8[dst..dst + 4].copy_from_slice(&color);
+ }
}
fn paint_building(