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),
|
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), mCollection)),
|
||||||
Collection::LEVEL_ACTOR);
|
Collection::LEVEL_ACTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
Physical::Physical(const PhysicalData& data) :
|
Physical::Physical(const PhysicalData& data) :
|
||||||
mDelete(false) {
|
mDelete(false) {
|
||||||
assert(data.size != Vector2i());
|
assert(data.size != Vector2i());
|
||||||
assert(data.category);
|
|
||||||
|
|
||||||
b2BodyDef bodyDef;
|
b2BodyDef bodyDef;
|
||||||
bodyDef.type = (data.moving)
|
bodyDef.type = (data.moving)
|
||||||
|
|
|
@ -76,7 +76,7 @@ public:
|
||||||
Vector2f getSpeed() const;
|
Vector2f getSpeed() const;
|
||||||
float getAngle() const;
|
float getAngle() const;
|
||||||
bool getDelete() const;
|
bool getDelete() const;
|
||||||
uint16 getCategory() const;
|
uint16 getCategory() const;
|
||||||
|
|
||||||
virtual bool doesCollide(Physical& other);
|
virtual bool doesCollide(Physical& other);
|
||||||
virtual void onCollide(Physical& other, uint16 category);
|
virtual void onCollide(Physical& other, uint16 category);
|
||||||
|
|
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_ */
|
|
@ -1,23 +1,34 @@
|
||||||
/*
|
/*
|
||||||
* Enemy.cpp
|
* Enemy.cpp
|
||||||
*
|
*
|
||||||
* Created on: 10.09.2012
|
* Created on: 10.09.2012
|
||||||
* Author: Felix
|
* Author: Felix
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Enemy.h"
|
#include "Enemy.h"
|
||||||
|
|
||||||
Enemy::Enemy(b2World& world, const Vector2f& position) :
|
#include "Body.h"
|
||||||
Sprite("enemy.png", PhysicalData(position, Vector2i(50, 50), world,
|
|
||||||
CATEGORY_ACTOR, MASK_ALL, true, false, true)),
|
Enemy::Enemy(b2World& world, const Vector2f& position, Collection& collection) :
|
||||||
Actor(100) {
|
Sprite("enemy.png", PhysicalData(position, Vector2i(50, 50), world,
|
||||||
|
CATEGORY_ACTOR, MASK_ALL, true, false, true)),
|
||||||
}
|
Actor(100),
|
||||||
|
mWorld(world),
|
||||||
Enemy::~Enemy() {
|
mCollection(collection) {
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
void
|
Enemy::~Enemy() {
|
||||||
Enemy::onThink(float elapsedTime) {
|
// 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);
|
||||||
|
}
|
||||||
|
|
|
@ -1,27 +1,33 @@
|
||||||
/*
|
/*
|
||||||
* Enemy.h
|
* Enemy.h
|
||||||
*
|
*
|
||||||
* Created on: 10.09.2012
|
* Created on: 10.09.2012
|
||||||
* Author: Felix
|
* Author: Felix
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DG_ENEMY_H_
|
#ifndef DG_ENEMY_H_
|
||||||
#define DG_ENEMY_H
|
#define DG_ENEMY_H
|
||||||
|
|
||||||
#include "../abstract/Actor.h"
|
#include "../abstract/Actor.h"
|
||||||
#include "../abstract/Sprite.h"
|
#include "../abstract/Sprite.h"
|
||||||
|
#include "../util/Collection.h"
|
||||||
#include "../util/Vector.h"
|
#include "../util/Vector.h"
|
||||||
|
|
||||||
class Enemy : public Sprite, public Actor {
|
class Enemy : public Sprite, public Actor {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Enemy(b2World& world, const Vector2f& position);
|
Enemy(b2World& world, const Vector2f& position, Collection& collection);
|
||||||
~Enemy();
|
~Enemy();
|
||||||
|
|
||||||
// Private functions.
|
// Private functions.
|
||||||
private:
|
private:
|
||||||
void onThink(float elapsedTime);
|
void onThink(float elapsedTime);
|
||||||
};
|
void onDeath();
|
||||||
|
|
||||||
#endif /* DG_ENEMY_H_ */
|
// Private variablese.
|
||||||
|
private:
|
||||||
|
b2World& mWorld;
|
||||||
|
Collection& mCollection;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* DG_ENEMY_H_ */
|
||||||
|
|
Reference in a new issue