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);
47 /** Called when the badguy is drawn. The default implementation simply draws
48 * the badguy sprite on screen
50 virtual void draw(DrawingContext& context);
51 /** Called each frame. The default implementation checks badguy state and
52 * calls active_update and inactive_update
54 virtual void update(float elapsed_time);
55 /** Called when a collision with another object occured. The default
56 * implemetnation calls collision_player, collision_solid, collision_badguy
57 * and collision_squished
59 virtual HitResponse collision(GameObject& other,
60 const CollisionHit& hit);
62 /** Called when a collision with tile with special attributes occured */
63 virtual void collision_tile(uint32_t tile_attributes);
65 /** Set the badguy to kill/falling state, which makes him falling of the
66 * screen (his sprite is turned upside-down)
68 virtual void kill_fall();
70 /** Writes out the badguy into the included lisp::Writer. Useful e.g. when
71 * converting an old-format level to the new format.
73 virtual void save(lisp::Writer& writer);
75 Vector get_start_position() const
77 return start_position;
79 void set_start_position(const Vector& vec)
84 /** Count this badguy to the statistics? This value should not be changed
97 /** Called when the badguy collided with a player */
98 virtual HitResponse collision_player(Player& player,
99 const CollisionHit& hit);
100 /** Called when the badguy collided with solid ground */
101 virtual HitResponse collision_solid(GameObject& other,
102 const CollisionHit& hit);
103 /** Called when the badguy collided with another badguy */
104 virtual HitResponse collision_badguy(BadGuy& other,
105 const CollisionHit& hit);
107 /** Called when the player hit the badguy from above. You should return true
108 * if the badguy was squished, false if squishing wasn't possible
110 virtual bool collision_squished(Player& player);
112 /** Called when the badguy collided with a bullet */
113 virtual HitResponse collision_bullet(Bullet& bullet,
114 const CollisionHit& hit);
116 /** called each frame when the badguy is activated. */
117 virtual void active_update(float elapsed_time);
118 /** called each frame when the badguy is not activated. */
119 virtual void inactive_update(float elapsed_time);
122 * called when the badguy has been activated. (As a side effect the dir
123 * variable might have been changed so that it faces towards the player.
125 virtual void activate();
126 /** called when the badguy has been deactivated */
127 virtual void deactivate();
129 void kill_squished(Player& player);
131 void set_state(State state);
132 State get_state() const
136 * returns a pointer to the nearest player or 0 if no player is available
138 Player* get_nearest_player();
142 /// is the enemy activated
145 * initial position of the enemy. Also the position where enemy respawns when
146 * after being deactivated.
150 * Returns true if we might soon fall at least @c height pixels. Minimum
151 * value for height is 1 pixel
153 bool might_fall(int height = 1);
155 Vector start_position;