Shots keep track of their launch time

This commit is contained in:
Josh Holtrop 2012-10-06 21:27:55 -04:00
parent 3237d4e0e6
commit 1ceacd913d
2 changed files with 4 additions and 2 deletions

View File

@ -44,8 +44,9 @@ Shot::Shot(const Vector2f & origin, double direction, double target_dist)
/ (2 * t * GRAVITY); / (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 horiz_dist = m_speed * time;
float z = INITIAL_SHOT_HEIGHT + m_speed * time - GRAVITY * time * time / 2.0; float z = INITIAL_SHOT_HEIGHT + m_speed * time - GRAVITY * time * time / 2.0;
Vector2f xy = m_direction * horiz_dist; Vector2f xy = m_direction * horiz_dist;

View File

@ -8,11 +8,12 @@ class Shot
{ {
public: public:
Shot(const sf::Vector2f & origin, double direction, double target_dist); Shot(const sf::Vector2f & origin, double direction, double target_dist);
sf::Vector3f get_pos_at_time(double time); sf::Vector3f get_position();
protected: protected:
sf::Vector2f m_origin; sf::Vector2f m_origin;
sf::Vector2f m_direction; sf::Vector2f m_direction;
double m_speed; double m_speed;
sf::Clock m_clock;
}; };
#endif #endif