From 1ab54f3155eff431fb1bd65a0bcad71701e9d9b5 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 16 Jul 2024 02:02:14 +0200 Subject: render connected tiles --- light-client/src/game.rs | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'light-client/src/game.rs') diff --git a/light-client/src/game.rs b/light-client/src/game.rs index c9b20e56..ed1cb7fe 100644 --- a/light-client/src/game.rs +++ b/light-client/src/game.rs @@ -15,41 +15,58 @@ along with this program. If not, see . */ -use crate::atlas::SpriteRenderer; -use hurrycurry_protocol::{glam::IVec2, PacketC, TileIndex}; +use crate::{sprite_renderer::SpriteRenderer, tilemap::Tilemap}; +use hurrycurry_protocol::{ + glam::{IVec2, Vec2}, + PacketC, PlayerID, TileIndex, +}; use std::collections::HashMap; pub struct Game { - tiles: HashMap, + tiles: HashMap, + tilemap: Tilemap, + players: HashMap, +} + +pub struct Tile { + kind: TileIndex, +} +pub struct Player { + character: i32, + position: Vec2, } impl Game { pub fn new() -> Self { Self { tiles: HashMap::new(), + players: HashMap::new(), + tilemap: Tilemap::default(), } } - pub fn packet_in(&mut self, packet: PacketC) { + pub fn packet_in(&mut self, packet: PacketC, renderer: &mut SpriteRenderer) { match packet { + PacketC::Data { data } => { + self.tilemap.init(&data.tile_names, renderer.metadata()); + } PacketC::UpdateMap { tile, kind, - neighbors: _, + neighbors, } => { if let Some(kind) = kind { - self.tiles.insert(tile, kind); + self.tiles.insert(tile, Tile { kind }); } else { self.tiles.remove(&tile); } + self.tilemap.set(tile, kind, neighbors); } _ => (), } } - pub fn render(&self, ctx: &mut SpriteRenderer) { - for (p, tile) in &self.tiles { - ctx.draw_tile(*tile, *p) - } + pub fn draw(&self, ctx: &mut SpriteRenderer) { + self.tilemap.draw(ctx) } } -- cgit v1.2.3-70-g09d2