newspeoplefor developersdocumentationdownloads

actoranimationproperty.cc

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 //  properties/actoranimationproperty.cc
00003 //  (C) 2005 Radon Labs GmbH
00004 //------------------------------------------------------------------------------
00005 #include "properties/actoranimationproperty.h"
00006 #include "game/entity.h"
00007 #include "msg/gfxsetanimation.h"
00008 #include "msg/movedirection.h"
00009 #include "msg/movesetvelocity.h"
00010 #include "msg/movestop.h"
00011 #include "msg/moveturn.h"
00012 
00013 namespace Properties
00014 {
00015 ImplementRtti(Properties::ActorAnimationProperty, Game::Property);
00016 ImplementFactory(Properties::ActorAnimationProperty);
00017 
00018 //------------------------------------------------------------------------------
00022 int
00023 ActorAnimationProperty::GetActiveEntityPools() const
00024 {
00025     return Game::Entity::LivePool;
00026 }
00027 
00028 //------------------------------------------------------------------------------
00031 bool
00032 ActorAnimationProperty::Accepts(Message::Msg* msg)
00033 {
00034     n_assert(msg);
00035     if (msg->CheckId(Message::MoveDirection::Id)) return true;
00036     if (msg->CheckId(Message::MoveSetVelocity::Id)) return true;
00037     if (msg->CheckId(Message::MoveStop::Id)) return true;
00038     if (msg->CheckId(Message::MoveTurn::Id)) return true;
00039     return Game::Property::Accepts(msg);
00040 }
00041 
00042 //------------------------------------------------------------------------------
00045 void
00046 ActorAnimationProperty::HandleMessage(Message::Msg* msg)
00047 {
00048     n_assert(msg);
00049     if (msg->CheckId(Message::MoveStop::Id))
00050     {
00051         this->RequestAnimation("Idle", "", 0.0f);
00052     }
00053     else if (msg->CheckId(Message::MoveDirection::Id) ||
00054              msg->CheckId(Message::MoveSetVelocity::Id))
00055     {
00056         this->RequestAnimation("Walk", "", 0.0f);
00057     }
00058 }
00059 
00060 //------------------------------------------------------------------------------
00063 void
00064 ActorAnimationProperty::OnActivate()
00065 {
00066     Game::Property::OnActivate();
00067     
00068     // by default go to idle animation
00069     this->RequestAnimation("Idle", "", 0.0f);
00070 }
00071 
00072 //------------------------------------------------------------------------------
00075 void
00076 ActorAnimationProperty::RequestAnimation(const nString& baseAnimation, const nString& overlayAnimation, float baseAnimTimeOffset) const
00077 {
00078     Ptr<Message::GfxSetAnimation> setAnimation = Message::GfxSetAnimation::Create();
00079     setAnimation->SetBaseAnimation(baseAnimation);
00080     setAnimation->SetOverlayAnimation(overlayAnimation);
00081     setAnimation->SetBaseAnimTimeOffset(baseAnimTimeOffset);
00082 
00083     this->GetEntity()->SendSync(setAnimation);
00084 }
00085 
00086 }; // namespace Properties

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.