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;
77 std::string badguykind_to_string(BadGuyKind kind)
102 case BAD_BOUNCINGSNOWBALL:
103 return "bouncingsnowball";
105 case BAD_FLYINGSNOWBALL:
106 return "flyingsnowball";
117 case BAD_WALKINGTREE:
118 return "walkingtree";
124 BadGuy::BadGuy(BadGuyKind kind_, LispReader& lispreader)
125 : removable(false), squishcount(0)
127 lispreader.read_float("x", start_position.x);
128 lispreader.read_float("y", start_position.y);
132 stay_on_platform = false;
133 lispreader.read_bool("stay-on-platform", stay_on_platform);
138 BadGuy::BadGuy(BadGuyKind kind_, float x, float y)
139 : removable(false), squishcount(0)
141 start_position.x = x;
142 start_position.y = y;
143 stay_on_platform = false;
167 animation_offset = 0;
168 target.x = target.y = -1;
170 frozen_timer.init(true);
173 specs = badguyspecs_manager->load(badguykind_to_string(kind));
175 // if we're in a solid tile at start correct that now
176 if(Sector::current()) {
177 if(kind != BAD_FLAME && kind != BAD_FISH && kind != BAD_FLAMEFISH && collision_object_map(base))
179 std::cout << "Warning: badguy started in wall: kind: " << badguykind_to_string(kind)
180 << " pos: (" << base.x << ", " << base.y << ")" << std::endl;
181 while(collision_object_map(base))
185 if(Sector::current()->camera) {
186 Vector scroll = Sector::current()->camera->get_translation();
188 if(start_position.x > scroll.x - X_OFFSCREEN_DISTANCE &&
189 start_position.x < scroll.x + screen->w + X_OFFSCREEN_DISTANCE &&
190 start_position.y > scroll.y - Y_OFFSCREEN_DISTANCE &&
191 start_position.y < scroll.y + screen->h + Y_OFFSCREEN_DISTANCE) {
195 if(start_position.x > 0 && start_position.x <= screen->w
196 && start_position.y > 0 && start_position.y <= screen->h)
202 BadGuy::write(LispWriter& writer)
204 writer.start_list(badguykind_to_string(kind));
206 writer.write_float("x", base.x);
207 writer.write_float("y", base.y);
208 writer.write_bool("stay-on-platform", stay_on_platform);
210 writer.end_list(badguykind_to_string(kind));
214 BadGuy::activate(Direction activation_dir)
217 animation_offset = 0;
218 target.x = target.y = -1;
220 frozen_timer.init(true);
223 dir = activation_dir;
224 float dirsign = activation_dir == LEFT ? -1 : 1;
226 set_action("left", "right");
227 if(kind == BAD_MRBOMB) {
228 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
229 } else if (kind == BAD_MRICEBLOCK) {
230 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
231 } else if(kind == BAD_JUMPY) {
232 set_action("left-up", "left-up");
233 } else if(kind == BAD_BOMB) {
234 set_action("ticking-left", "ticking-right");
235 // hack so that the bomb doesn't hurt until it expldes...
236 dying = DYING_SQUISHED;
237 } else if(kind == BAD_FLAME) {
239 physic.enable_gravity(false);
240 set_action("normal", "normal");
241 } else if(kind == BAD_BOUNCINGSNOWBALL) {
242 physic.set_velocity(dirsign * 1.3, 0);
243 } else if(kind == BAD_STALACTITE) {
244 physic.enable_gravity(false);
245 set_action("normal", "normal");
246 } else if(kind == BAD_FISH) {
247 set_action("normal", "normal");
248 physic.enable_gravity(true);
249 } else if(kind == BAD_FLAMEFISH) {
250 set_action("normal", "normal");
251 physic.enable_gravity(true);
252 } else if(kind == BAD_FLYINGSNOWBALL) {
253 set_action("normal", "normal");
254 physic.enable_gravity(false);
255 } else if(kind == BAD_SPIKY) {
256 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
257 } else if(kind == BAD_SNOWBALL) {
258 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
259 } else if(kind == BAD_WINGLING) {
260 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
261 physic.enable_gravity(false);
262 set_action("left", "left");
263 } else if (kind == BAD_WALKINGTREE) {
264 // TODO: why isn't the height/width being set properly in set_action?
265 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
267 set_action("left", "left");
272 base.x = start_position.x;
273 base.y = start_position.y;
281 return specs->sprite->get_frame(0);
285 BadGuy::action_mriceblock(double elapsed_time)
287 Player& tux = *Sector::current()->player;
292 /* Move left/right: */
296 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
297 if (dying != DYING_FALLING)
298 collision_swept_object_map(&old_base,&base);
300 else if (mode == HELD)
301 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
302 /* If we're holding the iceblock */
304 if(tux.size == SMALL)
307 base.x = tux.base.x + 24;
309 base.x = tux.base.x - 12;
310 base.y = tux.base.y + tux.base.height/1.5 - base.height;
315 base.x = tux.base.x + 24;
317 base.x = tux.base.x - 4;
318 base.y = tux.base.y + tux.base.height/1.5 - base.height;
321 if(collision_object_map(base))
324 base.y = tux.base.y + tux.base.height/1.5 - base.height;
327 if(tux.input.fire != DOWN) /* SHOOT! */
330 base.x = tux.base.x - base.width;
332 base.x = tux.base.x + tux.base.width;
336 tux.kick_timer.start(KICKING_TIME);
337 set_action("flat-left", "flat-right");
338 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
339 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
346 check_horizontal_bump();
347 if(mode == KICK && changed != dir)
349 SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(), Sector::current()->player->get_pos());
353 /* Handle mode timer: */
359 set_action("left", "right");
360 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
366 BadGuy::check_horizontal_bump(bool checkcliff)
368 float halfheight = base.height / 2;
369 if (dir == LEFT && issolid( base.x, base.y + halfheight))
371 if (kind == BAD_MRICEBLOCK && mode == KICK)
373 Sector::current()->trybreakbrick(Vector(base.x, base.y + halfheight), false);
374 Sector::current()->tryemptybox(Vector(base.x, base.y + halfheight), dir);
378 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
381 if (dir == RIGHT && issolid( base.x + base.width, base.y + halfheight))
383 if (kind == BAD_MRICEBLOCK && mode == KICK)
385 Sector::current()->trybreakbrick(
386 Vector(base.x + base.width, base.y + halfheight), false);
387 Sector::current()->tryemptybox(
388 Vector(base.x + base.width, base.y + halfheight), dir);
392 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
396 // don't check for cliffs when we're falling
399 if(!issolid(base.x + base.width/2, base.y + base.height))
402 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
405 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
408 if(dir == RIGHT && !issolid(base.x + base.width,
409 (int) base.y + base.height + halfheight))
412 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
420 /* Fall if we get off the ground: */
421 if (dying != DYING_FALLING)
423 if (!issolid(base.x+base.width/2, base.y + base.height))
425 // not solid below us? enable gravity
426 physic.enable_gravity(true);
431 if (physic.get_velocity_y() < 0)
433 base.y = int((base.y + base.height)/32) * 32 - base.height;
434 physic.set_velocity_y(0);
436 // no gravity anymore please
437 physic.enable_gravity(false);
439 if (stay_on_platform && mode == NORMAL)
441 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
442 base.y + base.height))
447 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
452 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
460 physic.enable_gravity(true);
465 BadGuy::action_jumpy(double elapsed_time)
467 if(frozen_timer.check())
469 set_action("left-iced", "left-iced");
473 const float vy = physic.get_velocity_y();
475 // XXX: These tests *should* use location from ground, not velocity
476 if (fabsf(vy) > 5.6f)
477 set_action("left-down", "left-down");
478 else if (fabsf(vy) > 5.3f)
479 set_action("left-middle", "left-middle");
481 set_action("left-up", "left-up");
483 Player& tux = *Sector::current()->player;
485 static const float JUMPV = 6;
488 // jump when on ground
489 if(dying == DYING_NOT && issolid(base.x, base.y+32))
491 physic.set_velocity_y(JUMPV);
492 physic.enable_gravity(true);
496 else if(mode == JUMPY_JUMP)
501 // set direction based on tux
502 if(tux.base.x > base.x)
508 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
509 if(dying == DYING_NOT)
510 collision_swept_object_map(&old_base, &base);
514 BadGuy::action_mrbomb(double elapsed_time)
516 if(frozen_timer.check())
518 set_action("iced-left", "iced-right");
522 if (dying == DYING_NOT)
523 check_horizontal_bump(true);
527 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
528 if (dying != DYING_FALLING)
529 collision_swept_object_map(&old_base,&base);
533 BadGuy::action_bomb(double elapsed_time)
535 static const int TICKINGTIME = 1000;
536 static const int EXPLODETIME = 1000;
542 timer.start(TICKINGTIME);
543 } else if(!timer.check()) {
544 if(mode == BOMB_TICKING) {
546 set_action("explosion", "explosion");
547 dying = DYING_NOT; // now the bomb hurts
548 timer.start(EXPLODETIME);
550 SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), this, Sector::current()->player->get_pos());
551 } else if(mode == BOMB_EXPLODE) {
558 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
559 collision_swept_object_map(&old_base,&base);
563 BadGuy::action_stalactite(double elapsed_time)
565 Player& tux = *Sector::current()->player;
567 static const int SHAKETIME = 800;
568 static const int RANGE = 40;
571 // start shaking when tux is below the stalactite and at least 40 pixels
573 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
574 && tux.base.y + tux.base.height > base.y
575 && tux.dying == DYING_NOT) {
576 timer.start(SHAKETIME);
577 mode = STALACTITE_SHAKING;
579 } if(mode == STALACTITE_SHAKING) {
580 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
582 mode = STALACTITE_FALL;
584 } else if(mode == STALACTITE_FALL) {
586 /* Destroy if we collides with land */
587 if(issolid(base.x+base.width/2, base.y+base.height))
590 dying = DYING_SQUISHED;
592 set_action("broken", "broken");
594 } else if(mode == FLAT) {
599 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
601 if(dying == DYING_SQUISHED && !timer.check())
606 BadGuy::action_flame(double elapsed_time)
608 static const float radius = 100;
609 static const float speed = 0.02;
610 base.x = old_base.x + cos(angle) * radius;
611 base.y = old_base.y + sin(angle) * radius;
613 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
617 BadGuy::action_fish(double elapsed_time)
619 if(frozen_timer.check())
621 if(physic.get_velocity_y() < 0)
622 set_action("iced-down", "iced-down");
624 set_action("iced", "iced");
629 static const float JUMPV = 6;
630 static const int WAITTIME = 1000;
632 // go in wait mode when back in water
633 if(dying == DYING_NOT
634 && gettile(base.x, base.y + base.height)
635 && gettile(base.x, base.y + base.height)->attributes & Tile::WATER
636 && physic.get_velocity_y() <= 0 && mode == NORMAL)
639 set_action("hide", "hide");
640 physic.set_velocity(0, 0);
641 physic.enable_gravity(false);
642 timer.start(WAITTIME);
644 else if(mode == FISH_WAIT && !timer.check())
647 set_action("normal", "normal");
649 physic.set_velocity(0, JUMPV);
650 physic.enable_gravity(true);
653 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
654 if(dying == DYING_NOT)
655 collision_swept_object_map(&old_base, &base);
657 if(physic.get_velocity_y() < 0)
659 set_action("down", "down");
664 BadGuy::action_bouncingsnowball(double elapsed_time)
666 static const float JUMPV = 4.5;
670 // jump when on ground
671 if(dying == DYING_NOT && issolid(base.x, base.y+32))
673 physic.set_velocity_y(JUMPV);
674 physic.enable_gravity(true);
681 // check for right/left collisions
682 check_horizontal_bump();
684 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
685 if(dying == DYING_NOT)
686 collision_swept_object_map(&old_base, &base);
688 // Handle dying timer:
689 if (dying == DYING_SQUISHED && !timer.check())
694 BadGuy::action_flyingsnowball(double elapsed_time)
696 static const float FLYINGSPEED = 1;
697 static const int DIRCHANGETIME = 1000;
699 // go into flyup mode if none specified yet
700 if(dying == DYING_NOT && mode == NORMAL) {
702 physic.set_velocity_y(FLYINGSPEED);
703 timer.start(DIRCHANGETIME/2);
706 if(dying == DYING_NOT && !timer.check()) {
709 physic.set_velocity_y(-FLYINGSPEED);
710 } else if(mode == FLY_DOWN) {
712 physic.set_velocity_y(FLYINGSPEED);
714 timer.start(DIRCHANGETIME);
717 if(dying != DYING_NOT)
718 physic.enable_gravity(true);
720 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
721 if(dying == DYING_NOT || dying == DYING_SQUISHED)
722 collision_swept_object_map(&old_base, &base);
724 // Handle dying timer:
725 if (dying == DYING_SQUISHED && !timer.check())
730 BadGuy::action_spiky(double elapsed_time)
732 if(frozen_timer.check())
734 set_action("iced-left", "iced-right");
738 if (dying == DYING_NOT)
739 check_horizontal_bump();
743 // jump when we're about to fall
744 if (physic.get_velocity_y() == 0 &&
745 !issolid(base.x+base.width/2, base.y + base.height)) {
746 physic.enable_gravity(true);
747 physic.set_velocity_y(2);
751 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
752 if (dying != DYING_FALLING)
753 collision_swept_object_map(&old_base,&base);
757 BadGuy::action_snowball(double elapsed_time)
759 if (dying == DYING_NOT)
760 check_horizontal_bump();
764 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
765 if (dying != DYING_FALLING)
766 collision_swept_object_map(&old_base,&base);
768 // Handle dying timer:
769 if (dying == DYING_SQUISHED && !timer.check())
774 BadGuy::action_wingling(double elapsed_time)
776 if (dying != DYING_NOT)
777 physic.enable_gravity(true);
780 Player& tux = *Sector::current()->player;
781 int dirsign = physic.get_velocity_x() < 0 ? -1 : 1;
783 if (fabsf(tux.base.x - base.x) < 150 && base.y < tux.base.y && tux.dying == DYING_NOT)
785 if (target.x < 0 && target.y < 0)
787 target.x = tux.base.x;
788 target.y = tux.base.y;
789 physic.set_velocity(dirsign * 1.5f, -2.25f);
792 else if (base.y >= target.y - 16)
793 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
796 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
799 // Handle dying timer:
800 if (dying == DYING_SQUISHED && !timer.check())
803 // TODO: Winglings should be removed after flying off the screen
807 BadGuy::action_walkingtree(double elapsed_time)
809 if (dying == DYING_NOT)
810 check_horizontal_bump();
814 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
815 if (dying != DYING_FALLING)
816 collision_swept_object_map(&old_base,&base);
818 // Handle dying timer:
819 if (dying == DYING_SQUISHED && !timer.check())
824 BadGuy::action(float elapsed_time)
826 float scroll_x = Sector::current()->camera->get_translation().x;
827 float scroll_y = Sector::current()->camera->get_translation().y;
829 // BadGuy fall below the ground
830 if (base.y > Sector::current()->solids->get_height() * 32) {
835 // Kill us if we landed on spikes
836 if (dying == DYING_NOT
837 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
838 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
839 || isspike(base.x, base.y + base.height)
840 || isspike(base.x + base.width, base.y + base.height)))
842 physic.set_velocity_y(3);
847 /* activate badguys if they're just inside the offscreen_distance around the
848 * screen. Don't activate them inside the screen, since that might have the
849 * effect of badguys suddenly popping up from nowhere
851 if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
852 start_position.x < scroll_x - base.width)
854 else if(start_position.x > scroll_y - Y_OFFSCREEN_DISTANCE &&
855 start_position.y < scroll_y - base.height)
857 else if(start_position.x > scroll_x + screen->w &&
858 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE)
860 else if(start_position.y > scroll_y + screen->h &&
861 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
864 if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4
865 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4
866 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4
867 || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4) {
869 if(dying != DYING_NOT)
880 action_mriceblock(elapsed_time);
884 action_jumpy(elapsed_time);
888 action_mrbomb(elapsed_time);
892 action_bomb(elapsed_time);
896 action_stalactite(elapsed_time);
900 action_flame(elapsed_time);
905 action_fish(elapsed_time);
908 case BAD_BOUNCINGSNOWBALL:
909 action_bouncingsnowball(elapsed_time);
912 case BAD_FLYINGSNOWBALL:
913 action_flyingsnowball(elapsed_time);
917 action_spiky(elapsed_time);
921 action_snowball(elapsed_time);
925 action_wingling(elapsed_time);
928 case BAD_WALKINGTREE:
929 action_walkingtree(elapsed_time);
938 BadGuy::draw(DrawingContext& context)
940 if((dir == LEFT && action_left == "hide") ||
941 (dir == RIGHT && action_right == "hide"))
945 specs->sprite->set_action(action_left);
946 else // if(dir == RIGHT)
947 specs->sprite->set_action(action_right);
949 if(dying == DYING_FALLING && physic.get_velocity_y() < 0)
950 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_FOREGROUNDTILES+1, VERTICAL_FLIP);
952 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
955 context.draw_filled_rect(Vector(base.x, base.y),
956 Vector(base.width, base.height), Color(75,0,75, 150), LAYER_OBJECTS+1);
960 BadGuy::set_action(std::string left, std::string right)
966 action_right = right;
976 // FIXME: Using the image size for the physics and collision is
977 // a bad idea, since images should always overlap there physical
980 if(base.width == 0 && base.height == 0) {
981 base.width = left->get_width();
982 base.height = left->get_height();
983 } else if(base.width != left->get_width() || base.height != left->get_height()) {
984 base.x -= (left->get_width() - base.width) / 2;
985 base.y -= left->get_height() - base.height;
986 base.width = left->get_width();
987 base.height = left->get_height();
991 base.width = base.height = 0;
995 animation_offset = 0;
997 sprite_right = right;
1004 // these can't be bumped
1005 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
1006 || kind == BAD_FLAMEFISH || kind == BAD_FLYINGSNOWBALL)
1009 physic.set_velocity_y(3);
1014 BadGuy::squish_me(Player* player)
1016 player->bounce(this);
1018 Sector::current()->add_score(Vector(base.x, base.y),
1019 25 * player_status.score_multiplier);
1021 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1022 player_status.score_multiplier++;
1024 dying = DYING_SQUISHED;
1026 physic.set_velocity(0, 0);
1030 BadGuy::squish(Player* player)
1032 static const int MAX_ICEBLOCK_SQUICHES = 10;
1034 if(kind == BAD_MRBOMB) {
1035 // mrbomb transforms into a bomb now
1038 player->bounce(this);
1039 Sector::current()->add_score(Vector(base.x, base.y),
1040 25 * player_status.score_multiplier);
1041 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1043 player_status.score_multiplier++;
1046 } else if (kind == BAD_MRICEBLOCK) {
1047 if (mode == NORMAL || mode == KICK)
1050 SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(), Sector::current()->player->get_pos());
1052 set_action("flat-left", "flat-right");
1053 physic.set_velocity_x(0);
1056 } else if (mode == FLAT) {
1058 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1060 if (player->base.x < base.x + (base.width/2)) {
1061 physic.set_velocity_x(5);
1064 physic.set_velocity_x(-5);
1069 player->kick_timer.start(KICKING_TIME);
1070 set_action("flat-left", "flat-right");
1073 player->bounce(this);
1075 player_status.score_multiplier++;
1077 // check for maximum number of squishes
1079 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
1085 } else if(kind == BAD_FISH || kind == BAD_FLAMEFISH) {
1086 // fish can only be killed when falling down
1087 if(physic.get_velocity_y() >= 0)
1090 player->bounce(this);
1092 Sector::current()->add_score(Vector(base.x, base.y),
1093 25 * player_status.score_multiplier);
1095 player_status.score_multiplier++;
1097 // simply remove the fish...
1100 } else if(kind == BAD_BOUNCINGSNOWBALL) {
1102 set_action("squished", "squished");
1104 } else if(kind == BAD_FLYINGSNOWBALL) {
1106 set_action("squished", "squished");
1108 } else if(kind == BAD_SNOWBALL) {
1110 set_action("squished-left", "squished-right");
1112 } else if(kind == BAD_WINGLING) {
1114 set_action("left", "right");
1115 } else if(kind == BAD_WALKINGTREE) {
1116 if (mode == BGM_BIG)
1118 set_action("left-small", "left-small");
1119 physic.set_velocity_x(physic.get_velocity_x() * 2.0f);
1121 /* Move to the player's direction */
1122 if(dir != Sector::current()->player->dir)
1123 physic.set_velocity_x(-physic.get_velocity_x());
1124 dir = Sector::current()->player->dir;
1126 // XXX magic number: 66 is BGM_BIG height
1128 player->bounce(this);
1129 base.y += 66 - base.height;
1131 Sector::current()->add_score(Vector(base.x, base.y),
1132 25 * player_status.score_multiplier);
1133 player_status.score_multiplier++;
1143 BadGuy::kill_me(int score)
1145 if(kind == BAD_BOMB)
1149 global_stats.add_points(BADGUYS_KILLED_STAT, 1);
1151 dying = DYING_FALLING;
1152 if(kind == BAD_MRICEBLOCK) {
1153 set_action("falling-left", "falling-right");
1156 Player& tux = *Sector::current()->player;
1157 tux.holding_something = false;
1161 physic.enable_gravity(true);
1163 /* Gain some points: */
1165 Sector::current()->add_score(Vector(base.x, base.y),
1166 score * player_status.score_multiplier);
1168 /* Play death sound: */
1169 SoundManager::get()->play_sound(IDToSound(SND_FALL), this, Sector::current()->player->get_pos());
1173 BadGuy::explode(bool right_way)
1175 BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
1178 badguy->timer.start(0);
1179 badguy->mode = BOMB_TICKING;
1186 BadGuy::collision(const MovingObject&, int)
1192 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1194 BadGuy* pbad_c = NULL;
1195 Bullet* pbullet_c = NULL;
1197 if(type == COLLISION_BUMP) {
1202 if(type == COLLISION_SQUISH) {
1203 Player* player = static_cast<Player*>(p_c_object);
1208 /* COLLISION_NORMAL */
1212 pbullet_c = (Bullet*) p_c_object;
1214 if(pbullet_c->kind == FIRE_BULLET)
1216 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME
1217 && kind != BAD_FLAMEFISH)
1220 else if(pbullet_c->kind == ICE_BULLET)
1222 if(kind == BAD_FLAME || kind == BAD_FLAMEFISH)
1225 frozen_timer.start(FROZEN_TIME);
1230 pbad_c = (BadGuy*) p_c_object;
1233 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1234 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1235 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1237 pbad_c->kill_me(25);
1240 // a held mriceblock kills the enemy too but falls to ground then
1241 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1243 pbad_c->kill_me(25);
1247 /* Kill badguys that run into exploding bomb */
1248 else if (kind == BAD_BOMB && dying == DYING_NOT)
1250 if (pbad_c->kind == BAD_MRBOMB)
1252 // mrbomb transforms into a bomb now
1253 pbad_c->explode(true);
1258 pbad_c->kill_me(50);
1262 /* Kill any badguys that get hit by stalactite */
1263 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1265 if (pbad_c->kind == BAD_MRBOMB)
1267 // mrbomb transforms into a bomb now
1268 pbad_c->explode(false);
1272 pbad_c->kill_me(50);
1275 /* When enemies run into eachother, make them change directions */
1278 // Wingling doesn't interact with other badguys
1279 if (pbad_c->kind == BAD_WINGLING || kind == BAD_WINGLING)
1282 // Jumpy, fish, flame, stalactites, wingling are exceptions
1283 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1284 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH
1285 || pbad_c->kind == BAD_FLAMEFISH)
1288 // Bounce off of other badguy if we land on top of him
1289 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1291 if (pbad_c->dir == LEFT)
1294 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1296 else if (pbad_c->dir == RIGHT)
1299 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1304 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1307 if (pbad_c->kind != BAD_FLAME)
1312 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1314 // Put bad guys a part (or they get jammed)
1315 // only needed to do to one of them
1316 if (physic.get_velocity_x() != 0)
1317 base.x = pbad_c->base.x + pbad_c->base.width + 1;
1319 else if (dir == RIGHT)
1322 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1331 Player* player = static_cast<Player*>(p_c_object);
1332 /* Get kicked if were flat */
1333 if (mode == FLAT && !dying)
1335 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1337 // Hit from left side
1338 if (player->base.x < base.x) {
1339 physic.set_velocity_x(5);
1342 // Hit from right side
1344 physic.set_velocity_x(-5);
1349 player->kick_timer.start(KICKING_TIME);
1350 set_action("flat-left", "flat-right");