diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-18 12:39:33 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-18 12:39:33 +0200 |
commit | 2a31d26fca33789ccf8ea28cdb214d20dd29f85d (patch) | |
tree | 426faa4d55905ecacdb9a1a4beca6d5a1ab97953 /pixel-client | |
parent | c4ae8c2df44cac2a8b3e4c8db43c2870b7d2bf69 (diff) | |
download | hurrycurry-2a31d26fca33789ccf8ea28cdb214d20dd29f85d.tar hurrycurry-2a31d26fca33789ccf8ea28cdb214d20dd29f85d.tar.bz2 hurrycurry-2a31d26fca33789ccf8ea28cdb214d20dd29f85d.tar.zst |
serve-authorative movement
Diffstat (limited to 'pixel-client')
-rw-r--r-- | pixel-client/src/game.rs | 5 | ||||
-rw-r--r-- | pixel-client/src/main.rs | 34 | ||||
-rw-r--r-- | pixel-client/src/menu.rs | 7 | ||||
-rw-r--r-- | pixel-client/src/render/mod.rs | 11 |
4 files changed, 15 insertions, 42 deletions
diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs index 1fc49c6b..7e43bdc9 100644 --- a/pixel-client/src/game.rs +++ b/pixel-client/src/game.rs @@ -348,7 +348,10 @@ impl Game { } pub fn draw(&self, ctx: &mut SpriteRenderer) { - ctx.set_view(-self.camera_center + (ctx.size / ctx.get_scale() / 2.), 1.); + ctx.set_view( + -self.camera_center + (ctx.size / ctx.get_scale() / 2.), + ctx.size.min_element() / 32. / 10., + ); self.tilemap.draw(ctx); diff --git a/pixel-client/src/main.rs b/pixel-client/src/main.rs index db2585af..7501aba2 100644 --- a/pixel-client/src/main.rs +++ b/pixel-client/src/main.rs @@ -15,10 +15,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use anyhow::anyhow; use clap::{Parser, Subcommand}; use game::Game; -use hurrycurry_protocol::glam::{UVec2, Vec2}; +use hurrycurry_protocol::glam::Vec2; use menu::Menu; use network::Network; use render::SpriteRenderer; @@ -27,10 +26,7 @@ use sdl2::{ keyboard::{KeyboardState, Keycode}, pixels::Color, }; -use std::{ - str::FromStr, - time::{Duration, Instant}, -}; +use std::time::{Duration, Instant}; pub mod game; pub mod helper; @@ -41,9 +37,6 @@ pub mod tilemap; #[derive(Debug, Parser)] pub struct Args { - #[arg(short = 'r', long, default_value = "320x240")] - logical_resolution: Resolution, - #[clap(subcommand)] action: Option<Action>, } @@ -58,16 +51,6 @@ pub enum Action { }, } -#[derive(Debug, Clone)] -struct Resolution(UVec2); -impl FromStr for Resolution { - type Err = anyhow::Error; - fn from_str(s: &str) -> Result<Self, Self::Err> { - let (x, y) = s.split_once("x").ok_or(anyhow!("sep missing"))?; - Ok(Resolution(UVec2::new(x.parse()?, y.parse()?))) - } -} - enum State { Ingame(Game), Menu(Menu), @@ -83,7 +66,6 @@ fn main() { .unwrap(); let sdl_context = sdl2::init().unwrap(); - let ttf_context = sdl2::ttf::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); let window = video_subsystem @@ -113,22 +95,12 @@ fn main() { )), }; - // let font = ttf_context - // .load_font("/usr/share/fonts/noto/NotoSansMono-Regular.ttf", 24) - // .unwrap(); - // let text = font.render("Hello world").blended(Color::WHITE).unwrap(); - // texture_creator.create_texture_from_surface(text).unwrap(); - let mut events = sdl_context.event_pump().unwrap(); let mut last_tick = Instant::now(); - canvas - .set_logical_size(args.logical_resolution.0.x, args.logical_resolution.0.y) - .unwrap(); - 'mainloop: loop { - let (width, height) = canvas.logical_size(); + let (width, height) = canvas.output_size().unwrap(); renderer.size = Vec2::new(width as f32, height as f32); let keyboard = KeyboardState::new(&events); diff --git a/pixel-client/src/menu.rs b/pixel-client/src/menu.rs index d1f43a84..0a05e84c 100644 --- a/pixel-client/src/menu.rs +++ b/pixel-client/src/menu.rs @@ -8,10 +8,5 @@ impl Menu { Self {} } pub fn tick(&mut self, dt: f32, keyboard: &KeyboardState, layout: &AtlasLayout) {} - pub fn draw(&self, ctx: &mut SpriteRenderer) { - - - - - } + pub fn draw(&self, ctx: &mut SpriteRenderer) {} } diff --git a/pixel-client/src/render/mod.rs b/pixel-client/src/render/mod.rs index a2aea365..f18d96ad 100644 --- a/pixel-client/src/render/mod.rs +++ b/pixel-client/src/render/mod.rs @@ -34,6 +34,8 @@ pub struct SpriteRenderer<'a> { pub size: Vec2, texture: Texture<'a>, + round: bool, + view_scale: Vec2, view_offset: Vec2, @@ -103,6 +105,7 @@ impl<'a> SpriteRenderer<'a> { .collect::<HashMap<_, _>>(); Self { + round: true, texture, size: Vec2::ONE, metadata, @@ -139,10 +142,10 @@ impl<'a> SpriteRenderer<'a> { z_order: sprite.z_order, src: sprite.src, dst: FRect::new( - ((sprite.dst.x + self.view_offset.x) * self.view_scale.x).round(), - ((sprite.dst.y + self.view_offset.y) * self.view_scale.y).round(), - (sprite.dst.w * self.view_scale.x).round(), - (sprite.dst.h * self.view_scale.y).round(), + (sprite.dst.x + self.view_offset.x) * self.view_scale.x, + (sprite.dst.y + self.view_offset.y) * self.view_scale.y, + sprite.dst.w * self.view_scale.x, + sprite.dst.h * self.view_scale.y, ), }) } |