From a09aa839cb548d9ea1ce2cdd30874054ed9a3a80 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 15 Jul 2024 17:01:29 +0200 Subject: first visible tiles in light client --- light-client/src/game.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'light-client/src/game.rs') diff --git a/light-client/src/game.rs b/light-client/src/game.rs index fd045f53..e432c517 100644 --- a/light-client/src/game.rs +++ b/light-client/src/game.rs @@ -1,4 +1,38 @@ +use crate::atlas::SpriteRenderer; +use hurrycurry_protocol::{glam::IVec2, PacketC, TileIndex}; +use std::collections::HashMap; pub struct Game { - + tiles: HashMap, +} + +impl Game { + pub fn new() -> Self { + Self { + tiles: HashMap::new(), + } + } + + pub fn packet_in(&mut self, packet: PacketC) { + match packet { + PacketC::UpdateMap { + tile, + kind, + neighbors: _, + } => { + if let Some(kind) = kind { + self.tiles.insert(tile, kind); + } else { + self.tiles.remove(&tile); + } + } + _ => (), + } + } + + pub fn render(&self, ctx: &mut SpriteRenderer) { + for (p, tile) in &self.tiles { + ctx.draw_tile(*tile, *p) + } + } } -- cgit v1.2.3-70-g09d2