Re-implemented movement.

This commit is contained in:
Felix Ableitner 2012-12-22 16:48:48 +01:00
parent 21040de4dc
commit e6b6bc58fc
3 changed files with 22 additions and 2 deletions

View file

@ -9,6 +9,8 @@
#include <algorithm>
#include <Thor/Vectors.hpp>
/**
* Insert a drawable into the group. Drawables should only be handled with shared_ptr.
* An object can't be inserted more than once at the same level.
@ -37,6 +39,13 @@ World::remove(std::shared_ptr<Sprite> drawable) {
void
World::step(int elapsed) {
for (auto v = mDrawables.begin(); v != mDrawables.end(); v++) {
for (auto item = v->second.begin(); item != v->second.end(); item++) {
sf::Vector2f speed = (*item)->getSpeed();
speed *= elapsed / 1000.0f;
(*item)->setPosition((*item)->getPosition() + speed);
}
}
}
/**

View file

@ -128,7 +128,7 @@ Body::setDelete(bool value) {
* Sets movement speed and direction of the body. Set either value to zero to stop movement.
*
* @param direction The direction the body moves in, does not have to be normalized.
* @param speed The value of the movement speed to be used.
* @param speed Movement speed in pixels per second.
*/
void
Body::setSpeed(sf::Vector2f direction, float speed) {
@ -139,9 +139,17 @@ Body::setSpeed(sf::Vector2f direction, float speed) {
}
/**
* Sets the angle of the body based on the direction of a vector.
* Sets the angle of the body.
*/
void
Body::setAngle(float angle) {
mAngle = angle;
}
/**
* Sets the position of thr body.
*/
void
Body::setPosition(const sf::Vector2f& position) {
mPosition = position;
}

View file

@ -77,9 +77,12 @@ public:
// Protected functions.
protected:
friend class World;
void setDelete(bool value);
void setSpeed(sf::Vector2f direction, float speed);
void setAngle(float angle);
void setPosition(const sf::Vector2f& position);
// Private variables.
private: