4 // Copyright (C) 2005 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
23 // moved them here to make it less typing when implementing new badguys
26 #include "moving_object.hpp"
27 #include "sprite/sprite.hpp"
29 #include "object/player.hpp"
30 #include "serializable.hpp"
31 #include "resources.hpp"
33 #include "direction.hpp"
34 #include "object_factory.hpp"
35 #include "lisp/parser.hpp"
36 #include "lisp/lisp.hpp"
37 #include "lisp/writer.hpp"
38 #include "video/drawing_context.hpp"
39 #include "audio/sound_manager.hpp"
40 #include "audio/sound_source.hpp"
41 #include "sprite/sprite_manager.hpp"
43 class BadGuy : public MovingObject, public Serializable
49 /** Called when the badguy is drawn. The default implementation simply draws
50 * the badguy sprite on screen
52 virtual void draw(DrawingContext& context);
53 /** Called each frame. The default implementation checks badguy state and
54 * calls active_update and inactive_update
56 virtual void update(float elapsed_time);
57 /** Called when a collision with another object occured. The default
58 * implemetnation calls collision_player, collision_solid, collision_badguy
59 * and collision_squished
61 virtual HitResponse collision(GameObject& other,
62 const CollisionHit& hit);
64 /** Set the badguy to kill/falling state, which makes him falling of the
65 * screen (his sprite is turned upside-down)
67 virtual void kill_fall();
69 Vector get_start_position() const
71 return start_position;
73 void set_start_position(const Vector& vec)
78 /** Count this badguy to the statistics? This value should not be changed
91 /** Called when the badguy collided with a player */
92 virtual HitResponse collision_player(Player& player,
93 const CollisionHit& hit);
94 /** Called when the badguy collided with solid ground */
95 virtual HitResponse collision_solid(GameObject& other,
96 const CollisionHit& hit);
97 /** Called when the badguy collided with another badguy */
98 virtual HitResponse collision_badguy(BadGuy& other,
99 const CollisionHit& hit);
101 /** Called when the player hit the badguy from above. You should return true
102 * if the badguy was squished, false if squishing wasn't possible
104 virtual bool collision_squished(Player& player);
106 /** called each frame when the badguy is activated. */
107 virtual void active_update(float elapsed_time);
108 /** called each frame when the badguy is not activated. */
109 virtual void inactive_update(float elapsed_time);
112 * called when the badguy has been activated. (As a side effect the dir
113 * variable might have been changed so that it faces towards the player.
115 virtual void activate();
116 /** called when the badguy has been deactivated */
117 virtual void deactivate();
119 void kill_squished(Player& player);
121 void set_state(State state);
122 State get_state() const
126 * returns a pointer to the player, try to avoid this function to avoid
127 * problems later when we have multiple players or no player in scripted
130 Player* get_player();
135 /// is the enemy activated
138 * initial position of the enemy. Also the position where enemy respawns when
139 * after being deactivated.
143 Vector start_position;