SuperTuxKart
Loading...
Searching...
No Matches
swatter.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2011-2015 Joerg Henrichs
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_SWATTER_HPP
20#define HEADER_SWATTER_HPP
21
22#include "config/stk_config.hpp"
23#include "items/attachment_plugin.hpp"
24#include "utils/cpp2011.hpp"
25#include "utils/no_copy.hpp"
26
27#include <limits>
28#include <set>
29#include <vector3d.h>
30
31namespace irr
32{
33 namespace scene
34 {
35 class IAnimatedMeshSceneNode;
36 }
37}
38
39using namespace irr;
40
41class Attachment;
42class AbstractKart;
43class Item;
44class Moveable;
45class SFXBase;
46
50class Swatter : public NoCopy, public AttachmentPlugin
51{
52
53private:
59 enum AnimationPhase : uint8_t
60 {
61 SWATTER_AIMING = 0,
62 SWATTER_TO_TARGET = 1,
63 SWATTER_FROM_TARGET = 2
64 };
65 AnimationPhase m_animation_phase;
66
69
70 SFXBase *m_swat_sound;
71
75 scene::IAnimatedMeshSceneNode *m_scene_node;
76
79 scene::IAnimatedMeshSceneNode *m_bomb_scene_node;
80
81 int m_discard_ticks;
82
83 int m_swatter_duration;
84
88
89 int16_t m_swatter_animation_ticks;
90
93
96public:
97 Swatter(AbstractKart *kart, int16_t bomb_ticks, int ticks,
98 Attachment* attachment);
99 virtual ~Swatter();
100 void updateGraphics(float dt) OVERRIDE;
101 bool updateAndTestFinished(int ticks) OVERRIDE;
102
103 // ------------------------------------------------------------------------
106 bool isSwatterReady() const
107 {
108 return m_animation_phase == SWATTER_AIMING;
109 } // isSwatterReady
110 // ------------------------------------------------------------------------
111 virtual void restoreState(BareNetworkString *buffer) OVERRIDE;
112 // ------------------------------------------------------------------------
113 virtual void saveState(BareNetworkString *buffer) const OVERRIDE;
114
115private:
117 void chooseTarget();
118
120 void pointToTarget();
121
123 void squashThingsAround();
124}; // Swatter
125
126#endif
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
This is the base class for a plugin into an attachment.
Definition: attachment_plugin.hpp:39
This objects is permanently available in a kart and stores information about addons.
Definition: attachment.hpp:52
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
Definition: item.hpp:324
Definition: moveable.hpp:46
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
The base class for sound effects.
Definition: sfx_base.hpp:43
Definition: swatter.hpp:51
void squashThingsAround()
Squash karts or items that are around the end position (determined using a joint) of the swatter.
Definition: swatter.cpp:391
bool updateAndTestFinished(int ticks) OVERRIDE
Updates an armed swatter: it checks for any karts that are close enough and not invulnerable,...
Definition: swatter.cpp:234
void pointToTarget()
If there is a current target, point to it, otherwise adopt the default position.
Definition: swatter.cpp:365
AbstractKart * m_closest_kart
The kart the swatter is aiming at.
Definition: swatter.hpp:68
AnimationPhase
State of the animation, the swatter is successively:
Definition: swatter.hpp:60
int16_t m_bomb_remaining
Set the bomb remaing ticks so we can set the timer on the removing bomb animation.
Definition: swatter.hpp:87
bool isSwatterReady() const
Returns if the swatter is currently aiming, i.e.
Definition: swatter.hpp:106
bool m_discard_now
True if the swatter will be discarded now.
Definition: swatter.hpp:92
scene::IAnimatedMeshSceneNode * m_scene_node
Set the end ticks to complete the removing an attached bomb animation.
Definition: swatter.hpp:75
bool m_played_swatter_animation
True if the swatter animation has been played.
Definition: swatter.hpp:95
void chooseTarget()
Determine the nearest kart or item and update the current target accordingly.
Definition: swatter.cpp:325
virtual ~Swatter()
Destructor, stops any playing sfx.
Definition: swatter.cpp:92
scene::IAnimatedMeshSceneNode * m_bomb_scene_node
The scene node where a bomb is saved (in case that the swatter replaces a bomb.
Definition: swatter.hpp:79