SuperTuxKart
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 #include <IAnimatedMeshSceneNode.h>
31 
32 using namespace irr;
33 
34 class Attachment;
35 class AbstractKart;
36 class Item;
37 class Moveable;
38 class SFXBase;
39 
43 class Swatter : public NoCopy, public AttachmentPlugin
44 {
45 
46 private:
52  enum AnimationPhase : uint8_t
53  {
54  SWATTER_AIMING = 0,
55  SWATTER_TO_TARGET = 1,
56  SWATTER_FROM_TARGET = 2
57  };
58  AnimationPhase m_animation_phase;
59 
62 
63  SFXBase *m_swat_sound;
64 
68  scene::IAnimatedMeshSceneNode *m_scene_node;
69 
72  scene::IAnimatedMeshSceneNode *m_bomb_scene_node;
73 
74  int m_discard_ticks;
75 
76  int m_swatter_duration;
77 
81 
82  int16_t m_swatter_animation_ticks;
83 
86 
89 public:
90  Swatter(AbstractKart *kart, int16_t bomb_ticks, int ticks,
91  Attachment* attachment);
92  virtual ~Swatter();
93  void updateGraphics(float dt) OVERRIDE;
94  bool updateAndTestFinished(int ticks) OVERRIDE;
95 
96  // ------------------------------------------------------------------------
99  bool isSwatterReady() const
100  {
101  return m_animation_phase == SWATTER_AIMING;
102  } // isSwatterReady
103  // ------------------------------------------------------------------------
104  virtual void restoreState(BareNetworkString *buffer) OVERRIDE;
105  // ------------------------------------------------------------------------
106  virtual void saveState(BareNetworkString *buffer) const OVERRIDE;
107 
108 private:
110  void chooseTarget();
111 
113  void pointToTarget();
114 
116  void squashThingsAround();
117 }; // Swatter
118 
119 #endif
Definition: swatter.hpp:43
int16_t m_bomb_remaining
Set the bomb remaing ticks so we can set the timer on the removing bomb animation.
Definition: swatter.hpp:80
bool m_discard_now
True if the swatter will be discarded now.
Definition: swatter.hpp:85
bool m_played_swatter_animation
True if the swatter animation has been played.
Definition: swatter.hpp:88
scene::IAnimatedMeshSceneNode * m_scene_node
Set the end ticks to complete the removing an attached bomb animation.
Definition: swatter.hpp:68
This objects is permanently available in a kart and stores information about addons.
Definition: attachment.hpp:51
AbstractKart * m_closest_kart
The kart the swatter is aiming at.
Definition: swatter.hpp:61
bool isSwatterReady() const
Returns if the swatter is currently aiming, i.e.
Definition: swatter.hpp:99
Definition: item.hpp:323
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
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:72
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:52
AnimationPhase
State of the animation, the swatter is successively:
Definition: swatter.hpp:52
This is the base class for a plugin into an attachment.
Definition: attachment_plugin.hpp:38
Definition: moveable.hpp:44
The base class for sound effects.
Definition: sfx_base.hpp:42
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61