Code Search for Developers
 
 
  

EntityController.cpp from palisma2d at Krugle


Show EntityController.cpp syntax highlighted

#include "StdAfx.h"
#include "EntityController.h"
#include "EntityEvents.h"
#include "EntityManager.h"
#include "IEntity.h"
#include "../kernel.h"

extern Kernel* g_kernel;
#define TIME g_kernel->GetTime()

/**
=============================
Construct a controller object
registering the listener
=============================
*/
EntityController::EntityController(void) : IEventListener()
{
    m_entity = NULL;
    EventManager::GetInstance()->AddListener(this);
}

/**
=============================
Deconstructor - destroy
=============================
*/
EntityController::~EntityController(void)
{
    EventManager::GetInstance()->RemoveListener(this);
    IEventListener::~IEventListener();   
}


/** 
 *  Handle a giving event, switch the entities state
 *  based off the FSM 
 */
bool EntityController::HandleEvent( IEvent* e )
{
    switch( e->GetType() )
    {
    /*--- entity event ----*/
    case EVT_ENTITY:
        EntityEvents* evt = e->GetData<EntityEvents>();
        if ( m_entity->GetID() != evt->ent_id ) return false;
        int actions =  evt->buttons;
        m_entity->m_actions = actions;
        //// The entity is attempting to attack
        //if ( actions & BUTTON_ATTACK1 )
        //{
        //    if ( m_entity->CarryingEntity() )
        //    {
        //        m_entity->Throw();
        //    }
        //    else
        //    {
        //        m_entity->m_nextUpdate = TIME + 450; // TEMP
        //        m_entity->SetState( ENT_STATES[ATTACKING1] );
        //        return true;
        //    }
        //}

        //// The entity is attempting to 'use'
        //if ( actions & BUTTON_USE )
        //{
        //    if ( m_entity->CarryingEntity() )
        //    {
        //        m_entity->Throw();
        //    }
        //    else
        //    {
        //        // search for an entity in a region -- TODO THIS IS HORRIBLY SLOW!!!
        //        IEntity* ent = EntityManager::GetInstance()->FindInRegion( m_entity->GetReachRectangle(), m_entity );
        //        
        //        if ( ent )
        //        {  
        //            if ( ent->m_attributes.Has( "dialog" ) ) 
        //            {
        //                ent->SetFace( (m_entity->GetFace() + 2) % 4);
        //                ent->SetState( ENT_STATES[TALKING] );
        //            }
        //            else if ( ent->m_attributes.Has( "liftable" ) ) 
        //            {
        //                if ( !m_entity->CarryingEntity() )
        //                {
        //                    m_entity->Carry( ent );
        //                }
        //            }
        //        }
        //    }
        //    return true;
        //}

        //// Check for movement
        //if ( m_entity->m_velocity.Length() )
        //{
        //    // switch the state to walking
        //    if ( m_entity->CarryingEntity() )
        //    {
        //        m_entity->SetState( ENT_STATES[CARRYING_WALKING] );
        //    }
        //    else
        //    {
        //        m_entity->SetState( ENT_STATES[WALKING] );
        //    }
        //} 
        //else
        //{
        //    // switch the state to idle
        //    if ( m_entity->CarryingEntity() )
        //    {
        //        m_entity->SetState( ENT_STATES[CARRYING] );
        //    }
        //    else
        //    {
        //        m_entity->SetState( ENT_STATES[IDLE] );
        //    }
        //}
        //break;

    ///*--- entity is moving ----*/
    //case EVT_MOVE:
    //    m_entity->m_velocity.Set( e->GetData<EntityMovement>()->m_velocity );

    //    // switch the state to walking
    //    if ( m_entity->CarryingEntity() )
    //    {
    //        m_entity->SetState( ENT_STATES[CARRYING_WALKING] );
    //    }
    //    else
    //    {
    //        m_entity->SetState( ENT_STATES[WALKING] );
    //    }
    //    break;

    ///*--- entity is attacking ----*/
    //case EVT_ATTACK:
    //    if ( m_entity->CarryingEntity() )
    //    {
    //        m_entity->Throw();
    //    }
    //    else
    //    {
    //        m_entity->SetState( ENT_STATES[ATTACKING1] );
    //    }
    //    break;

    ///*--- entity is using ----*/
    //case EVT_USE:
    //    if ( m_entity->CarryingEntity() )
    //    {
    //        m_entity->Throw();
    //    }
    //    else
    //    {
    //        // TODO - search around for lifting/talking ?
    //    }
    //    break;

    };
    return true;
}




See more files for this project here

palisma2d

The University of Wisconsin-Parkside Developers Union first product. More info to come. Code name Palisma.

Project homepage: http://code.google.com/p/palisma2d/
Programming language(s): C,C++
License: gpl2

  DialogModel.cpp
  DialogModel.h
  DialogState.cpp
  DialogState.h
  Enemy.cpp
  Enemy.h
  EntityController.cpp
  EntityController.h
  EntityEvents.cpp
  EntityEvents.h
  EntityFactory.cpp
  EntityFactory.h
  EntityManager.cpp
  EntityManager.h
  EntityStates.cpp
  EntityStates.h
  Event.h
  HUD.cpp
  HUD.h
  IEntity.cpp
  IEntity.h
  IWeapon.cpp
  IWeapon.h
  InGameState.cpp
  InGameState.h
  Inventory.cpp
  Inventory.h
  MissionHolder.cpp
  MissionHolder.h
  Player.cpp
  Player.h
  PlayerConfig.cpp
  PlayerConfig.h
  PlayerController.cpp
  PlayerController.h
  QuestImporter.cpp
  QuestImporter.h
  ReadMe.txt
  Scene.cpp
  Scene.h
  Shotgun.cpp
  Shotgun.h
  State.h
  StateFactory.cpp
  StateFactory.h
  StateMachine.cpp
  StateMachine.h
  Tile.cpp
  Tile.h
  Weather.cpp
  Weather.h
  stdafx.cpp
  stdafx.h