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"
{
public:
EggEntity(float fallSpeed = 100.0f);
virtual ~EggEntity(void);
protected:
virtual void OnAdded(void) override;
virtual void OnRemoved(void) override;
virtual void OnUpdate(
const float deltaTime)
override;
virtual void OnRender(
void)
const 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) :
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)
{
position.y += mFallSpeed * kFixedTime;
SetPosition(position);
if (position.y > tbGraphics::ScreenHeight())
{
GetEntityManager()->RemoveEntity(this);
}
}
void EggEntity::OnUpdate(const float deltaTime)
{
}
void EggEntity::OnRender(void) const
{
}
{
tbGame::Entity::OnCollideWith(otherEntity);
}
Previous Step :: Next Step