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;
162 base.x = start_position.x;
163 base.y = start_position.y;
171 animation_offset = 0;
172 target.x = target.y = -1;
174 frozen_timer.init(true);
177 specs = badguyspecs_manager->load(badguykind_to_string(kind));
179 // if we're in a solid tile at start correct that now
180 if(Sector::current()) {
181 if(kind != BAD_FLAME && kind != BAD_FISH && kind != BAD_FLAMEFISH && collision_object_map(base))
183 std::cout << "Warning: badguy started in wall: kind: " << badguykind_to_string(kind)
184 << " pos: (" << base.x << ", " << base.y << ")" << std::endl;
185 while(collision_object_map(base))
192 BadGuy::write(LispWriter& writer)
194 writer.start_list(badguykind_to_string(kind));
196 writer.write_float("x", base.x);
197 writer.write_float("y", base.y);
198 writer.write_bool("stay-on-platform", stay_on_platform);
200 writer.end_list(badguykind_to_string(kind));
204 BadGuy::activate(Direction activation_dir)
207 animation_offset = 0;
208 target.x = target.y = -1;
210 frozen_timer.init(true);
215 dir = activation_dir;
216 float dirsign = activation_dir == LEFT ? -1 : 1;
218 set_action("left", "right");
219 if(kind == BAD_MRBOMB) {
220 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
221 } else if (kind == BAD_MRICEBLOCK) {
222 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
223 } else if(kind == BAD_JUMPY) {
224 set_action("left-up", "right-up");
225 } else if(kind == BAD_BOMB) {
226 set_action("ticking-left", "ticking-right");
227 // hack so that the bomb doesn't hurt until it expldes...
228 dying = DYING_SQUISHED;
229 } else if(kind == BAD_FLAME) {
231 physic.enable_gravity(false);
232 set_action("normal", "normal");
233 } else if(kind == BAD_BOUNCINGSNOWBALL) {
234 physic.set_velocity(dirsign * 1.3, 0);
235 } else if(kind == BAD_STALACTITE) {
236 physic.enable_gravity(false);
237 set_action("normal", "normal");
238 } else if(kind == BAD_FISH) {
239 set_action("normal", "normal");
240 physic.enable_gravity(true);
241 } else if(kind == BAD_FLAMEFISH) {
242 set_action("normal", "normal");
243 physic.enable_gravity(true);
244 } else if(kind == BAD_FLYINGSNOWBALL) {
245 physic.enable_gravity(false);
246 } else if(kind == BAD_SPIKY) {
247 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
248 } else if(kind == BAD_SNOWBALL) {
249 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
250 } else if(kind == BAD_WINGLING) {
251 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
252 physic.enable_gravity(false);
253 set_action("left", "left");
254 } else if (kind == BAD_WALKINGTREE) {
255 // TODO: why isn't the height/width being set properly in set_action?
256 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
258 set_action("left", "left");
267 // Set action as the "default" one.
268 specs->sprite->set_action("left");
270 specs->sprite->set_action("left-up");
271 else if(kind == BAD_BOMB)
272 specs->sprite->set_action("ticking-left");
273 else if(kind == BAD_FLAME)
274 specs->sprite->set_action("normal");
275 else if(kind == BAD_STALACTITE)
276 specs->sprite->set_action("normal");
277 else if(kind == BAD_FISH)
278 specs->sprite->set_action("normal");
279 else if(kind == BAD_FLAMEFISH)
280 specs->sprite->set_action("normal");
282 return specs->sprite->get_frame(0);
286 BadGuy::action_mriceblock(double elapsed_time)
288 Player& tux = *Sector::current()->player;
293 /* Move left/right: */
297 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
298 if (dying != DYING_FALLING)
299 collision_swept_object_map(&old_base,&base);
301 else if (mode == HELD)
302 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
303 /* If we're holding the iceblock */
305 if(tux.size == SMALL)
308 base.x = tux.base.x + 24;
310 base.x = tux.base.x - 12;
311 base.y = tux.base.y + tux.base.height/1.5 - base.height;
316 base.x = tux.base.x + 24;
318 base.x = tux.base.x - 4;
319 base.y = tux.base.y + tux.base.height/1.5 - base.height;
322 if(collision_object_map(base))
325 base.y = tux.base.y + tux.base.height/1.5 - base.height;
328 if(tux.input.fire != DOWN) /* SHOOT! */
331 base.x = tux.base.x - base.width;
333 base.x = tux.base.x + tux.base.width;
337 tux.kick_timer.start(KICKING_TIME);
338 set_action("flat-left", "flat-right");
339 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
340 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
347 check_horizontal_bump();
348 if(mode == KICK && changed != dir)
350 SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(), Sector::current()->player->get_pos());
354 /* Handle mode timer: */
360 set_action("left", "right");
361 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
367 BadGuy::check_horizontal_bump(bool checkcliff)
369 float halfheight = base.height / 2;
370 if (dir == LEFT && issolid( base.x, base.y + halfheight))
372 if (kind == BAD_MRICEBLOCK && mode == KICK)
374 Sector::current()->trybreakbrick(Vector(base.x, base.y + halfheight), false);
375 Sector::current()->tryemptybox(Vector(base.x, base.y + halfheight), dir);
379 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
382 if (dir == RIGHT && issolid( base.x + base.width, base.y + halfheight))
384 if (kind == BAD_MRICEBLOCK && mode == KICK)
386 Sector::current()->trybreakbrick(
387 Vector(base.x + base.width, base.y + halfheight), false);
388 Sector::current()->tryemptybox(
389 Vector(base.x + base.width, base.y + halfheight), dir);
393 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
397 // don't check for cliffs when we're falling
400 if(!issolid(base.x + base.width/2, base.y + base.height))
403 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
406 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
409 if(dir == RIGHT && !issolid(base.x + base.width,
410 (int) base.y + base.height + halfheight))
413 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
421 /* Fall if we get off the ground: */
422 if (dying != DYING_FALLING)
424 if (!issolid(base.x+base.width/2, base.y + base.height))
426 // not solid below us? enable gravity
427 physic.enable_gravity(true);
432 if (physic.get_velocity_y() < 0)
434 base.y = int((base.y + base.height)/32) * 32 - base.height;
435 physic.set_velocity_y(0);
437 // no gravity anymore please
438 physic.enable_gravity(false);
440 if (stay_on_platform && mode == NORMAL)
442 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
443 base.y + base.height))
448 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
453 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
461 physic.enable_gravity(true);
466 BadGuy::action_jumpy(double elapsed_time)
468 if(frozen_timer.check())
470 set_action("left-iced", "right-iced");
474 const float vy = physic.get_velocity_y();
476 // XXX: These tests *should* use location from ground, not velocity
477 if (fabsf(vy) > 5.6f)
478 set_action("left-down", "right-down");
479 else if (fabsf(vy) > 5.3f)
480 set_action("left-middle", "right-middle");
482 set_action("left-up", "right-up");
484 Player& tux = *Sector::current()->player;
486 static const float JUMPV = 6;
489 // jump when on ground
490 if(dying == DYING_NOT && issolid(base.x, base.y+32))
492 physic.set_velocity_y(JUMPV);
493 physic.enable_gravity(true);
497 else if(mode == JUMPY_JUMP)
502 // set direction based on tux
503 if(dying == DYING_NOT)
505 if(tux.base.x > base.x)
512 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
513 if(dying == DYING_NOT)
514 collision_swept_object_map(&old_base, &base);
518 BadGuy::action_mrbomb(double elapsed_time)
520 if(frozen_timer.check())
522 set_action("iced-left", "iced-right");
526 if (dying == DYING_NOT)
527 check_horizontal_bump(true);
531 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
532 if (dying != DYING_FALLING)
533 collision_swept_object_map(&old_base,&base);
537 BadGuy::action_bomb(double elapsed_time)
539 static const int TICKINGTIME = 1000;
540 static const int EXPLODETIME = 1000;
546 timer.start(TICKINGTIME);
547 } else if(!timer.check()) {
548 if(mode == BOMB_TICKING) {
550 set_action("explosion", "explosion");
551 dying = DYING_NOT; // now the bomb hurts
552 timer.start(EXPLODETIME);
554 SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), this, Sector::current()->player->get_pos());
555 } else if(mode == BOMB_EXPLODE) {
562 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
563 collision_swept_object_map(&old_base,&base);
567 BadGuy::action_stalactite(double elapsed_time)
569 Player& tux = *Sector::current()->player;
571 static const int SHAKETIME = 800;
572 static const int RANGE = 40;
575 // start shaking when tux is below the stalactite and at least 40 pixels
577 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
578 && tux.base.y + tux.base.height > base.y
579 && tux.dying == DYING_NOT) {
580 timer.start(SHAKETIME);
581 mode = STALACTITE_SHAKING;
583 } if(mode == STALACTITE_SHAKING) {
584 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
586 mode = STALACTITE_FALL;
588 } else if(mode == STALACTITE_FALL) {
590 /* Destroy if we collides with land */
591 if(issolid(base.x+base.width/2, base.y+base.height))
594 dying = DYING_SQUISHED;
596 set_action("broken", "broken");
598 } else if(mode == FLAT) {
603 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
605 if(dying == DYING_SQUISHED && !timer.check())
610 BadGuy::action_flame(double elapsed_time)
612 static const float radius = 100;
613 static const float speed = 0.02;
614 base.x = old_base.x + cos(angle) * radius;
615 base.y = old_base.y + sin(angle) * radius;
617 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
621 BadGuy::action_fish(double elapsed_time)
623 if(frozen_timer.check())
625 if(physic.get_velocity_y() < 0)
626 set_action("iced-down", "iced-down");
628 set_action("iced", "iced");
633 static const float JUMPV = 6;
634 static const int WAITTIME = 1000;
636 // go in wait mode when back in water
637 if(dying == DYING_NOT
638 && gettile(base.x, base.y + base.height)
639 && gettile(base.x, base.y + base.height)->attributes & Tile::WATER
640 && physic.get_velocity_y() <= 0 && mode == NORMAL)
643 set_action("hide", "hide");
644 physic.set_velocity(0, 0);
645 physic.enable_gravity(false);
646 timer.start(WAITTIME);
648 else if(mode == FISH_WAIT && !timer.check())
651 set_action("normal", "normal");
653 physic.set_velocity(0, JUMPV);
654 physic.enable_gravity(true);
657 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
658 if(dying == DYING_NOT)
659 collision_swept_object_map(&old_base, &base);
661 if(physic.get_velocity_y() < 0)
663 set_action("down", "down");
668 BadGuy::action_bouncingsnowball(double elapsed_time)
670 static const float JUMPV = 4.5;
674 // jump when on ground
675 if(dying == DYING_NOT && issolid(base.x, base.y+32))
677 physic.set_velocity_y(JUMPV);
678 physic.enable_gravity(true);
685 // check for right/left collisions
686 check_horizontal_bump();
688 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
689 if(dying == DYING_NOT)
690 collision_swept_object_map(&old_base, &base);
692 // Handle dying timer:
693 if (dying == DYING_SQUISHED && !timer.check())
698 BadGuy::action_flyingsnowball(double elapsed_time)
700 static const float FLYINGSPEED = 1;
701 static const int DIRCHANGETIME = 1000;
703 // go into flyup mode if none specified yet
704 if(dying == DYING_NOT && mode == NORMAL) {
706 physic.set_velocity_y(FLYINGSPEED);
707 timer.start(DIRCHANGETIME/2);
710 if(dying == DYING_NOT && !timer.check()) {
713 physic.set_velocity_y(-FLYINGSPEED);
714 } else if(mode == FLY_DOWN) {
716 physic.set_velocity_y(FLYINGSPEED);
718 timer.start(DIRCHANGETIME);
721 if(dying != DYING_NOT)
722 physic.enable_gravity(true);
724 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
725 if(dying == DYING_NOT || dying == DYING_SQUISHED)
726 collision_swept_object_map(&old_base, &base);
728 if(dying == DYING_NOT)
730 // set direction based on tux
731 if(Sector::current()->player->base.x > base.x)
737 // Handle dying timer:
738 if (dying == DYING_SQUISHED && !timer.check())
743 BadGuy::action_spiky(double elapsed_time)
745 if(frozen_timer.check())
747 set_action("iced-left", "iced-right");
751 if (dying == DYING_NOT)
752 check_horizontal_bump();
756 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
757 if (dying != DYING_FALLING)
758 collision_swept_object_map(&old_base,&base);
762 BadGuy::action_snowball(double elapsed_time)
764 if (dying == DYING_NOT)
765 check_horizontal_bump();
769 // jump when we're about to fall
770 if (physic.get_velocity_y() == 0 &&
771 !issolid(base.x+base.width/2, base.y + base.height)) {
772 physic.enable_gravity(true);
773 physic.set_velocity_y(2);
776 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
777 if (dying != DYING_FALLING)
778 collision_swept_object_map(&old_base,&base);
780 // Handle dying timer:
781 if (dying == DYING_SQUISHED && !timer.check())
786 BadGuy::action_wingling(double elapsed_time)
788 if (dying != DYING_NOT)
789 physic.enable_gravity(true);
792 Player& tux = *Sector::current()->player;
793 int dirsign = physic.get_velocity_x() < 0 ? -1 : 1;
795 if (fabsf(tux.base.x - base.x) < 150 && base.y < tux.base.y && tux.dying == DYING_NOT)
797 if (target.x < 0 && target.y < 0)
799 target.x = tux.base.x;
800 target.y = tux.base.y;
801 physic.set_velocity(dirsign * 1.5f, -2.25f);
804 else if (base.y >= target.y - 16)
805 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
808 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
811 // Handle dying timer:
812 if (dying == DYING_SQUISHED && !timer.check())
815 // TODO: Winglings should be removed after flying off the screen
819 BadGuy::action_walkingtree(double elapsed_time)
821 if (dying == DYING_NOT)
822 check_horizontal_bump();
826 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
827 if (dying != DYING_FALLING)
828 collision_swept_object_map(&old_base,&base);
830 // Handle dying timer:
831 if (dying == DYING_SQUISHED && !timer.check())
836 BadGuy::action(float elapsed_time)
838 float scroll_x = Sector::current()->camera->get_translation().x;
839 float scroll_y = Sector::current()->camera->get_translation().y;
841 // BadGuy fall below the ground
842 if (base.y > Sector::current()->solids->get_height() * 32) {
847 // Kill us if we landed on spikes
848 if (dying == DYING_NOT
849 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
850 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
851 || isspike(base.x, base.y + base.height)
852 || isspike(base.x + base.width, base.y + base.height)))
854 physic.set_velocity_y(3);
860 /* Activate badguys if they're just around the screen to avoid
861 * the effect of having badguys suddenly popping up from nowhere.
863 if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
864 start_position.x < scroll_x - base.width &&
865 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
866 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
868 else if (start_position.x > scroll_x + screen->w &&
869 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
870 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
871 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
873 else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
874 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
875 ((start_position.y > scroll_y + screen->h &&
876 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE) ||
877 (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
878 start_position.y < scroll_y)))
880 if(start_position.x < scroll_x - screen->w/2)
885 /* Special case for badguys on start of the level.
886 * If in the future, it's possible to set Tux start pos, this case
887 * should contemplate that. */
888 else if (start_position.x > 0 && start_position.x < screen->w &&
889 start_position.y > 0 && start_position.y < screen->h)
894 if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4
895 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4
896 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4
897 || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4)
900 if(dying != DYING_NOT)
911 action_mriceblock(elapsed_time);
915 action_jumpy(elapsed_time);
919 action_mrbomb(elapsed_time);
923 action_bomb(elapsed_time);
927 action_stalactite(elapsed_time);
931 action_flame(elapsed_time);
936 action_fish(elapsed_time);
939 case BAD_BOUNCINGSNOWBALL:
940 action_bouncingsnowball(elapsed_time);
943 case BAD_FLYINGSNOWBALL:
944 action_flyingsnowball(elapsed_time);
948 action_spiky(elapsed_time);
952 action_snowball(elapsed_time);
956 action_wingling(elapsed_time);
959 case BAD_WALKINGTREE:
960 action_walkingtree(elapsed_time);
969 BadGuy::draw(DrawingContext& context)
974 if((dir == LEFT && action_left == "hide") ||
975 (dir == RIGHT && action_right == "hide"))
979 specs->sprite->set_action(action_left);
980 else // if(dir == RIGHT)
981 specs->sprite->set_action(action_right);
983 if(dying == DYING_FALLING && physic.get_velocity_y() < 0)
984 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_FOREGROUNDTILES+1, VERTICAL_FLIP);
986 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
989 context.draw_filled_rect(Vector(base.x, base.y),
990 Vector(base.width, base.height), Color(75,0,75, 150), LAYER_OBJECTS+1);
994 BadGuy::set_action(std::string left, std::string right)
1000 action_right = right;
1010 // FIXME: Using the image size for the physics and collision is
1011 // a bad idea, since images should always overlap their physical
1014 if(base.width == 0 && base.height == 0) {
1015 base.width = left->get_width();
1016 base.height = left->get_height();
1017 } else if(base.width != left->get_width() || base.height != left->get_height()) {
1018 base.x -= (left->get_width() - base.width) / 2;
1019 base.y -= left->get_height() - base.height;
1020 base.width = left->get_width();
1021 base.height = left->get_height();
1025 base.width = base.height = 0;
1029 animation_offset = 0;
1031 sprite_right = right;
1038 // these can't be bumped
1039 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
1040 || kind == BAD_FLAMEFISH || kind == BAD_FLYINGSNOWBALL)
1043 physic.set_velocity_y(3);
1048 BadGuy::squish_me(Player* player)
1050 player->bounce(this);
1052 Sector::current()->add_score(Vector(base.x, base.y),
1053 25 * player_status.score_multiplier);
1055 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1056 player_status.score_multiplier++;
1058 dying = DYING_SQUISHED;
1060 physic.set_velocity(0, 0);
1064 BadGuy::squish(Player* player)
1066 static const int MAX_ICEBLOCK_SQUICHES = 10;
1068 if(kind == BAD_MRBOMB) {
1069 // mrbomb transforms into a bomb now
1072 player->bounce(this);
1073 Sector::current()->add_score(Vector(base.x, base.y),
1074 25 * player_status.score_multiplier);
1075 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1077 player_status.score_multiplier++;
1080 } else if (kind == BAD_MRICEBLOCK) {
1081 if (mode == NORMAL || mode == KICK)
1084 SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(), Sector::current()->player->get_pos());
1086 set_action("flat-left", "flat-right");
1087 physic.set_velocity_x(0);
1090 } else if (mode == FLAT) {
1092 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1094 if (player->base.x < base.x + (base.width/2)) {
1095 physic.set_velocity_x(5);
1098 physic.set_velocity_x(-5);
1103 player->kick_timer.start(KICKING_TIME);
1104 set_action("flat-left", "flat-right");
1107 player->bounce(this);
1109 player_status.score_multiplier++;
1111 // check for maximum number of squishes
1113 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
1119 } else if(kind == BAD_FISH || kind == BAD_FLAMEFISH) {
1120 // fish can only be killed when falling down
1121 if(physic.get_velocity_y() >= 0)
1124 player->bounce(this);
1126 Sector::current()->add_score(Vector(base.x, base.y),
1127 25 * player_status.score_multiplier);
1129 player_status.score_multiplier++;
1131 // simply remove the fish...
1134 } else if(kind == BAD_BOUNCINGSNOWBALL) {
1136 set_action("squished", "squished");
1138 } else if(kind == BAD_FLYINGSNOWBALL) {
1140 set_action("squished-left", "squished-right");
1142 } else if(kind == BAD_SNOWBALL) {
1144 set_action("squished-left", "squished-right");
1146 } else if(kind == BAD_WINGLING) {
1148 set_action("left", "right");
1149 } else if(kind == BAD_WALKINGTREE) {
1150 if (mode == BGM_BIG)
1152 set_action("left-small", "left-small");
1153 physic.set_velocity_x(physic.get_velocity_x() * 2.0f);
1155 /* Move to the player's direction */
1156 if(dir != Sector::current()->player->dir)
1157 physic.set_velocity_x(-physic.get_velocity_x());
1158 dir = Sector::current()->player->dir;
1160 // XXX magic number: 66 is BGM_BIG height
1162 player->bounce(this);
1163 base.y += 66 - base.height;
1165 Sector::current()->add_score(Vector(base.x, base.y),
1166 25 * player_status.score_multiplier);
1167 player_status.score_multiplier++;
1177 BadGuy::kill_me(int score)
1179 if(kind == BAD_BOMB)
1183 global_stats.add_points(BADGUYS_KILLED_STAT, 1);
1185 dying = DYING_FALLING;
1186 if(kind == BAD_MRICEBLOCK) {
1187 set_action("falling-left", "falling-right");
1190 Player& tux = *Sector::current()->player;
1191 tux.holding_something = false;
1195 physic.enable_gravity(true);
1197 /* Gain some points: */
1199 Sector::current()->add_score(Vector(base.x, base.y),
1200 score * player_status.score_multiplier);
1202 /* Play death sound: */
1203 SoundManager::get()->play_sound(IDToSound(SND_FALL), this, Sector::current()->player->get_pos());
1207 BadGuy::explode(bool right_way)
1209 BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB, true);
1212 badguy->timer.start(0);
1213 badguy->mode = BOMB_TICKING;
1221 BadGuy::collision(const MovingObject&, int)
1227 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1232 BadGuy* pbad_c = NULL;
1233 Bullet* pbullet_c = NULL;
1235 if(type == COLLISION_BUMP) {
1240 if(type == COLLISION_SQUISH) {
1241 Player* player = static_cast<Player*>(p_c_object);
1246 /* COLLISION_NORMAL */
1250 pbullet_c = (Bullet*) p_c_object;
1252 if(pbullet_c->kind == FIRE_BULLET)
1254 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME
1255 && kind != BAD_FLAMEFISH)
1258 else if(pbullet_c->kind == ICE_BULLET)
1260 if(kind == BAD_FLAME || kind == BAD_FLAMEFISH)
1263 frozen_timer.start(FROZEN_TIME);
1268 pbad_c = (BadGuy*) p_c_object;
1271 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1272 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1273 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1275 pbad_c->kill_me(25);
1278 // a held mriceblock kills the enemy too but falls to ground then
1279 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1281 pbad_c->kill_me(25);
1285 /* Kill badguys that run into exploding bomb */
1286 else if (kind == BAD_BOMB && dying == DYING_NOT)
1288 if (pbad_c->kind == BAD_MRBOMB)
1290 // mrbomb transforms into a bomb now
1291 pbad_c->explode(true);
1296 pbad_c->kill_me(50);
1300 /* Kill any badguys that get hit by stalactite */
1301 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1303 if (pbad_c->kind == BAD_MRBOMB)
1305 // mrbomb transforms into a bomb now
1306 pbad_c->explode(false);
1310 pbad_c->kill_me(50);
1313 /* When enemies run into eachother, make them change directions */
1316 // Wingling doesn't interact with other badguys
1317 if (pbad_c->kind == BAD_WINGLING || kind == BAD_WINGLING)
1320 // Jumpy, fish, flame, stalactites, wingling are exceptions
1321 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1322 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH
1323 || pbad_c->kind == BAD_FLAMEFISH)
1326 // Bounce off of other badguy if we land on top of him
1327 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1329 if (pbad_c->dir == LEFT)
1332 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1334 else if (pbad_c->dir == RIGHT)
1337 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1342 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1345 if (pbad_c->kind != BAD_FLAME)
1350 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1352 // Put bad guys a part (or they get jammed)
1353 // only needed to do to one of them
1354 if (physic.get_velocity_x() != 0)
1355 base.x = pbad_c->base.x + pbad_c->base.width + 1;
1357 else if (dir == RIGHT)
1360 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1369 Player* player = static_cast<Player*>(p_c_object);
1370 /* Get kicked if were flat */
1371 if (mode == FLAT && !dying)
1373 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1375 // Hit from left side
1376 if (player->base.x < base.x) {
1377 physic.set_velocity_x(5);
1380 // Hit from right side
1382 physic.set_velocity_x(-5);
1387 player->kick_timer.start(KICKING_TIME);
1388 set_action("flat-left", "flat-right");