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);
216 dir = activation_dir;
217 float dirsign = activation_dir == LEFT ? -1 : 1;
219 set_action("left", "right");
220 if(kind == BAD_MRBOMB) {
221 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
222 } else if (kind == BAD_MRICEBLOCK) {
223 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
224 } else if(kind == BAD_JUMPY) {
225 set_action("left-up", "right-up");
226 } else if(kind == BAD_BOMB) {
227 set_action("ticking-left", "ticking-right");
228 // hack so that the bomb doesn't hurt until it expldes...
229 dying = DYING_SQUISHED;
230 } else if(kind == BAD_FLAME) {
232 physic.enable_gravity(false);
233 set_action("normal", "normal");
234 } else if(kind == BAD_BOUNCINGSNOWBALL) {
235 physic.set_velocity(dirsign * 1.3, 0);
236 } else if(kind == BAD_STALACTITE) {
237 physic.enable_gravity(false);
238 set_action("normal", "normal");
239 } else if(kind == BAD_FISH) {
240 set_action("normal", "normal");
241 physic.enable_gravity(true);
242 } else if(kind == BAD_FLAMEFISH) {
243 set_action("normal", "normal");
244 physic.enable_gravity(true);
245 } else if(kind == BAD_FLYINGSNOWBALL) {
246 physic.enable_gravity(false);
247 } else if(kind == BAD_SPIKY) {
248 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
249 } else if(kind == BAD_SNOWBALL) {
250 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
251 } else if(kind == BAD_WINGLING) {
252 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
253 physic.enable_gravity(false);
254 set_action("left", "left");
255 } else if (kind == BAD_WALKINGTREE) {
256 // TODO: why isn't the height/width being set properly in set_action?
257 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
259 set_action("left", "left");
268 // Set action as the "default" one.
269 specs->sprite->set_action("left");
271 specs->sprite->set_action("left-up");
272 else if(kind == BAD_BOMB)
273 specs->sprite->set_action("ticking-left");
274 else if(kind == BAD_FLAME)
275 specs->sprite->set_action("normal");
276 else if(kind == BAD_STALACTITE)
277 specs->sprite->set_action("normal");
278 else if(kind == BAD_FISH)
279 specs->sprite->set_action("normal");
280 else if(kind == BAD_FLAMEFISH)
281 specs->sprite->set_action("normal");
283 return specs->sprite->get_frame(0);
287 BadGuy::action_mriceblock(double elapsed_time)
289 Player& tux = *Sector::current()->player;
294 /* Move left/right: */
298 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
299 if (dying != DYING_FALLING)
300 collision_swept_object_map(&old_base,&base);
302 else if (mode == HELD)
303 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
304 /* If we're holding the iceblock */
306 if(tux.size == SMALL)
309 base.x = tux.base.x + 24;
311 base.x = tux.base.x - 12;
312 base.y = tux.base.y + tux.base.height/1.5 - base.height;
317 base.x = tux.base.x + 24;
319 base.x = tux.base.x - 4;
320 base.y = tux.base.y + tux.base.height/1.5 - base.height;
323 if(collision_object_map(base))
326 base.y = tux.base.y + tux.base.height/1.5 - base.height;
329 if(tux.input.fire != DOWN) /* SHOOT! */
332 base.x = tux.base.x - base.width;
334 base.x = tux.base.x + tux.base.width;
338 tux.kick_timer.start(KICKING_TIME);
339 set_action("flat-left", "flat-right");
340 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
341 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
348 check_horizontal_bump();
349 if(mode == KICK && changed != dir)
351 SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(), Sector::current()->player->get_pos());
355 /* Handle mode timer: */
361 set_action("left", "right");
362 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
368 BadGuy::check_horizontal_bump(bool checkcliff)
370 float halfheight = base.height / 2;
371 if (dir == LEFT && issolid( base.x, base.y + halfheight))
373 if (kind == BAD_MRICEBLOCK && mode == KICK)
375 Sector::current()->trybreakbrick(Vector(base.x, base.y + halfheight), false);
376 Sector::current()->tryemptybox(Vector(base.x, base.y + halfheight), dir);
380 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
383 if (dir == RIGHT && issolid( base.x + base.width, base.y + halfheight))
385 if (kind == BAD_MRICEBLOCK && mode == KICK)
387 Sector::current()->trybreakbrick(
388 Vector(base.x + base.width, base.y + halfheight), false);
389 Sector::current()->tryemptybox(
390 Vector(base.x + base.width, base.y + halfheight), dir);
394 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
398 // don't check for cliffs when we're falling
401 if(!issolid(base.x + base.width/2, base.y + base.height))
404 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
407 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
410 if(dir == RIGHT && !issolid(base.x + base.width,
411 (int) base.y + base.height + halfheight))
414 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
422 /* Fall if we get off the ground: */
423 if (dying != DYING_FALLING)
425 if (!issolid(base.x+base.width/2, base.y + base.height))
427 // not solid below us? enable gravity
428 physic.enable_gravity(true);
433 if (physic.get_velocity_y() < 0)
435 base.y = int((base.y + base.height)/32) * 32 - base.height;
436 physic.set_velocity_y(0);
438 // no gravity anymore please
439 physic.enable_gravity(false);
441 if (stay_on_platform && mode == NORMAL)
443 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
444 base.y + base.height))
449 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
454 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
462 physic.enable_gravity(true);
467 BadGuy::action_jumpy(double elapsed_time)
469 if(frozen_timer.check())
471 set_action("left-iced", "right-iced");
475 const float vy = physic.get_velocity_y();
477 // XXX: These tests *should* use location from ground, not velocity
478 if (fabsf(vy) > 5.6f)
479 set_action("left-down", "right-down");
480 else if (fabsf(vy) > 5.3f)
481 set_action("left-middle", "right-middle");
483 set_action("left-up", "right-up");
485 Player& tux = *Sector::current()->player;
487 static const float JUMPV = 6;
490 // jump when on ground
491 if(dying == DYING_NOT && issolid(base.x, base.y+32))
493 physic.set_velocity_y(JUMPV);
494 physic.enable_gravity(true);
498 else if(mode == JUMPY_JUMP)
503 // set direction based on tux
504 if(dying == DYING_NOT)
506 if(tux.base.x > base.x)
513 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
514 if(dying == DYING_NOT)
515 collision_swept_object_map(&old_base, &base);
519 BadGuy::action_mrbomb(double elapsed_time)
521 if(frozen_timer.check())
523 set_action("iced-left", "iced-right");
527 if (dying == DYING_NOT)
528 check_horizontal_bump(true);
532 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
533 if (dying != DYING_FALLING)
534 collision_swept_object_map(&old_base,&base);
538 BadGuy::action_bomb(double elapsed_time)
540 static const int TICKINGTIME = 1000;
541 static const int EXPLODETIME = 1000;
547 timer.start(TICKINGTIME);
548 } else if(!timer.check()) {
549 if(mode == BOMB_TICKING) {
551 set_action("explosion", "explosion");
552 dying = DYING_NOT; // now the bomb hurts
553 timer.start(EXPLODETIME);
555 SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), this, Sector::current()->player->get_pos());
556 } else if(mode == BOMB_EXPLODE) {
563 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
564 collision_swept_object_map(&old_base,&base);
568 BadGuy::action_stalactite(double elapsed_time)
570 Player& tux = *Sector::current()->player;
572 static const int SHAKETIME = 800;
573 static const int RANGE = 40;
576 // start shaking when tux is below the stalactite and at least 40 pixels
578 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
579 && tux.base.y + tux.base.height > base.y
580 && tux.dying == DYING_NOT) {
581 timer.start(SHAKETIME);
582 mode = STALACTITE_SHAKING;
584 } if(mode == STALACTITE_SHAKING) {
585 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
587 mode = STALACTITE_FALL;
589 } else if(mode == STALACTITE_FALL) {
591 /* Destroy if we collides with land */
592 if(issolid(base.x+base.width/2, base.y+base.height))
595 dying = DYING_SQUISHED;
597 set_action("broken", "broken");
599 } else if(mode == FLAT) {
604 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
606 if(dying == DYING_SQUISHED && !timer.check())
611 BadGuy::action_flame(double elapsed_time)
613 static const float radius = 100;
614 static const float speed = 0.02;
615 base.x = old_base.x + cos(angle) * radius;
616 base.y = old_base.y + sin(angle) * radius;
618 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
622 BadGuy::action_fish(double elapsed_time)
624 if(frozen_timer.check())
626 if(physic.get_velocity_y() < 0)
627 set_action("iced-down", "iced-down");
629 set_action("iced", "iced");
634 static const float JUMPV = 6;
635 static const int WAITTIME = 1000;
637 // go in wait mode when back in water
638 if(dying == DYING_NOT
639 && gettile(base.x, base.y + base.height)
640 && gettile(base.x, base.y + base.height)->attributes & Tile::WATER
641 && physic.get_velocity_y() <= 0 && mode == NORMAL)
644 set_action("hide", "hide");
645 physic.set_velocity(0, 0);
646 physic.enable_gravity(false);
647 timer.start(WAITTIME);
649 else if(mode == FISH_WAIT && !timer.check())
652 set_action("normal", "normal");
654 physic.set_velocity(0, JUMPV);
655 physic.enable_gravity(true);
658 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
659 if(dying == DYING_NOT)
660 collision_swept_object_map(&old_base, &base);
662 if(physic.get_velocity_y() < 0)
664 set_action("down", "down");
669 BadGuy::action_bouncingsnowball(double elapsed_time)
671 static const float JUMPV = 4.5;
675 // jump when on ground
676 if(dying == DYING_NOT && issolid(base.x, base.y+32))
678 physic.set_velocity_y(JUMPV);
679 physic.enable_gravity(true);
686 // check for right/left collisions
687 check_horizontal_bump();
689 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
690 if(dying == DYING_NOT)
691 collision_swept_object_map(&old_base, &base);
693 // Handle dying timer:
694 if (dying == DYING_SQUISHED && !timer.check())
699 BadGuy::action_flyingsnowball(double elapsed_time)
701 static const float FLYINGSPEED = 1;
702 static const int DIRCHANGETIME = 1000;
704 // go into flyup mode if none specified yet
705 if(dying == DYING_NOT && mode == NORMAL) {
707 physic.set_velocity_y(FLYINGSPEED);
708 timer.start(DIRCHANGETIME/2);
711 if(dying == DYING_NOT && !timer.check()) {
714 physic.set_velocity_y(-FLYINGSPEED);
715 } else if(mode == FLY_DOWN) {
717 physic.set_velocity_y(FLYINGSPEED);
719 timer.start(DIRCHANGETIME);
722 if(dying != DYING_NOT)
723 physic.enable_gravity(true);
725 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
726 if(dying == DYING_NOT || dying == DYING_SQUISHED)
727 collision_swept_object_map(&old_base, &base);
729 if(dying == DYING_NOT)
731 // set direction based on tux
732 if(Sector::current()->player->base.x > base.x)
738 // Handle dying timer:
739 if (dying == DYING_SQUISHED && !timer.check())
744 BadGuy::action_spiky(double elapsed_time)
746 if(frozen_timer.check())
748 set_action("iced-left", "iced-right");
752 if (dying == DYING_NOT)
753 check_horizontal_bump();
757 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
758 if (dying != DYING_FALLING)
759 collision_swept_object_map(&old_base,&base);
763 BadGuy::action_snowball(double elapsed_time)
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);
777 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
778 if (dying != DYING_FALLING)
779 collision_swept_object_map(&old_base,&base);
781 // Handle dying timer:
782 if (dying == DYING_SQUISHED && !timer.check())
787 BadGuy::action_wingling(double elapsed_time)
789 if (dying != DYING_NOT)
790 physic.enable_gravity(true);
793 Player& tux = *Sector::current()->player;
794 int dirsign = physic.get_velocity_x() < 0 ? -1 : 1;
796 if (fabsf(tux.base.x - base.x) < 150 && base.y < tux.base.y && tux.dying == DYING_NOT)
798 if (target.x < 0 && target.y < 0)
800 target.x = tux.base.x;
801 target.y = tux.base.y;
802 physic.set_velocity(dirsign * 1.5f, -2.25f);
805 else if (base.y >= target.y - 16)
806 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
809 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
812 // Handle dying timer:
813 if (dying == DYING_SQUISHED && !timer.check())
816 // TODO: Winglings should be removed after flying off the screen
820 BadGuy::action_walkingtree(double elapsed_time)
822 if (dying == DYING_NOT)
823 check_horizontal_bump();
827 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
828 if (dying != DYING_FALLING)
829 collision_swept_object_map(&old_base,&base);
831 // Handle dying timer:
832 if (dying == DYING_SQUISHED && !timer.check())
837 BadGuy::action(float elapsed_time)
839 float scroll_x = Sector::current()->camera->get_translation().x;
840 float scroll_y = Sector::current()->camera->get_translation().y;
842 // BadGuy fall below the ground
843 if (base.y > Sector::current()->solids->get_height() * 32) {
848 // Kill us if we landed on spikes
849 if (dying == DYING_NOT
850 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
851 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
852 || isspike(base.x, base.y + base.height)
853 || isspike(base.x + base.width, base.y + base.height)))
855 physic.set_velocity_y(3);
861 /* Activate badguys if they're just around the screen to avoid
862 * the effect of having badguys suddenly popping up from nowhere.
864 if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
865 start_position.x < scroll_x - base.width &&
866 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
867 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
869 else if (start_position.x > scroll_x + screen->w &&
870 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
871 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
872 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
874 else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
875 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
876 ((start_position.y > scroll_y + screen->h &&
877 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE) ||
878 (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
879 start_position.y < scroll_y)))
881 if(start_position.x < scroll_x - screen->w/2)
886 /* Special case for badguys on start of the level.
887 * If in the future, it's possible to set Tux start pos, this case
888 * should contemplate that. */
889 else if (start_position.x > 0 && start_position.x < screen->w &&
890 start_position.y > 0 && start_position.y < screen->h)
895 if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4
896 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4
897 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4
898 || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4)
901 if(dying != DYING_NOT)
912 action_mriceblock(elapsed_time);
916 action_jumpy(elapsed_time);
920 action_mrbomb(elapsed_time);
924 action_bomb(elapsed_time);
928 action_stalactite(elapsed_time);
932 action_flame(elapsed_time);
937 action_fish(elapsed_time);
940 case BAD_BOUNCINGSNOWBALL:
941 action_bouncingsnowball(elapsed_time);
944 case BAD_FLYINGSNOWBALL:
945 action_flyingsnowball(elapsed_time);
949 action_spiky(elapsed_time);
953 action_snowball(elapsed_time);
957 action_wingling(elapsed_time);
960 case BAD_WALKINGTREE:
961 action_walkingtree(elapsed_time);
970 BadGuy::draw(DrawingContext& context)
975 if((dir == LEFT && action_left == "hide") ||
976 (dir == RIGHT && action_right == "hide"))
980 specs->sprite->set_action(action_left);
981 else // if(dir == RIGHT)
982 specs->sprite->set_action(action_right);
984 if(dying == DYING_FALLING && physic.get_velocity_y() < 0)
985 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_FOREGROUNDTILES+1, VERTICAL_FLIP);
987 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
990 context.draw_filled_rect(Vector(base.x, base.y),
991 Vector(base.width, base.height), Color(75,0,75, 150), LAYER_OBJECTS+1);
995 BadGuy::set_action(std::string left, std::string right)
1001 action_right = right;
1011 // FIXME: Using the image size for the physics and collision is
1012 // a bad idea, since images should always overlap their physical
1015 if(base.width == 0 && base.height == 0) {
1016 base.width = left->get_width();
1017 base.height = left->get_height();
1018 } else if(base.width != left->get_width() || base.height != left->get_height()) {
1019 base.x -= (left->get_width() - base.width) / 2;
1020 base.y -= left->get_height() - base.height;
1021 base.width = left->get_width();
1022 base.height = left->get_height();
1026 base.width = base.height = 0;
1030 animation_offset = 0;
1032 sprite_right = right;
1039 // these can't be bumped
1040 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
1041 || kind == BAD_FLAMEFISH || kind == BAD_FLYINGSNOWBALL)
1044 physic.set_velocity_y(3);
1049 BadGuy::squish_me(Player* player)
1051 player->bounce(this);
1053 Sector::current()->add_score(Vector(base.x, base.y),
1054 25 * player_status.score_multiplier);
1056 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1057 player_status.score_multiplier++;
1059 dying = DYING_SQUISHED;
1061 physic.set_velocity(0, 0);
1065 BadGuy::squish(Player* player)
1067 static const int MAX_ICEBLOCK_SQUICHES = 10;
1069 if(kind == BAD_MRBOMB) {
1070 // mrbomb transforms into a bomb now
1073 player->bounce(this);
1074 Sector::current()->add_score(Vector(base.x, base.y),
1075 25 * player_status.score_multiplier);
1076 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1078 player_status.score_multiplier++;
1081 } else if (kind == BAD_MRICEBLOCK) {
1082 if (mode == NORMAL || mode == KICK)
1085 SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(), Sector::current()->player->get_pos());
1087 set_action("flat-left", "flat-right");
1088 physic.set_velocity_x(0);
1091 } else if (mode == FLAT) {
1093 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1095 if (player->base.x < base.x + (base.width/2)) {
1096 physic.set_velocity_x(5);
1099 physic.set_velocity_x(-5);
1104 player->kick_timer.start(KICKING_TIME);
1105 set_action("flat-left", "flat-right");
1108 player->bounce(this);
1110 player_status.score_multiplier++;
1112 // check for maximum number of squishes
1114 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
1120 } else if(kind == BAD_FISH || kind == BAD_FLAMEFISH) {
1121 // fish can only be killed when falling down
1122 if(physic.get_velocity_y() >= 0)
1125 player->bounce(this);
1127 Sector::current()->add_score(Vector(base.x, base.y),
1128 25 * player_status.score_multiplier);
1130 player_status.score_multiplier++;
1132 // simply remove the fish...
1135 } else if(kind == BAD_BOUNCINGSNOWBALL) {
1137 set_action("squished", "squished");
1139 } else if(kind == BAD_FLYINGSNOWBALL) {
1141 set_action("squished-left", "squished-right");
1143 } else if(kind == BAD_SNOWBALL) {
1145 set_action("squished-left", "squished-right");
1147 } else if(kind == BAD_WINGLING) {
1149 set_action("left", "right");
1150 } else if(kind == BAD_WALKINGTREE) {
1151 if (mode == BGM_BIG)
1153 set_action("left-small", "left-small");
1154 physic.set_velocity_x(physic.get_velocity_x() * 2.0f);
1156 /* Move to the player's direction */
1157 if(dir != Sector::current()->player->dir)
1158 physic.set_velocity_x(-physic.get_velocity_x());
1159 dir = Sector::current()->player->dir;
1161 // XXX magic number: 66 is BGM_BIG height
1163 player->bounce(this);
1164 base.y += 66 - base.height;
1166 Sector::current()->add_score(Vector(base.x, base.y),
1167 25 * player_status.score_multiplier);
1168 player_status.score_multiplier++;
1178 BadGuy::kill_me(int score)
1180 if(kind == BAD_BOMB)
1184 global_stats.add_points(BADGUYS_KILLED_STAT, 1);
1186 dying = DYING_FALLING;
1187 if(kind == BAD_MRICEBLOCK) {
1188 set_action("falling-left", "falling-right");
1191 Player& tux = *Sector::current()->player;
1192 tux.holding_something = false;
1196 physic.enable_gravity(true);
1198 /* Gain some points: */
1200 Sector::current()->add_score(Vector(base.x, base.y),
1201 score * player_status.score_multiplier);
1203 /* Play death sound: */
1204 SoundManager::get()->play_sound(IDToSound(SND_FALL), this, Sector::current()->player->get_pos());
1208 BadGuy::explode(bool right_way)
1210 BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB, true);
1213 badguy->timer.start(0);
1214 badguy->mode = BOMB_TICKING;
1222 BadGuy::collision(const MovingObject&, int)
1228 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1230 BadGuy* pbad_c = NULL;
1231 Bullet* pbullet_c = NULL;
1233 if(type == COLLISION_BUMP) {
1238 if(type == COLLISION_SQUISH) {
1239 Player* player = static_cast<Player*>(p_c_object);
1244 /* COLLISION_NORMAL */
1248 pbullet_c = (Bullet*) p_c_object;
1250 if(pbullet_c->kind == FIRE_BULLET)
1252 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME
1253 && kind != BAD_FLAMEFISH)
1256 else if(pbullet_c->kind == ICE_BULLET)
1258 if(kind == BAD_FLAME || kind == BAD_FLAMEFISH)
1261 frozen_timer.start(FROZEN_TIME);
1266 pbad_c = (BadGuy*) p_c_object;
1269 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1270 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1271 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1273 pbad_c->kill_me(25);
1276 // a held mriceblock kills the enemy too but falls to ground then
1277 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1279 pbad_c->kill_me(25);
1283 /* Kill badguys that run into exploding bomb */
1284 else if (kind == BAD_BOMB && dying == DYING_NOT)
1286 if (pbad_c->kind == BAD_MRBOMB)
1288 // mrbomb transforms into a bomb now
1289 pbad_c->explode(true);
1294 pbad_c->kill_me(50);
1298 /* Kill any badguys that get hit by stalactite */
1299 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1301 if (pbad_c->kind == BAD_MRBOMB)
1303 // mrbomb transforms into a bomb now
1304 pbad_c->explode(false);
1308 pbad_c->kill_me(50);
1311 /* When enemies run into eachother, make them change directions */
1314 // Wingling doesn't interact with other badguys
1315 if (pbad_c->kind == BAD_WINGLING || kind == BAD_WINGLING)
1318 // Jumpy, fish, flame, stalactites, wingling are exceptions
1319 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1320 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH
1321 || pbad_c->kind == BAD_FLAMEFISH)
1324 // Bounce off of other badguy if we land on top of him
1325 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1327 if (pbad_c->dir == LEFT)
1330 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1332 else if (pbad_c->dir == RIGHT)
1335 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1340 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1343 if (pbad_c->kind != BAD_FLAME)
1348 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1350 // Put bad guys a part (or they get jammed)
1351 // only needed to do to one of them
1352 if (physic.get_velocity_x() != 0)
1353 base.x = pbad_c->base.x + pbad_c->base.width + 1;
1355 else if (dir == RIGHT)
1358 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1367 Player* player = static_cast<Player*>(p_c_object);
1368 /* Get kicked if were flat */
1369 if (mode == FLAT && !dying)
1371 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1373 // Hit from left side
1374 if (player->base.x < base.x) {
1375 physic.set_velocity_x(5);
1378 // Hit from right side
1380 physic.set_velocity_x(-5);
1385 player->kick_timer.start(KICKING_TIME);
1386 set_action("flat-left", "flat-right");