Removed secondary Sprite constructor (now only via Yaml).

This commit is contained in:
Felix Ableitner 2012-10-13 12:48:16 +02:00
parent 9b61304d1e
commit 516633a374
12 changed files with 26 additions and 44 deletions

View file

@ -33,7 +33,7 @@ TileManager::TileManager(b2World& world) :
* @param world Box2D world object.
*/
TileManager::Tile::Tile(Type type, const TilePosition& position, b2World& world) :
Sprite(getTexture(type), PhysicalData(Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y),
Sprite(Yaml(getConfig(type)), PhysicalData(Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y),
world, CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL, false)),
mType(type) {
}
@ -44,20 +44,20 @@ TileManager::Tile::Tile(Type type, const TilePosition& position, b2World& world)
* @param type The type of tile to load a resource key for.
* @return Resource key to the correct texture.
*/
std::shared_ptr<sf::Texture>
TileManager::Tile::getTexture(Type type) {
String
TileManager::Tile::getConfig(Type type) {
String filename;
switch (type) {
case Type::FLOOR:
filename = "floor.png";
filename = "tile_floor.yaml";
break;
case Type::WALL:
filename = "wall.png";
filename = "tile_wall.yaml";
break;
default:
throw new aurora::Exception("Invalid tile type.");
}
return ResourceManager::i().acquire(Loader::i().fromFile<sf::Texture>(filename));
return filename;
}
/**

View file

@ -12,12 +12,11 @@
#include <memory>
#include <vector>
#include <SFML/Graphics.hpp>
#include <Box2D/Box2D.h>
#include "util/Vector.h"
#include "abstract/Sprite.h"
#include "util/String.h"
class Sprite;
@ -70,7 +69,7 @@ public:
Type getType() const;
TilePosition getTilePosition() const;
static std::shared_ptr<sf::Texture> getTexture(Type type);
static String getConfig(Type type);
// Private variables.
private:

View file

@ -89,6 +89,10 @@ public:
virtual bool doesCollide(Physical& other);
virtual void onCollide(Physical& other, uint16 category);
// Public variables.
public:
static const String KEY_SIZE;
// Protected functions.
protected:
void setDelete(bool value);
@ -98,8 +102,6 @@ protected:
// Private variables.
private:
static const String KEY_SIZE;
b2Body* mBody;
bool mDelete;
};

View file

@ -24,17 +24,6 @@ Sprite::Sprite(const Yaml& config, const PhysicalData& data) :
mSize(Vector2i(getSize())) {
}
/**
* Loads sprite from ResourceManager, sets world position. Use this if the texture has already been loaded.
*
* @param texture Pointer to the texture to be used (must already be loaded).
*/
Sprite::Sprite(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data) :
Physical(data, Yaml("tile.yaml")),
mTexture(texture),
mSize(Vector2i(getSize())) {
}
/**
* Does nothing.
*/

View file

@ -11,7 +11,6 @@
#include "../util/Loader.h"
#include "../util/ResourceManager.h"
const Vector2i Bullet::SIZE = Vector2i(20, 20);
const String Bullet::KEY_DAMAGE = "damage";
const String Bullet::KEY_SPEED = "speed";
@ -24,9 +23,8 @@ const String Bullet::KEY_SPEED = "speed";
*/
Bullet::Bullet(const Vector2f& position, b2World& world, Physical& shooter, float direction,
const Yaml& config) :
Particle(ResourceManager::i().acquire(Loader::i().fromFile<sf::Texture>("bullet.png")),
PhysicalData(position, world, CATEGORY_PARTICLE, CATEGORY_PARTICLE,
true, true, true), config),
Particle(config, PhysicalData(position, world, CATEGORY_PARTICLE, CATEGORY_PARTICLE,
true, true, true)),
mShooter(shooter),
mDamage(config.get<int>(KEY_DAMAGE)),
mSpeed(config.get<int>(KEY_SPEED)) {

View file

@ -27,10 +27,6 @@ public:
void onCollide(Physical& other, uint16 category);
bool doesCollide(Physical& other);
// Public variables.
public:
static const Vector2i SIZE;
// Private variables.
private:
static const String KEY_DAMAGE;

View file

@ -20,10 +20,12 @@ Weapon::Weapon(const Instances& instances, Physical& holder, const Yaml& config)
Emitter(instances.collection),
mHolder(holder),
mWorld(instances.world),
mOffset(0, std::max(mHolder.getSize().x, mHolder.getSize().y) / 2 +
b2_linearSlop +
std::max(Bullet::SIZE.x, Bullet::SIZE.y) / 2),
mBullet(config.get<String>(KEY_BULLET)) {
Yaml bullet(mBullet);
Vector2i bulletSize = bullet.get<Vector2i>(Physical::KEY_SIZE);
mOffset = Vector2f(0, std::max(mHolder.getSize().x, mHolder.getSize().y) / 2 +
b2_linearSlop +
std::max(bulletSize.x, bulletSize.y) / 2);
}
/**

View file

@ -43,7 +43,7 @@ private:
Physical& mHolder;
b2World& mWorld;
const Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).
Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).
const String mBullet;
};

View file

@ -7,9 +7,8 @@
#include "Particle.h"
Particle::Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data,
const Yaml& config) :
Sprite(texture, data) {
Particle::Particle(const Yaml& config, const PhysicalData& data) :
Sprite(config, data) {
}
Particle::~Particle() {

View file

@ -20,8 +20,7 @@ class Yaml;
class Particle : public Sprite {
// Public functions.
public:
Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data,
const Yaml& config);
Particle(const Yaml& config, const PhysicalData& data);
virtual ~Particle();
};

View file

@ -14,7 +14,6 @@
#include "../util/String.h"
const float Player::SPEED = 100.0f;
const Vector2i Player::SIZE = Vector2i(50, 50);
const float Player::POINT_REACHED_DISTANCE = 1.0f;
/**

View file

@ -57,7 +57,6 @@ private:
// Private variables.
private:
static const float SPEED;
static const Vector2i SIZE;
/// The distance to a point where it is considered reached.
static const float POINT_REACHED_DISTANCE;