diff --git a/res/tiles.png b/res/tiles.png index 21d6e73..008e901 100644 Binary files a/res/tiles.png and b/res/tiles.png differ diff --git a/src/app.rs b/src/app.rs index 4f38a0a..d19a5ac 100644 --- a/src/app.rs +++ b/src/app.rs @@ -86,7 +86,7 @@ impl App { } fn do_rendering(&mut self) { - self.rw.clear(Color::BLACK); + self.rw.clear(Color::rgb(55, 221, 231)); self.game.draw_world(&mut self.rw, &self.res); self.sf_egui .do_frame(|ctx| { diff --git a/src/game.rs b/src/game.rs index 19a8f63..70595b1 100644 --- a/src/game.rs +++ b/src/game.rs @@ -4,7 +4,7 @@ use crate::{ graphics::{ScreenPos, ScreenPosScalar, NATIVE_RESOLUTION}, math::{wp_to_tp, WorldPos, WorldPosScalar}, res::Res, - world::{TilePos, World}, + world::{Tile, TilePos, World}, }; pub struct GameState { @@ -16,7 +16,10 @@ 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); - s.set_texture_rect(Rect::new(tile.id as i32 * 32, 0, 32, 32)); + 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); }); diff --git a/src/world.rs b/src/world.rs index 72a1eb6..1a49597 100644 --- a/src/world.rs +++ b/src/world.rs @@ -28,7 +28,7 @@ impl World { /// Loads or generates the containing chunk if necessary. pub fn tile_at_mut(&mut self, pos: TilePos) -> &mut Tile { let (chk, local) = pos.to_chunk_and_local(); - let chk = self.chunks.entry(chk).or_insert_with(Chunk::new_rand); + let chk = self.chunks.entry(chk).or_insert_with(|| Chunk::gen(chk)); chk.at_mut(local) } } @@ -107,11 +107,13 @@ pub struct Chunk { } impl Chunk { - pub fn new_rand() -> Self { + pub fn gen(pos: ChunkPos) -> Self { let mut rng = thread_rng(); let mut tiles = [Tile { id: 0 }; CHUNK_N_TILES]; - for b in &mut tiles { - b.id = rng.gen_range(0..8); + if pos.y > 40 { + for b in &mut tiles { + b.id = rng.gen_range(1..5); + } } Self { tiles } } @@ -127,3 +129,7 @@ type TileId = u16; pub struct Tile { pub id: TileId, } + +impl Tile { + pub const AIR: TileId = 0; +}