Renamed Body to Corpse, Physical to Body.

This commit is contained in:
Felix Ableitner 2012-12-20 10:31:32 +01:00
parent 1e0d005a1b
commit 88db5d5324
21 changed files with 83 additions and 83 deletions

View file

@ -251,8 +251,8 @@ Game::getFps() {
*/
void
Game::BeginContact(b2Contact* contact) {
Physical& first = *static_cast<Physical*>(contact->GetFixtureA()->GetBody()->GetUserData());
Physical& second = *static_cast<Physical*>(contact->GetFixtureB()->GetBody()->GetUserData());
Body& first = *static_cast<Body*>(contact->GetFixtureA()->GetBody()->GetUserData());
Body& second = *static_cast<Body*>(contact->GetFixtureB()->GetBody()->GetUserData());
if (!first.doesCollide(second) || !second.doesCollide(first)) {
contact->SetEnabled(false);

View file

@ -1,24 +1,24 @@
/*
* Physical.cpp
* Body.cpp
*
* Created on: 11.08.2012
* Author: Felix
*/
#include "Physical.h"
#include "Body.h"
#include <math.h>
#include <Thor/Vectors.hpp>
const String Physical::KEY_SIZE = "size";
const String Body::KEY_SIZE = "size";
/**
* Initializes Box2D body.
*
* @param data Data needed for construction.
*/
Physical::Physical(const PhysicalData& data, const Yaml& config, const Vector2i& pSize) :
Body::Body(const PhysicalData& data, const Yaml& config, const Vector2i& pSize) :
mDelete(false) {
Vector2i size = (pSize == Vector2i())
? config.get<Vector2i>(KEY_SIZE)
@ -66,7 +66,7 @@ Physical::Physical(const PhysicalData& data, const Yaml& config, const Vector2i&
/**
* Removes body from world.
*/
Physical::~Physical() {
Body::~Body() {
mBody->GetWorld()->DestroyBody(mBody);
}
@ -75,7 +75,7 @@ Physical::~Physical() {
*
* @link Physical::PhysicalData
*/
Physical::PhysicalData::PhysicalData( const Vector2f& position, b2World& world, uint16 category,
Body::PhysicalData::PhysicalData( const Vector2f& position, b2World& world, uint16 category,
uint16 maskExclude, bool moving, bool bullet, bool circle) :
position(position),
world(world),
@ -90,7 +90,7 @@ Physical::PhysicalData::PhysicalData( const Vector2f& position, b2World& world,
* Returns the position of the sprite (center).
*/
Vector2f
Physical::getPosition() const {
Body::getPosition() const {
return vector(mBody->GetPosition());
}
@ -98,7 +98,7 @@ Physical::getPosition() const {
* Returns the movement speed of the body.
*/
Vector2f
Physical::getSpeed() const {
Body::getSpeed() const {
return vector(mBody->GetLinearVelocity());
}
@ -106,7 +106,7 @@ Physical::getSpeed() const {
* Returns the rotation of the body (converted to an SFML angle).
*/
float
Physical::getAngle() const {
Body::getAngle() const {
return thor::toDegree(mBody->GetAngle());
}
@ -114,15 +114,15 @@ Physical::getAngle() const {
* Returns true if this object should be deleted.
*/
bool
Physical::getDelete() const {
Body::getDelete() const {
return mDelete;
}
/**
* Returns the Physical::Category of this object.
*/
Physical::Category
Physical::getCategory() const {
Body::Category
Body::getCategory() const {
return (Category) mBody->GetFixtureList()->GetFilterData().categoryBits;
}
@ -130,7 +130,7 @@ Physical::getCategory() const {
* Returns the size of the body as a vector.
*/
Vector2f
Physical::getSize() const {
Body::getSize() const {
b2AABB aabb(mBody->GetFixtureList()->GetAABB(0));
return vector(aabb.upperBound - aabb.lowerBound);
}
@ -139,7 +139,7 @@ Physical::getSize() const {
* Returns true if collisions are enabled for the body.
*/
bool
Physical::isSolid() const {
Body::isSolid() const {
return mBody->GetFixtureList()->GetFilterData().maskBits != 0;
}
@ -147,7 +147,7 @@ Physical::isSolid() const {
* Returns true if the body is able to move.
*/
bool
Physical::isMovable() const {
Body::isMovable() const {
return mBody->GetType() != b2_staticBody;
}
@ -159,7 +159,7 @@ Physical::isMovable() const {
* @return True if the objects should collide.
*/
bool
Physical::doesCollide(Physical& other) {
Body::doesCollide(Body& other) {
return true;
}
@ -171,14 +171,14 @@ Physical::doesCollide(Physical& other) {
* @param category The Category of the other object (as passed in constructor).
*/
void
Physical::onCollide(Physical& other, uint16 type) {
Body::onCollide(Body& other, uint16 type) {
}
/**
* Set to true to mark this object for deletion from the world.
*/
void
Physical::setDelete(bool value) {
Body::setDelete(bool value) {
mDelete = value;
}
@ -189,7 +189,7 @@ Physical::setDelete(bool value) {
* @param speed The value of the movement speed to be used.
*/
void
Physical::setSpeed(Vector2f direction, float speed) {
Body::setSpeed(Vector2f direction, float speed) {
if (direction != Vector2f()) {
direction = thor::unitVector<float>(direction);
}
@ -201,6 +201,6 @@ Physical::setSpeed(Vector2f direction, float speed) {
* Sets the angle of the body based on the direction of a vector.
*/
void
Physical::setAngle(float angle) {
Body::setAngle(float angle) {
mBody->SetTransform(mBody->GetPosition(), thor::toRadian(angle));
}

View file

@ -21,7 +21,7 @@ class Yaml;
*
* @warning May only handle bodies with one fixture.
*/
class Physical {
class Body {
// Public types.
public:
/**
@ -73,8 +73,8 @@ public:
// Public functions.
public:
Physical(const PhysicalData& data, const Yaml& config, const Vector2i& pSize = Vector2i());
virtual ~Physical() = 0;
Body(const PhysicalData& data, const Yaml& config, const Vector2i& pSize = Vector2i());
virtual ~Body() = 0;
Vector2f getPosition() const;
Vector2f getSpeed() const;
@ -86,8 +86,8 @@ public:
bool isSolid() const;
bool isMovable() const;
virtual bool doesCollide(Physical& other);
virtual void onCollide(Physical& other, uint16 category);
virtual bool doesCollide(Body& other);
virtual void onCollide(Body& other, uint16 category);
// Public variables.
public:

View file

@ -12,7 +12,7 @@
#include <Thor/Vectors.hpp>
#include "../sprites/Body.h"
#include "../sprites/Corpse.h"
#include "../util/Log.h"
const String Character::KEY_HEALTH = "health";
@ -44,7 +44,7 @@ Character::~Character() {
assert(it != mCharacterInstances.end());
mCharacterInstances.erase(it);
mInstances.collection.insert(std::shared_ptr<Sprite>(new Body(mInstances.world,
mInstances.collection.insert(std::shared_ptr<Sprite>(new Corpse(mInstances.world,
getPosition(), Yaml("body.yaml"))));
}

View file

@ -18,7 +18,7 @@ const String Sprite::KEY_TEXTURE = "texture";
* @param texturePath Relative path to the texture file in the resource folder.
*/
Sprite::Sprite(const Yaml& config, const PhysicalData& data, const Vector2i& size) :
Physical(data, config, size),
Body(data, config, size),
mTexture(ResourceManager::i().acquire(Loader::i()
.fromFile<sf::Texture>(config.get<String>(KEY_TEXTURE)))),
mSize(Vector2i(getSize())) {

View file

@ -12,12 +12,12 @@
#include <Thor/Resources.hpp>
#include "Physical.h"
#include "Body.h"
#include "../types/String.h"
#include "../types/Vector.h"
#include "../util/Yaml.h"
class Physical;
class Body;
class Yaml;
/**
@ -25,7 +25,7 @@ class Yaml;
*
* Handles drawing to world.
*/
class Sprite : public sf::Drawable, public Physical {
class Sprite : public sf::Drawable, public Body {
// Public functions.
public:
Sprite(const Yaml& config, const PhysicalData& data, const Vector2i& size = Vector2i());

View file

@ -21,7 +21,7 @@ const String Bullet::KEY_SPEED = "speed";
* @param world Box2d world.
* @param texture Texture to display for bullet.
*/
Bullet::Bullet(const Vector2f& position, b2World& world, Physical& shooter, float direction,
Bullet::Bullet(const Vector2f& position, b2World& world, Body& shooter, float direction,
const Yaml& config) :
Particle(config, PhysicalData(position, world, CATEGORY_PARTICLE, CATEGORY_PARTICLE,
true, true, true)),
@ -36,7 +36,7 @@ Bullet::Bullet(const Vector2f& position, b2World& world, Physical& shooter, floa
* @copydoc Physical::onCollide
*/
void
Bullet::onCollide(Physical& other, uint16 type) {
Bullet::onCollide(Body& other, uint16 type) {
// Make sure we do not damage twice.
if (!getDelete()) {
// Call onShot on other, with damage as param.
@ -49,6 +49,6 @@ Bullet::onCollide(Physical& other, uint16 type) {
}
bool
Bullet::doesCollide(Physical& other) {
Bullet::doesCollide(Body& other) {
return &other != &mShooter;
}

View file

@ -21,18 +21,18 @@ class Yaml;
class Bullet : public Particle {
// Public functions.
public:
Bullet(const Vector2f& position, b2World& world, Physical& shooter, float direction,
Bullet(const Vector2f& position, b2World& world, Body& shooter, float direction,
const Yaml& config);
void onCollide(Physical& other, uint16 category);
bool doesCollide(Physical& other);
void onCollide(Body& other, uint16 category);
bool doesCollide(Body& other);
// Private variables.
private:
static const String KEY_DAMAGE;
static const String KEY_SPEED;
Physical& mShooter;
Body& mShooter;
const int mDamage;
const float mSpeed;
};

View file

@ -17,14 +17,14 @@
const String Weapon::KEY_BULLET = "bullet";
const String Weapon::KEY_INTERVAL = "interval";
Weapon::Weapon(const Instances& instances, Physical& holder, const Yaml& config) :
Weapon::Weapon(const Instances& instances, Body& holder, const Yaml& config) :
Emitter(instances.collection),
mHolder(holder),
mWorld(instances.world),
mBullet(config.get<String>(KEY_BULLET)),
mTimer(sf::milliseconds(config.get<int>(KEY_INTERVAL))) {
Yaml bullet(mBullet);
Vector2i bulletSize = bullet.get<Vector2i>(Physical::KEY_SIZE);
Vector2i bulletSize = bullet.get<Vector2i>(Body::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

@ -10,7 +10,7 @@
#include <Thor/Particles.hpp>
#include "../abstract/Physical.h"
#include "../abstract/Body.h"
#include "../particle/Emitter.h"
#include "../types/Instances.h"
#include "../util/Timer.h"
@ -18,7 +18,7 @@
class Emitter;
class Instances;
class Physical;
class Body;
class Timer;
class Yaml;
@ -30,7 +30,7 @@ class Yaml;
class Weapon : public Emitter {
// Public functions.
public:
Weapon(const Instances& instances, Physical& holder, const Yaml& config);
Weapon(const Instances& instances, Body& holder, const Yaml& config);
void fire();
@ -43,7 +43,7 @@ private:
static const String KEY_BULLET;
static const String KEY_INTERVAL;
Physical& mHolder;
Body& mHolder;
b2World& mWorld;
Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).

View file

@ -8,11 +8,11 @@
#ifndef DG_EMITTER_H_
#define DG_EMITTER_H_
#include "../abstract/Physical.h"
#include "../abstract/Body.h"
#include "../util/Collection.h"
#include "Particle.h"
class Physical;
class Body;
class Collection;
class Particle;

View file

@ -1,23 +0,0 @@
/*
* Body.h
*
* Created on: 13.09.2012
* Author: Felix
*/
#ifndef DG_BODY_H_
#define DG_BODY_H_
#include "../abstract/Sprite.h"
#include "../util/Yaml.h"
class Sprite;
class Yaml;
class Body : public Sprite {
// Public functions.
public:
Body(b2World& world, const Vector2f& position, const Yaml& config);
};
#endif /* DG_BODY_H_ */

View file

@ -1,13 +1,13 @@
/*
* Body.cpp
* Corpse.cpp
*
* Created on: 13.09.2012
* Author: Felix
*/
#include "Body.h"
#include "Corpse.h"
Body::Body(b2World& world, const Vector2f& position, const Yaml& config) :
Corpse::Corpse(b2World& world, const Vector2f& position, const Yaml& config) :
Sprite(config, PhysicalData(position, world, CATEGORY_NONSOLID, MASK_NONE, false)) {
}

23
source/sprites/Corpse.h Normal file
View file

@ -0,0 +1,23 @@
/*
* Corpse.h
*
* Created on: 13.09.2012
* Author: Felix
*/
#ifndef DG_CORPSE_H_
#define DG_CORPSE_H_
#include "../abstract/Sprite.h"
#include "../util/Yaml.h"
class Sprite;
class Yaml;
class Corpse : public Sprite {
// Public functions.
public:
Corpse(b2World& world, const Vector2f& position, const Yaml& config);
};
#endif /* DG_CORPSE_H_ */

View file

@ -7,7 +7,7 @@
#include "Enemy.h"
#include "Body.h"
#include "Corpse.h"
Enemy::Enemy(const Instances& instances, const Vector2f& position, const Yaml& config) :
Character(instances, "enemy.png", PhysicalData(position, instances.world,

View file

@ -99,7 +99,7 @@ Player::onThink(float elapsedTime) {
* Stop movement if we collide with anything except bullets.
*/
void
Player::onCollide(Physical& other, uint16 category) {
Player::onCollide(Body& other, uint16 category) {
if (category != CATEGORY_PARTICLE) {
setDestination(getPosition());
}

View file

@ -51,7 +51,7 @@ public:
// Private functions.
private:
void onCollide(Physical& other, uint16 category);
void onCollide(Body& other, uint16 category);
void onThink(float elapsedTime);
// Private variables.

View file

@ -15,7 +15,7 @@
*/
void
Collection::insert(std::shared_ptr<Sprite> drawable) {
Physical::Category cat = drawable->getCategory();
Body::Category cat = drawable->getCategory();
auto item = std::find(mDrawables[cat].begin(), mDrawables[cat].end(), drawable);
if (item == mDrawables[cat].end()) {
mDrawables[cat].push_back(drawable);

View file

@ -36,7 +36,7 @@ private:
// Private variables.
private:
std::map<Physical::Category, std::vector<std::shared_ptr<Sprite> > > mDrawables;
std::map<Body::Category, std::vector<std::shared_ptr<Sprite> > > mDrawables;
};
#endif /* DG_COLLECTION_H_ */

View file

@ -305,7 +305,7 @@ Pathfinder::Pathfinder(b2World& world) :
* Sometimes moves into wall and instantly out again.
*/
std::vector<Vector2f>
Pathfinder::getPath(Physical& physical, const Vector2f& destination) {
Pathfinder::getPath(Body& physical, const Vector2f& destination) {
Vertex start(vertex(physical.getPosition()));
Vertex goal(vertex(destination));
@ -389,7 +389,7 @@ FilterVertex::operator()(Vertex const& vertex) const {
bool
FilterVertex::Callback::ReportFixture(b2Fixture* fixture) {
Physical& physical = *static_cast<Physical*>(fixture->GetBody()->GetUserData());
Body& physical = *static_cast<Body*>(fixture->GetBody()->GetUserData());
if (!physical.isMovable() && physical.isSolid()) {
empty = false;
return true;

View file

@ -10,7 +10,7 @@
#include <Box2D/Box2D.h>
#include "../abstract/Physical.h"
#include "../abstract/Body.h"
#include "../types/Vector.h"
/**
@ -21,7 +21,7 @@ class Pathfinder {
public:
Pathfinder(b2World& world);
std::vector<Vector2f> getPath(Physical& physical, const Vector2f& destination);
std::vector<Vector2f> getPath(Body& physical, const Vector2f& destination);
// Private variables.
private: