Minor cleanup

master
Mark 2023-12-21 12:29:30 -08:00
parent 8fc23dd359
commit 53927a9944
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
4 changed files with 16 additions and 42 deletions

View File

@ -1,6 +1,3 @@
use sdl2::gfx::primitives::DrawRenderer;
use sdl2::pixels::Color;
use crate::DrawContext;
use crate::Drawable;
use crate::SpriteAtlas;
@ -19,11 +16,6 @@ impl Drawable for Doodad {
let sprite = sa.get(&self.sprite);
sprite.draw(dc.canvas, pos, self.angle, 1.0)?;
let p = self.pos.screen_position_real(dc);
dc.canvas
.aa_circle(p.x as i16, p.y as i16, 5, Color::RGB(255, 0, 0))?;
dc.canvas.set_draw_color(Color::RGB(0, 0, 0));
return Ok(());
}
}

View File

@ -10,6 +10,12 @@ impl Cartesian {
pub fn new(x: f64, y: f64) -> Self {
Cartesian { x, y }
}
/*
pub fn norm(&self) -> f64 {
return (self.x * self.x + self.y * self.y).sqrt();
}
*/
}
impl From<(u32, u32)> for Cartesian {

View File

@ -13,45 +13,32 @@ impl WorldPosition {
WorldPosition { pos: pos, par }
}
/*
fn from_screen_position(dc: &DrawContext, pos: Cartesian, par: f64) -> Self {
WorldPosition {
par,
pos: ((pos * Cartesian::new(1.0, -1.0)) + dc.top_left) * par + dc.camera.pos,
}
}
*/
/// Get the position of this drawable on the screen
/// (0, 0) is at top-left corner.
///
/// Transform this world coordinate into a position on the screen,
/// taking parallax into account. (0, 0) is at top-left corner.
/// Returned position is this object's center.
pub fn screen_position(&self, dc: &DrawContext) -> Cartesian {
let par = self.par;
let pos: Cartesian = self.pos.into();
let pos: Cartesian = self.pos;
return (((pos - dc.camera.pos) / par) - dc.top_left) * Cartesian::new(1.0, -1.0);
}
/// Get the position of this drawable on the screen
/// (0, 0) is at top-left corner.
///
/// Returned position is this object's center.
/*
/// Transform this world coordinate into a position on the screen, ignoring parallax.
/// Used for debugging.
pub fn screen_position_real(&self, dc: &DrawContext) -> Cartesian {
let pos: Cartesian = self.pos.into();
let pos: Cartesian = self.pos;
return ((pos - dc.camera.pos) - dc.top_left) * Cartesian::new(1.0, -1.0);
}
/// Is this object on screen?
fn on_screen(&self, dc: &DrawContext) -> bool {
let pos = self.screen_position(dc);
let (width, height) = (10, 10); //TODO: actual
// Don't draw if we're not on the screen.
// An offset is included to ensure we're completely
// off the screen. We add the whole width intentionally.
return !(pos.x < -1.0 * (width as f64)
|| pos.x > dc.window_size.x + width as f64
|| pos.y < -1.0 * (height as f64)
|| pos.y > dc.window_size.y + height as f64);
}
*/
}
impl Into<Cartesian> for WorldPosition {

View File

@ -60,17 +60,6 @@ impl<'a> Sprite<'a> {
false,
)?;
/*
canvas.set_draw_color(Color::RGB(255, 0, 0));
canvas.aa_circle(
position.x as i16,
position.y as i16,
5,
Color::RGB(255, 0, 0),
)?;
canvas.set_draw_color(Color::RGB(0, 0, 0));
*/
return Ok(());
}
}