Added Body class to be dropped by Enemy on death.
This commit is contained in:
parent
86e7da2303
commit
69eca24bd2
7 changed files with 102 additions and 53 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
Physical::Physical(const PhysicalData& data) :
|
||||
mDelete(false) {
|
||||
assert(data.size != Vector2i());
|
||||
assert(data.category);
|
||||
|
||||
b2BodyDef bodyDef;
|
||||
bodyDef.type = (data.moving)
|
||||
|
|
14
source/sprite/Body.cpp
Executable file
14
source/sprite/Body.cpp
Executable 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
19
source/sprite/Body.h
Executable 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_ */
|
|
@ -7,17 +7,28 @@
|
|||
|
||||
#include "Enemy.h"
|
||||
|
||||
Enemy::Enemy(b2World& world, const Vector2f& position) :
|
||||
#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) {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -10,18 +10,24 @@
|
|||
|
||||
#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);
|
||||
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_ */
|
||||
|
|
Reference in a new issue