LPCGame
A Simple 2d Game Engine
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Entity Class Reference

The Entity class, to provide functions that call to attached Lua scripts. More...

#include <entity.h>

Inherited by Button, and TileBar.

Public Member Functions

 Entity (std::string file)
 
virtual void Init (std::shared_ptr< Entity > self=nullptr)
 
virtual void Free ()
 
virtual void Update ()
 Update the game object.
 
virtual void Move (float deltaT)
 
virtual void Draw (std::weak_ptr< Camera > camera)
 
virtual void OnMouseDown ()
 On mouse down events.
 
virtual void OnMouseUp ()
 On mouse up event.
 
virtual void OnClick ()
 
virtual void OnMouseEnter ()
 On mouse enter.
 
virtual void OnMouseExit ()
 On mouse exit.
 
virtual void CheckMouseOver (const Vector2f &pos)
 
bool GetMouseOver () const
 Return T/F is the mouse is over the object.
 
PhysicsGetPhysics ()
 
std::weak_ptr< PhysicsGetPhysicsWeakPtr ()
 
void SetCollisionMap (CollisionMap map)
 
Rectf Box () const
 Get the object's box.
 
void SetTag (std::string tag)
 Set the entity's tag.
 
std::string Tag () const
 Get the entity's tag.
 
void SetName (std::string name)
 
std::string Name () const
 
void Render (bool b)
 Set the Entity render flag.
 
bool Render () const
 Check if the Entity should be drawn.
 
void IsUiElement (bool b)
 Set the Entity "is ui element" flag.
 
bool IsUiElement () const
 Check if the Entity is a ui element.
 
LuaScriptScript ()
 Get a pointer to the Entity's LuaScript.
 
virtual Json::Value Save () const
 
virtual void Save (const std::string &file) const
 
virtual void Load (Json::Value val)
 
virtual void Load (const std::string &file, Json::Value overrides=Json::Value())
 

Protected Attributes

Image mImage
 
std::shared_ptr< PhysicsmPhysics
 Handle's the objects physics.
 
std::string mTag
 A general tag for the entity.
 
std::string mName
 The entity's name.
 
std::string mConfigFile
 
bool mMouseOver
 For tracking mouse over and clicks.
 
bool mClicked
 
bool mRender
 For tracking if the entity should be rendered, and if it's a ui element.
 
bool mUiElement
 
LuaScript mScript
 The entity's lua script.
 

Detailed Description

The Entity class, to provide functions that call to attached Lua scripts.

Base class for Entities, has functions that simply provide a call to the function of the same name on the Entity's attached Lua script

Constructor & Destructor Documentation

Entity::Entity ( std::string  file)

Construct the Entity from a entity data file

Parameters
scriptThe object's data file

Member Function Documentation

void Entity::CheckMouseOver ( const Vector2f pos)
virtual

Check if mouse entered the object's box Updates mMouseOver accordingly

Parameters
posThe mouse pos to check
void Entity::Draw ( std::weak_ptr< Camera camera)
virtual

Draw the Entity, apply an adjustment for the camera if one is desired

Parameters
camThe camera to adjust for

Reimplemented in Button.

Physics * Entity::GetPhysics ( )

Get a pointer to the object's Physics component, for use in allowing it to be gotten and used in a script

Returns
A pointer to the entity's Physics member
std::weak_ptr< Physics > Entity::GetPhysicsWeakPtr ( )

Get a weak_ptr to the Entity's physics lib TODO: Migrate to using this exclusively

Returns
a weak_ptr to the Physics component
void Entity::Init ( std::shared_ptr< Entity self = nullptr)
virtual

Initialize the object and give the script the shared_ptr to the entity it's managing

Parameters
selfThe shared_ptr to this entity that the manager is also using, so references are counted properly
void Entity::Load ( Json::Value  val)
virtual

Load the Entity from a Json::Value The Entity instance of the function takes care of loading the base object members, physics, image and tags

Parameters
valThe Json::Value to load from

Reimplemented in ObjectButton< T >, Button, and TileBar.

void Entity::Load ( const std::string &  file,
Json::Value  overrides = Json::Value() 
)
virtual

Load the Entity from a file with the option for loading overrides as well

Parameters
fileThe file to load from
overridesThe state-specific overrides to load
void Entity::Move ( float  deltaT)
virtual

Move the object

Parameters
deltaTThe elapsed time
void Entity::OnClick ( )
virtual

On mouse click event, a mouse click event is described as a mouse-down followed by a mouse-up

Reimplemented in ObjectButton< T >, and Button.

Json::Value Entity::Save ( ) const
virtual

Save the Entity data to a json value and return it The Entity instance of the function takes care of saving the base object members, physics, image and tags

Returns
Json::Value containing the Entity data

Reimplemented in ObjectButton< T >, and TileBar.

void Entity::Save ( const std::string &  file) const
virtual

Save the Entity to a file

Parameters
fileThe file to save the entity too
void Entity::SetCollisionMap ( CollisionMap  map)

Set a collision map for the physics member to check against

Parameters
mapThe collision map

Member Data Documentation

Image Entity::mImage
protected

Note: Once Lua entity scripting is fully implemented, Image should no longer be a member, but rather should be created and given to the Lua instance to handle if an image is desired


The documentation for this class was generated from the following files: