Added Body class to be dropped by Enemy on death.

This commit is contained in:
Felix Ableitner 2012-09-14 20:33:32 +02:00
parent 86e7da2303
commit 69eca24bd2
7 changed files with 102 additions and 53 deletions

View file

@ -43,7 +43,7 @@ Game::Game(const Vector2i& resolution) :
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))),
mCollection.insert(std::shared_ptr<Sprite>(new Enemy(mWorld, Vector2f(400.0f, 200.0f), mCollection)),
Collection::LEVEL_ACTOR);
}

View file

@ -19,7 +19,6 @@
Physical::Physical(const PhysicalData& data) :
mDelete(false) {
assert(data.size != Vector2i());
assert(data.category);
b2BodyDef bodyDef;
bodyDef.type = (data.moving)

View file

@ -76,7 +76,7 @@ public:
Vector2f getSpeed() const;
float getAngle() const;
bool getDelete() const;
uint16 getCategory() const;
uint16 getCategory() const;
virtual bool doesCollide(Physical& other);
virtual void onCollide(Physical& other, uint16 category);

14
source/sprite/Body.cpp Executable file
View file

@ -0,0 +1,14 @@
/*
* Body.cpp
*
* Created on: 13.09.2012
* Author: Felix
*/
#include "Body.h"
Body::Body(b2World& world, const Vector2f& position) :
Sprite("body.png", PhysicalData(position, Vector2i(50, 50), world,
CATEGORY_NONSOLID, MASK_NONE, false)) {
}

19
source/sprite/Body.h Executable file
View file

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

View file

@ -1,23 +1,34 @@
/*
* Enemy.cpp
*
* Created on: 10.09.2012
* Author: Felix
*/
#include "Enemy.h"
Enemy::Enemy(b2World& world, const Vector2f& position) :
Sprite("enemy.png", PhysicalData(position, Vector2i(50, 50), world,
CATEGORY_ACTOR, MASK_ALL, true, false, true)),
Actor(100) {
}
Enemy::~Enemy() {
}
void
Enemy::onThink(float elapsedTime) {
}
/*
* Enemy.cpp
*
* Created on: 10.09.2012
* Author: Felix
*/
#include "Enemy.h"
#include "Body.h"
Enemy::Enemy(b2World& world, const Vector2f& position, Collection& collection) :
Sprite("enemy.png", PhysicalData(position, Vector2i(50, 50), world,
CATEGORY_ACTOR, MASK_ALL, true, false, true)),
Actor(100),
mWorld(world),
mCollection(collection) {
}
Enemy::~Enemy() {
// Insert here to avoid altering b2d data during timestep.
mCollection.insert(std::shared_ptr<Sprite>(new Body(mWorld, getPosition())),
Collection::LEVEL_STATIC);
}
void
Enemy::onThink(float elapsedTime) {
}
void
Enemy::onDeath() {
setDelete(true);
}

View file

@ -1,27 +1,33 @@
/*
* Enemy.h
*
* Created on: 10.09.2012
* Author: Felix
*/
#ifndef DG_ENEMY_H_
#define DG_ENEMY_H
#include "../abstract/Actor.h"
#include "../abstract/Sprite.h"
#include "../util/Vector.h"
class Enemy : public Sprite, public Actor {
// Public functions.
public:
Enemy(b2World& world, const Vector2f& position);
~Enemy();
// Private functions.
private:
void onThink(float elapsedTime);
};
#endif /* DG_ENEMY_H_ */
/*
* Enemy.h
*
* Created on: 10.09.2012
* Author: Felix
*/
#ifndef DG_ENEMY_H_
#define DG_ENEMY_H
#include "../abstract/Actor.h"
#include "../abstract/Sprite.h"
#include "../util/Collection.h"
#include "../util/Vector.h"
class Enemy : public Sprite, public Actor {
// Public functions.
public:
Enemy(b2World& world, const Vector2f& position, Collection& collection);
~Enemy();
// Private functions.
private:
void onThink(float elapsedTime);
void onDeath();
// Private variablese.
private:
b2World& mWorld;
Collection& mCollection;
};
#endif /* DG_ENEMY_H_ */