4 // Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 // Copyright (C) 2004 Matthias Braun <matze@braunis.de>
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "app/globals.h"
28 #include "special/sprite_manager.h"
29 #include "utils/lispwriter.h"
32 #include "resources.h"
37 #include "statistics.h"
38 #include "badguy_specs.h"
40 #define BADGUY_WALK_SPEED .8f
41 #define WINGLING_FLY_SPEED 1.6f
43 BadGuyKind badguykind_from_string(const std::string& str)
45 if (str == "jumpy" || str == "money") // was "money" in ancient versions
47 else if (str == "mriceblock" || str == "laptop") // was "laptop" in ancient versions
48 return BAD_MRICEBLOCK;
49 else if (str == "mrbomb")
51 else if (str == "stalactite")
52 return BAD_STALACTITE;
53 else if (str == "flame")
55 else if (str == "fish")
57 else if (str == "flamefish")
59 else if (str == "bouncingsnowball")
60 return BAD_BOUNCINGSNOWBALL;
61 else if (str == "flyingsnowball")
62 return BAD_FLYINGSNOWBALL;
63 else if (str == "spiky")
65 else if (str == "snowball" || str == "bsod") // was "bsod" in ancient versions
67 else if (str == "wingling")
69 else if (str == "walkingtree")
70 return BAD_WALKINGTREE;
71 else if(str == "bomb") // not to be used as a real bad guys
79 std::string badguykind_to_string(BadGuyKind kind)
104 case BAD_BOUNCINGSNOWBALL:
105 return "bouncingsnowball";
107 case BAD_FLYINGSNOWBALL:
108 return "flyingsnowball";
119 case BAD_WALKINGTREE:
120 return "walkingtree";
121 case BAD_BOMB: // not to be used as a real bad guys
129 BadGuy::BadGuy(BadGuyKind kind_, LispReader& lispreader)
130 : removable(false), squishcount(0)
132 lispreader.read_float("x", start_position.x);
133 lispreader.read_float("y", start_position.y);
137 stay_on_platform = false;
138 lispreader.read_bool("stay-on-platform", stay_on_platform);
143 BadGuy::BadGuy(BadGuyKind kind_, float x, float y)
144 : removable(false), squishcount(0)
146 start_position.x = x;
147 start_position.y = y;
148 stay_on_platform = false;
172 animation_offset = 0;
173 target.x = target.y = -1;
175 frozen_timer.init(true);
178 specs = badguyspecs_manager->load(badguykind_to_string(kind));
180 set_action("hide", "hide");
182 // if we're in a solid tile at start correct that now
183 if(Sector::current()) {
184 if(kind != BAD_FLAME && kind != BAD_FISH && kind != BAD_FLAMEFISH && collision_object_map(base))
186 std::cout << "Warning: badguy started in wall: kind: " << badguykind_to_string(kind)
187 << " pos: (" << base.x << ", " << base.y << ")" << std::endl;
188 while(collision_object_map(base))
192 if(Sector::current()->camera) {
193 Vector scroll = Sector::current()->camera->get_translation();
195 if(start_position.x > scroll.x - X_OFFSCREEN_DISTANCE &&
196 start_position.x < scroll.x + screen->w + X_OFFSCREEN_DISTANCE &&
197 start_position.y > scroll.y - Y_OFFSCREEN_DISTANCE &&
198 start_position.y < scroll.y + screen->h + Y_OFFSCREEN_DISTANCE) {
202 if(start_position.x >= 0 && start_position.x < screen->w
203 && start_position.y >= 0 && start_position.y < screen->h)
209 BadGuy::write(LispWriter& writer)
211 writer.start_list(badguykind_to_string(kind));
213 writer.write_float("x", base.x);
214 writer.write_float("y", base.y);
215 writer.write_bool("stay-on-platform", stay_on_platform);
217 writer.end_list(badguykind_to_string(kind));
221 BadGuy::activate(Direction activation_dir)
224 animation_offset = 0;
225 target.x = target.y = -1;
227 frozen_timer.init(true);
230 dir = activation_dir;
231 float dirsign = activation_dir == LEFT ? -1 : 1;
233 set_action("left", "right");
234 if(kind == BAD_MRBOMB) {
235 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
236 } else if (kind == BAD_MRICEBLOCK) {
237 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
238 } else if(kind == BAD_JUMPY) {
239 set_action("left-up", "right-up");
240 } else if(kind == BAD_BOMB) {
241 set_action("ticking-left", "ticking-right");
242 // hack so that the bomb doesn't hurt until it expldes...
243 dying = DYING_SQUISHED;
244 } else if(kind == BAD_FLAME) {
246 physic.enable_gravity(false);
247 set_action("normal", "normal");
248 } else if(kind == BAD_BOUNCINGSNOWBALL) {
249 physic.set_velocity(dirsign * 1.3, 0);
250 } else if(kind == BAD_STALACTITE) {
251 physic.enable_gravity(false);
252 set_action("normal", "normal");
253 } else if(kind == BAD_FISH) {
254 set_action("normal", "normal");
255 physic.enable_gravity(true);
256 } else if(kind == BAD_FLAMEFISH) {
257 set_action("normal", "normal");
258 physic.enable_gravity(true);
259 } else if(kind == BAD_FLYINGSNOWBALL) {
260 physic.enable_gravity(false);
261 } else if(kind == BAD_SPIKY) {
262 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
263 } else if(kind == BAD_SNOWBALL) {
264 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
265 } else if(kind == BAD_WINGLING) {
266 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
267 physic.enable_gravity(false);
268 set_action("left", "left");
269 } else if (kind == BAD_WALKINGTREE) {
270 // TODO: why isn't the height/width being set properly in set_action?
271 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
273 set_action("left", "left");
278 base.x = start_position.x;
279 base.y = start_position.y;
287 // Set action as the "default" one.
288 specs->sprite->set_action("left");
290 specs->sprite->set_action("left-up");
291 else if(kind == BAD_BOMB)
292 specs->sprite->set_action("ticking-left");
293 else if(kind == BAD_FLAME)
294 specs->sprite->set_action("normal");
295 else if(kind == BAD_STALACTITE)
296 specs->sprite->set_action("normal");
297 else if(kind == BAD_FISH)
298 specs->sprite->set_action("normal");
299 else if(kind == BAD_FLAMEFISH)
300 specs->sprite->set_action("normal");
302 return specs->sprite->get_frame(0);
306 BadGuy::action_mriceblock(double elapsed_time)
308 Player& tux = *Sector::current()->player;
313 /* Move left/right: */
317 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
318 if (dying != DYING_FALLING)
319 collision_swept_object_map(&old_base,&base);
321 else if (mode == HELD)
322 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
323 /* If we're holding the iceblock */
325 if(tux.size == SMALL)
328 base.x = tux.base.x + 24;
330 base.x = tux.base.x - 12;
331 base.y = tux.base.y + tux.base.height/1.5 - base.height;
336 base.x = tux.base.x + 24;
338 base.x = tux.base.x - 4;
339 base.y = tux.base.y + tux.base.height/1.5 - base.height;
342 if(collision_object_map(base))
345 base.y = tux.base.y + tux.base.height/1.5 - base.height;
348 if(tux.input.fire != DOWN) /* SHOOT! */
351 base.x = tux.base.x - base.width;
353 base.x = tux.base.x + tux.base.width;
357 tux.kick_timer.start(KICKING_TIME);
358 set_action("flat-left", "flat-right");
359 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
360 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
367 check_horizontal_bump();
368 if(mode == KICK && changed != dir)
370 SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(), Sector::current()->player->get_pos());
374 /* Handle mode timer: */
380 set_action("left", "right");
381 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
387 BadGuy::check_horizontal_bump(bool checkcliff)
389 float halfheight = base.height / 2;
390 if (dir == LEFT && issolid( base.x, base.y + halfheight))
392 if (kind == BAD_MRICEBLOCK && mode == KICK)
394 Sector::current()->trybreakbrick(Vector(base.x, base.y + halfheight), false);
395 Sector::current()->tryemptybox(Vector(base.x, base.y + halfheight), dir);
399 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
402 if (dir == RIGHT && issolid( base.x + base.width, base.y + halfheight))
404 if (kind == BAD_MRICEBLOCK && mode == KICK)
406 Sector::current()->trybreakbrick(
407 Vector(base.x + base.width, base.y + halfheight), false);
408 Sector::current()->tryemptybox(
409 Vector(base.x + base.width, base.y + halfheight), dir);
413 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
417 // don't check for cliffs when we're falling
420 if(!issolid(base.x + base.width/2, base.y + base.height))
423 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
426 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
429 if(dir == RIGHT && !issolid(base.x + base.width,
430 (int) base.y + base.height + halfheight))
433 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
441 /* Fall if we get off the ground: */
442 if (dying != DYING_FALLING)
444 if (!issolid(base.x+base.width/2, base.y + base.height))
446 // not solid below us? enable gravity
447 physic.enable_gravity(true);
452 if (physic.get_velocity_y() < 0)
454 base.y = int((base.y + base.height)/32) * 32 - base.height;
455 physic.set_velocity_y(0);
457 // no gravity anymore please
458 physic.enable_gravity(false);
460 if (stay_on_platform && mode == NORMAL)
462 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
463 base.y + base.height))
468 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
473 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
481 physic.enable_gravity(true);
486 BadGuy::action_jumpy(double elapsed_time)
488 if(frozen_timer.check())
490 set_action("left-iced", "right-iced");
494 const float vy = physic.get_velocity_y();
496 // XXX: These tests *should* use location from ground, not velocity
497 if (fabsf(vy) > 5.6f)
498 set_action("left-down", "right-down");
499 else if (fabsf(vy) > 5.3f)
500 set_action("left-middle", "right-middle");
502 set_action("left-up", "right-up");
504 Player& tux = *Sector::current()->player;
506 static const float JUMPV = 6;
509 // jump when on ground
510 if(dying == DYING_NOT && issolid(base.x, base.y+32))
512 physic.set_velocity_y(JUMPV);
513 physic.enable_gravity(true);
517 else if(mode == JUMPY_JUMP)
522 // set direction based on tux
523 if(tux.base.x > base.x)
529 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
530 if(dying == DYING_NOT)
531 collision_swept_object_map(&old_base, &base);
535 BadGuy::action_mrbomb(double elapsed_time)
537 if(frozen_timer.check())
539 set_action("iced-left", "iced-right");
543 if (dying == DYING_NOT)
544 check_horizontal_bump(true);
548 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
549 if (dying != DYING_FALLING)
550 collision_swept_object_map(&old_base,&base);
554 BadGuy::action_bomb(double elapsed_time)
556 static const int TICKINGTIME = 1000;
557 static const int EXPLODETIME = 1000;
563 timer.start(TICKINGTIME);
564 } else if(!timer.check()) {
565 if(mode == BOMB_TICKING) {
567 set_action("explosion", "explosion");
568 dying = DYING_NOT; // now the bomb hurts
569 timer.start(EXPLODETIME);
571 SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), this, Sector::current()->player->get_pos());
572 } else if(mode == BOMB_EXPLODE) {
579 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
580 collision_swept_object_map(&old_base,&base);
584 BadGuy::action_stalactite(double elapsed_time)
586 Player& tux = *Sector::current()->player;
588 static const int SHAKETIME = 800;
589 static const int RANGE = 40;
592 // start shaking when tux is below the stalactite and at least 40 pixels
594 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
595 && tux.base.y + tux.base.height > base.y
596 && tux.dying == DYING_NOT) {
597 timer.start(SHAKETIME);
598 mode = STALACTITE_SHAKING;
600 } if(mode == STALACTITE_SHAKING) {
601 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
603 mode = STALACTITE_FALL;
605 } else if(mode == STALACTITE_FALL) {
607 /* Destroy if we collides with land */
608 if(issolid(base.x+base.width/2, base.y+base.height))
611 dying = DYING_SQUISHED;
613 set_action("broken", "broken");
615 } else if(mode == FLAT) {
620 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
622 if(dying == DYING_SQUISHED && !timer.check())
627 BadGuy::action_flame(double elapsed_time)
629 static const float radius = 100;
630 static const float speed = 0.02;
631 base.x = old_base.x + cos(angle) * radius;
632 base.y = old_base.y + sin(angle) * radius;
634 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
638 BadGuy::action_fish(double elapsed_time)
640 if(frozen_timer.check())
642 if(physic.get_velocity_y() < 0)
643 set_action("iced-down", "iced-down");
645 set_action("iced", "iced");
650 static const float JUMPV = 6;
651 static const int WAITTIME = 1000;
653 // go in wait mode when back in water
654 if(dying == DYING_NOT
655 && gettile(base.x, base.y + base.height)
656 && gettile(base.x, base.y + base.height)->attributes & Tile::WATER
657 && physic.get_velocity_y() <= 0 && mode == NORMAL)
660 set_action("hide", "hide");
661 physic.set_velocity(0, 0);
662 physic.enable_gravity(false);
663 timer.start(WAITTIME);
665 else if(mode == FISH_WAIT && !timer.check())
668 set_action("normal", "normal");
670 physic.set_velocity(0, JUMPV);
671 physic.enable_gravity(true);
674 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
675 if(dying == DYING_NOT)
676 collision_swept_object_map(&old_base, &base);
678 if(physic.get_velocity_y() < 0)
680 set_action("down", "down");
685 BadGuy::action_bouncingsnowball(double elapsed_time)
687 static const float JUMPV = 4.5;
691 // jump when on ground
692 if(dying == DYING_NOT && issolid(base.x, base.y+32))
694 physic.set_velocity_y(JUMPV);
695 physic.enable_gravity(true);
702 // check for right/left collisions
703 check_horizontal_bump();
705 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
706 if(dying == DYING_NOT)
707 collision_swept_object_map(&old_base, &base);
709 // Handle dying timer:
710 if (dying == DYING_SQUISHED && !timer.check())
715 BadGuy::action_flyingsnowball(double elapsed_time)
717 static const float FLYINGSPEED = 1;
718 static const int DIRCHANGETIME = 1000;
720 // go into flyup mode if none specified yet
721 if(dying == DYING_NOT && mode == NORMAL) {
723 physic.set_velocity_y(FLYINGSPEED);
724 timer.start(DIRCHANGETIME/2);
727 if(dying == DYING_NOT && !timer.check()) {
730 physic.set_velocity_y(-FLYINGSPEED);
731 } else if(mode == FLY_DOWN) {
733 physic.set_velocity_y(FLYINGSPEED);
735 timer.start(DIRCHANGETIME);
738 if(dying != DYING_NOT)
739 physic.enable_gravity(true);
741 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
742 if(dying == DYING_NOT || dying == DYING_SQUISHED)
743 collision_swept_object_map(&old_base, &base);
745 // set direction based on tux
746 if(Sector::current()->player->base.x > base.x)
751 // Handle dying timer:
752 if (dying == DYING_SQUISHED && !timer.check())
757 BadGuy::action_spiky(double elapsed_time)
759 if(frozen_timer.check())
761 set_action("iced-left", "iced-right");
765 if (dying == DYING_NOT)
766 check_horizontal_bump();
770 // jump when we're about to fall
771 if (physic.get_velocity_y() == 0 &&
772 !issolid(base.x+base.width/2, base.y + base.height)) {
773 physic.enable_gravity(true);
774 physic.set_velocity_y(2);
778 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
779 if (dying != DYING_FALLING)
780 collision_swept_object_map(&old_base,&base);
784 BadGuy::action_snowball(double elapsed_time)
786 if (dying == DYING_NOT)
787 check_horizontal_bump();
791 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
792 if (dying != DYING_FALLING)
793 collision_swept_object_map(&old_base,&base);
795 // Handle dying timer:
796 if (dying == DYING_SQUISHED && !timer.check())
801 BadGuy::action_wingling(double elapsed_time)
803 if (dying != DYING_NOT)
804 physic.enable_gravity(true);
807 Player& tux = *Sector::current()->player;
808 int dirsign = physic.get_velocity_x() < 0 ? -1 : 1;
810 if (fabsf(tux.base.x - base.x) < 150 && base.y < tux.base.y && tux.dying == DYING_NOT)
812 if (target.x < 0 && target.y < 0)
814 target.x = tux.base.x;
815 target.y = tux.base.y;
816 physic.set_velocity(dirsign * 1.5f, -2.25f);
819 else if (base.y >= target.y - 16)
820 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
823 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
826 // Handle dying timer:
827 if (dying == DYING_SQUISHED && !timer.check())
830 // TODO: Winglings should be removed after flying off the screen
834 BadGuy::action_walkingtree(double elapsed_time)
836 if (dying == DYING_NOT)
837 check_horizontal_bump();
841 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
842 if (dying != DYING_FALLING)
843 collision_swept_object_map(&old_base,&base);
845 // Handle dying timer:
846 if (dying == DYING_SQUISHED && !timer.check())
851 BadGuy::action(float elapsed_time)
853 float scroll_x = Sector::current()->camera->get_translation().x;
854 float scroll_y = Sector::current()->camera->get_translation().y;
856 // BadGuy fall below the ground
857 if (base.y > Sector::current()->solids->get_height() * 32) {
862 // Kill us if we landed on spikes
863 if (dying == DYING_NOT
864 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
865 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
866 || isspike(base.x, base.y + base.height)
867 || isspike(base.x + base.width, base.y + base.height)))
869 physic.set_velocity_y(3);
874 /* activate badguys if they're just inside the offscreen_distance around the
875 * screen. Don't activate them inside the screen, since that might have the
876 * effect of badguys suddenly popping up from nowhere
878 if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
879 start_position.x < scroll_x - base.width)
881 else if(start_position.x > scroll_y - Y_OFFSCREEN_DISTANCE &&
882 start_position.y < scroll_y - base.height)
884 else if(start_position.x > scroll_x + screen->w &&
885 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE)
887 else if(start_position.y > scroll_y + screen->h &&
888 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
891 if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4
892 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4
893 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4
894 || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4) {
896 if(dying != DYING_NOT)
907 action_mriceblock(elapsed_time);
911 action_jumpy(elapsed_time);
915 action_mrbomb(elapsed_time);
919 action_bomb(elapsed_time);
923 action_stalactite(elapsed_time);
927 action_flame(elapsed_time);
932 action_fish(elapsed_time);
935 case BAD_BOUNCINGSNOWBALL:
936 action_bouncingsnowball(elapsed_time);
939 case BAD_FLYINGSNOWBALL:
940 action_flyingsnowball(elapsed_time);
944 action_spiky(elapsed_time);
948 action_snowball(elapsed_time);
952 action_wingling(elapsed_time);
955 case BAD_WALKINGTREE:
956 action_walkingtree(elapsed_time);
965 BadGuy::draw(DrawingContext& context)
967 if((dir == LEFT && action_left == "hide") ||
968 (dir == RIGHT && action_right == "hide"))
972 specs->sprite->set_action(action_left);
973 else // if(dir == RIGHT)
974 specs->sprite->set_action(action_right);
976 if(dying == DYING_FALLING && physic.get_velocity_y() < 0)
977 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_FOREGROUNDTILES+1, VERTICAL_FLIP);
979 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
982 context.draw_filled_rect(Vector(base.x, base.y),
983 Vector(base.width, base.height), Color(75,0,75, 150), LAYER_OBJECTS+1);
987 BadGuy::set_action(std::string left, std::string right)
993 action_right = right;
1003 // FIXME: Using the image size for the physics and collision is
1004 // a bad idea, since images should always overlap there physical
1007 if(base.width == 0 && base.height == 0) {
1008 base.width = left->get_width();
1009 base.height = left->get_height();
1010 } else if(base.width != left->get_width() || base.height != left->get_height()) {
1011 base.x -= (left->get_width() - base.width) / 2;
1012 base.y -= left->get_height() - base.height;
1013 base.width = left->get_width();
1014 base.height = left->get_height();
1018 base.width = base.height = 0;
1022 animation_offset = 0;
1024 sprite_right = right;
1031 // these can't be bumped
1032 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
1033 || kind == BAD_FLAMEFISH || kind == BAD_FLYINGSNOWBALL)
1036 physic.set_velocity_y(3);
1041 BadGuy::squish_me(Player* player)
1043 player->bounce(this);
1045 Sector::current()->add_score(Vector(base.x, base.y),
1046 25 * player_status.score_multiplier);
1048 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1049 player_status.score_multiplier++;
1051 dying = DYING_SQUISHED;
1053 physic.set_velocity(0, 0);
1057 BadGuy::squish(Player* player)
1059 static const int MAX_ICEBLOCK_SQUICHES = 10;
1061 if(kind == BAD_MRBOMB) {
1062 // mrbomb transforms into a bomb now
1065 player->bounce(this);
1066 Sector::current()->add_score(Vector(base.x, base.y),
1067 25 * player_status.score_multiplier);
1068 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1070 player_status.score_multiplier++;
1073 } else if (kind == BAD_MRICEBLOCK) {
1074 if (mode == NORMAL || mode == KICK)
1077 SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(), Sector::current()->player->get_pos());
1079 set_action("flat-left", "flat-right");
1080 physic.set_velocity_x(0);
1083 } else if (mode == FLAT) {
1085 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1087 if (player->base.x < base.x + (base.width/2)) {
1088 physic.set_velocity_x(5);
1091 physic.set_velocity_x(-5);
1096 player->kick_timer.start(KICKING_TIME);
1097 set_action("flat-left", "flat-right");
1100 player->bounce(this);
1102 player_status.score_multiplier++;
1104 // check for maximum number of squishes
1106 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
1112 } else if(kind == BAD_FISH || kind == BAD_FLAMEFISH) {
1113 // fish can only be killed when falling down
1114 if(physic.get_velocity_y() >= 0)
1117 player->bounce(this);
1119 Sector::current()->add_score(Vector(base.x, base.y),
1120 25 * player_status.score_multiplier);
1122 player_status.score_multiplier++;
1124 // simply remove the fish...
1127 } else if(kind == BAD_BOUNCINGSNOWBALL) {
1129 set_action("squished", "squished");
1131 } else if(kind == BAD_FLYINGSNOWBALL) {
1133 set_action("squished-left", "squished-right");
1135 } else if(kind == BAD_SNOWBALL) {
1137 set_action("squished-left", "squished-right");
1139 } else if(kind == BAD_WINGLING) {
1141 set_action("left", "right");
1142 } else if(kind == BAD_WALKINGTREE) {
1143 if (mode == BGM_BIG)
1145 set_action("left-small", "left-small");
1146 physic.set_velocity_x(physic.get_velocity_x() * 2.0f);
1148 /* Move to the player's direction */
1149 if(dir != Sector::current()->player->dir)
1150 physic.set_velocity_x(-physic.get_velocity_x());
1151 dir = Sector::current()->player->dir;
1153 // XXX magic number: 66 is BGM_BIG height
1155 player->bounce(this);
1156 base.y += 66 - base.height;
1158 Sector::current()->add_score(Vector(base.x, base.y),
1159 25 * player_status.score_multiplier);
1160 player_status.score_multiplier++;
1170 BadGuy::kill_me(int score)
1172 if(kind == BAD_BOMB)
1176 global_stats.add_points(BADGUYS_KILLED_STAT, 1);
1178 dying = DYING_FALLING;
1179 if(kind == BAD_MRICEBLOCK) {
1180 set_action("falling-left", "falling-right");
1183 Player& tux = *Sector::current()->player;
1184 tux.holding_something = false;
1188 physic.enable_gravity(true);
1190 /* Gain some points: */
1192 Sector::current()->add_score(Vector(base.x, base.y),
1193 score * player_status.score_multiplier);
1195 /* Play death sound: */
1196 SoundManager::get()->play_sound(IDToSound(SND_FALL), this, Sector::current()->player->get_pos());
1200 BadGuy::explode(bool right_way)
1202 BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
1205 badguy->timer.start(0);
1206 badguy->mode = BOMB_TICKING;
1214 BadGuy::collision(const MovingObject&, int)
1220 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1222 BadGuy* pbad_c = NULL;
1223 Bullet* pbullet_c = NULL;
1225 if(type == COLLISION_BUMP) {
1230 if(type == COLLISION_SQUISH) {
1231 Player* player = static_cast<Player*>(p_c_object);
1236 /* COLLISION_NORMAL */
1240 pbullet_c = (Bullet*) p_c_object;
1242 if(pbullet_c->kind == FIRE_BULLET)
1244 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME
1245 && kind != BAD_FLAMEFISH)
1248 else if(pbullet_c->kind == ICE_BULLET)
1250 if(kind == BAD_FLAME || kind == BAD_FLAMEFISH)
1253 frozen_timer.start(FROZEN_TIME);
1258 pbad_c = (BadGuy*) p_c_object;
1261 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1262 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1263 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1265 pbad_c->kill_me(25);
1268 // a held mriceblock kills the enemy too but falls to ground then
1269 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1271 pbad_c->kill_me(25);
1275 /* Kill badguys that run into exploding bomb */
1276 else if (kind == BAD_BOMB && dying == DYING_NOT)
1278 if (pbad_c->kind == BAD_MRBOMB)
1280 // mrbomb transforms into a bomb now
1281 pbad_c->explode(true);
1286 pbad_c->kill_me(50);
1290 /* Kill any badguys that get hit by stalactite */
1291 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1293 if (pbad_c->kind == BAD_MRBOMB)
1295 // mrbomb transforms into a bomb now
1296 pbad_c->explode(false);
1300 pbad_c->kill_me(50);
1303 /* When enemies run into eachother, make them change directions */
1306 // Wingling doesn't interact with other badguys
1307 if (pbad_c->kind == BAD_WINGLING || kind == BAD_WINGLING)
1310 // Jumpy, fish, flame, stalactites, wingling are exceptions
1311 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1312 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH
1313 || pbad_c->kind == BAD_FLAMEFISH)
1316 // Bounce off of other badguy if we land on top of him
1317 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1319 if (pbad_c->dir == LEFT)
1322 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1324 else if (pbad_c->dir == RIGHT)
1327 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1332 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1335 if (pbad_c->kind != BAD_FLAME)
1340 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1342 // Put bad guys a part (or they get jammed)
1343 // only needed to do to one of them
1344 if (physic.get_velocity_x() != 0)
1345 base.x = pbad_c->base.x + pbad_c->base.width + 1;
1347 else if (dir == RIGHT)
1350 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1359 Player* player = static_cast<Player*>(p_c_object);
1360 /* Get kicked if were flat */
1361 if (mode == FLAT && !dying)
1363 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1365 // Hit from left side
1366 if (player->base.x < base.x) {
1367 physic.set_velocity_x(5);
1370 // Hit from right side
1372 physic.set_velocity_x(-5);
1377 player->kick_timer.start(KICKING_TIME);
1378 set_action("flat-left", "flat-right");