mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-14 11:45:01 +01:00
Super basic map rendering
This commit is contained in:
parent
5e539d668f
commit
49c47ac718
6 changed files with 60 additions and 22 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -300,6 +300,11 @@ dependencies = [
|
|||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gamedebug_core"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/crumblingstatue/gamedebug_core.git#0afa12c84d865e266ccf6ee31970ff70da0e2ac6"
|
||||
|
||||
[[package]]
|
||||
name = "gdk-pixbuf-sys"
|
||||
version = "0.16.3"
|
||||
|
|
@ -534,6 +539,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"egui-sfml",
|
||||
"fnv",
|
||||
"gamedebug_core",
|
||||
"hecs",
|
||||
"rand",
|
||||
"rfd",
|
||||
|
|
@ -690,9 +696,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.54"
|
||||
version = "1.0.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534"
|
||||
checksum = "1d0dd4be24fcdcfeaa12a432d588dc59bbad6cad3510c67e74a2b6b2fc950564"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -19,3 +19,6 @@ git = "https://github.com/crumblingstatue/s2dc.git"
|
|||
|
||||
[dependencies.sfml-xt]
|
||||
git = "https://github.com/crumblingstatue/sfml-xt.git"
|
||||
|
||||
[dependencies.gamedebug_core]
|
||||
git = "https://github.com/crumblingstatue/gamedebug_core.git"
|
||||
|
|
|
|||
39
src/app.rs
39
src/app.rs
|
|
@ -1,3 +1,5 @@
|
|||
use egui_sfml::{egui, SfEgui};
|
||||
use gamedebug_core::imm;
|
||||
use sfml::{
|
||||
graphics::{Color, RenderTarget, RenderWindow},
|
||||
window::Event,
|
||||
|
|
@ -7,19 +9,23 @@ use crate::{game::GameState, graphics, res::Res};
|
|||
|
||||
/// Application level state (includes game and ui state, etc.)
|
||||
pub struct App {
|
||||
rw: RenderWindow,
|
||||
should_quit: bool,
|
||||
game: GameState,
|
||||
res: Res,
|
||||
pub rw: RenderWindow,
|
||||
pub should_quit: bool,
|
||||
pub game: GameState,
|
||||
pub res: Res,
|
||||
pub sf_egui: SfEgui,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> anyhow::Result<Self> {
|
||||
let rw = graphics::make_window();
|
||||
let sf_egui = SfEgui::new(&rw);
|
||||
Ok(Self {
|
||||
rw: graphics::make_window(),
|
||||
rw,
|
||||
should_quit: false,
|
||||
game: GameState::default(),
|
||||
res: Res::load()?,
|
||||
sf_egui,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -28,11 +34,13 @@ impl App {
|
|||
self.do_event_handling();
|
||||
self.do_update();
|
||||
self.do_rendering();
|
||||
gamedebug_core::inc_frame();
|
||||
}
|
||||
}
|
||||
|
||||
fn do_event_handling(&mut self) {
|
||||
while let Some(ev) = self.rw.poll_event() {
|
||||
self.sf_egui.add_event(&ev);
|
||||
match ev {
|
||||
Event::Closed => self.should_quit = true,
|
||||
_ => {}
|
||||
|
|
@ -45,6 +53,27 @@ impl App {
|
|||
fn do_rendering(&mut self) {
|
||||
self.rw.clear(Color::BLACK);
|
||||
self.game.draw_world(&mut self.rw, &self.res);
|
||||
self.sf_egui
|
||||
.do_frame(|ctx| {
|
||||
egui::Window::new("Debug").show(ctx, |ui| {
|
||||
ui.label("Cam x");
|
||||
ui.add(egui::DragValue::new(&mut self.game.camera_offset.x));
|
||||
ui.label("Cam y");
|
||||
ui.add(egui::DragValue::new(&mut self.game.camera_offset.y));
|
||||
ui.separator();
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
gamedebug_core::for_each_imm(|info| match info {
|
||||
gamedebug_core::Info::Msg(msg) => {
|
||||
ui.label(msg);
|
||||
}
|
||||
gamedebug_core::Info::Rect(_, _, _, _, _) => todo!(),
|
||||
});
|
||||
});
|
||||
gamedebug_core::clear_immediates();
|
||||
});
|
||||
})
|
||||
.unwrap();
|
||||
self.sf_egui.draw(&mut self.rw, None);
|
||||
self.rw.display();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
21
src/game.rs
21
src/game.rs
|
|
@ -1,3 +1,4 @@
|
|||
use gamedebug_core::imm_dbg;
|
||||
use sfml::graphics::{Rect, RenderTarget, RenderWindow, Sprite, Transformable};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -8,8 +9,8 @@ use crate::{
|
|||
};
|
||||
|
||||
pub struct GameState {
|
||||
camera_offset: WorldPos,
|
||||
world: World,
|
||||
pub camera_offset: WorldPos,
|
||||
pub world: World,
|
||||
}
|
||||
impl GameState {
|
||||
pub(crate) fn draw_world(&mut self, rw: &mut RenderWindow, res: &Res) {
|
||||
|
|
@ -24,19 +25,17 @@ impl GameState {
|
|||
}
|
||||
|
||||
fn for_each_tile(camera_offset: WorldPos, mut f: impl FnMut(TilePos, ScreenPos)) {
|
||||
for y in (camera_offset.y..camera_offset.y + NATIVE_RESOLUTION.h as WorldPosScalar).step_by(32)
|
||||
{
|
||||
for x in
|
||||
(camera_offset.x..camera_offset.x + NATIVE_RESOLUTION.w as WorldPosScalar).step_by(32)
|
||||
{
|
||||
for y in (0..NATIVE_RESOLUTION.h).step_by(32) {
|
||||
for x in (0..NATIVE_RESOLUTION.w).step_by(32) {
|
||||
f(
|
||||
TilePos {
|
||||
x: x / 32,
|
||||
y: y / 32,
|
||||
x: (camera_offset.x + x as i32) / 32,
|
||||
y: (camera_offset.y + y as i32) / 32,
|
||||
},
|
||||
ScreenPos {
|
||||
x: (x - camera_offset.x) as i16,
|
||||
y: (y - camera_offset.y) as i16,
|
||||
x: imm_dbg!(imm_dbg!(x as i32) - (imm_dbg!(camera_offset.x as i32)) % 32)
|
||||
as i16,
|
||||
y: (y as i32 - (camera_offset.y as i32 % 32)) as i16,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@ use sfml::{
|
|||
use sfml_xt::graphics::RenderWindowExt;
|
||||
|
||||
pub struct ScreenRes {
|
||||
pub w: u16,
|
||||
pub h: u16,
|
||||
pub w: i16,
|
||||
pub h: i16,
|
||||
}
|
||||
|
||||
impl ScreenRes {
|
||||
fn to_sf(&self) -> VideoMode {
|
||||
VideoMode {
|
||||
width: self.w.into(),
|
||||
height: self.h.into(),
|
||||
width: self.w as _,
|
||||
height: self.h as _,
|
||||
bits_per_pixel: 32,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ mod world;
|
|||
use app::App;
|
||||
|
||||
fn try_main() -> anyhow::Result<()> {
|
||||
gamedebug_core::set_enabled(true);
|
||||
let mut app = App::new()?;
|
||||
app.do_game_loop();
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue