TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
Add the EggEntity

Now we can add awesome things to the game. [documentation still in progress, need to write a full sample project]

egg_entity.h

#ifndef _EggDropExample_EggEntity_h_
#define _EggDropExample_EggEntity_h_
#include "turtle_brains/tb_game_kit.h"
class EggEntity : public tbGame::Entity
{
public:
EggEntity(float fallSpeed = 100.0f);
virtual ~EggEntity(void);
protected:
virtual void OnAdded(void) override;
virtual void OnRemoved(void) override;
virtual void OnSimulate(void) override;
virtual void OnUpdate(const float deltaTime) override;
virtual void OnRender(void) const override;
virtual void OnCollideWith(tbGame::Entity& otherEntity) override;
private:
tbGame::Sprite mSprite;
float mFallSpeed;
};
#endif _EggDropExample_EggEntity_h_

egg_entity.cpp

#include "egg_entity.h"
#include "turtle_brains/tb_application_kit.h"
EggEntity::EggEntity(float fallSpeed) :
tbGame::Entity("EggEntity"),
mSprite("data/egg.png"),
mFallSpeed(fallSpeed)
{
mSprite.SetOrigin(tbGraphics::kAnchorCenter);
AddGraphic(mSprite);
AddBoundingCircle(16.0f);
}
EggEntity::~EggEntity(void)
{
}
void EggEntity::OnAdded(void)
{
tbGame::Entity::OnAdded();
}
void EggEntity::OnRemoved(void)
{
tbGame::Entity::OnRemoved();
}
void EggEntity::OnSimulate(void)
{
const float kFixedTime(tbGame::GameTimer::GetSecondsPerStep());
tbMath::Vector2 position(GetPosition());
position.y += mFallSpeed * kFixedTime;
SetPosition(position);
if (position.y > tbGraphics::ScreenHeight())
{ //The egg has hit the ground, splat.
GetEntityManager()->RemoveEntity(this);
}
}
void EggEntity::OnUpdate(const float deltaTime)
{
}
void EggEntity::OnRender(void) const
{
}
void EggEntity::OnCollideWith(tbGame::Entity& otherEntity)
{
tbGame::Entity::OnCollideWith(otherEntity);
}

Previous Step :: Next Step