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))
195 BadGuy::write(LispWriter& writer)
197 writer.start_list(badguykind_to_string(kind));
199 writer.write_float("x", base.x);
200 writer.write_float("y", base.y);
201 writer.write_bool("stay-on-platform", stay_on_platform);
203 writer.end_list(badguykind_to_string(kind));
207 BadGuy::activate(Direction activation_dir)
210 animation_offset = 0;
211 target.x = target.y = -1;
213 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");
264 base.x = start_position.x;
265 base.y = start_position.y;
273 // Set action as the "default" one.
274 specs->sprite->set_action("left");
276 specs->sprite->set_action("left-up");
277 else if(kind == BAD_BOMB)
278 specs->sprite->set_action("ticking-left");
279 else if(kind == BAD_FLAME)
280 specs->sprite->set_action("normal");
281 else if(kind == BAD_STALACTITE)
282 specs->sprite->set_action("normal");
283 else if(kind == BAD_FISH)
284 specs->sprite->set_action("normal");
285 else if(kind == BAD_FLAMEFISH)
286 specs->sprite->set_action("normal");
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", "right-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", "right-down");
485 else if (fabsf(vy) > 5.3f)
486 set_action("left-middle", "right-middle");
488 set_action("left-up", "right-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(dying == DYING_NOT)
511 if(tux.base.x > base.x)
518 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
519 if(dying == DYING_NOT)
520 collision_swept_object_map(&old_base, &base);
524 BadGuy::action_mrbomb(double elapsed_time)
526 if(frozen_timer.check())
528 set_action("iced-left", "iced-right");
532 if (dying == DYING_NOT)
533 check_horizontal_bump(true);
537 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
538 if (dying != DYING_FALLING)
539 collision_swept_object_map(&old_base,&base);
543 BadGuy::action_bomb(double elapsed_time)
545 static const int TICKINGTIME = 1000;
546 static const int EXPLODETIME = 1000;
552 timer.start(TICKINGTIME);
553 } else if(!timer.check()) {
554 if(mode == BOMB_TICKING) {
556 set_action("explosion", "explosion");
557 dying = DYING_NOT; // now the bomb hurts
558 timer.start(EXPLODETIME);
560 SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), this, Sector::current()->player->get_pos());
561 } else if(mode == BOMB_EXPLODE) {
568 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
569 collision_swept_object_map(&old_base,&base);
573 BadGuy::action_stalactite(double elapsed_time)
575 Player& tux = *Sector::current()->player;
577 static const int SHAKETIME = 800;
578 static const int RANGE = 40;
581 // start shaking when tux is below the stalactite and at least 40 pixels
583 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
584 && tux.base.y + tux.base.height > base.y
585 && tux.dying == DYING_NOT) {
586 timer.start(SHAKETIME);
587 mode = STALACTITE_SHAKING;
589 } if(mode == STALACTITE_SHAKING) {
590 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
592 mode = STALACTITE_FALL;
594 } else if(mode == STALACTITE_FALL) {
596 /* Destroy if we collides with land */
597 if(issolid(base.x+base.width/2, base.y+base.height))
600 dying = DYING_SQUISHED;
602 set_action("broken", "broken");
604 } else if(mode == FLAT) {
609 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
611 if(dying == DYING_SQUISHED && !timer.check())
616 BadGuy::action_flame(double elapsed_time)
618 static const float radius = 100;
619 static const float speed = 0.02;
620 base.x = old_base.x + cos(angle) * radius;
621 base.y = old_base.y + sin(angle) * radius;
623 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
627 BadGuy::action_fish(double elapsed_time)
629 if(frozen_timer.check())
631 if(physic.get_velocity_y() < 0)
632 set_action("iced-down", "iced-down");
634 set_action("iced", "iced");
639 static const float JUMPV = 6;
640 static const int WAITTIME = 1000;
642 // go in wait mode when back in water
643 if(dying == DYING_NOT
644 && gettile(base.x, base.y + base.height)
645 && gettile(base.x, base.y + base.height)->attributes & Tile::WATER
646 && physic.get_velocity_y() <= 0 && mode == NORMAL)
649 set_action("hide", "hide");
650 physic.set_velocity(0, 0);
651 physic.enable_gravity(false);
652 timer.start(WAITTIME);
654 else if(mode == FISH_WAIT && !timer.check())
657 set_action("normal", "normal");
659 physic.set_velocity(0, JUMPV);
660 physic.enable_gravity(true);
663 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
664 if(dying == DYING_NOT)
665 collision_swept_object_map(&old_base, &base);
667 if(physic.get_velocity_y() < 0)
669 set_action("down", "down");
674 BadGuy::action_bouncingsnowball(double elapsed_time)
676 static const float JUMPV = 4.5;
680 // jump when on ground
681 if(dying == DYING_NOT && issolid(base.x, base.y+32))
683 physic.set_velocity_y(JUMPV);
684 physic.enable_gravity(true);
691 // check for right/left collisions
692 check_horizontal_bump();
694 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
695 if(dying == DYING_NOT)
696 collision_swept_object_map(&old_base, &base);
698 // Handle dying timer:
699 if (dying == DYING_SQUISHED && !timer.check())
704 BadGuy::action_flyingsnowball(double elapsed_time)
706 static const float FLYINGSPEED = 1;
707 static const int DIRCHANGETIME = 1000;
709 // go into flyup mode if none specified yet
710 if(dying == DYING_NOT && mode == NORMAL) {
712 physic.set_velocity_y(FLYINGSPEED);
713 timer.start(DIRCHANGETIME/2);
716 if(dying == DYING_NOT && !timer.check()) {
719 physic.set_velocity_y(-FLYINGSPEED);
720 } else if(mode == FLY_DOWN) {
722 physic.set_velocity_y(FLYINGSPEED);
724 timer.start(DIRCHANGETIME);
727 if(dying != DYING_NOT)
728 physic.enable_gravity(true);
730 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
731 if(dying == DYING_NOT || dying == DYING_SQUISHED)
732 collision_swept_object_map(&old_base, &base);
734 if(dying == DYING_NOT)
736 // set direction based on tux
737 if(Sector::current()->player->base.x > base.x)
743 // Handle dying timer:
744 if (dying == DYING_SQUISHED && !timer.check())
749 BadGuy::action_spiky(double elapsed_time)
751 if(frozen_timer.check())
753 set_action("iced-left", "iced-right");
757 if (dying == DYING_NOT)
758 check_horizontal_bump();
762 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
763 if (dying != DYING_FALLING)
764 collision_swept_object_map(&old_base,&base);
768 BadGuy::action_snowball(double elapsed_time)
770 if (dying == DYING_NOT)
771 check_horizontal_bump();
775 // jump when we're about to fall
776 if (physic.get_velocity_y() == 0 &&
777 !issolid(base.x+base.width/2, base.y + base.height)) {
778 physic.enable_gravity(true);
779 physic.set_velocity_y(2);
782 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
783 if (dying != DYING_FALLING)
784 collision_swept_object_map(&old_base,&base);
786 // Handle dying timer:
787 if (dying == DYING_SQUISHED && !timer.check())
792 BadGuy::action_wingling(double elapsed_time)
794 if (dying != DYING_NOT)
795 physic.enable_gravity(true);
798 Player& tux = *Sector::current()->player;
799 int dirsign = physic.get_velocity_x() < 0 ? -1 : 1;
801 if (fabsf(tux.base.x - base.x) < 150 && base.y < tux.base.y && tux.dying == DYING_NOT)
803 if (target.x < 0 && target.y < 0)
805 target.x = tux.base.x;
806 target.y = tux.base.y;
807 physic.set_velocity(dirsign * 1.5f, -2.25f);
810 else if (base.y >= target.y - 16)
811 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
814 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
817 // Handle dying timer:
818 if (dying == DYING_SQUISHED && !timer.check())
821 // TODO: Winglings should be removed after flying off the screen
825 BadGuy::action_walkingtree(double elapsed_time)
827 if (dying == DYING_NOT)
828 check_horizontal_bump();
832 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
833 if (dying != DYING_FALLING)
834 collision_swept_object_map(&old_base,&base);
836 // Handle dying timer:
837 if (dying == DYING_SQUISHED && !timer.check())
842 BadGuy::action(float elapsed_time)
844 float scroll_x = Sector::current()->camera->get_translation().x;
845 float scroll_y = Sector::current()->camera->get_translation().y;
847 // BadGuy fall below the ground
848 if (base.y > Sector::current()->solids->get_height() * 32) {
853 // Kill us if we landed on spikes
854 if (dying == DYING_NOT
855 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
856 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
857 || isspike(base.x, base.y + base.height)
858 || isspike(base.x + base.width, base.y + base.height)))
860 physic.set_velocity_y(3);
866 /* Activate badguys if they're just around the screen to avoid
867 * the effect of having badguys suddenly popping up from nowhere.
869 if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
870 start_position.x < scroll_x - base.width &&
871 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
872 start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE)
874 else if (start_position.x > scroll_x + screen->w &&
875 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
876 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
877 start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE)
879 /* Special case for badguys on start of the level.
880 * If in the future, it's possible to set Tux start pos, this case
881 * should contemplate that. */
882 else if (start_position.x > 0 && start_position.x < screen->w &&
883 start_position.y > 0 && start_position.y < screen->h)
888 if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4
889 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4
890 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4
891 || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4)
894 if(dying != DYING_NOT)
905 action_mriceblock(elapsed_time);
909 action_jumpy(elapsed_time);
913 action_mrbomb(elapsed_time);
917 action_bomb(elapsed_time);
921 action_stalactite(elapsed_time);
925 action_flame(elapsed_time);
930 action_fish(elapsed_time);
933 case BAD_BOUNCINGSNOWBALL:
934 action_bouncingsnowball(elapsed_time);
937 case BAD_FLYINGSNOWBALL:
938 action_flyingsnowball(elapsed_time);
942 action_spiky(elapsed_time);
946 action_snowball(elapsed_time);
950 action_wingling(elapsed_time);
953 case BAD_WALKINGTREE:
954 action_walkingtree(elapsed_time);
963 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)
1220 BadGuy* pbad_c = NULL;
1221 Bullet* pbullet_c = NULL;
1223 if(type == COLLISION_BUMP) {
1228 if(type == COLLISION_SQUISH) {
1229 Player* player = static_cast<Player*>(p_c_object);
1234 /* COLLISION_NORMAL */
1238 pbullet_c = (Bullet*) p_c_object;
1240 if(pbullet_c->kind == FIRE_BULLET)
1242 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME
1243 && kind != BAD_FLAMEFISH)
1246 else if(pbullet_c->kind == ICE_BULLET)
1248 if(kind == BAD_FLAME || kind == BAD_FLAMEFISH)
1251 frozen_timer.start(FROZEN_TIME);
1256 pbad_c = (BadGuy*) p_c_object;
1259 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1260 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1261 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1263 pbad_c->kill_me(25);
1266 // a held mriceblock kills the enemy too but falls to ground then
1267 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1269 pbad_c->kill_me(25);
1273 /* Kill badguys that run into exploding bomb */
1274 else if (kind == BAD_BOMB && dying == DYING_NOT)
1276 if (pbad_c->kind == BAD_MRBOMB)
1278 // mrbomb transforms into a bomb now
1279 pbad_c->explode(true);
1284 pbad_c->kill_me(50);
1288 /* Kill any badguys that get hit by stalactite */
1289 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1291 if (pbad_c->kind == BAD_MRBOMB)
1293 // mrbomb transforms into a bomb now
1294 pbad_c->explode(false);
1298 pbad_c->kill_me(50);
1301 /* When enemies run into eachother, make them change directions */
1304 // Wingling doesn't interact with other badguys
1305 if (pbad_c->kind == BAD_WINGLING || kind == BAD_WINGLING)
1308 // Jumpy, fish, flame, stalactites, wingling are exceptions
1309 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1310 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH
1311 || pbad_c->kind == BAD_FLAMEFISH)
1314 // Bounce off of other badguy if we land on top of him
1315 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1317 if (pbad_c->dir == LEFT)
1320 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1322 else if (pbad_c->dir == RIGHT)
1325 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1330 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1333 if (pbad_c->kind != BAD_FLAME)
1338 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1340 // Put bad guys a part (or they get jammed)
1341 // only needed to do to one of them
1342 if (physic.get_velocity_x() != 0)
1343 base.x = pbad_c->base.x + pbad_c->base.width + 1;
1345 else if (dir == RIGHT)
1348 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1357 Player* player = static_cast<Player*>(p_c_object);
1358 /* Get kicked if were flat */
1359 if (mode == FLAT && !dying)
1361 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1363 // Hit from left side
1364 if (player->base.x < base.x) {
1365 physic.set_velocity_x(5);
1368 // Hit from right side
1370 physic.set_velocity_x(-5);
1375 player->kick_timer.start(KICKING_TIME);
1376 set_action("flat-left", "flat-right");