4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // moved them here to make it less typing when implementing new badguys
26 #include "object/moving_sprite.hpp"
28 #include "object/player.hpp"
29 #include "serializable.hpp"
30 #include "resources.hpp"
32 #include "direction.hpp"
33 #include "object_factory.hpp"
34 #include "lisp/parser.hpp"
35 #include "lisp/lisp.hpp"
36 #include "lisp/writer.hpp"
37 #include "video/drawing_context.hpp"
38 #include "audio/sound_manager.hpp"
39 #include "audio/sound_source.hpp"
41 class BadGuy : public MovingSprite, public Serializable
44 BadGuy(const Vector& pos, const std::string& sprite_name, int layer = LAYER_OBJECTS);
45 BadGuy(const lisp::Lisp& reader, const std::string& sprite_name, int layer = LAYER_OBJECTS);
46 virtual BadGuy* clone() const = 0;
48 /** Called when the badguy is drawn. The default implementation simply draws
49 * the badguy sprite on screen
51 virtual void draw(DrawingContext& context);
52 /** Called each frame. The default implementation checks badguy state and
53 * calls active_update and inactive_update
55 virtual void update(float elapsed_time);
56 /** Called when a collision with another object occured. The default
57 * implemetnation calls collision_player, collision_solid, collision_badguy
58 * and collision_squished
60 virtual HitResponse collision(GameObject& other,
61 const CollisionHit& hit);
63 /** Called when a collision with tile with special attributes occured */
64 virtual void collision_tile(uint32_t tile_attributes);
66 /** Set the badguy to kill/falling state, which makes him falling of the
67 * screen (his sprite is turned upside-down)
69 virtual void kill_fall();
71 /** Writes out the badguy into the included lisp::Writer. Useful e.g. when
72 * converting an old-format level to the new format.
74 virtual void save(lisp::Writer& writer);
76 Vector get_start_position() const
78 return start_position;
80 void set_start_position(const Vector& vec)
85 /** Count this badguy to the statistics? This value should not be changed
98 /** Called when the badguy collided with a player */
99 virtual HitResponse collision_player(Player& player,
100 const CollisionHit& hit);
101 /** Called when the badguy collided with solid ground */
102 virtual HitResponse collision_solid(GameObject& other,
103 const CollisionHit& hit);
104 /** Called when the badguy collided with another badguy */
105 virtual HitResponse collision_badguy(BadGuy& other,
106 const CollisionHit& hit);
108 /** Called when the player hit the badguy from above. You should return true
109 * if the badguy was squished, false if squishing wasn't possible
111 virtual bool collision_squished(Player& player);
113 /** Called when the badguy collided with a bullet */
114 virtual HitResponse collision_bullet(Bullet& bullet,
115 const CollisionHit& hit);
117 /** called each frame when the badguy is activated. */
118 virtual void active_update(float elapsed_time);
119 /** called each frame when the badguy is not activated. */
120 virtual void inactive_update(float elapsed_time);
123 * called when the badguy has been activated. (As a side effect the dir
124 * variable might have been changed so that it faces towards the player.
126 virtual void activate();
127 /** called when the badguy has been deactivated */
128 virtual void deactivate();
130 void kill_squished(Player& player);
132 void set_state(State state);
133 State get_state() const
137 * returns a pointer to the nearest player or 0 if no player is available
139 Player* get_nearest_player();
143 /// is the enemy activated
146 * initial position of the enemy. Also the position where enemy respawns when
147 * after being deactivated.
151 * Returns true if we might soon fall at least @c height pixels. Minimum
152 * value for height is 1 pixel
154 bool might_fall(int height = 1);
156 Vector start_position;