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);
213 dir = activation_dir;
214 float dirsign = activation_dir == LEFT ? -1 : 1;
216 set_action("left", "right");
217 if(kind == BAD_MRBOMB) {
218 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
219 } else if (kind == BAD_MRICEBLOCK) {
220 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
221 } else if(kind == BAD_JUMPY) {
222 set_action("left-up", "right-up");
223 } else if(kind == BAD_BOMB) {
224 set_action("ticking-left", "ticking-right");
225 // hack so that the bomb doesn't hurt until it expldes...
226 dying = DYING_SQUISHED;
227 } else if(kind == BAD_FLAME) {
229 physic.enable_gravity(false);
230 set_action("normal", "normal");
231 } else if(kind == BAD_BOUNCINGSNOWBALL) {
232 physic.set_velocity(dirsign * 1.3, 0);
233 } else if(kind == BAD_STALACTITE) {
234 physic.enable_gravity(false);
235 set_action("normal", "normal");
236 } else if(kind == BAD_FISH) {
237 set_action("normal", "normal");
238 physic.enable_gravity(true);
239 } else if(kind == BAD_FLAMEFISH) {
240 set_action("normal", "normal");
241 physic.enable_gravity(true);
242 } else if(kind == BAD_FLYINGSNOWBALL) {
243 physic.enable_gravity(false);
244 } else if(kind == BAD_SPIKY) {
245 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
246 } else if(kind == BAD_SNOWBALL) {
247 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
248 } else if(kind == BAD_WINGLING) {
249 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
250 physic.enable_gravity(false);
251 set_action("left", "left");
252 } else if (kind == BAD_WALKINGTREE) {
253 // TODO: why isn't the height/width being set properly in set_action?
254 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
256 set_action("left", "left");
261 base.x = start_position.x;
262 base.y = start_position.y;
270 // Set action as the "default" one.
271 specs->sprite->set_action("left");
273 specs->sprite->set_action("left-up");
274 else if(kind == BAD_BOMB)
275 specs->sprite->set_action("ticking-left");
276 else if(kind == BAD_FLAME)
277 specs->sprite->set_action("normal");
278 else if(kind == BAD_STALACTITE)
279 specs->sprite->set_action("normal");
280 else if(kind == BAD_FISH)
281 specs->sprite->set_action("normal");
282 else if(kind == BAD_FLAMEFISH)
283 specs->sprite->set_action("normal");
285 return specs->sprite->get_frame(0);
289 BadGuy::action_mriceblock(double elapsed_time)
291 Player& tux = *Sector::current()->player;
296 /* Move left/right: */
300 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
301 if (dying != DYING_FALLING)
302 collision_swept_object_map(&old_base,&base);
304 else if (mode == HELD)
305 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
306 /* If we're holding the iceblock */
308 if(tux.size == SMALL)
311 base.x = tux.base.x + 24;
313 base.x = tux.base.x - 12;
314 base.y = tux.base.y + tux.base.height/1.5 - base.height;
319 base.x = tux.base.x + 24;
321 base.x = tux.base.x - 4;
322 base.y = tux.base.y + tux.base.height/1.5 - base.height;
325 if(collision_object_map(base))
328 base.y = tux.base.y + tux.base.height/1.5 - base.height;
331 if(tux.input.fire != DOWN) /* SHOOT! */
334 base.x = tux.base.x - base.width;
336 base.x = tux.base.x + tux.base.width;
340 tux.kick_timer.start(KICKING_TIME);
341 set_action("flat-left", "flat-right");
342 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
343 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
350 check_horizontal_bump();
351 if(mode == KICK && changed != dir)
353 SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(), Sector::current()->player->get_pos());
357 /* Handle mode timer: */
363 set_action("left", "right");
364 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
370 BadGuy::check_horizontal_bump(bool checkcliff)
372 float halfheight = base.height / 2;
373 if (dir == LEFT && issolid( base.x, base.y + halfheight))
375 if (kind == BAD_MRICEBLOCK && mode == KICK)
377 Sector::current()->trybreakbrick(Vector(base.x, base.y + halfheight), false);
378 Sector::current()->tryemptybox(Vector(base.x, base.y + halfheight), dir);
382 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
385 if (dir == RIGHT && issolid( base.x + base.width, base.y + halfheight))
387 if (kind == BAD_MRICEBLOCK && mode == KICK)
389 Sector::current()->trybreakbrick(
390 Vector(base.x + base.width, base.y + halfheight), false);
391 Sector::current()->tryemptybox(
392 Vector(base.x + base.width, base.y + halfheight), dir);
396 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
400 // don't check for cliffs when we're falling
403 if(!issolid(base.x + base.width/2, base.y + base.height))
406 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
409 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
412 if(dir == RIGHT && !issolid(base.x + base.width,
413 (int) base.y + base.height + halfheight))
416 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
424 /* Fall if we get off the ground: */
425 if (dying != DYING_FALLING)
427 if (!issolid(base.x+base.width/2, base.y + base.height))
429 // not solid below us? enable gravity
430 physic.enable_gravity(true);
435 if (physic.get_velocity_y() < 0)
437 base.y = int((base.y + base.height)/32) * 32 - base.height;
438 physic.set_velocity_y(0);
440 // no gravity anymore please
441 physic.enable_gravity(false);
443 if (stay_on_platform && mode == NORMAL)
445 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
446 base.y + base.height))
451 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
456 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
464 physic.enable_gravity(true);
469 BadGuy::action_jumpy(double elapsed_time)
471 if(frozen_timer.check())
473 set_action("left-iced", "right-iced");
477 const float vy = physic.get_velocity_y();
479 // XXX: These tests *should* use location from ground, not velocity
480 if (fabsf(vy) > 5.6f)
481 set_action("left-down", "right-down");
482 else if (fabsf(vy) > 5.3f)
483 set_action("left-middle", "right-middle");
485 set_action("left-up", "right-up");
487 Player& tux = *Sector::current()->player;
489 static const float JUMPV = 6;
492 // jump when on ground
493 if(dying == DYING_NOT && issolid(base.x, base.y+32))
495 physic.set_velocity_y(JUMPV);
496 physic.enable_gravity(true);
500 else if(mode == JUMPY_JUMP)
505 // set direction based on tux
506 if(dying == DYING_NOT)
508 if(tux.base.x > base.x)
515 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
516 if(dying == DYING_NOT)
517 collision_swept_object_map(&old_base, &base);
521 BadGuy::action_mrbomb(double elapsed_time)
523 if(frozen_timer.check())
525 set_action("iced-left", "iced-right");
529 if (dying == DYING_NOT)
530 check_horizontal_bump(true);
534 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
535 if (dying != DYING_FALLING)
536 collision_swept_object_map(&old_base,&base);
540 BadGuy::action_bomb(double elapsed_time)
542 static const int TICKINGTIME = 1000;
543 static const int EXPLODETIME = 1000;
549 timer.start(TICKINGTIME);
550 } else if(!timer.check()) {
551 if(mode == BOMB_TICKING) {
553 set_action("explosion", "explosion");
554 dying = DYING_NOT; // now the bomb hurts
555 timer.start(EXPLODETIME);
557 SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), this, Sector::current()->player->get_pos());
558 } else if(mode == BOMB_EXPLODE) {
565 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
566 collision_swept_object_map(&old_base,&base);
570 BadGuy::action_stalactite(double elapsed_time)
572 Player& tux = *Sector::current()->player;
574 static const int SHAKETIME = 800;
575 static const int RANGE = 40;
578 // start shaking when tux is below the stalactite and at least 40 pixels
580 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
581 && tux.base.y + tux.base.height > base.y
582 && tux.dying == DYING_NOT) {
583 timer.start(SHAKETIME);
584 mode = STALACTITE_SHAKING;
586 } if(mode == STALACTITE_SHAKING) {
587 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
589 mode = STALACTITE_FALL;
591 } else if(mode == STALACTITE_FALL) {
593 /* Destroy if we collides with land */
594 if(issolid(base.x+base.width/2, base.y+base.height))
597 dying = DYING_SQUISHED;
599 set_action("broken", "broken");
601 } else if(mode == FLAT) {
606 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
608 if(dying == DYING_SQUISHED && !timer.check())
613 BadGuy::action_flame(double elapsed_time)
615 static const float radius = 100;
616 static const float speed = 0.02;
617 base.x = old_base.x + cos(angle) * radius;
618 base.y = old_base.y + sin(angle) * radius;
620 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
624 BadGuy::action_fish(double elapsed_time)
626 if(frozen_timer.check())
628 if(physic.get_velocity_y() < 0)
629 set_action("iced-down", "iced-down");
631 set_action("iced", "iced");
636 static const float JUMPV = 6;
637 static const int WAITTIME = 1000;
639 // go in wait mode when back in water
640 if(dying == DYING_NOT
641 && gettile(base.x, base.y + base.height)
642 && gettile(base.x, base.y + base.height)->attributes & Tile::WATER
643 && physic.get_velocity_y() <= 0 && mode == NORMAL)
646 set_action("hide", "hide");
647 physic.set_velocity(0, 0);
648 physic.enable_gravity(false);
649 timer.start(WAITTIME);
651 else if(mode == FISH_WAIT && !timer.check())
654 set_action("normal", "normal");
656 physic.set_velocity(0, JUMPV);
657 physic.enable_gravity(true);
660 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
661 if(dying == DYING_NOT)
662 collision_swept_object_map(&old_base, &base);
664 if(physic.get_velocity_y() < 0)
666 set_action("down", "down");
671 BadGuy::action_bouncingsnowball(double elapsed_time)
673 static const float JUMPV = 4.5;
677 // jump when on ground
678 if(dying == DYING_NOT && issolid(base.x, base.y+32))
680 physic.set_velocity_y(JUMPV);
681 physic.enable_gravity(true);
688 // check for right/left collisions
689 check_horizontal_bump();
691 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
692 if(dying == DYING_NOT)
693 collision_swept_object_map(&old_base, &base);
695 // Handle dying timer:
696 if (dying == DYING_SQUISHED && !timer.check())
701 BadGuy::action_flyingsnowball(double elapsed_time)
703 static const float FLYINGSPEED = 1;
704 static const int DIRCHANGETIME = 1000;
706 // go into flyup mode if none specified yet
707 if(dying == DYING_NOT && mode == NORMAL) {
709 physic.set_velocity_y(FLYINGSPEED);
710 timer.start(DIRCHANGETIME/2);
713 if(dying == DYING_NOT && !timer.check()) {
716 physic.set_velocity_y(-FLYINGSPEED);
717 } else if(mode == FLY_DOWN) {
719 physic.set_velocity_y(FLYINGSPEED);
721 timer.start(DIRCHANGETIME);
724 if(dying != DYING_NOT)
725 physic.enable_gravity(true);
727 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
728 if(dying == DYING_NOT || dying == DYING_SQUISHED)
729 collision_swept_object_map(&old_base, &base);
731 if(dying == DYING_NOT)
733 // set direction based on tux
734 if(Sector::current()->player->base.x > base.x)
740 // Handle dying timer:
741 if (dying == DYING_SQUISHED && !timer.check())
746 BadGuy::action_spiky(double elapsed_time)
748 if(frozen_timer.check())
750 set_action("iced-left", "iced-right");
754 if (dying == DYING_NOT)
755 check_horizontal_bump();
759 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
760 if (dying != DYING_FALLING)
761 collision_swept_object_map(&old_base,&base);
765 BadGuy::action_snowball(double elapsed_time)
767 if (dying == DYING_NOT)
768 check_horizontal_bump();
772 // jump when we're about to fall
773 if (physic.get_velocity_y() == 0 &&
774 !issolid(base.x+base.width/2, base.y + base.height)) {
775 physic.enable_gravity(true);
776 physic.set_velocity_y(2);
779 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
780 if (dying != DYING_FALLING)
781 collision_swept_object_map(&old_base,&base);
783 // Handle dying timer:
784 if (dying == DYING_SQUISHED && !timer.check())
789 BadGuy::action_wingling(double elapsed_time)
791 if (dying != DYING_NOT)
792 physic.enable_gravity(true);
795 Player& tux = *Sector::current()->player;
796 int dirsign = physic.get_velocity_x() < 0 ? -1 : 1;
798 if (fabsf(tux.base.x - base.x) < 150 && base.y < tux.base.y && tux.dying == DYING_NOT)
800 if (target.x < 0 && target.y < 0)
802 target.x = tux.base.x;
803 target.y = tux.base.y;
804 physic.set_velocity(dirsign * 1.5f, -2.25f);
807 else if (base.y >= target.y - 16)
808 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
811 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
814 // Handle dying timer:
815 if (dying == DYING_SQUISHED && !timer.check())
818 // TODO: Winglings should be removed after flying off the screen
822 BadGuy::action_walkingtree(double elapsed_time)
824 if (dying == DYING_NOT)
825 check_horizontal_bump();
829 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
830 if (dying != DYING_FALLING)
831 collision_swept_object_map(&old_base,&base);
833 // Handle dying timer:
834 if (dying == DYING_SQUISHED && !timer.check())
839 BadGuy::action(float elapsed_time)
841 float scroll_x = Sector::current()->camera->get_translation().x;
842 float scroll_y = Sector::current()->camera->get_translation().y;
844 // BadGuy fall below the ground
845 if (base.y > Sector::current()->solids->get_height() * 32) {
850 // Kill us if we landed on spikes
851 if (dying == DYING_NOT
852 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
853 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
854 || isspike(base.x, base.y + base.height)
855 || isspike(base.x + base.width, base.y + base.height)))
857 physic.set_velocity_y(3);
863 /* Activate badguys if they're just around the screen to avoid
864 * the effect of having badguys suddenly popping up from nowhere.
866 if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
867 start_position.x < scroll_x - base.width &&
868 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
869 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
871 else if (start_position.x > scroll_x + screen->w &&
872 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
873 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
874 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
876 /* Special case for badguys on start of the level.
877 * If in the future, it's possible to set Tux start pos, this case
878 * should contemplate that. */
879 else if (start_position.x > 0 && start_position.x < screen->w &&
880 start_position.y > 0 && start_position.y < screen->h)
885 if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4
886 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4
887 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4
888 || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4)
891 if(dying != DYING_NOT)
902 action_mriceblock(elapsed_time);
906 action_jumpy(elapsed_time);
910 action_mrbomb(elapsed_time);
914 action_bomb(elapsed_time);
918 action_stalactite(elapsed_time);
922 action_flame(elapsed_time);
927 action_fish(elapsed_time);
930 case BAD_BOUNCINGSNOWBALL:
931 action_bouncingsnowball(elapsed_time);
934 case BAD_FLYINGSNOWBALL:
935 action_flyingsnowball(elapsed_time);
939 action_spiky(elapsed_time);
943 action_snowball(elapsed_time);
947 action_wingling(elapsed_time);
950 case BAD_WALKINGTREE:
951 action_walkingtree(elapsed_time);
960 BadGuy::draw(DrawingContext& context)
965 if((dir == LEFT && action_left == "hide") ||
966 (dir == RIGHT && action_right == "hide"))
970 specs->sprite->set_action(action_left);
971 else // if(dir == RIGHT)
972 specs->sprite->set_action(action_right);
974 if(dying == DYING_FALLING && physic.get_velocity_y() < 0)
975 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_FOREGROUNDTILES+1, VERTICAL_FLIP);
977 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
980 context.draw_filled_rect(Vector(base.x, base.y),
981 Vector(base.width, base.height), Color(75,0,75, 150), LAYER_OBJECTS+1);
985 BadGuy::set_action(std::string left, std::string right)
991 action_right = right;
1001 // FIXME: Using the image size for the physics and collision is
1002 // a bad idea, since images should always overlap their physical
1005 if(base.width == 0 && base.height == 0) {
1006 base.width = left->get_width();
1007 base.height = left->get_height();
1008 } else if(base.width != left->get_width() || base.height != left->get_height()) {
1009 base.x -= (left->get_width() - base.width) / 2;
1010 base.y -= left->get_height() - base.height;
1011 base.width = left->get_width();
1012 base.height = left->get_height();
1016 base.width = base.height = 0;
1020 animation_offset = 0;
1022 sprite_right = right;
1029 // these can't be bumped
1030 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
1031 || kind == BAD_FLAMEFISH || kind == BAD_FLYINGSNOWBALL)
1034 physic.set_velocity_y(3);
1039 BadGuy::squish_me(Player* player)
1041 player->bounce(this);
1043 Sector::current()->add_score(Vector(base.x, base.y),
1044 25 * player_status.score_multiplier);
1046 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1047 player_status.score_multiplier++;
1049 dying = DYING_SQUISHED;
1051 physic.set_velocity(0, 0);
1055 BadGuy::squish(Player* player)
1057 static const int MAX_ICEBLOCK_SQUICHES = 10;
1059 if(kind == BAD_MRBOMB) {
1060 // mrbomb transforms into a bomb now
1063 player->bounce(this);
1064 Sector::current()->add_score(Vector(base.x, base.y),
1065 25 * player_status.score_multiplier);
1066 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1068 player_status.score_multiplier++;
1071 } else if (kind == BAD_MRICEBLOCK) {
1072 if (mode == NORMAL || mode == KICK)
1075 SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(), Sector::current()->player->get_pos());
1077 set_action("flat-left", "flat-right");
1078 physic.set_velocity_x(0);
1081 } else if (mode == FLAT) {
1083 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1085 if (player->base.x < base.x + (base.width/2)) {
1086 physic.set_velocity_x(5);
1089 physic.set_velocity_x(-5);
1094 player->kick_timer.start(KICKING_TIME);
1095 set_action("flat-left", "flat-right");
1098 player->bounce(this);
1100 player_status.score_multiplier++;
1102 // check for maximum number of squishes
1104 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
1110 } else if(kind == BAD_FISH || kind == BAD_FLAMEFISH) {
1111 // fish can only be killed when falling down
1112 if(physic.get_velocity_y() >= 0)
1115 player->bounce(this);
1117 Sector::current()->add_score(Vector(base.x, base.y),
1118 25 * player_status.score_multiplier);
1120 player_status.score_multiplier++;
1122 // simply remove the fish...
1125 } else if(kind == BAD_BOUNCINGSNOWBALL) {
1127 set_action("squished", "squished");
1129 } else if(kind == BAD_FLYINGSNOWBALL) {
1131 set_action("squished-left", "squished-right");
1133 } else if(kind == BAD_SNOWBALL) {
1135 set_action("squished-left", "squished-right");
1137 } else if(kind == BAD_WINGLING) {
1139 set_action("left", "right");
1140 } else if(kind == BAD_WALKINGTREE) {
1141 if (mode == BGM_BIG)
1143 set_action("left-small", "left-small");
1144 physic.set_velocity_x(physic.get_velocity_x() * 2.0f);
1146 /* Move to the player's direction */
1147 if(dir != Sector::current()->player->dir)
1148 physic.set_velocity_x(-physic.get_velocity_x());
1149 dir = Sector::current()->player->dir;
1151 // XXX magic number: 66 is BGM_BIG height
1153 player->bounce(this);
1154 base.y += 66 - base.height;
1156 Sector::current()->add_score(Vector(base.x, base.y),
1157 25 * player_status.score_multiplier);
1158 player_status.score_multiplier++;
1168 BadGuy::kill_me(int score)
1170 if(kind == BAD_BOMB)
1174 global_stats.add_points(BADGUYS_KILLED_STAT, 1);
1176 dying = DYING_FALLING;
1177 if(kind == BAD_MRICEBLOCK) {
1178 set_action("falling-left", "falling-right");
1181 Player& tux = *Sector::current()->player;
1182 tux.holding_something = false;
1186 physic.enable_gravity(true);
1188 /* Gain some points: */
1190 Sector::current()->add_score(Vector(base.x, base.y),
1191 score * player_status.score_multiplier);
1193 /* Play death sound: */
1194 SoundManager::get()->play_sound(IDToSound(SND_FALL), this, Sector::current()->player->get_pos());
1198 BadGuy::explode(bool right_way)
1200 BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB, true);
1203 badguy->timer.start(0);
1204 badguy->mode = BOMB_TICKING;
1212 BadGuy::collision(const MovingObject&, int)
1218 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1223 BadGuy* pbad_c = NULL;
1224 Bullet* pbullet_c = NULL;
1226 if(type == COLLISION_BUMP) {
1231 if(type == COLLISION_SQUISH) {
1232 Player* player = static_cast<Player*>(p_c_object);
1237 /* COLLISION_NORMAL */
1241 pbullet_c = (Bullet*) p_c_object;
1243 if(pbullet_c->kind == FIRE_BULLET)
1245 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME
1246 && kind != BAD_FLAMEFISH)
1249 else if(pbullet_c->kind == ICE_BULLET)
1251 if(kind == BAD_FLAME || kind == BAD_FLAMEFISH)
1254 frozen_timer.start(FROZEN_TIME);
1259 pbad_c = (BadGuy*) p_c_object;
1262 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1263 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1264 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1266 pbad_c->kill_me(25);
1269 // a held mriceblock kills the enemy too but falls to ground then
1270 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1272 pbad_c->kill_me(25);
1276 /* Kill badguys that run into exploding bomb */
1277 else if (kind == BAD_BOMB && dying == DYING_NOT)
1279 if (pbad_c->kind == BAD_MRBOMB)
1281 // mrbomb transforms into a bomb now
1282 pbad_c->explode(true);
1287 pbad_c->kill_me(50);
1291 /* Kill any badguys that get hit by stalactite */
1292 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1294 if (pbad_c->kind == BAD_MRBOMB)
1296 // mrbomb transforms into a bomb now
1297 pbad_c->explode(false);
1301 pbad_c->kill_me(50);
1304 /* When enemies run into eachother, make them change directions */
1307 // Wingling doesn't interact with other badguys
1308 if (pbad_c->kind == BAD_WINGLING || kind == BAD_WINGLING)
1311 // Jumpy, fish, flame, stalactites, wingling are exceptions
1312 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1313 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH
1314 || pbad_c->kind == BAD_FLAMEFISH)
1317 // Bounce off of other badguy if we land on top of him
1318 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1320 if (pbad_c->dir == LEFT)
1323 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1325 else if (pbad_c->dir == RIGHT)
1328 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1333 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1336 if (pbad_c->kind != BAD_FLAME)
1341 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1343 // Put bad guys a part (or they get jammed)
1344 // only needed to do to one of them
1345 if (physic.get_velocity_x() != 0)
1346 base.x = pbad_c->base.x + pbad_c->base.width + 1;
1348 else if (dir == RIGHT)
1351 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1360 Player* player = static_cast<Player*>(p_c_object);
1361 /* Get kicked if were flat */
1362 if (mode == FLAT && !dying)
1364 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1366 // Hit from left side
1367 if (player->base.x < base.x) {
1368 physic.set_velocity_x(5);
1371 // Hit from right side
1373 physic.set_velocity_x(-5);
1378 player->kick_timer.start(KICKING_TIME);
1379 set_action("flat-left", "flat-right");