Re-implemented movement.
This commit is contained in:
parent
21040de4dc
commit
e6b6bc58fc
3 changed files with 22 additions and 2 deletions
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <Thor/Vectors.hpp>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a drawable into the group. Drawables should only be handled with shared_ptr.
|
* 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.
|
* 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
|
void
|
||||||
World::step(int elapsed) {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -128,7 +128,7 @@ Body::setDelete(bool value) {
|
||||||
* Sets movement speed and direction of the body. Set either value to zero to stop movement.
|
* 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 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
|
void
|
||||||
Body::setSpeed(sf::Vector2f direction, float speed) {
|
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
|
void
|
||||||
Body::setAngle(float angle) {
|
Body::setAngle(float angle) {
|
||||||
mAngle = angle;
|
mAngle = angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the position of thr body.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Body::setPosition(const sf::Vector2f& position) {
|
||||||
|
mPosition = position;
|
||||||
|
}
|
||||||
|
|
|
@ -77,9 +77,12 @@ public:
|
||||||
|
|
||||||
// Protected functions.
|
// Protected functions.
|
||||||
protected:
|
protected:
|
||||||
|
friend class World;
|
||||||
|
|
||||||
void setDelete(bool value);
|
void setDelete(bool value);
|
||||||
void setSpeed(sf::Vector2f direction, float speed);
|
void setSpeed(sf::Vector2f direction, float speed);
|
||||||
void setAngle(float angle);
|
void setAngle(float angle);
|
||||||
|
void setPosition(const sf::Vector2f& position);
|
||||||
|
|
||||||
// Private variables.
|
// Private variables.
|
||||||
private:
|
private:
|
||||||
|
|
Reference in a new issue