Merged invalid branch.
This commit is contained in:
commit
a793cc8933
10 changed files with 56 additions and 55 deletions
|
@ -8,12 +8,11 @@
|
|||
#include "Game.h"
|
||||
|
||||
#include "abstract/Actor.h"
|
||||
#include "sprite/Cover.h"
|
||||
#include "sprite/Enemy.h"
|
||||
#include "sprite/Cover.h"
|
||||
#include "sprite/Enemy.h"
|
||||
#include "util/Loader.h"
|
||||
#include "util/ResourceManager.h"
|
||||
#include "util/String.h"
|
||||
#include "util/Log.h"
|
||||
|
||||
/// Goal amount of frames per second.
|
||||
const int Game::FPS_GOAL = 60;
|
||||
|
@ -30,23 +29,22 @@ Game::Game(const Vector2i& resolution) :
|
|||
sf::Style::Close | sf::Style::Titlebar),
|
||||
mView(Vector2f(0, 0), Vector2f(resolution)),
|
||||
//mFps("test"),
|
||||
mTileManager(mWorld),
|
||||
mPlayer(mWorld, mCollection, Vector2f(200.0f, 100.0f)),
|
||||
mTileManager(mWorld),
|
||||
mPlayer(mWorld, mCollection, Vector2f(200.0f, 100.0f)),
|
||||
mElapsed(0),
|
||||
mQuit(false),
|
||||
mPaused(false) {
|
||||
mWindow.setFramerateLimit(FPS_GOAL);
|
||||
mWindow.setKeyRepeatEnabled(true);
|
||||
mWindow.setKeyRepeatEnabled(true);
|
||||
mWorld.SetContactListener(this);
|
||||
|
||||
mTileManager.generate();
|
||||
mTileManager.generate();
|
||||
for (int i = 0; i < 500; i += 50) {
|
||||
mCollection.insert(std::shared_ptr<Sprite>(new Cover(Vector2f(i, i), Vector2i(20, 20),
|
||||
mWorld)), Collection::LEVEL_STATIC);
|
||||
}
|
||||
}
|
||||
mCollection.insert(std::shared_ptr<Sprite>(new Enemy(mWorld, Vector2f(400.0f, 200.0f))),
|
||||
Collection::LEVEL_ACTOR);
|
||||
|
||||
Collection::LEVEL_ACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,10 +14,10 @@ std::vector<Actor*> Actor::mInstances = std::vector<Actor*>();
|
|||
|
||||
/**
|
||||
* Saves pointer to this instance in static var for think().
|
||||
*/
|
||||
*/
|
||||
Actor::Actor(int health) :
|
||||
mMaxHealth(health),
|
||||
mCurrentHealth(health) {
|
||||
mCurrentHealth(health) {
|
||||
mInstances.push_back(this);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ Actor::think(float elapsedTime) {
|
|||
for (auto i : mInstances) {
|
||||
i->onThink(elapsedTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts health from Actor.
|
||||
|
@ -61,4 +61,4 @@ Actor::onDamage(int damage) {
|
|||
*/
|
||||
void
|
||||
Actor::onDeath() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,14 +15,14 @@
|
|||
*/
|
||||
class Actor {
|
||||
// Public functions.
|
||||
public:
|
||||
Actor(int health);
|
||||
public:
|
||||
Actor(int health);
|
||||
virtual ~Actor() = 0;
|
||||
|
||||
static void think(float elapsedTime);
|
||||
|
||||
|
||||
void onDamage(int damage);
|
||||
|
||||
|
||||
// Protected functions.
|
||||
protected:
|
||||
/**
|
||||
|
@ -31,7 +31,7 @@ protected:
|
|||
* @param elapsedTime Amount of time to simulate.
|
||||
*/
|
||||
virtual void onThink(float elapsedTime) = 0;
|
||||
|
||||
|
||||
virtual void onDeath();
|
||||
|
||||
// Private variables.
|
||||
|
@ -39,7 +39,7 @@ private:
|
|||
static std::vector<Actor*> mInstances;
|
||||
|
||||
const int mMaxHealth;
|
||||
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
|
||||
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
|
||||
};
|
||||
|
||||
#endif /* DG_ACTOR_H_ */
|
||||
|
|
|
@ -21,12 +21,9 @@ Physical::Physical(const PhysicalData& data) :
|
|||
assert(data.size != Vector2i());
|
||||
assert(data.category);
|
||||
|
||||
b2BodyDef bodyDef;
|
||||
// not moving -> static body
|
||||
// moving -> dynamic body
|
||||
// bullet -> kinematic body
|
||||
b2BodyDef bodyDef;
|
||||
bodyDef.type = (data.moving)
|
||||
? b2_dynamicBody
|
||||
? b2_dynamicBody
|
||||
: b2_staticBody;
|
||||
bodyDef.position = vector(data.position);
|
||||
bodyDef.allowSleep = true;
|
||||
|
@ -44,8 +41,8 @@ Physical::Physical(const PhysicalData& data) :
|
|||
fixtureDef.density = 1.0f;
|
||||
fixtureDef.filter.categoryBits = data.category;
|
||||
fixtureDef.filter.maskBits = ~data.maskExclude;
|
||||
fixtureDef.restitution = 0;
|
||||
fixtureDef.density = (data.bullet) ? 0 : 10000;
|
||||
fixtureDef.restitution = 0;
|
||||
fixtureDef.density = (data.bullet) ? 0 : 10000;
|
||||
|
||||
mBody->CreateFixture(&fixtureDef);
|
||||
}
|
||||
|
@ -90,7 +87,11 @@ Physical::getSpeed() const {
|
|||
}
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* Returns the rotation of the body as an SFML angle.
|
||||
=======
|
||||
* Returns the rotation of the body (converted to an SFML angle).
|
||||
>>>>>>> origin/master
|
||||
*/
|
||||
float
|
||||
Physical::getAngle() const {
|
||||
|
@ -104,10 +105,10 @@ bool
|
|||
Physical::getDelete() const {
|
||||
return mDelete;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Physical::Category of this object.
|
||||
*/
|
||||
*/
|
||||
uint16
|
||||
Physical::getCategory() const {
|
||||
return mBody->GetFixtureList()->GetFilterData().categoryBits;
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
*/
|
||||
|
||||
#include "Bullet.h"
|
||||
|
||||
|
||||
#include "../abstract/Actor.h"
|
||||
#include "../util/Log.h"
|
||||
|
||||
const Vector2i Bullet::SIZE = Vector2i(20, 20);
|
||||
|
||||
const float Bullet::SPEED = 500.0f;
|
||||
|
||||
/**
|
||||
|
@ -20,12 +20,12 @@ const float Bullet::SPEED = 500.0f;
|
|||
* @param world Box2d world.
|
||||
* @param texture Texture to display for bullet.
|
||||
*/
|
||||
Bullet::Bullet(const Vector2f& position, b2World& world,
|
||||
Bullet::Bullet(const Vector2f& position, b2World& world,
|
||||
const std::shared_ptr<sf::Texture>& texture, Physical& shooter, float direction, int damage) :
|
||||
Particle(texture, PhysicalData(position, SIZE, world, CATEGORY_PARTICLE,
|
||||
CATEGORY_PARTICLE, true, true)),
|
||||
mShooter(shooter),
|
||||
mDamage(damage) {
|
||||
mDamage(damage) {
|
||||
setSpeed(angle(direction), SPEED);
|
||||
setAngle(direction);
|
||||
}
|
||||
|
@ -37,11 +37,11 @@ void
|
|||
Bullet::onCollide(Physical& other, uint16 type) {
|
||||
// Make sure we do not damage twice.
|
||||
if (!getDelete()) {
|
||||
// Call onShot on other, with damage as param.
|
||||
// Call onShot on other, with damage as param.
|
||||
if (type == CATEGORY_ACTOR) {
|
||||
Actor& a = dynamic_cast<Actor&>(other);
|
||||
a.onDamage(mDamage);
|
||||
}
|
||||
}
|
||||
setDelete(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,20 +16,21 @@
|
|||
class Bullet : public Particle {
|
||||
// Public functions.
|
||||
public:
|
||||
Bullet(const Vector2f& position, b2World& world, const std::shared_ptr<sf::Texture>& texture,
|
||||
Physical& shooter, float direction, int damage);
|
||||
Bullet(const Vector2f& position, b2World& world, const std::shared_ptr<sf::Texture>& texture,
|
||||
Physical& shooter, float direction, int damage);
|
||||
|
||||
void onCollide(Physical& other, uint16 category);
|
||||
bool doesCollide(Physical& other);
|
||||
|
||||
|
||||
// Public variables.
|
||||
public:
|
||||
static const Vector2i SIZE;
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
static const float SPEED; //< If speed is too low, bullets push each other away on insert.
|
||||
Physical& mShooter;
|
||||
const int mDamage;
|
||||
const int mDamage;
|
||||
};
|
||||
|
||||
#endif /* DG_BULLET_H_ */
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
*/
|
||||
|
||||
#include "Weapon.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <thor/Vectors.hpp>
|
||||
|
||||
|
||||
#include "../util/Collection.h"
|
||||
#include "../effects/Bullet.h"
|
||||
#include "../util/Loader.h"
|
||||
#include "../util/ResourceManager.h"
|
||||
#include "../util/ResourceManager.h"
|
||||
|
||||
const int Weapon::BULLET_DAMAGE = 10;
|
||||
|
||||
|
@ -27,7 +27,7 @@ Weapon::Weapon(Physical& holder, Collection& collection, b2World& world,
|
|||
mWorld(world),
|
||||
mOffset(0, std::max(holderSize.x, holderSize.y) / 2 +
|
||||
b2_linearSlop +
|
||||
std::max(Bullet::SIZE.x, Bullet::SIZE.y) / 2) {
|
||||
std::max(Bullet::SIZE.x, Bullet::SIZE.y) / 2) {
|
||||
}
|
||||
|
||||
Weapon::~Weapon() {
|
||||
|
@ -43,7 +43,7 @@ Weapon::fire() {
|
|||
}
|
||||
|
||||
std::shared_ptr<Particle>
|
||||
Weapon::createParticle() {
|
||||
Weapon::createParticle() {
|
||||
// Minus to account for positive y-axis going downwards in SFML.
|
||||
Vector2f offset(- mOffset);
|
||||
thor::rotate(offset, mHolder.getAngle());
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
* - pass enum value and load mapped xml
|
||||
* - pass xml filename
|
||||
*/
|
||||
class Weapon : public Emitter {
|
||||
class Weapon : public Emitter {
|
||||
// Public functions.
|
||||
public:
|
||||
Weapon(Physical& holder, Collection& collection, b2World& world, const Vector2i& holderSize);
|
||||
Weapon(Physical& holder, Collection& collection, b2World& world, const Vector2i& holderSize);
|
||||
~Weapon();
|
||||
|
||||
void fire();
|
||||
|
||||
|
||||
// Protected functions.
|
||||
protected:
|
||||
std::shared_ptr<Particle> createParticle();
|
||||
|
@ -37,7 +37,7 @@ private:
|
|||
Physical& mHolder;
|
||||
std::shared_ptr<sf::Texture> mBulletTexture;
|
||||
b2World& mWorld;
|
||||
const Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).
|
||||
const Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).
|
||||
};
|
||||
|
||||
#endif /* DG_WEAPON_H_ */
|
||||
|
|
|
@ -12,17 +12,17 @@
|
|||
#include "../util/Vector.h"
|
||||
#include "../items/Weapon.h"
|
||||
|
||||
const float Player::SPEED = 100.0f;
|
||||
const Vector2i Player::SIZE = Vector2i(50, 50);
|
||||
const float Player::SPEED = 100.0f;
|
||||
const Vector2i Player::SIZE = Vector2i(50, 50);
|
||||
|
||||
/**
|
||||
* Initializes Sprite.
|
||||
*/
|
||||
*/
|
||||
Player::Player(b2World& world, Collection& collection, const Vector2f& position) :
|
||||
Sprite("player.png", PhysicalData(position, SIZE, world,
|
||||
CATEGORY_ACTOR, MASK_ALL, true)),
|
||||
Actor(100),
|
||||
mWeapon(*this, collection, world, SIZE),
|
||||
mWeapon(*this, collection, world, SIZE),
|
||||
mDestination(Vector2i(50, 50)) {
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ class Sprite;
|
|||
*/
|
||||
class Player : public Sprite, public Actor {
|
||||
// Public functions.
|
||||
public:
|
||||
Player(b2World& world, Collection& collection, const Vector2f& position);
|
||||
public:
|
||||
Player(b2World& world, Collection& collection, const Vector2f& position);
|
||||
|
||||
void setCrosshairPosition(const Vector2f& position);
|
||||
void fire();
|
||||
|
@ -37,8 +37,9 @@ protected:
|
|||
|
||||
// Private variables.
|
||||
private:
|
||||
static const float SPEED;
|
||||
static const float SPEED;
|
||||
static const Vector2i SIZE;
|
||||
|
||||
Weapon mWeapon; //< Weapon object used for Player::fire().
|
||||
Vector2f mDestination; //< Absolute position of the movement destination.
|
||||
Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor).
|
||||
|
|
Reference in a new issue