From 20409e3ee23f2d83d3a7f24138f3f23fb1b7d415 Mon Sep 17 00:00:00 2001 From: crumblingstatue Date: Mon, 3 Apr 2023 22:21:36 +0200 Subject: [PATCH] Add tile placement --- src/app.rs | 9 +++++++++ src/game.rs | 4 +++- src/world.rs | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app.rs b/src/app.rs index fb31c78..9014614 100644 --- a/src/app.rs +++ b/src/app.rs @@ -157,6 +157,13 @@ impl App { let t = self.game.world.tile_at_mut(mouse_tpos); t.mid = 0; t.fg = 0; + } else if self.input.rmb_down { + let t = self.game.world.tile_at_mut(mouse_tpos); + if self.game.tile_to_place != 7 { + t.mid = self.game.tile_to_place; + } else { + t.bg = self.game.tile_to_place; + } } } @@ -234,6 +241,8 @@ fn debug_panel_ui(debug: &mut DebugState, game: &mut GameState, ctx: &egui::Cont ui.label("Gravity"); ui.add(egui::DragValue::new(&mut game.gravity)); } + ui.label("Tile to place"); + ui.add(egui::DragValue::new(&mut game.tile_to_place)); ui.separator(); egui::ScrollArea::vertical().show(ui, |ui| { gamedebug_core::for_each_imm(|info| match info { diff --git a/src/game.rs b/src/game.rs index e80c6b2..e4afee7 100644 --- a/src/game.rs +++ b/src/game.rs @@ -6,7 +6,7 @@ use crate::{ graphics::{ScreenPos, ScreenPosScalar, NATIVE_RESOLUTION}, math::{wp_to_tp, WorldPos}, res::Res, - world::{Tile, TilePos, World}, + world::{Tile, TileId, TilePos, World}, }; use self::player::Player; @@ -16,6 +16,7 @@ pub struct GameState { pub world: World, pub player: Player, pub gravity: f32, + pub tile_to_place: TileId, } impl GameState { pub(crate) fn draw_world(&mut self, rw: &mut RenderWindow, res: &Res) { @@ -75,6 +76,7 @@ impl Default for GameState { world: Default::default(), player: Player::new_at(spawn_point), gravity: 0.7, + tile_to_place: 1, } } } diff --git a/src/world.rs b/src/world.rs index 3fd6aeb..4aad911 100644 --- a/src/world.rs +++ b/src/world.rs @@ -137,7 +137,7 @@ impl Chunk { } } -type TileId = u16; +pub type TileId = u16; #[derive(Clone, Copy)] pub struct Tile {