aboutsummaryrefslogtreecommitdiff
path: root/light-client/src/game.rs
diff options
context:
space:
mode:
Diffstat (limited to 'light-client/src/game.rs')
-rw-r--r--light-client/src/game.rs37
1 files changed, 27 insertions, 10 deletions
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 <https://www.gnu.org/licenses/>.
*/
-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<IVec2, TileIndex>,
+ tiles: HashMap<IVec2, Tile>,
+ tilemap: Tilemap,
+ players: HashMap<PlayerID, Player>,
+}
+
+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)
}
}