diff --git a/res/tiles.png b/res/tiles.png index c3223e8..8a2ac71 100644 Binary files a/res/tiles.png and b/res/tiles.png differ diff --git a/src/app.rs b/src/app.rs index e828e61..1780100 100644 --- a/src/app.rs +++ b/src/app.rs @@ -98,8 +98,8 @@ impl App { .move_y(self.game.player.vspeed, |player_en, off| { let mut col = false; for_each_tile_on_screen(self.game.camera_offset, |tp, _sp| { - let tid = self.game.world.tile_at_mut(tp).id; - if tid == Tile::AIR { + let tid = self.game.world.tile_at_mut(tp).mid; + if tid == Tile::EMPTY { return; } let tsize = TILE_SIZE as i32; @@ -119,8 +119,8 @@ impl App { .move_x(self.game.player.hspeed, |player_en, off| { let mut col = false; for_each_tile_on_screen(self.game.camera_offset, |tp, _sp| { - let tid = self.game.world.tile_at_mut(tp).id; - if tid == Tile::AIR { + let tid = self.game.world.tile_at_mut(tp).mid; + if tid == Tile::EMPTY { return; } let tsize = TILE_SIZE as i32; @@ -147,7 +147,9 @@ impl App { imm!("Mouse down at {}, {}", wpos.x, wpos.y); let tpos = wpos.tile_pos(); imm_dbg!(tpos); - self.game.world.tile_at_mut(tpos).id = 0; + let t = self.game.world.tile_at_mut(tpos); + t.mid = 0; + t.fg = 0; } } diff --git a/src/game.rs b/src/game.rs index 4fd8d6a..e80c6b2 100644 --- a/src/game.rs +++ b/src/game.rs @@ -22,12 +22,19 @@ impl GameState { let mut s = Sprite::with_texture(&res.tile_atlas); for_each_tile_on_screen(self.camera_offset, |tp, sp| { let tile = self.world.tile_at_mut(tp); - if tile.id == Tile::AIR { - return; - } - s.set_texture_rect(Rect::new((tile.id - 1) as i32 * 32, 0, 32, 32)); s.set_position(sp.to_sf_vec()); - rw.draw(&s); + if tile.bg != Tile::EMPTY { + s.set_texture_rect(Rect::new((tile.bg - 1) as i32 * 32, 0, 32, 32)); + rw.draw(&s); + } + if tile.mid != Tile::EMPTY { + s.set_texture_rect(Rect::new((tile.mid - 1) as i32 * 32, 0, 32, 32)); + rw.draw(&s); + } + if tile.fg != Tile::EMPTY { + s.set_texture_rect(Rect::new((tile.fg - 1) as i32 * 32, 0, 32, 32)); + rw.draw(&s); + } }); } pub fn draw_entities(&mut self, rw: &mut RenderWindow) { diff --git a/src/world.rs b/src/world.rs index 203f0d4..3fd6aeb 100644 --- a/src/world.rs +++ b/src/world.rs @@ -109,16 +109,24 @@ pub struct Chunk { impl Chunk { pub fn gen(pos: ChunkPos) -> Self { let mut rng = thread_rng(); - let mut tiles = [Tile { id: 0 }; CHUNK_N_TILES]; + let mut tiles = [Tile { + bg: 0, + mid: 0, + fg: 0, + }; CHUNK_N_TILES]; if pos.y > 38 { for b in &mut tiles { - b.id = rng.gen_range(1..5); + b.bg = 7; + b.mid = rng.gen_range(1..5); + if rng.gen_bool(0.1) { + b.fg = 6; + } } } // Unbreakable layer at bottom if pos.y > 510 { for b in &mut tiles { - b.id = Tile::UNBREAKANIUM; + b.mid = Tile::UNBREAKANIUM; } } Self { tiles } @@ -133,10 +141,15 @@ type TileId = u16; #[derive(Clone, Copy)] pub struct Tile { - pub id: TileId, + /// Background wall behind entities + pub bg: TileId, + /// The solid wall on the same level as entities + pub mid: TileId, + /// A layer on top of the mid wall. Usually ores or decorative pieces. + pub fg: TileId, } impl Tile { - pub const AIR: TileId = 0; + pub const EMPTY: TileId = 0; pub const UNBREAKANIUM: TileId = 5; }