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
28 #include "app/globals.h"
30 #include "special/sprite_manager.h"
31 #include "utils/lispwriter.h"
34 #include "resources.h"
39 #include "statistics.h"
40 #include "badguy_specs.h"
42 #define BADGUY_WALK_SPEED .8f
43 #define WINGLING_FLY_SPEED 1.6f
45 BadGuyKind badguykind_from_string(const std::string& str)
47 if (str == "jumpy" || str == "money") // was "money" in ancient versions
49 else if (str == "mriceblock" || str == "laptop") // was "laptop" in ancient versions
50 return BAD_MRICEBLOCK;
51 else if (str == "mrbomb")
53 else if (str == "stalactite")
54 return BAD_STALACTITE;
55 else if (str == "flame")
57 else if (str == "fish")
59 else if (str == "flamefish")
61 else if (str == "bouncingsnowball")
62 return BAD_BOUNCINGSNOWBALL;
63 else if (str == "flyingsnowball")
64 return BAD_FLYINGSNOWBALL;
65 else if (str == "spiky")
67 else if (str == "snowball" || str == "bsod") // was "bsod" in ancient versions
69 else if (str == "wingling")
71 else if (str == "walkingtree")
72 return BAD_WALKINGTREE;
73 else if(str == "bomb") // not to be used as a real bad guys
81 std::string badguykind_to_string(BadGuyKind kind)
106 case BAD_BOUNCINGSNOWBALL:
107 return "bouncingsnowball";
109 case BAD_FLYINGSNOWBALL:
110 return "flyingsnowball";
121 case BAD_WALKINGTREE:
122 return "walkingtree";
123 case BAD_BOMB: // not to be used as a real bad guys
132 BadGuy::BadGuy(BadGuyKind kind_, LispReader& lispreader)
135 lispreader.read_float("x", start_position.x);
136 lispreader.read_float("y", start_position.y);
140 stay_on_platform = false;
141 lispreader.read_bool("stay-on-platform", stay_on_platform);
146 BadGuy::BadGuy(BadGuyKind kind_, float x, float y)
149 start_position.x = x;
150 start_position.y = y;
151 stay_on_platform = false;
165 bbox.set_pos(start_position);
166 bbox.set_size(32, 32);
172 animation_offset = 0;
173 target.x = target.y = -1;
175 frozen_timer.init(true);
178 specs = badguyspecs_manager->load(badguykind_to_string(kind));
182 BadGuy::write(LispWriter& writer)
184 writer.start_list(badguykind_to_string(kind));
186 writer.write_float("x", base.x);
187 writer.write_float("y", base.y);
188 writer.write_bool("stay-on-platform", stay_on_platform);
190 writer.end_list(badguykind_to_string(kind));
194 BadGuy::activate(Direction activation_dir)
197 animation_offset = 0;
198 target.x = target.y = -1;
200 frozen_timer.start(0);
206 dir = activation_dir;
207 float dirsign = activation_dir == LEFT ? -1 : 1;
209 set_action("left", "right");
210 if(kind == BAD_MRBOMB) {
211 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
212 } else if (kind == BAD_MRICEBLOCK) {
213 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
214 } else if(kind == BAD_JUMPY) {
215 set_action("left-up", "right-up");
216 } else if(kind == BAD_BOMB) {
217 set_action("ticking-left", "ticking-right");
218 // hack so that the bomb doesn't hurt until it explodes...
219 dying = DYING_SQUISHED;
220 } else if(kind == BAD_FLAME) {
222 physic.enable_gravity(false);
223 set_action("normal", "normal");
224 } else if(kind == BAD_BOUNCINGSNOWBALL) {
225 physic.set_velocity(dirsign * 1.3, 0);
226 } else if(kind == BAD_STALACTITE) {
227 physic.enable_gravity(false);
228 set_action("normal", "normal");
229 } else if(kind == BAD_FISH) {
230 set_action("normal", "normal");
231 physic.enable_gravity(true);
232 } else if(kind == BAD_FLAMEFISH) {
233 set_action("normal", "normal");
234 physic.enable_gravity(true);
235 } else if(kind == BAD_FLYINGSNOWBALL) {
236 physic.enable_gravity(false);
237 } else if(kind == BAD_SPIKY) {
238 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
239 } else if(kind == BAD_SNOWBALL) {
240 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
241 } else if(kind == BAD_WINGLING) {
242 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
243 physic.enable_gravity(false);
244 set_action("left", "left");
245 } else if (kind == BAD_WALKINGTREE) {
246 // TODO: why isn't the height/width being set properly in set_action?
247 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
249 set_action("left", "left");
250 bbox.set_size(66, 66);
257 // Set action as the "default" one.
258 specs->sprite->set_action("left");
260 specs->sprite->set_action("left-up");
261 else if(kind == BAD_BOMB)
262 specs->sprite->set_action("ticking-left");
263 else if(kind == BAD_FLAME)
264 specs->sprite->set_action("normal");
265 else if(kind == BAD_STALACTITE)
266 specs->sprite->set_action("normal");
267 else if(kind == BAD_FISH)
268 specs->sprite->set_action("normal");
269 else if(kind == BAD_FLAMEFISH)
270 specs->sprite->set_action("normal");
272 return specs->sprite->get_frame(0);
277 BadGuy::action_mriceblock(double elapsed_time)
279 Player& tux = *Sector::current()->player;
284 /* Move left/right: */
288 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
289 if (dying != DYING_FALLING)
290 collision_swept_object_map(&old_base,&base);
292 else if (state == HELD)
293 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
294 /* If we're holding the iceblock */
296 if(tux.size == SMALL)
299 base.x = tux.base.x + 24;
301 base.x = tux.base.x - 12;
302 base.y = tux.base.y + tux.base.height/1.5 - base.height;
307 base.x = tux.base.x + 24;
309 base.x = tux.base.x - 4;
310 base.y = tux.base.y + tux.base.height/1.5 - base.height;
313 if(collision_object_map(base))
316 base.y = tux.base.y + tux.base.height/1.5 - base.height;
319 if(tux.input.fire != DOWN) /* SHOOT! */
322 base.x = tux.base.x - base.width;
324 base.x = tux.base.x + tux.base.width;
328 tux.kick_timer.start(KICKING_TIME);
329 set_action("flat-left", "flat-right");
330 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
331 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
338 check_horizontal_bump();
339 if(state == KICK && changed != dir)
341 SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(), Sector::current()->player->get_pos());
345 /* Handle state timer: */
351 set_action("left", "right");
352 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
358 BadGuy::check_horizontal_bump(bool checkcliff)
360 float halfheight = base.height / 2;
361 if (dir == LEFT && issolid( base.x, base.y + halfheight))
363 if (kind == BAD_MRICEBLOCK && state == KICK)
365 Sector::current()->trybreakbrick(Vector(base.x, base.y + halfheight), false);
366 Sector::current()->tryemptybox(Vector(base.x, base.y + halfheight), dir);
370 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
373 if (dir == RIGHT && issolid( base.x + base.width, base.y + halfheight))
375 if (kind == BAD_MRICEBLOCK && state == KICK)
377 Sector::current()->trybreakbrick(
378 Vector(base.x + base.width, base.y + halfheight), false);
379 Sector::current()->tryemptybox(
380 Vector(base.x + base.width, base.y + halfheight), dir);
384 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
388 // don't check for cliffs when we're falling
391 if(!issolid(base.x + base.width/2, base.y + base.height))
394 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
397 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
400 if(dir == RIGHT && !issolid(base.x + base.width,
401 (int) base.y + base.height + halfheight))
404 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
412 /* Fall if we get off the ground: */
413 if (dying != DYING_FALLING)
415 if (!issolid(base.x+base.width/2, base.y + base.height))
417 // not solid below us? enable gravity
418 physic.enable_gravity(true);
423 if (physic.get_velocity_y() < 0)
425 base.y = int((base.y + base.height)/32) * 32 - base.height;
426 physic.set_velocity_y(0);
428 // no gravity anymore please
429 physic.enable_gravity(false);
431 if (stay_on_platform && state == NORMAL)
433 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
434 base.y + base.height))
439 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
444 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
452 physic.enable_gravity(true);
458 BadGuy::action_jumpy(double elapsed_time)
460 if(frozen_timer.check()) {
461 set_action("left-iced", "right-iced");
465 const float vy = physic.get_velocity_y();
467 // XXX: These tests *should* use location from ground, not velocity
469 set_action("left-down", "right-down");
470 else if (fabsf(vy) > 530)
471 set_action("left-middle", "right-middle");
473 set_action("left-up", "right-up");
475 Player& tux = *Sector::current()->player;
477 static const float JUMPV = 6;
480 // jump when on ground
481 if(dying == DYING_NOT && issolid(base.x, base.y+32))
483 physic.set_velocity_y(JUMPV);
484 physic.enable_gravity(true);
488 else if(state == JUMPY_JUMP)
493 // set direction based on tux
494 if(dying == DYING_NOT) {
495 if(tux.base.x > base.x)
502 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
503 if(dying == DYING_NOT)
504 collision_swept_object_map(&old_base, &base);
508 BadGuy::action_mrbomb(double elapsed_time)
510 if(frozen_timer.check())
512 set_action("iced-left", "iced-right");
516 if (dying == DYING_NOT)
517 check_horizontal_bump(true);
521 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
522 if (dying != DYING_FALLING)
523 collision_swept_object_map(&old_base,&base);
527 BadGuy::action_bomb(double elapsed_time)
529 static const int TICKINGTIME = 1000;
530 static const int EXPLODETIME = 1000;
534 if(state == NORMAL) {
535 state = BOMB_TICKING;
536 timer.start(TICKINGTIME);
537 } else if(!timer.check()) {
538 if(state == BOMB_TICKING) {
539 state = BOMB_EXPLODE;
540 set_action("explosion", "explosion");
541 dying = DYING_NOT; // now the bomb hurts
542 timer.start(EXPLODETIME);
544 SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), this, Sector::current()->player->get_pos());
545 } else if(state == BOMB_EXPLODE) {
552 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
553 collision_swept_object_map(&old_base,&base);
557 BadGuy::action_stalactite(double elapsed_time)
559 Player& tux = *Sector::current()->player;
561 static const int SHAKETIME = 800;
562 static const int RANGE = 40;
564 if(state == NORMAL) {
565 // start shaking when tux is below the stalactite and at least 40 pixels
567 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
568 && tux.base.y + tux.base.height > base.y
569 && tux.dying == DYING_NOT) {
570 timer.start(SHAKETIME);
571 state = STALACTITE_SHAKING;
573 } if(state == STALACTITE_SHAKING) {
574 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
576 state = STALACTITE_FALL;
578 } else if(state == STALACTITE_FALL) {
580 /* Destroy if we collides with land */
581 if(issolid(base.x+base.width/2, base.y+base.height))
584 dying = DYING_SQUISHED;
586 set_action("broken", "broken");
588 } else if(state == FLAT) {
593 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
595 if(dying == DYING_SQUISHED && !timer.check())
600 BadGuy::action_flame(double elapsed_time)
602 static const float radius = 100;
603 static const float speed = 0.02;
604 base.x = old_base.x + cos(angle) * radius;
605 base.y = old_base.y + sin(angle) * radius;
607 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
611 BadGuy::action_fish(double elapsed_time)
613 if(frozen_timer.check())
615 if(physic.get_velocity_y() < 0)
616 set_action("iced-down", "iced-down");
618 set_action("iced", "iced");
623 static const float JUMPV = 6;
624 static const int WAITTIME = 1000;
626 // go in wait state when back in water
627 if(dying == DYING_NOT
628 && gettile(base.x, base.y + base.height)
629 && gettile(base.x, base.y + base.height)->attributes & Tile::WATER
630 && physic.get_velocity_y() <= 0 && state == NORMAL)
633 set_action("hide", "hide");
634 physic.set_velocity(0, 0);
635 physic.enable_gravity(false);
636 timer.start(WAITTIME);
638 else if(state == FISH_WAIT && !timer.check())
641 set_action("normal", "normal");
643 physic.set_velocity(0, JUMPV);
644 physic.enable_gravity(true);
647 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
648 if(dying == DYING_NOT)
649 collision_swept_object_map(&old_base, &base);
651 if(physic.get_velocity_y() < 0)
653 set_action("down", "down");
658 BadGuy::action_bouncingsnowball(double elapsed_time)
660 static const float JUMPV = 4.5;
664 // jump when on ground
665 if(dying == DYING_NOT && issolid(base.x, base.y+32))
667 physic.set_velocity_y(JUMPV);
668 physic.enable_gravity(true);
675 // check for right/left collisions
676 check_horizontal_bump();
678 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
679 if(dying == DYING_NOT)
680 collision_swept_object_map(&old_base, &base);
682 // Handle dying timer:
683 if (dying == DYING_SQUISHED && !timer.check())
688 BadGuy::action_flyingsnowball(double elapsed_time)
690 static const float FLYINGSPEED = 1;
691 static const int DIRCHANGETIME = 1000;
693 // go into flyup state if none specified yet
694 if(dying == DYING_NOT && state == NORMAL) {
696 physic.set_velocity_y(FLYINGSPEED);
697 timer.start(DIRCHANGETIME/2);
700 if(dying == DYING_NOT && !timer.check()) {
701 if(state == FLY_UP) {
703 physic.set_velocity_y(-FLYINGSPEED);
704 } else if(state == FLY_DOWN) {
706 physic.set_velocity_y(FLYINGSPEED);
708 timer.start(DIRCHANGETIME);
711 if(dying != DYING_NOT)
712 physic.enable_gravity(true);
714 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
715 if(dying == DYING_NOT || dying == DYING_SQUISHED)
716 collision_swept_object_map(&old_base, &base);
718 if(dying == DYING_NOT)
720 // set direction based on tux
721 if(Sector::current()->player->base.x > base.x)
727 // Handle dying timer:
728 if (dying == DYING_SQUISHED && !timer.check())
733 BadGuy::action_spiky(double elapsed_time)
735 if(frozen_timer.check())
737 set_action("iced-left", "iced-right");
741 if (dying == DYING_NOT)
742 check_horizontal_bump();
746 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
747 if (dying != DYING_FALLING)
748 collision_swept_object_map(&old_base,&base);
752 BadGuy::action_snowball(double elapsed_time)
754 if (dying == DYING_NOT)
755 check_horizontal_bump();
759 // jump when we're about to fall
760 if (physic.get_velocity_y() == 0 &&
761 !issolid(base.x+base.width/2, base.y + base.height)) {
762 physic.enable_gravity(true);
763 physic.set_velocity_y(2);
766 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
767 if (dying != DYING_FALLING)
768 collision_swept_object_map(&old_base,&base);
770 // Handle dying timer:
771 if (dying == DYING_SQUISHED && !timer.check())
776 BadGuy::action_wingling(double elapsed_time)
778 if (dying != DYING_NOT)
779 physic.enable_gravity(true);
782 Player& tux = *Sector::current()->player;
783 int dirsign = physic.get_velocity_x() < 0 ? -1 : 1;
785 if (fabsf(tux.base.x - base.x) < 150 && base.y < tux.base.y && tux.dying == DYING_NOT)
787 if (target.x < 0 && target.y < 0)
789 target.x = tux.base.x;
790 target.y = tux.base.y;
791 physic.set_velocity(dirsign * 1.5f, -2.25f);
794 else if (base.y >= target.y - 16)
795 physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0);
798 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
801 // Handle dying timer:
802 if (dying == DYING_SQUISHED && !timer.check())
805 // TODO: Winglings should be removed after flying off the screen
809 BadGuy::action_walkingtree(double elapsed_time)
811 if (dying == DYING_NOT)
812 check_horizontal_bump();
816 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
817 if (dying != DYING_FALLING)
818 collision_swept_object_map(&old_base,&base);
820 // Handle dying timer:
821 if (dying == DYING_SQUISHED && !timer.check())
826 BadGuy::action(float elapsed_time)
828 float scroll_x = Sector::current()->camera->get_translation().x;
829 float scroll_y = Sector::current()->camera->get_translation().y;
831 // BadGuy fall below the ground
832 if (base.y > Sector::current()->solids->get_height() * 32) {
837 // Kill us if we landed on spikes
838 if (dying == DYING_NOT
839 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
840 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
841 || isspike(base.x, base.y + base.height)
842 || isspike(base.x + base.width, base.y + base.height)))
844 physic.set_velocity_y(3);
850 /* Activate badguys if they're just around the screen to avoid
851 * the effect of having badguys suddenly popping up from nowhere.
853 if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
854 start_position.x < scroll_x - base.width &&
855 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
856 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
858 else if (start_position.x > scroll_x + screen->w &&
859 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
860 start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
861 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
863 else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
864 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
865 ((start_position.y > scroll_y + screen->h &&
866 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE) ||
867 (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
868 start_position.y < scroll_y)))
870 if(start_position.x < scroll_x - screen->w/2)
875 /* Special case for badguys on start of the level.
876 * If in the future, it's possible to set Tux start pos, this case
877 * should contemplate that. */
878 else if (start_position.x > 0 && start_position.x < screen->w &&
879 start_position.y > 0 && start_position.y < screen->h)
884 if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4
885 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4
886 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4
887 || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4)
890 if(dying != DYING_NOT)
901 action_mriceblock(elapsed_time);
905 action_jumpy(elapsed_time);
909 action_mrbomb(elapsed_time);
913 action_bomb(elapsed_time);
917 action_stalactite(elapsed_time);
921 action_flame(elapsed_time);
926 action_fish(elapsed_time);
929 case BAD_BOUNCINGSNOWBALL:
930 action_bouncingsnowball(elapsed_time);
933 case BAD_FLYINGSNOWBALL:
934 action_flyingsnowball(elapsed_time);
938 action_spiky(elapsed_time);
942 action_snowball(elapsed_time);
946 action_wingling(elapsed_time);
949 case BAD_WALKINGTREE:
950 action_walkingtree(elapsed_time);
959 BadGuy::draw(DrawingContext& context)
964 if((dir == LEFT && action_left == "hide") ||
965 (dir == RIGHT && action_right == "hide"))
969 specs->sprite->set_action(action_left);
970 else // if(dir == RIGHT)
971 specs->sprite->set_action(action_right);
973 if(dying == DYING_FALLING && physic.get_velocity_y() < 0)
974 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_FOREGROUNDTILES+1, VERTICAL_FLIP);
976 specs->sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
979 context.draw_filled_rect(Vector(base.x, base.y),
980 Vector(base.width, base.height), Color(75,0,75, 150), LAYER_OBJECTS+1);
984 BadGuy::set_action(std::string left, std::string right)
990 action_right = right;
1000 // FIXME: Using the image size for the physics and collision is
1001 // a bad idea, since images should always overlap their physical
1004 if(base.width == 0 && base.height == 0) {
1005 base.width = left->get_width();
1006 base.height = left->get_height();
1007 } else if(base.width != left->get_width() || base.height != left->get_height()) {
1008 base.x -= (left->get_width() - base.width) / 2;
1009 base.y -= left->get_height() - base.height;
1010 base.width = left->get_width();
1011 base.height = left->get_height();
1015 base.width = base.height = 0;
1019 animation_offset = 0;
1021 sprite_right = right;
1028 // these can't be bumped
1029 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
1030 || kind == BAD_FLAMEFISH || kind == BAD_FLYINGSNOWBALL)
1033 physic.set_velocity_y(3);
1038 BadGuy::squish_me(Player* player)
1040 player->bounce(this);
1042 Sector::current()->add_score(Vector(base.x, base.y),
1043 25 * player_status.score_multiplier);
1045 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1046 player_status.score_multiplier++;
1048 dying = DYING_SQUISHED;
1050 physic.set_velocity(0, 0);
1054 BadGuy::squish(Player* player)
1056 static const int MAX_ICEBLOCK_SQUICHES = 10;
1058 if(kind == BAD_MRBOMB) {
1059 // mrbomb transforms into a bomb now
1062 player->bounce(this);
1063 Sector::current()->add_score(Vector(base.x, base.y),
1064 25 * player_status.score_multiplier);
1065 SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
1067 player_status.score_multiplier++;
1070 } else if (kind == BAD_MRICEBLOCK) {
1071 if (state == NORMAL || state == KICK)
1074 SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(), Sector::current()->player->get_pos());
1076 set_action("flat-left", "flat-right");
1077 physic.set_velocity_x(0);
1080 } else if (state == FLAT) {
1082 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1084 if (player->base.x < base.x + (base.width/2)) {
1085 physic.set_velocity_x(5);
1088 physic.set_velocity_x(-5);
1093 player->kick_timer.start(KICKING_TIME);
1094 set_action("flat-left", "flat-right");
1097 player->bounce(this);
1099 player_status.score_multiplier++;
1101 // check for maximum number of squishes
1103 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
1109 } else if(kind == BAD_FISH || kind == BAD_FLAMEFISH) {
1110 // fish can only be killed when falling down
1111 if(physic.get_velocity_y() >= 0)
1114 player->bounce(this);
1116 Sector::current()->add_score(Vector(base.x, base.y),
1117 25 * player_status.score_multiplier);
1119 player_status.score_multiplier++;
1121 // simply remove the fish...
1124 } else if(kind == BAD_BOUNCINGSNOWBALL) {
1126 set_action("squished", "squished");
1128 } else if(kind == BAD_FLYINGSNOWBALL) {
1130 set_action("squished-left", "squished-right");
1132 } else if(kind == BAD_SNOWBALL) {
1134 set_action("squished-left", "squished-right");
1136 } else if(kind == BAD_WINGLING) {
1138 set_action("left", "right");
1139 } else if(kind == BAD_WALKINGTREE) {
1140 if (state == BGM_BIG)
1142 set_action("left-small", "left-small");
1143 physic.set_velocity_x(physic.get_velocity_x() * 2.0f);
1145 /* Move to the player's direction */
1146 if(dir != Sector::current()->player->dir)
1147 physic.set_velocity_x(-physic.get_velocity_x());
1148 dir = Sector::current()->player->dir;
1150 // XXX magic number: 66 is BGM_BIG height
1152 player->bounce(this);
1153 base.y += 66 - base.height;
1155 Sector::current()->add_score(Vector(base.x, base.y),
1156 25 * player_status.score_multiplier);
1157 player_status.score_multiplier++;
1167 BadGuy::kill_me(int score)
1169 if(kind == BAD_BOMB)
1173 global_stats.add_points(BADGUYS_KILLED_STAT, 1);
1175 dying = DYING_FALLING;
1176 if(kind == BAD_MRICEBLOCK) {
1177 set_action("falling-left", "falling-right");
1180 Player& tux = *Sector::current()->player;
1181 tux.holding_something = false;
1185 physic.enable_gravity(true);
1187 /* Gain some points: */
1189 Sector::current()->add_score(Vector(base.x, base.y),
1190 score * player_status.score_multiplier);
1192 /* Play death sound: */
1193 SoundManager::get()->play_sound(IDToSound(SND_FALL), this, Sector::current()->player->get_pos());
1197 BadGuy::explode(bool right_way)
1199 BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB, true);
1202 badguy->timer.start(0);
1203 badguy->state = BOMB_TICKING;
1211 BadGuy::collision(const MovingObject&, int)
1217 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1219 BadGuy* pbad_c = NULL;
1220 Bullet* pbullet_c = NULL;
1222 if(type == COLLISION_BUMP) {
1227 if(type == COLLISION_SQUISH) {
1228 Player* player = static_cast<Player*>(p_c_object);
1233 /* COLLISION_NORMAL */
1237 pbullet_c = (Bullet*) p_c_object;
1239 if(pbullet_c->kind == FIRE_BULLET)
1241 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME
1242 && kind != BAD_FLAMEFISH)
1245 else if(pbullet_c->kind == ICE_BULLET)
1247 if(kind == BAD_FLAME || kind == BAD_FLAMEFISH)
1250 frozen_timer.start(FROZEN_TIME);
1255 pbad_c = (BadGuy*) p_c_object;
1258 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1259 if(kind == BAD_MRICEBLOCK && state == KICK &&
1260 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1262 pbad_c->kill_me(25);
1265 // a held mriceblock kills the enemy too but falls to ground then
1266 else if(kind == BAD_MRICEBLOCK && state == HELD)
1268 pbad_c->kill_me(25);
1272 /* Kill badguys that run into exploding bomb */
1273 else if (kind == BAD_BOMB && dying == DYING_NOT)
1275 if (pbad_c->kind == BAD_MRBOMB)
1277 // mrbomb transforms into a bomb now
1278 pbad_c->explode(true);
1283 pbad_c->kill_me(50);
1287 /* Kill any badguys that get hit by stalactite */
1288 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1290 if (pbad_c->kind == BAD_MRBOMB)
1292 // mrbomb transforms into a bomb now
1293 pbad_c->explode(false);
1297 pbad_c->kill_me(50);
1300 /* When enemies run into eachother, make them change directions */
1303 // Wingling doesn't interact with other badguys
1304 if (pbad_c->kind == BAD_WINGLING || kind == BAD_WINGLING)
1307 // Jumpy, fish, flame, stalactites, wingling are exceptions
1308 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1309 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH
1310 || pbad_c->kind == BAD_FLAMEFISH)
1313 // Bounce off of other badguy if we land on top of him
1314 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1316 if (pbad_c->dir == LEFT)
1319 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1321 else if (pbad_c->dir == RIGHT)
1324 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1329 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1332 if (pbad_c->kind != BAD_FLAME)
1337 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1339 // Put bad guys a part (or they get jammed)
1340 // only needed to do to one of them
1341 if (physic.get_velocity_x() != 0)
1342 base.x = pbad_c->base.x + pbad_c->base.width + 1;
1344 else if (dir == RIGHT)
1347 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1356 Player* player = static_cast<Player*>(p_c_object);
1357 /* Get kicked if were flat */
1358 if (state == FLAT && !dying)
1360 SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos());
1362 // Hit from left side
1363 if (player->base.x < base.x) {
1364 physic.set_velocity_x(5);
1367 // Hit from right side
1369 physic.set_velocity_x(-5);
1374 player->kick_timer.start(KICKING_TIME);
1375 set_action("flat-left", "flat-right");