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