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
24 // moved them here to make it less typing when implementing new badguys
27 #include "moving_object.h"
28 #include "sprite/sprite.h"
29 #include "math/physic.h"
30 #include "object/player.h"
31 #include "serializable.h"
32 #include "resources.h"
34 #include "direction.h"
35 #include "object_factory.h"
36 #include "lisp/parser.h"
37 #include "lisp/lisp.h"
38 #include "lisp/writer.h"
39 #include "video/drawing_context.h"
40 #include "sprite/sprite_manager.h"
42 using namespace SuperTux;
44 class BadGuy : public MovingObject, public Serializable
50 /** Called when the badguy is drawn. The default implementation simply draws
51 * the badguy sprite on screen
53 virtual void draw(DrawingContext& context);
54 /** Called each frame. The default implementation checks badguy state and
55 * calls active_action and inactive_action
57 virtual void action(float elapsed_time);
58 /** Called when a collision with another object occured. The default
59 * implemetnation calls collision_player, collision_solid, collision_badguy
60 * and collision_squished
62 virtual HitResponse collision(GameObject& other,
63 const CollisionHit& hit);
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 Vector get_start_position() const
72 return start_position;
74 void set_start_position(const Vector& vec)
88 /** Called when the badguy collided with a player */
89 virtual HitResponse collision_player(Player& player,
90 const CollisionHit& hit);
91 /** Called when the badguy collided with solid ground */
92 virtual HitResponse collision_solid(GameObject& other,
93 const CollisionHit& hit);
94 /** Called when the badguy collided with another badguy */
95 virtual HitResponse collision_badguy(BadGuy& other,
96 const CollisionHit& hit);
98 /** Called when the player hit the badguy from above. You should return true
99 * if the badguy was squished, false if squishing wasn't possible
101 virtual bool collision_squished(Player& player);
103 /** called each frame when the badguy is activated. */
104 virtual void active_action(float elapsed_time);
105 /** called each frame when the badguy is not activated. */
106 virtual void inactive_action(float elapsed_time);
109 * called when the badguy has been activated. (As a side effect the dir
110 * variable might have been changed so that it faces towards the player.
112 virtual void activate();
113 /** called when the badguy has been deactivated */
114 virtual void deactivate();
116 void kill_squished(Player& player);
118 void set_state(State state);
119 State get_state() const
123 * returns a pointer to the player, try to avoid this function to avoid
124 * problems later when we have multiple players or no player in scripted
127 Player* get_player();
132 /// is the enemy activated
135 * initial position of the enemy. Also the position where enemy respawns when
136 * after being deactivated.
140 Vector start_position;
145 int bullet_hitpoints;