From 1ceacd913d14e10cc6876a2eea82580b58549d3d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 6 Oct 2012 21:27:55 -0400 Subject: [PATCH] Shots keep track of their launch time --- src/common/Shot.cc | 3 ++- src/common/Shot.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/Shot.cc b/src/common/Shot.cc index 1b2f1c2..763bde4 100644 --- a/src/common/Shot.cc +++ b/src/common/Shot.cc @@ -44,8 +44,9 @@ Shot::Shot(const Vector2f & origin, double direction, double target_dist) / (2 * t * GRAVITY); } -Vector3f Shot::get_pos_at_time(double time) +Vector3f Shot::get_position() { + float time = m_clock.getElapsedTime().asSeconds(); float horiz_dist = m_speed * time; float z = INITIAL_SHOT_HEIGHT + m_speed * time - GRAVITY * time * time / 2.0; Vector2f xy = m_direction * horiz_dist; diff --git a/src/common/Shot.h b/src/common/Shot.h index 5421351..f70dbc7 100644 --- a/src/common/Shot.h +++ b/src/common/Shot.h @@ -8,11 +8,12 @@ class Shot { public: Shot(const sf::Vector2f & origin, double direction, double target_dist); - sf::Vector3f get_pos_at_time(double time); + sf::Vector3f get_position(); protected: sf::Vector2f m_origin; sf::Vector2f m_direction; double m_speed; + sf::Clock m_clock; }; #endif