diff --git a/source/abstract/Sprite.cpp b/source/abstract/Sprite.cpp index 34cb391..2b2c183 100755 --- a/source/abstract/Sprite.cpp +++ b/source/abstract/Sprite.cpp @@ -57,7 +57,7 @@ Sprite::Sprite(const Data& data, const Yaml& config) : mShape.shape->setTexture(&*mTexture, false); setPosition(data.position); - setAngle(data.angle); + setDirection(data.direction); } /** @@ -69,10 +69,10 @@ Sprite::~Sprite() { /** * Initializes container. */ -Sprite::Data::Data(const sf::Vector2f& position, float angle, +Sprite::Data::Data(const sf::Vector2f& position, const sf::Vector2f& direction, Category category, unsigned short mask) : position(position), - angle(angle), + direction(direction), category(category), mask(mask) { } @@ -96,9 +96,9 @@ Sprite::getSpeed() const { /** * Returns the angle of the sprite. */ -float -Sprite::getAngle() const { - return mShape.shape->getRotation(); +sf::Vector2f +Sprite::getDirection() const { + return thor::rotatedVector(sf::Vector2f(1, 0), mShape.shape->getRotation()); } /** @@ -172,12 +172,11 @@ Sprite::setSpeed(sf::Vector2f direction, float speed) { mSpeed = direction; } -/** - * Sets the angle of the Sprite. - */ void -Sprite::setAngle(float angle) { - mShape.shape->setRotation(angle); +Sprite::setDirection(const sf::Vector2f& direction) { + if (direction != sf::Vector2f()) { + mShape.shape->setRotation(thor::polarAngle(direction) + 90); + } } /** diff --git a/source/abstract/Sprite.h b/source/abstract/Sprite.h index d0c8f76..9ae0686 100755 --- a/source/abstract/Sprite.h +++ b/source/abstract/Sprite.h @@ -36,10 +36,10 @@ public: */ class Data { public: - Data(const sf::Vector2f& position, float angle, Category category, - unsigned short mask); + Data(const sf::Vector2f& position, const sf::Vector2f& direction, + Category category, unsigned short mask); const sf::Vector2f& position; - float angle; + const sf::Vector2f& direction; Category category; unsigned short mask; }; @@ -59,7 +59,7 @@ public: sf::Vector2f getPosition() const; sf::Vector2f getSpeed() const; - float getAngle() const; + sf::Vector2f getDirection() const; bool getDelete() const; Category getCategory() const; sf::Vector2f getSize() const; @@ -78,7 +78,7 @@ public: protected: void setDelete(bool value); void setSpeed(sf::Vector2f direction, float speed); - void setAngle(float angle); + void setDirection(const sf::Vector2f& direction); void setPosition(const sf::Vector2f& position); float getRadius() const; diff --git a/source/effects/Bullet.cpp b/source/effects/Bullet.cpp index 62d5eca..e9b7dcc 100755 --- a/source/effects/Bullet.cpp +++ b/source/effects/Bullet.cpp @@ -24,16 +24,16 @@ const float Bullet::DEFAULT_SPEED = 500; * @param world Box2d world. * @param texture Texture to display for bullet. */ -Bullet::Bullet(const sf::Vector2f& position, Sprite& shooter, float direction, - const Yaml& config) : - Particle(config, Data(position, 0, CATEGORY_PARTICLE, ~CATEGORY_PARTICLE)), +Bullet::Bullet(const sf::Vector2f& position, Sprite& shooter, + sf::Vector2f direction, const Yaml& config) : + Particle(config, Data(position, sf::Vector2f(0, 0), CATEGORY_PARTICLE, + ~CATEGORY_PARTICLE)), mShooter(shooter), mDamage(config.get(KEY_DAMAGE, DEFAULT_DAMAGE)), mSpeed(config.get(KEY_SPEED, DEFAULT_SPEED)) { - sf::Vector2f dir(1.0f, 0); - thor::setPolarAngle(dir, direction - 90); - setSpeed(dir, mSpeed); - setAngle(direction); + thor::rotate(direction, - 90.0f); + setSpeed(direction, mSpeed); + setDirection(direction); } /** diff --git a/source/effects/Bullet.h b/source/effects/Bullet.h index 57d3c1d..b91a1ce 100755 --- a/source/effects/Bullet.h +++ b/source/effects/Bullet.h @@ -18,8 +18,8 @@ class Yaml; class Bullet : public Particle { // Public functions. public: - Bullet(const sf::Vector2f& position, Sprite& shooter, float direction, - const Yaml& config); + Bullet(const sf::Vector2f& position, Sprite& shooter, + sf::Vector2f direction, const Yaml& config); void onCollide(std::shared_ptr other); diff --git a/source/items/Weapon.cpp b/source/items/Weapon.cpp index d80362e..8266a7d 100755 --- a/source/items/Weapon.cpp +++ b/source/items/Weapon.cpp @@ -81,7 +81,7 @@ std::shared_ptr Weapon::createParticle() { // Minus to account for positive y-axis going downwards in SFML. sf::Vector2f offset(- mOffset); - thor::rotate(offset, mHolder.getAngle()); + thor::rotate(offset, thor::polarAngle(mHolder.getDirection())); return std::shared_ptr(new Bullet(mHolder.getPosition() + offset, - mHolder, mHolder.getAngle(), Yaml(mBullet))); + mHolder, mHolder.getDirection(), Yaml(mBullet))); } diff --git a/source/sprites/Corpse.cpp b/source/sprites/Corpse.cpp index 45c45b0..ba53c4e 100644 --- a/source/sprites/Corpse.cpp +++ b/source/sprites/Corpse.cpp @@ -8,6 +8,7 @@ #include "Corpse.h" Corpse::Corpse(const sf::Vector2f& position, const Yaml& config) : - Sprite(Data(position, 0, CATEGORY_NONSOLID, MASK_NONE), config) { + Sprite(Data(position, sf::Vector2f(0, 0), CATEGORY_NONSOLID, MASK_NONE), + config) { } diff --git a/source/sprites/Enemy.cpp b/source/sprites/Enemy.cpp index 3145549..e6fed40 100644 --- a/source/sprites/Enemy.cpp +++ b/source/sprites/Enemy.cpp @@ -7,7 +7,8 @@ #include "Enemy.h" -Enemy::Enemy(World& collection, const sf::Vector2f& position, const Yaml& config) : - Character(collection, Data(position, 0, CATEGORY_ACTOR, MASK_ALL), - config) { +Enemy::Enemy(World& world, const sf::Vector2f& position, + const Yaml& config) : + Character(world, Data(position, sf::Vector2f(0, 0), + CATEGORY_ACTOR, MASK_ALL), config) { } diff --git a/source/sprites/Enemy.h b/source/sprites/Enemy.h index 8d2c57d..35c4067 100644 --- a/source/sprites/Enemy.h +++ b/source/sprites/Enemy.h @@ -16,7 +16,7 @@ class Yaml; class Enemy : public Character { // Public functions. public: - Enemy(World& collection, const sf::Vector2f& position, const Yaml& config); + Enemy(World& world, const sf::Vector2f& position, const Yaml& config); }; #endif /* DG_ENEMY_H_ */ diff --git a/source/sprites/Player.cpp b/source/sprites/Player.cpp index 678ac6d..c2db0f7 100644 --- a/source/sprites/Player.cpp +++ b/source/sprites/Player.cpp @@ -13,8 +13,8 @@ * Initializes Sprite. */ Player::Player(World& world, const sf::Vector2f& position, const Yaml& config) : - Character(world, Data(position, 0, CATEGORY_ACTOR, MASK_ALL), - config), + Character(world, Data(position, sf::Vector2f(0, 0), CATEGORY_ACTOR, + MASK_ALL), config), mDirection(0) { } @@ -97,7 +97,5 @@ Player::onThink(int elapsed) { Character::move(); } // Look towards crosshair. - if (mCrosshairPosition != sf::Vector2f()) { - setAngle(thor::polarAngle(mCrosshairPosition) + 90); - } + Sprite::setDirection(mCrosshairPosition); } diff --git a/source/sprites/TileManager.cpp b/source/sprites/TileManager.cpp index 98f3b37..5e8c71a 100644 --- a/source/sprites/TileManager.cpp +++ b/source/sprites/TileManager.cpp @@ -31,7 +31,7 @@ TileManager::TileManager(World& world) : */ TileManager::Tile::Tile(Type type, const TilePosition& position) : Sprite(Data(sf::Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y), - 0, CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL), + sf::Vector2f(0, 0), CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL), Yaml(getConfig(type))), mType(type) { }