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", "left-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 set_action("normal", "normal");
261 physic.enable_gravity(false);
262 } else if(kind == BAD_SPIKY) {
263 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
264 } else if(kind == BAD_SNOWBALL) {
265 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
266 } else if(kind == BAD_WINGLING) {
267 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
268 physic.enable_gravity(false);
269 set_action("left", "left");
270 } else if (kind == BAD_WALKINGTREE) {
271 // TODO: why isn't the height/width being set properly in set_action?
272 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
274 set_action("left", "left");
279 base.x = start_position.x;
280 base.y = start_position.y;
288 return specs->sprite->get_frame(0);
292 BadGuy::action_mriceblock(double elapsed_time)
294 Player& tux = *Sector::current()->player;
299 /* Move left/right: */
303 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
304 if (dying != DYING_FALLING)
305 collision_swept_object_map(&old_base,&base);
307 else if (mode == HELD)
308 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
309 /* If we're holding the iceblock */
311 if(tux.size == SMALL)
314 base.x = tux.base.x + 24;
316 base.x = tux.base.x - 12;
317 base.y = tux.base.y + tux.base.height/1.5 - base.height;
322 base.x = tux.base.x + 24;
324 base.x = tux.base.x - 4;
325 base.y = tux.base.y + tux.base.height/1.5 - base.height;
328 if(collision_object_map(base))
331 base.y = tux.base.y + tux.base.height/1.5 - base.height;
334 if(tux.input.fire != DOWN) /* SHOOT! */
337 base.x = tux.base.x - base.width;
339 base.x = tux.base.x + tux.base.width;
343 tux.kick_timer.start(KICKING_TIME);
344 set_action("flat-left", "flat-right");
345 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
346 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
353 check_horizontal_bump();
354 if(mode == KICK && changed != dir)
356 SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(), Sector::current()->player->get_pos());
360 /* Handle mode timer: */
366 set_action("left", "right");
367 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
373 BadGuy::check_horizontal_bump(bool checkcliff)
375 float halfheight = base.height / 2;
376 if (dir == LEFT && issolid( base.x, base.y + halfheight))
378 if (kind == BAD_MRICEBLOCK && mode == KICK)
380 Sector::current()->trybreakbrick(Vector(base.x, base.y + halfheight), false);
381 Sector::current()->tryemptybox(Vector(base.x, base.y + halfheight), dir);
385 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
388 if (dir == RIGHT && issolid( base.x + base.width, base.y + halfheight))
390 if (kind == BAD_MRICEBLOCK && mode == KICK)
392 Sector::current()->trybreakbrick(
393 Vector(base.x + base.width, base.y + halfheight), false);
394 Sector::current()->tryemptybox(
395 Vector(base.x + base.width, base.y + halfheight), dir);
399 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
403 // don't check for cliffs when we're falling
406 if(!issolid(base.x + base.width/2, base.y + base.height))
409 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
412 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
415 if(dir == RIGHT && !issolid(base.x + base.width,
416 (int) base.y + base.height + halfheight))
419 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
427 /* Fall if we get off the ground: */
428 if (dying != DYING_FALLING)
430 if (!issolid(base.x+base.width/2, base.y + base.height))
432 // not solid below us? enable gravity
433 physic.enable_gravity(true);
438 if (physic.get_velocity_y() < 0)
440 base.y = int((base.y + base.height)/32) * 32 - base.height;
441 physic.set_velocity_y(0);
443 // no gravity anymore please
444 physic.enable_gravity(false);
446 if (stay_on_platform && mode == NORMAL)
448 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
449 base.y + base.height))
454 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
459 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
467 physic.enable_gravity(true);
472 BadGuy::action_jumpy(double elapsed_time)
474 if(frozen_timer.check())
476 set_action("left-iced", "left-iced");
480 const float vy = physic.get_velocity_y();
482 // XXX: These tests *should* use location from ground, not velocity
483 if (fabsf(vy) > 5.6f)
484 set_action("left-down", "left-down");
485 else if (fabsf(vy) > 5.3f)
486 set_action("left-middle", "left-middle");
488 set_action("left-up", "left-up");
490 Player& tux = *Sector::current()->player;
492 static const float JUMPV = 6;
495 // jump when on ground
496 if(dying == DYING_NOT && issolid(base.x, base.y+32))
498 physic.set_velocity_y(JUMPV);
499 physic.enable_gravity(true);
503 else if(mode == JUMPY_JUMP)
508 // set direction based on tux
509 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 // Handle dying timer:
732 if (dying == DYING_SQUISHED && !timer.check())
737 BadGuy::action_spiky(double elapsed_time)
739 if(frozen_timer.check())
741 set_action("iced-left", "iced-right");
745 if (dying == DYING_NOT)
746 check_horizontal_bump();
750 // jump when we're about to fall
751 if (physic.get_velocity_y() == 0 &&
752 !issolid(base.x+base.width/2, base.y + base.height)) {
753 physic.enable_gravity(true);
754 physic.set_velocity_y(2);
758 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
759 if (dying != DYING_FALLING)
760 collision_swept_object_map(&old_base,&base);
764 BadGuy::action_snowball(double elapsed_time)
766 if (dying == DYING_NOT)
767 check_horizontal_bump();
771 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
772 if (dying != DYING_FALLING)
773 collision_swept_object_map(&old_base,&base);
775 // Handle dying timer:
776 if (dying == DYING_SQUISHED && !timer.check())
781 BadGuy::action_wingling(double elapsed_time)
783 if (dying != DYING_NOT)
784 physic.enable_gravity(true);
787 Player& tux = *Sector::current()->player;
788 int dirsign = physic.get_velocity_x() < 0 ? -1 : 1;
790 if (fabsf(tux.base.x - base.x) < 150 && base.y < tux.base.y && tux.dying == DYING_NOT)
792 if (target.x < 0 && target.y < 0)
794 target.x = tux.base.x;
795 target.y = tux.base.y;
796 physic.set_velocity(dirsign * 1.5f, -2.25f);
799 else if (base.y >= target.y - 16)
800 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
803 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
806 // Handle dying timer:
807 if (dying == DYING_SQUISHED && !timer.check())
810 // TODO: Winglings should be removed after flying off the screen
814 BadGuy::action_walkingtree(double elapsed_time)
816 if (dying == DYING_NOT)
817 check_horizontal_bump();
821 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
822 if (dying != DYING_FALLING)
823 collision_swept_object_map(&old_base,&base);
825 // Handle dying timer:
826 if (dying == DYING_SQUISHED && !timer.check())
831 BadGuy::action(float elapsed_time)
833 float scroll_x = Sector::current()->camera->get_translation().x;
834 float scroll_y = Sector::current()->camera->get_translation().y;
836 // BadGuy fall below the ground
837 if (base.y > Sector::current()->solids->get_height() * 32) {
842 // Kill us if we landed on spikes
843 if (dying == DYING_NOT
844 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
845 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
846 || isspike(base.x, base.y + base.height)
847 || isspike(base.x + base.width, base.y + base.height)))
849 physic.set_velocity_y(3);
854 /* activate badguys if they're just inside the offscreen_distance around the
855 * screen. Don't activate them inside the screen, since that might have the
856 * effect of badguys suddenly popping up from nowhere
858 if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
859 start_position.x < scroll_x - base.width)
861 else if(start_position.x > scroll_y - Y_OFFSCREEN_DISTANCE &&
862 start_position.y < scroll_y - base.height)
864 else if(start_position.x > scroll_x + screen->w &&
865 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE)
867 else if(start_position.y > scroll_y + screen->h &&
868 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
871 if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4
872 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4
873 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4
874 || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4) {
876 if(dying != DYING_NOT)
887 action_mriceblock(elapsed_time);
891 action_jumpy(elapsed_time);
895 action_mrbomb(elapsed_time);
899 action_bomb(elapsed_time);
903 action_stalactite(elapsed_time);
907 action_flame(elapsed_time);
912 action_fish(elapsed_time);
915 case BAD_BOUNCINGSNOWBALL:
916 action_bouncingsnowball(elapsed_time);
919 case BAD_FLYINGSNOWBALL:
920 action_flyingsnowball(elapsed_time);
924 action_spiky(elapsed_time);
928 action_snowball(elapsed_time);
932 action_wingling(elapsed_time);
935 case BAD_WALKINGTREE:
936 action_walkingtree(elapsed_time);
945 BadGuy::draw(DrawingContext& context)
947 if((dir == LEFT && action_left == "hide") ||
948 (dir == RIGHT && action_right == "hide"))
952 specs->sprite->set_action(action_left);
953 else // if(dir == RIGHT)
954 specs->sprite->set_action(action_right);
956 if(dying == DYING_FALLING && physic.get_velocity_y() < 0)
957 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_FOREGROUNDTILES+1, VERTICAL_FLIP);
959 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
962 context.draw_filled_rect(Vector(base.x, base.y),
963 Vector(base.width, base.height), Color(75,0,75, 150), LAYER_OBJECTS+1);
967 BadGuy::set_action(std::string left, std::string right)
973 action_right = right;
975 std::cerr << "set_action(" << left << ", " << right << ") of " << badguykind_to_string(kind) << std::endl;
985 // FIXME: Using the image size for the physics and collision is
986 // a bad idea, since images should always overlap there physical
989 if(base.width == 0 && base.height == 0) {
990 base.width = left->get_width();
991 base.height = left->get_height();
992 } else if(base.width != left->get_width() || base.height != left->get_height()) {
993 base.x -= (left->get_width() - base.width) / 2;
994 base.y -= left->get_height() - base.height;
995 base.width = left->get_width();
996 base.height = left->get_height();
1000 base.width = base.height = 0;
1004 animation_offset = 0;
1006 sprite_right = right;
1013 // these can't be bumped
1014 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
1015 || kind == BAD_FLAMEFISH || kind == BAD_FLYINGSNOWBALL)
1018 physic.set_velocity_y(3);
1023 BadGuy::squish_me(Player* player)
1025 player->bounce(this);
1027 Sector::current()->add_score(Vector(base.x, base.y),
1028 25 * player_status.score_multiplier);
1030 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1031 player_status.score_multiplier++;
1033 dying = DYING_SQUISHED;
1035 physic.set_velocity(0, 0);
1039 BadGuy::squish(Player* player)
1041 static const int MAX_ICEBLOCK_SQUICHES = 10;
1043 if(kind == BAD_MRBOMB) {
1044 // mrbomb transforms into a bomb now
1047 player->bounce(this);
1048 Sector::current()->add_score(Vector(base.x, base.y),
1049 25 * player_status.score_multiplier);
1050 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1052 player_status.score_multiplier++;
1055 } else if (kind == BAD_MRICEBLOCK) {
1056 if (mode == NORMAL || mode == KICK)
1059 SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(), Sector::current()->player->get_pos());
1061 set_action("flat-left", "flat-right");
1062 physic.set_velocity_x(0);
1065 } else if (mode == FLAT) {
1067 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1069 if (player->base.x < base.x + (base.width/2)) {
1070 physic.set_velocity_x(5);
1073 physic.set_velocity_x(-5);
1078 player->kick_timer.start(KICKING_TIME);
1079 set_action("flat-left", "flat-right");
1082 player->bounce(this);
1084 player_status.score_multiplier++;
1086 // check for maximum number of squishes
1088 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
1094 } else if(kind == BAD_FISH || kind == BAD_FLAMEFISH) {
1095 // fish can only be killed when falling down
1096 if(physic.get_velocity_y() >= 0)
1099 player->bounce(this);
1101 Sector::current()->add_score(Vector(base.x, base.y),
1102 25 * player_status.score_multiplier);
1104 player_status.score_multiplier++;
1106 // simply remove the fish...
1109 } else if(kind == BAD_BOUNCINGSNOWBALL) {
1111 set_action("squished", "squished");
1113 } else if(kind == BAD_FLYINGSNOWBALL) {
1115 set_action("squished", "squished");
1117 } else if(kind == BAD_SNOWBALL) {
1119 set_action("squished-left", "squished-right");
1121 } else if(kind == BAD_WINGLING) {
1123 set_action("left", "right");
1124 } else if(kind == BAD_WALKINGTREE) {
1125 if (mode == BGM_BIG)
1127 set_action("left-small", "left-small");
1128 physic.set_velocity_x(physic.get_velocity_x() * 2.0f);
1130 /* Move to the player's direction */
1131 if(dir != Sector::current()->player->dir)
1132 physic.set_velocity_x(-physic.get_velocity_x());
1133 dir = Sector::current()->player->dir;
1135 // XXX magic number: 66 is BGM_BIG height
1137 player->bounce(this);
1138 base.y += 66 - base.height;
1140 Sector::current()->add_score(Vector(base.x, base.y),
1141 25 * player_status.score_multiplier);
1142 player_status.score_multiplier++;
1152 BadGuy::kill_me(int score)
1154 if(kind == BAD_BOMB)
1158 global_stats.add_points(BADGUYS_KILLED_STAT, 1);
1160 dying = DYING_FALLING;
1161 if(kind == BAD_MRICEBLOCK) {
1162 set_action("falling-left", "falling-right");
1165 Player& tux = *Sector::current()->player;
1166 tux.holding_something = false;
1170 physic.enable_gravity(true);
1172 /* Gain some points: */
1174 Sector::current()->add_score(Vector(base.x, base.y),
1175 score * player_status.score_multiplier);
1177 /* Play death sound: */
1178 SoundManager::get()->play_sound(IDToSound(SND_FALL), this, Sector::current()->player->get_pos());
1182 BadGuy::explode(bool right_way)
1184 BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
1187 badguy->timer.start(0);
1188 badguy->mode = BOMB_TICKING;
1195 BadGuy::collision(const MovingObject&, int)
1201 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1203 BadGuy* pbad_c = NULL;
1204 Bullet* pbullet_c = NULL;
1206 if(type == COLLISION_BUMP) {
1211 if(type == COLLISION_SQUISH) {
1212 Player* player = static_cast<Player*>(p_c_object);
1217 /* COLLISION_NORMAL */
1221 pbullet_c = (Bullet*) p_c_object;
1223 if(pbullet_c->kind == FIRE_BULLET)
1225 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME
1226 && kind != BAD_FLAMEFISH)
1229 else if(pbullet_c->kind == ICE_BULLET)
1231 if(kind == BAD_FLAME || kind == BAD_FLAMEFISH)
1234 frozen_timer.start(FROZEN_TIME);
1239 pbad_c = (BadGuy*) p_c_object;
1242 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1243 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1244 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1246 pbad_c->kill_me(25);
1249 // a held mriceblock kills the enemy too but falls to ground then
1250 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1252 pbad_c->kill_me(25);
1256 /* Kill badguys that run into exploding bomb */
1257 else if (kind == BAD_BOMB && dying == DYING_NOT)
1259 if (pbad_c->kind == BAD_MRBOMB)
1261 // mrbomb transforms into a bomb now
1262 pbad_c->explode(true);
1267 pbad_c->kill_me(50);
1271 /* Kill any badguys that get hit by stalactite */
1272 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1274 if (pbad_c->kind == BAD_MRBOMB)
1276 // mrbomb transforms into a bomb now
1277 pbad_c->explode(false);
1281 pbad_c->kill_me(50);
1284 /* When enemies run into eachother, make them change directions */
1287 // Wingling doesn't interact with other badguys
1288 if (pbad_c->kind == BAD_WINGLING || kind == BAD_WINGLING)
1291 // Jumpy, fish, flame, stalactites, wingling are exceptions
1292 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1293 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH
1294 || pbad_c->kind == BAD_FLAMEFISH)
1297 // Bounce off of other badguy if we land on top of him
1298 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1300 if (pbad_c->dir == LEFT)
1303 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1305 else if (pbad_c->dir == RIGHT)
1308 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1313 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1316 if (pbad_c->kind != BAD_FLAME)
1321 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1323 // Put bad guys a part (or they get jammed)
1324 // only needed to do to one of them
1325 if (physic.get_velocity_x() != 0)
1326 base.x = pbad_c->base.x + pbad_c->base.width + 1;
1328 else if (dir == RIGHT)
1331 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1340 Player* player = static_cast<Player*>(p_c_object);
1341 /* Get kicked if were flat */
1342 if (mode == FLAT && !dying)
1344 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1346 // Hit from left side
1347 if (player->base.x < base.x) {
1348 physic.set_velocity_x(5);
1351 // Hit from right side
1353 physic.set_velocity_x(-5);
1358 player->kick_timer.start(KICKING_TIME);
1359 set_action("flat-left", "flat-right");