3 // SuperTux - Badguy "Snail"
4 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.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.
24 #include "object/block.hpp"
25 #include "lisp/writer.hpp"
26 #include "sprite/sprite.hpp"
27 #include "object_factory.hpp"
28 #include "audio/sound_manager.hpp"
29 #include "object/player.hpp"
34 const float KICKSPEED = 500;
35 const int MAXSQUISHES = 10;
36 const float KICKSPEED_Y = -500; /**< y-velocity gained when kicked */
39 Snail::Snail(const lisp::Lisp& reader)
40 : WalkingBadguy(reader, "images/creatures/snail/snail.sprite", "left", "right"), state(STATE_NORMAL), squishcount(0)
43 max_drop_height = 600;
44 sound_manager->preload("sounds/iceblock_bump.wav");
45 sound_manager->preload("sounds/stomp.wav");
46 sound_manager->preload("sounds/kick.wav");
49 Snail::Snail(const Vector& pos, Direction d)
50 : WalkingBadguy(pos, d, "images/creatures/snail/snail.sprite", "left", "right"), state(STATE_NORMAL), squishcount(0)
53 max_drop_height = 600;
54 sound_manager->preload("sounds/iceblock_bump.wav");
55 sound_manager->preload("sounds/stomp.wav");
56 sound_manager->preload("sounds/kick.wav");
60 Snail::write(lisp::Writer& writer)
62 writer.start_list("snail");
63 WalkingBadguy::write(writer);
64 writer.end_list("snail");
70 WalkingBadguy::initialize();
77 if (state == STATE_NORMAL) return;
80 WalkingBadguy::initialize();
87 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
90 physic.set_velocity_x(0);
91 physic.set_velocity_y(0);
99 state = STATE_KICKED_DELAY;
100 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
103 physic.set_velocity_x(0);
104 physic.set_velocity_y(0);
106 // start a timer to delay addition of upward movement until we are (hopefully) out from under the player
107 kicked_delay_timer.start(0.05f);
112 return state == STATE_KICKED;
116 Snail::active_update(float elapsed_time)
121 WalkingBadguy::active_update(elapsed_time);
125 if (flat_timer.started()) {
126 sprite->set_fps(64 - 15 * flat_timer.get_timegone());
128 if (flat_timer.check()) {
131 BadGuy::active_update(elapsed_time);
134 case STATE_KICKED_DELAY:
135 if (kicked_delay_timer.check()) {
136 physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED);
137 physic.set_velocity_y(KICKSPEED_Y);
138 state = STATE_KICKED;
140 BadGuy::active_update(elapsed_time);
144 physic.set_velocity_x(physic.get_velocity_x() * pow(0.99, elapsed_time/0.02));
145 if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
146 BadGuy::active_update(elapsed_time);
153 Snail::collision_solid(const CollisionHit& hit)
155 update_on_ground_flag(hit);
159 WalkingBadguy::collision_solid(hit);
162 if(hit.top || hit.bottom) {
163 physic.set_velocity_y(0);
165 if(hit.left || hit.right) {
168 case STATE_KICKED_DELAY:
169 if(hit.top || hit.bottom) {
170 physic.set_velocity_y(0);
172 if(hit.left || hit.right) {
173 physic.set_velocity_x(0);
177 if(hit.top || hit.bottom) {
178 physic.set_velocity_y(0);
180 if(hit.left || hit.right) {
181 sound_manager->play("sounds/iceblock_bump.wav", get_pos());
183 if( ( dir == LEFT && hit.left ) || ( dir == RIGHT && hit.right) ){
184 dir = (dir == LEFT) ? RIGHT : LEFT;
185 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
187 physic.set_velocity_x(-physic.get_velocity_x()*0.75);
188 if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
198 Snail::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
202 return WalkingBadguy::collision_badguy(badguy, hit);
204 case STATE_KICKED_DELAY:
217 Snail::collision_squished(GameObject& object)
224 Player* player = dynamic_cast<Player*>(&object);
226 if ((squishcount >= MAXSQUISHES) || (player && player->does_buttjump)) {
232 sound_manager->play("sounds/stomp.wav", get_pos());
237 sound_manager->play("sounds/kick.wav", get_pos());
239 MovingObject* movingobject = dynamic_cast<MovingObject*>(&object);
240 if (movingobject && (movingobject->get_pos().x < get_pos().x)) {
249 case STATE_KICKED_DELAY:
254 Player* player = dynamic_cast<Player*>(&object);
255 if (player) player->bounce(*this);
259 IMPLEMENT_FACTORY(Snail, "snail")