Add get-rid-of-bomb animation for swatter
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9793 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
58c634e1f4
commit
6698949799
BIN
data/models/swatter_anim2.b3d
Executable file
BIN
data/models/swatter_anim2.b3d
Executable file
Binary file not shown.
@ -72,15 +72,35 @@ Attachment::~Attachment()
|
||||
//-----------------------------------------------------------------------------
|
||||
void Attachment::set(AttachmentType type, float time, Kart *current_kart)
|
||||
{
|
||||
bool was_bomb = (m_type == ATTACH_BOMB);
|
||||
scene::ISceneNode* bomb_scene_node = NULL;
|
||||
if (was_bomb && type == ATTACH_SWATTER)
|
||||
{
|
||||
// let's keep the bomb node, and create a new one for the new attachment
|
||||
bomb_scene_node = m_node;
|
||||
|
||||
m_node = irr_driver->addAnimatedMesh(
|
||||
attachment_manager->getMesh(Attachment::ATTACH_BOMB));
|
||||
#ifdef DEBUG
|
||||
std::string debug_name = (current_kart ? current_kart->getIdent() : "somekart") +" (attachment)";
|
||||
m_node->setName(debug_name.c_str());
|
||||
#endif
|
||||
m_node->setAnimationEndCallback(this);
|
||||
m_node->setParent(m_kart->getNode());
|
||||
m_node->setVisible(false);
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
// If necessary create the appropriate plugin which encapsulates the associated behavior
|
||||
switch(type)
|
||||
{
|
||||
case ATTACH_SWATTER :
|
||||
m_plugin = new Swatter(this, m_kart);
|
||||
case ATTACH_SWATTER :
|
||||
m_node->setMesh(attachment_manager->getMesh(type));
|
||||
m_plugin = new Swatter(this, m_kart, was_bomb, bomb_scene_node);
|
||||
break;
|
||||
case ATTACH_BOMB:
|
||||
m_node->setMesh(attachment_manager->getMesh(type));
|
||||
if (m_bomb_sound) sfx_manager->deleteSFX(m_bomb_sound);
|
||||
m_bomb_sound = sfx_manager->createSoundSource("clock");
|
||||
m_bomb_sound->setLoop(true);
|
||||
@ -88,11 +108,10 @@ void Attachment::set(AttachmentType type, float time, Kart *current_kart)
|
||||
m_bomb_sound->play();
|
||||
break;
|
||||
default:
|
||||
m_node->setMesh(attachment_manager->getMesh(type));
|
||||
break;
|
||||
} // switch(type)
|
||||
|
||||
m_node->setMesh(attachment_manager->getMesh(type));
|
||||
|
||||
if (!UserConfigParams::m_graphical_effects)
|
||||
{
|
||||
m_node->setAnimationSpeed(0);
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "audio/music_manager.hpp"
|
||||
#include "audio/sfx_base.hpp"
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "items/attachment.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
@ -40,17 +41,33 @@
|
||||
#define SWAT_ANGLE_OFFSET (90.0f + 15.0f)
|
||||
#define SWATTER_ANIMATION_SPEED 100.0f
|
||||
|
||||
Swatter::Swatter(Attachment *attachment, Kart *kart)
|
||||
Swatter::Swatter(Attachment *attachment, Kart *kart, bool was_bomb,
|
||||
scene::ISceneNode* bomb_scene_node)
|
||||
: AttachmentPlugin(attachment, kart)
|
||||
{
|
||||
m_animation_phase = SWATTER_AIMING;
|
||||
m_target = NULL;
|
||||
|
||||
m_removing_bomb = was_bomb;
|
||||
m_bomb_scene_node = bomb_scene_node;
|
||||
m_swat_bomb_frame = 0.0f;
|
||||
|
||||
// Setup the node
|
||||
scene::IAnimatedMeshSceneNode* node = m_attachment->getNode();
|
||||
node->setPosition(SWAT_POS_OFFSET);
|
||||
node->setAnimationSpeed(0);
|
||||
|
||||
if (m_removing_bomb)
|
||||
{
|
||||
printf("Loading '%s'\n", file_manager->getModelFile("swatter_anim2.b3d").c_str());
|
||||
node->setMesh(irr_driver->getAnimatedMesh( file_manager->getModelFile("swatter_anim2.b3d") ));
|
||||
node->setRotation(core::vector3df(0.0, -180.0, 0.0));
|
||||
node->setAnimationSpeed(0.9f);
|
||||
node->setCurrentFrame(0.0f);
|
||||
node->setLoopMode(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
node->setAnimationSpeed(0);
|
||||
}
|
||||
m_swat_sound = sfx_manager->createSoundSource("swatter");
|
||||
} // Swatter
|
||||
|
||||
@ -71,6 +88,38 @@ Swatter::~Swatter()
|
||||
*/
|
||||
bool Swatter::updateAndTestFinished(float dt)
|
||||
{
|
||||
if (m_removing_bomb)
|
||||
{
|
||||
m_swat_bomb_frame += dt*25.0f;
|
||||
//printf("%f\n", (float)m_attachment->getNode()->getFrameNr() );
|
||||
m_attachment->getNode()->setRotation(core::vector3df(0.0, -180.0, 0.0));
|
||||
|
||||
m_attachment->getNode()->setCurrentFrame(m_swat_bomb_frame);
|
||||
|
||||
if (m_swat_bomb_frame >= 32.5f && m_bomb_scene_node != NULL)
|
||||
{
|
||||
m_bomb_scene_node->setPosition(m_bomb_scene_node->getPosition() +
|
||||
core::vector3df(-dt*15.0f, 0.0f, 0.0f) );
|
||||
m_bomb_scene_node->setRotation(m_bomb_scene_node->getRotation() +
|
||||
core::vector3df(-dt*15.0f, 0.0f, 0.0f) );
|
||||
}
|
||||
|
||||
if (m_swat_bomb_frame >= m_attachment->getNode()->getEndFrame())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (m_swat_bomb_frame >= 35)
|
||||
{
|
||||
if (m_bomb_scene_node != NULL)
|
||||
{
|
||||
irr_driver->removeNode(m_bomb_scene_node);
|
||||
m_bomb_scene_node = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(m_animation_phase)
|
||||
{
|
||||
case SWATTER_AIMING:
|
||||
|
@ -49,12 +49,20 @@ private:
|
||||
m_animation_phase;
|
||||
|
||||
/** The kart the swatter is aiming at. */
|
||||
Moveable *m_target;
|
||||
Moveable *m_target;
|
||||
|
||||
SFXBase *m_swat_sound;
|
||||
SFXBase *m_swat_sound;
|
||||
|
||||
bool m_removing_bomb;
|
||||
|
||||
scene::ISceneNode *m_bomb_scene_node;
|
||||
|
||||
/** For some reason the built-in animation system doesn't work correctly here?? */
|
||||
float m_swat_bomb_frame;
|
||||
|
||||
public:
|
||||
Swatter(Attachment *attachment, Kart *kart);
|
||||
Swatter(Attachment *attachment, Kart *kart, bool was_bomb,
|
||||
scene::ISceneNode* bomb_scene_node);
|
||||
virtual ~Swatter();
|
||||
bool updateAndTestFinished(float dt);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user