TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D game development.
Add an Interactive Entity

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

basket_entity.h

#ifndef _EggDropExample_BasketEntity_h_
#define _EggDropExample_BasketEntity_h_
#include "turtle_brains/tb_game_kit.h"
class BasketEntity : public tbGame::Entity
{
public:
BasketEntity(void);
virtual ~BasketEntity(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;
};
#endif _EggDropExample_BasketEntity_h_

basket_entity.cpp

#include "basket_entity.h"
#include "turtle_brains/tb_application_kit.h"
BasketEntity::BasketEntity(void) :
tbGame::Entity("BasketEntity"),
mSprite("data/basket.png")
{
mSprite.SetOrigin(tbGraphics::kAnchorCenter);
AddGraphic(mSprite);
AddBoundingCircle(16.0f);
}
BasketEntity::~BasketEntity(void)
{
}
void BasketEntity::OnAdded(void)
{
tbGame::Entity::OnAdded();
}
void BasketEntity::OnRemoved(void)
{
tbGame::Entity::OnRemoved();
}
void BasketEntity::OnSimulate(void)
{
}
void BasketEntity::OnUpdate(const float deltaTime)
{
const tbMath::Vector2 mousePosition(tbGame::Input::GetMousePosition());
//Set the basket near the bottom of the screen and left/right horizontally positioned by mouse.
const float basketX = tbMath::Clamp(mousePosition.x, 0.0f, tbGraphics::ScreenWidth());
SetPosition(basketX, tbGraphics::ScreenHeight() - 50.0f);
}
void BasketEntity::OnRender(void) const
{
}
void BasketEntity::OnCollideWith(tbGame::Entity& otherEntity)
{
tbGame::Entity::OnCollideWith(otherEntity);
}

Previous Step :: Next Step