Removed secondary Sprite constructor (now only via Yaml).
This commit is contained in:
parent
9b61304d1e
commit
516633a374
12 changed files with 26 additions and 44 deletions
|
@ -33,7 +33,7 @@ TileManager::TileManager(b2World& world) :
|
||||||
* @param world Box2D world object.
|
* @param world Box2D world object.
|
||||||
*/
|
*/
|
||||||
TileManager::Tile::Tile(Type type, const TilePosition& position, b2World& world) :
|
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)),
|
world, CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL, false)),
|
||||||
mType(type) {
|
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.
|
* @param type The type of tile to load a resource key for.
|
||||||
* @return Resource key to the correct texture.
|
* @return Resource key to the correct texture.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<sf::Texture>
|
String
|
||||||
TileManager::Tile::getTexture(Type type) {
|
TileManager::Tile::getConfig(Type type) {
|
||||||
String filename;
|
String filename;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::FLOOR:
|
case Type::FLOOR:
|
||||||
filename = "floor.png";
|
filename = "tile_floor.yaml";
|
||||||
break;
|
break;
|
||||||
case Type::WALL:
|
case Type::WALL:
|
||||||
filename = "wall.png";
|
filename = "tile_wall.yaml";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new aurora::Exception("Invalid tile type.");
|
throw new aurora::Exception("Invalid tile type.");
|
||||||
}
|
}
|
||||||
return ResourceManager::i().acquire(Loader::i().fromFile<sf::Texture>(filename));
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,12 +12,11 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
|
|
||||||
#include <Box2D/Box2D.h>
|
#include <Box2D/Box2D.h>
|
||||||
|
|
||||||
#include "util/Vector.h"
|
#include "util/Vector.h"
|
||||||
#include "abstract/Sprite.h"
|
#include "abstract/Sprite.h"
|
||||||
|
#include "util/String.h"
|
||||||
|
|
||||||
class Sprite;
|
class Sprite;
|
||||||
|
|
||||||
|
@ -70,7 +69,7 @@ public:
|
||||||
Type getType() const;
|
Type getType() const;
|
||||||
TilePosition getTilePosition() const;
|
TilePosition getTilePosition() const;
|
||||||
|
|
||||||
static std::shared_ptr<sf::Texture> getTexture(Type type);
|
static String getConfig(Type type);
|
||||||
|
|
||||||
// Private variables.
|
// Private variables.
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -89,6 +89,10 @@ public:
|
||||||
virtual bool doesCollide(Physical& other);
|
virtual bool doesCollide(Physical& other);
|
||||||
virtual void onCollide(Physical& other, uint16 category);
|
virtual void onCollide(Physical& other, uint16 category);
|
||||||
|
|
||||||
|
// Public variables.
|
||||||
|
public:
|
||||||
|
static const String KEY_SIZE;
|
||||||
|
|
||||||
// Protected functions.
|
// Protected functions.
|
||||||
protected:
|
protected:
|
||||||
void setDelete(bool value);
|
void setDelete(bool value);
|
||||||
|
@ -98,8 +102,6 @@ protected:
|
||||||
|
|
||||||
// Private variables.
|
// Private variables.
|
||||||
private:
|
private:
|
||||||
static const String KEY_SIZE;
|
|
||||||
|
|
||||||
b2Body* mBody;
|
b2Body* mBody;
|
||||||
bool mDelete;
|
bool mDelete;
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,17 +24,6 @@ Sprite::Sprite(const Yaml& config, const PhysicalData& data) :
|
||||||
mSize(Vector2i(getSize())) {
|
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.
|
* Does nothing.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "../util/Loader.h"
|
#include "../util/Loader.h"
|
||||||
#include "../util/ResourceManager.h"
|
#include "../util/ResourceManager.h"
|
||||||
|
|
||||||
const Vector2i Bullet::SIZE = Vector2i(20, 20);
|
|
||||||
const String Bullet::KEY_DAMAGE = "damage";
|
const String Bullet::KEY_DAMAGE = "damage";
|
||||||
const String Bullet::KEY_SPEED = "speed";
|
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,
|
Bullet::Bullet(const Vector2f& position, b2World& world, Physical& shooter, float direction,
|
||||||
const Yaml& config) :
|
const Yaml& config) :
|
||||||
Particle(ResourceManager::i().acquire(Loader::i().fromFile<sf::Texture>("bullet.png")),
|
Particle(config, PhysicalData(position, world, CATEGORY_PARTICLE, CATEGORY_PARTICLE,
|
||||||
PhysicalData(position, world, CATEGORY_PARTICLE, CATEGORY_PARTICLE,
|
true, true, true)),
|
||||||
true, true, true), config),
|
|
||||||
mShooter(shooter),
|
mShooter(shooter),
|
||||||
mDamage(config.get<int>(KEY_DAMAGE)),
|
mDamage(config.get<int>(KEY_DAMAGE)),
|
||||||
mSpeed(config.get<int>(KEY_SPEED)) {
|
mSpeed(config.get<int>(KEY_SPEED)) {
|
||||||
|
|
|
@ -27,10 +27,6 @@ public:
|
||||||
void onCollide(Physical& other, uint16 category);
|
void onCollide(Physical& other, uint16 category);
|
||||||
bool doesCollide(Physical& other);
|
bool doesCollide(Physical& other);
|
||||||
|
|
||||||
// Public variables.
|
|
||||||
public:
|
|
||||||
static const Vector2i SIZE;
|
|
||||||
|
|
||||||
// Private variables.
|
// Private variables.
|
||||||
private:
|
private:
|
||||||
static const String KEY_DAMAGE;
|
static const String KEY_DAMAGE;
|
||||||
|
|
|
@ -20,10 +20,12 @@ Weapon::Weapon(const Instances& instances, Physical& holder, const Yaml& config)
|
||||||
Emitter(instances.collection),
|
Emitter(instances.collection),
|
||||||
mHolder(holder),
|
mHolder(holder),
|
||||||
mWorld(instances.world),
|
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)) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,7 +43,7 @@ private:
|
||||||
Physical& mHolder;
|
Physical& mHolder;
|
||||||
b2World& mWorld;
|
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;
|
const String mBullet;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,8 @@
|
||||||
|
|
||||||
#include "Particle.h"
|
#include "Particle.h"
|
||||||
|
|
||||||
Particle::Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data,
|
Particle::Particle(const Yaml& config, const PhysicalData& data) :
|
||||||
const Yaml& config) :
|
Sprite(config, data) {
|
||||||
Sprite(texture, data) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Particle::~Particle() {
|
Particle::~Particle() {
|
||||||
|
|
|
@ -20,8 +20,7 @@ class Yaml;
|
||||||
class Particle : public Sprite {
|
class Particle : public Sprite {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data,
|
Particle(const Yaml& config, const PhysicalData& data);
|
||||||
const Yaml& config);
|
|
||||||
virtual ~Particle();
|
virtual ~Particle();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include "../util/String.h"
|
#include "../util/String.h"
|
||||||
|
|
||||||
const float Player::SPEED = 100.0f;
|
const float Player::SPEED = 100.0f;
|
||||||
const Vector2i Player::SIZE = Vector2i(50, 50);
|
|
||||||
const float Player::POINT_REACHED_DISTANCE = 1.0f;
|
const float Player::POINT_REACHED_DISTANCE = 1.0f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -57,7 +57,6 @@ private:
|
||||||
// Private variables.
|
// Private variables.
|
||||||
private:
|
private:
|
||||||
static const float SPEED;
|
static const float SPEED;
|
||||||
static const Vector2i SIZE;
|
|
||||||
/// The distance to a point where it is considered reached.
|
/// The distance to a point where it is considered reached.
|
||||||
static const float POINT_REACHED_DISTANCE;
|
static const float POINT_REACHED_DISTANCE;
|
||||||
|
|
||||||
|
|
Reference in a new issue