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.
23 #include "object/block.hpp"
26 const float KICKSPEED = 500;
27 const int MAXSQUISHES = 10;
28 const float KICKSPEED_Y = -500; /**< y-velocity gained when kicked */
31 Snail::Snail(const lisp::Lisp& reader)
32 : WalkingBadguy(reader, "images/creatures/snail/snail.sprite", "left", "right"), state(STATE_NORMAL), squishcount(0)
35 max_drop_height = 600;
36 sound_manager->preload("sounds/iceblock_bump.wav");
37 sound_manager->preload("sounds/stomp.wav");
38 sound_manager->preload("sounds/kick.wav");
41 Snail::Snail(const Vector& pos, Direction d)
42 : WalkingBadguy(pos, d, "images/creatures/snail/snail.sprite", "left", "right"), state(STATE_NORMAL), squishcount(0)
45 max_drop_height = 600;
46 sound_manager->preload("sounds/iceblock_bump.wav");
47 sound_manager->preload("sounds/stomp.wav");
48 sound_manager->preload("sounds/kick.wav");
52 Snail::write(lisp::Writer& writer)
54 writer.start_list("snail");
55 WalkingBadguy::write(writer);
56 writer.end_list("snail");
62 WalkingBadguy::activate();
69 if (state == STATE_NORMAL) return;
72 WalkingBadguy::activate();
79 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
82 physic.set_velocity_x(0);
83 physic.set_velocity_y(0);
91 state = STATE_KICKED_DELAY;
92 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
95 physic.set_velocity_x(0);
96 physic.set_velocity_y(0);
98 // start a timer to delay addition of upward movement until we are (hopefully) out from under the player
99 kicked_delay_timer.start(0.05f);
104 return state == STATE_KICKED;
108 Snail::active_update(float elapsed_time)
113 WalkingBadguy::active_update(elapsed_time);
117 if (flat_timer.started()) {
118 sprite->set_fps(64 - 15 * flat_timer.get_timegone());
120 if (flat_timer.check()) {
123 BadGuy::active_update(elapsed_time);
126 case STATE_KICKED_DELAY:
127 if (kicked_delay_timer.check()) {
128 physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED);
129 physic.set_velocity_y(KICKSPEED_Y);
130 state = STATE_KICKED;
132 BadGuy::active_update(elapsed_time);
136 physic.set_velocity_x(physic.get_velocity_x() * pow(0.99, elapsed_time/0.02));
137 if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
138 BadGuy::active_update(elapsed_time);
145 Snail::collision_solid(const CollisionHit& hit)
147 update_on_ground_flag(hit);
151 WalkingBadguy::collision_solid(hit);
154 if(hit.top || hit.bottom) {
155 physic.set_velocity_y(0);
157 if(hit.left || hit.right) {
160 case STATE_KICKED_DELAY:
161 if(hit.top || hit.bottom) {
162 physic.set_velocity_y(0);
164 if(hit.left || hit.right) {
165 physic.set_velocity_x(0);
169 if(hit.top || hit.bottom) {
170 physic.set_velocity_y(0);
172 if(hit.left || hit.right) {
173 sound_manager->play("sounds/iceblock_bump.wav", get_pos());
175 if( ( dir == LEFT && hit.left ) || ( dir == RIGHT && hit.right) ){
176 dir = (dir == LEFT) ? RIGHT : LEFT;
177 sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
179 physic.set_velocity_x(-physic.get_velocity_x()*0.75);
180 if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
190 Snail::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
194 return WalkingBadguy::collision_badguy(badguy, hit);
196 case STATE_KICKED_DELAY:
209 Snail::collision_squished(GameObject& object)
216 if(squishcount >= MAXSQUISHES) {
221 sound_manager->play("sounds/stomp.wav", get_pos());
226 sound_manager->play("sounds/kick.wav", get_pos());
228 MovingObject* movingobject = dynamic_cast<MovingObject*>(&object);
229 if (movingobject && (movingobject->get_pos().x < get_pos().x)) {
238 case STATE_KICKED_DELAY:
243 Player* player = dynamic_cast<Player*>(&object);
244 if (player) player->bounce(*this);
248 IMPLEMENT_FACTORY(Snail, "snail")