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.h"
27 #include "sprite/sprite.h"
29 #include "object/player.h"
30 #include "serializable.h"
31 #include "resources.h"
33 #include "direction.h"
34 #include "object_factory.h"
35 #include "lisp/parser.h"
36 #include "lisp/lisp.h"
37 #include "lisp/writer.h"
38 #include "video/drawing_context.h"
39 #include "sprite/sprite_manager.h"
41 class BadGuy : public MovingObject, public Serializable
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_action and inactive_action
54 virtual void action(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 /** Set the badguy to kill/falling state, which makes him falling of the
63 * screen (his sprite is turned upside-down)
65 virtual void kill_fall();
67 Vector get_start_position() const
69 return start_position;
71 void set_start_position(const Vector& vec)
85 /** Called when the badguy collided with a player */
86 virtual HitResponse collision_player(Player& player,
87 const CollisionHit& hit);
88 /** Called when the badguy collided with solid ground */
89 virtual HitResponse collision_solid(GameObject& other,
90 const CollisionHit& hit);
91 /** Called when the badguy collided with another badguy */
92 virtual HitResponse collision_badguy(BadGuy& other,
93 const CollisionHit& hit);
95 /** Called when the player hit the badguy from above. You should return true
96 * if the badguy was squished, false if squishing wasn't possible
98 virtual bool collision_squished(Player& player);
100 /** called each frame when the badguy is activated. */
101 virtual void active_action(float elapsed_time);
102 /** called each frame when the badguy is not activated. */
103 virtual void inactive_action(float elapsed_time);
106 * called when the badguy has been activated. (As a side effect the dir
107 * variable might have been changed so that it faces towards the player.
109 virtual void activate();
110 /** called when the badguy has been deactivated */
111 virtual void deactivate();
113 void kill_squished(Player& player);
115 void set_state(State state);
116 State get_state() const
120 * returns a pointer to the player, try to avoid this function to avoid
121 * problems later when we have multiple players or no player in scripted
124 Player* get_player();
129 /// is the enemy activated
132 * initial position of the enemy. Also the position where enemy respawns when
133 * after being deactivated.
137 Vector start_position;
142 int bullet_hitpoints;