From 284163b428f089561c6dc89f144274e64d44cc9a Mon Sep 17 00:00:00 2001 From: luckyturtledev Date: Sat, 6 Jul 2024 17:19:44 +0200 Subject: [PATCH] draw overworld --- src/activities/overworld.rs | 16 +++++++++++++++- src/activities/overworld/worldgen.rs | 9 ++++++--- src/game.rs | 24 ++++++++++++++++++++++++ src/main.rs | 1 + 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/activities/overworld.rs b/src/activities/overworld.rs index b1a6300..6f530b1 100644 --- a/src/activities/overworld.rs +++ b/src/activities/overworld.rs @@ -1,9 +1,23 @@ use comfy::{draw_circle, vec2, EngineContext, GREEN}; +use crate::game::ZLayer; + pub mod worldgen; -pub fn draw(_state: &crate::State, _engine: &EngineContext<'_>) { +pub fn draw(state: &crate::State, _engine: &comfy::EngineContext) { draw_circle(vec2(0.0, 0.0), 0.5, GREEN, 0); + for (coords, tile) in state.overworld.iter_tiles() { + for (i, texture) in tile.textures.iter().rev().enumerate() { + let i = i as i32; + draw_sprite( + *texture, + coords.as_vec2(), + Default::default(), + ZLayer::MapMax - i, + Vec2::ONE + ) + } + } } pub fn update(_state: &mut crate::State, _engine: &mut EngineContext<'_>) {} diff --git a/src/activities/overworld/worldgen.rs b/src/activities/overworld/worldgen.rs index 6b8d664..53f633a 100644 --- a/src/activities/overworld/worldgen.rs +++ b/src/activities/overworld/worldgen.rs @@ -1,7 +1,8 @@ -use comfy::{IVec2, UVec2}; +use comfy::{IVec2, TextureHandle, UVec2}; + use std::collections::HashMap; -enum MovementCost { +pub enum MovementCost { /// No movement possible - cost infinitely high. Infinite, /// There is a path for this movement - movement is cheap. @@ -13,7 +14,9 @@ enum MovementCost { } #[derive(Debug)] -struct Tile; +pub struct Tile { + pub textures: Vec +} impl Tile { pub fn can_stand_inside(&self) -> bool { diff --git a/src/game.rs b/src/game.rs index 9e8eb7a..e80c3c9 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,3 +1,5 @@ +use std::ops::Sub; + use comfy::*; use crate::{ @@ -5,6 +7,28 @@ use crate::{ State }; +#[repr(i32)] +pub enum ZLayer { + MapMax = -1, + Human = 0, + Ghost = 1 +} + +impl From for i32 { + fn from(value: ZLayer) -> Self { + // safe because #[repr(i32)] + value as i32 + } +} + +impl Sub for ZLayer { + type Output = i32; + + fn sub(self, other: i32) -> Self::Output { + i32::from(self) - other + } +} + pub fn update(state: &mut State, engine: &mut EngineContext<'_>) { match state.activity { Activity::House => house::update(state, engine), diff --git a/src/main.rs b/src/main.rs index f231ac7..b27adb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#[allow(dead_code, unused_variables)] #![warn(rust_2018_idioms)] #![forbid(clippy::wildcard_imports, elided_lifetimes_in_paths, unsafe_code)]