diff --git a/src/doodad.rs b/src/doodad.rs index a2cdd63..feb735d 100644 --- a/src/doodad.rs +++ b/src/doodad.rs @@ -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(()); } } diff --git a/src/physics/cartesian.rs b/src/physics/cartesian.rs index ceb4aea..fb8f2c7 100644 --- a/src/physics/cartesian.rs +++ b/src/physics/cartesian.rs @@ -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 { diff --git a/src/physics/worldposition.rs b/src/physics/worldposition.rs index 09e44e0..bb42704 100644 --- a/src/physics/worldposition.rs +++ b/src/physics/worldposition.rs @@ -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 for WorldPosition { diff --git a/src/sprite.rs b/src/sprite.rs index 073a140..3a99f9f 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -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(()); } }