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
33 #include "resources.h"
34 #include "sprite_manager.h"
36 #include "display_manager.h"
37 #include "lispwriter.h"
40 Sprite* img_mriceblock_flat_left;
41 Sprite* img_mriceblock_flat_right;
42 Sprite* img_mriceblock_falling_left;
43 Sprite* img_mriceblock_falling_right;
44 Sprite* img_mriceblock_left;
45 Sprite* img_mriceblock_right;
46 Sprite* img_jumpy_left_up;
47 Sprite* img_jumpy_left_down;
48 Sprite* img_jumpy_left_middle;
49 Sprite* img_jumpy_left_iced;
50 Sprite* img_mrbomb_left;
51 Sprite* img_mrbomb_right;
52 Sprite* img_mrbomb_iced_left;
53 Sprite* img_mrbomb_iced_right;
54 Sprite* img_mrbomb_ticking_left;
55 Sprite* img_mrbomb_ticking_right;
56 Sprite* img_mrbomb_explosion;
57 Sprite* img_stalactite;
58 Sprite* img_stalactite_broken;
61 Sprite* img_fish_down;
62 Sprite* img_fish_iced;
63 Sprite* img_fish_iced_down;
64 Sprite* img_bouncingsnowball_left;
65 Sprite* img_bouncingsnowball_right;
66 Sprite* img_bouncingsnowball_squished;
67 Sprite* img_flyingsnowball;
68 Sprite* img_flyingsnowball_squished;
69 Sprite* img_spiky_left;
70 Sprite* img_spiky_right;
71 Sprite* img_spiky_iced_left;
72 Sprite* img_spiky_iced_right;
73 Sprite* img_snowball_left;
74 Sprite* img_snowball_right;
75 Sprite* img_snowball_squished_left;
76 Sprite* img_snowball_squished_right;
78 #define BADGUY_WALK_SPEED .8f
80 BadGuyKind badguykind_from_string(const std::string& str)
82 if (str == "money" || str == "jumpy") // was money in old maps
84 else if (str == "laptop" || str == "mriceblock") // was laptop in old maps
85 return BAD_MRICEBLOCK;
86 else if (str == "mrbomb")
88 else if (str == "stalactite")
89 return BAD_STALACTITE;
90 else if (str == "flame")
92 else if (str == "fish")
94 else if (str == "bouncingsnowball")
95 return BAD_BOUNCINGSNOWBALL;
96 else if (str == "flyingsnowball")
97 return BAD_FLYINGSNOWBALL;
98 else if (str == "spiky")
100 else if (str == "snowball" || str == "bsod") // was bsod in old maps
104 printf("Couldn't convert badguy: '%s'\n", str.c_str());
109 std::string badguykind_to_string(BadGuyKind kind)
131 case BAD_BOUNCINGSNOWBALL:
132 return "bouncingsnowball";
134 case BAD_FLYINGSNOWBALL:
135 return "flyingsnowball";
148 BadGuy::BadGuy(DisplayManager& display_manager, BadGuyKind kind_,
149 LispReader& lispreader)
150 : removable(false), squishcount(0)
152 display_manager.add_drawable(this, LAYER_OBJECTS);
154 lispreader.read_float("x", &start_position.x);
155 lispreader.read_float("y", &start_position.y);
159 stay_on_platform = false;
160 lispreader.read_bool("stay-on-platform", &stay_on_platform);
165 BadGuy::BadGuy(DisplayManager& display_manager, BadGuyKind kind_,
168 display_manager.add_drawable(this, LAYER_OBJECTS);
170 start_position.x = x;
171 start_position.y = y;
172 stay_on_platform = false;
196 animation_offset = 0;
197 sprite_left = sprite_right = 0;
199 frozen_timer.init(true);
202 // if we're in a solid tile at start correct that now
203 if(kind != BAD_FLAME && kind != BAD_FISH && collision_object_map(base))
205 std::cout << "Warning: badguy started in wall: kind: " << badguykind_to_string(kind)
206 << " pos: (" << base.x << ", " << base.y << ")" << std::endl;
207 while(collision_object_map(base))
211 // just activate the badguy, since he might be on screen already. If not he
212 // gets deactivated anyway
217 BadGuy::write(LispWriter& writer)
219 writer.start_list(badguykind_to_string(kind));
221 writer.write_float("x", base.x);
222 writer.write_float("y", base.y);
223 writer.write_bool("stay-on-platform", stay_on_platform);
225 writer.end_list(badguykind_to_string(kind));
229 BadGuy::activate(Direction activation_dir)
232 animation_offset = 0;
234 frozen_timer.init(true);
237 dir = activation_dir;
238 float dirsign = activation_dir == LEFT ? -1 : 1;
240 if(kind == BAD_MRBOMB) {
241 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
242 set_sprite(img_mrbomb_left, img_mrbomb_right);
243 } else if (kind == BAD_MRICEBLOCK) {
244 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
245 set_sprite(img_mriceblock_left, img_mriceblock_right);
246 } else if(kind == BAD_JUMPY) {
247 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
248 } else if(kind == BAD_BOMB) {
249 set_sprite(img_mrbomb_ticking_left, img_mrbomb_ticking_right);
250 // hack so that the bomb doesn't hurt until it expldes...
251 dying = DYING_SQUISHED;
252 } else if(kind == BAD_FLAME) {
254 physic.enable_gravity(false);
255 set_sprite(img_flame, img_flame);
256 } else if(kind == BAD_BOUNCINGSNOWBALL) {
257 physic.set_velocity(dirsign * 1.3, 0);
258 set_sprite(img_bouncingsnowball_left, img_bouncingsnowball_right);
259 } else if(kind == BAD_STALACTITE) {
260 physic.enable_gravity(false);
261 set_sprite(img_stalactite, img_stalactite);
262 } else if(kind == BAD_FISH) {
263 set_sprite(img_fish, img_fish);
264 physic.enable_gravity(true);
265 } else if(kind == BAD_FLYINGSNOWBALL) {
266 set_sprite(img_flyingsnowball, img_flyingsnowball);
267 physic.enable_gravity(false);
268 } else if(kind == BAD_SPIKY) {
269 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
270 set_sprite(img_spiky_left, img_spiky_right);
271 } else if(kind == BAD_SNOWBALL) {
272 physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
273 set_sprite(img_snowball_left, img_snowball_right);
276 base.x = start_position.x;
277 base.y = start_position.y;
283 BadGuy::action_mriceblock(double elapsed_time)
285 Player& tux = *World::current()->get_tux();
290 /* Move left/right: */
294 physic.apply(elapsed_time, base.x, base.y);
295 if (dying != DYING_FALLING)
296 collision_swept_object_map(&old_base,&base);
298 else if (mode == HELD)
299 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
300 /* If we're holding the iceblock */
304 base.x = tux.base.x + 16;
305 base.y = tux.base.y + tux.base.height/1.5 - base.height;
307 else /* facing left */
309 base.x = tux.base.x - 16;
310 base.y = tux.base.y + tux.base.height/1.5 - base.height;
312 if(collision_object_map(base))
315 base.y = tux.base.y + tux.base.height/1.5 - base.height;
318 if(tux.input.fire != DOWN) /* SHOOT! */
327 tux.kick_timer.start(KICKING_TIME);
328 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
329 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
330 play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
337 check_horizontal_bump();
338 if(mode == KICK && changed != dir)
340 float scroll_x = World::current()->camera->get_translation().x;
342 /* handle stereo sound (number 10 should be tweaked...)*/
343 if (base.x < scroll_x + screen->w/2 - 10)
344 play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
345 else if (base.x > scroll_x + screen->w/2 + 10)
346 play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
348 play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
352 /* Handle mode timer: */
358 set_sprite(img_mriceblock_left, img_mriceblock_right);
359 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
365 BadGuy::check_horizontal_bump(bool checkcliff)
367 float halfheight = base.height / 2;
368 if (dir == LEFT && issolid( base.x, (int) base.y + halfheight))
370 if (kind == BAD_MRICEBLOCK && mode == KICK)
371 World::current()->trybreakbrick(base.x, (int) base.y + halfheight, false);
374 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
377 if (dir == RIGHT && issolid( base.x + base.width, (int)base.y + halfheight))
379 if (kind == BAD_MRICEBLOCK && mode == KICK)
380 World::current()->trybreakbrick(base.x + base.width, (int) base.y + halfheight, false);
383 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
387 // don't check for cliffs when we're falling
390 if(!issolid(base.x + base.width/2, base.y + base.height))
393 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
396 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
399 if(dir == RIGHT && !issolid(base.x + base.width,
400 (int) base.y + base.height + halfheight))
403 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
411 /* Fall if we get off the ground: */
412 if (dying != DYING_FALLING)
414 if (!issolid(base.x+base.width/2, base.y + base.height))
416 // not solid below us? enable gravity
417 physic.enable_gravity(true);
422 if (physic.get_velocity_y() < 0)
424 base.y = int((base.y + base.height)/32) * 32 - base.height;
425 physic.set_velocity_y(0);
427 // no gravity anymore please
428 physic.enable_gravity(false);
430 if (stay_on_platform && mode == NORMAL)
432 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
433 base.y + base.height))
438 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
443 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
451 physic.enable_gravity(true);
456 BadGuy::action_jumpy(double elapsed_time)
458 if(frozen_timer.check())
460 set_sprite(img_jumpy_left_iced, img_jumpy_left_iced);
464 const float vy = physic.get_velocity_y();
466 // XXX: These tests *should* use location from ground, not velocity
467 if (fabsf(vy) > 5.6f)
468 set_sprite(img_jumpy_left_down, img_jumpy_left_down);
469 else if (fabsf(vy) > 5.3f)
470 set_sprite(img_jumpy_left_middle, img_jumpy_left_middle);
472 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
474 Player& tux = *World::current()->get_tux();
476 static const float JUMPV = 6;
479 // jump when on ground
480 if(dying == DYING_NOT && issolid(base.x, base.y+32))
482 physic.set_velocity_y(JUMPV);
483 physic.enable_gravity(true);
487 else if(mode == JUMPY_JUMP)
492 // set direction based on tux
493 if(tux.base.x > base.x)
499 physic.apply(elapsed_time, base.x, base.y);
500 if(dying == DYING_NOT)
501 collision_swept_object_map(&old_base, &base);
505 BadGuy::action_mrbomb(double elapsed_time)
507 if(frozen_timer.check())
509 set_sprite(img_mrbomb_iced_left, img_mrbomb_iced_right);
513 if (dying == DYING_NOT)
514 check_horizontal_bump(true);
518 physic.apply(elapsed_time, base.x, base.y);
519 if (dying != DYING_FALLING)
520 collision_swept_object_map(&old_base,&base);
524 BadGuy::action_bomb(double elapsed_time)
526 static const int TICKINGTIME = 1000;
527 static const int EXPLODETIME = 1000;
533 timer.start(TICKINGTIME);
534 } else if(!timer.check()) {
535 if(mode == BOMB_TICKING) {
537 set_sprite(img_mrbomb_explosion, img_mrbomb_explosion);
538 dying = DYING_NOT; // now the bomb hurts
539 timer.start(EXPLODETIME);
541 float scroll_x = World::current()->camera->get_translation().x;
543 /* play explosion sound */ // FIXME: is the stereo all right? maybe we should use player cordinates...
544 if (base.x < scroll_x + screen->w/2 - 10)
545 play_sound(sounds[SND_EXPLODE], SOUND_LEFT_SPEAKER);
546 else if (base.x > scroll_x + screen->w/2 + 10)
547 play_sound(sounds[SND_EXPLODE], SOUND_RIGHT_SPEAKER);
549 play_sound(sounds[SND_EXPLODE], SOUND_CENTER_SPEAKER);
551 } else if(mode == BOMB_EXPLODE) {
558 physic.apply(elapsed_time, base.x, base.y);
559 collision_swept_object_map(&old_base,&base);
563 BadGuy::action_stalactite(double elapsed_time)
565 Player& tux = *World::current()->get_tux();
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 timer.start(SHAKETIME);
576 mode = STALACTITE_SHAKING;
578 } if(mode == STALACTITE_SHAKING) {
579 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
581 mode = STALACTITE_FALL;
583 } else if(mode == STALACTITE_FALL) {
585 /* Destroy if we collides with land */
586 if(issolid(base.x+base.width/2, base.y+base.height))
589 dying = DYING_SQUISHED;
591 set_sprite(img_stalactite_broken, img_stalactite_broken);
593 } else if(mode == FLAT) {
598 physic.apply(elapsed_time, base.x, base.y);
600 if(dying == DYING_SQUISHED && !timer.check())
605 BadGuy::action_flame(double elapsed_time)
607 static const float radius = 100;
608 static const float speed = 0.02;
609 base.x = old_base.x + cos(angle) * radius;
610 base.y = old_base.y + sin(angle) * radius;
612 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
616 BadGuy::action_fish(double elapsed_time)
618 if(frozen_timer.check())
620 if(physic.get_velocity_y() < 0)
621 set_sprite(img_fish_iced_down, img_fish_iced_down);
623 set_sprite(img_fish_iced, img_fish_iced);
628 static const float JUMPV = 6;
629 static const int WAITTIME = 1000;
631 // go in wait mode when back in water
632 if(dying == DYING_NOT && gettile(base.x, base.y+ base.height)->water
633 && physic.get_velocity_y() <= 0 && mode == NORMAL)
637 physic.set_velocity(0, 0);
638 physic.enable_gravity(false);
639 timer.start(WAITTIME);
641 else if(mode == FISH_WAIT && !timer.check())
644 set_sprite(img_fish, img_fish);
646 physic.set_velocity(0, JUMPV);
647 physic.enable_gravity(true);
650 physic.apply(elapsed_time, base.x, base.y);
651 if(dying == DYING_NOT)
652 collision_swept_object_map(&old_base, &base);
654 if(physic.get_velocity_y() < 0)
655 set_sprite(img_fish_down, img_fish_down);
659 BadGuy::action_bouncingsnowball(double elapsed_time)
661 static const float JUMPV = 4.5;
665 // jump when on ground
666 if(dying == DYING_NOT && issolid(base.x, base.y+32))
668 physic.set_velocity_y(JUMPV);
669 physic.enable_gravity(true);
676 // check for right/left collisions
677 check_horizontal_bump();
679 physic.apply(elapsed_time, base.x, base.y);
680 if(dying == DYING_NOT)
681 collision_swept_object_map(&old_base, &base);
683 // Handle dying timer:
684 if (dying == DYING_SQUISHED && !timer.check())
689 BadGuy::action_flyingsnowball(double elapsed_time)
691 static const float FLYINGSPEED = 1;
692 static const int DIRCHANGETIME = 1000;
694 // go into flyup mode if none specified yet
695 if(dying == DYING_NOT && mode == NORMAL) {
697 physic.set_velocity_y(FLYINGSPEED);
698 timer.start(DIRCHANGETIME/2);
701 if(dying == DYING_NOT && !timer.check()) {
704 physic.set_velocity_y(-FLYINGSPEED);
705 } else if(mode == FLY_DOWN) {
707 physic.set_velocity_y(FLYINGSPEED);
709 timer.start(DIRCHANGETIME);
712 if(dying != DYING_NOT)
713 physic.enable_gravity(true);
715 physic.apply(elapsed_time, base.x, base.y);
716 if(dying == DYING_NOT || dying == DYING_SQUISHED)
717 collision_swept_object_map(&old_base, &base);
719 // Handle dying timer:
720 if (dying == DYING_SQUISHED && !timer.check())
725 BadGuy::action_spiky(double elapsed_time)
727 if(frozen_timer.check())
729 set_sprite(img_spiky_iced_left, img_spiky_iced_right);
733 if (dying == DYING_NOT)
734 check_horizontal_bump();
738 // jump when we're about to fall
739 if (physic.get_velocity_y() == 0 &&
740 !issolid(base.x+base.width/2, base.y + base.height)) {
741 physic.enable_gravity(true);
742 physic.set_velocity_y(2);
746 physic.apply(elapsed_time, base.x, base.y);
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 physic.apply(elapsed_time, base.x, base.y);
760 if (dying != DYING_FALLING)
761 collision_swept_object_map(&old_base,&base);
763 // Handle dying timer:
764 if (dying == DYING_SQUISHED && !timer.check())
769 BadGuy::action(float elapsed_time)
771 float scroll_x = World::current()->camera->get_translation().x;
772 float scroll_y = World::current()->camera->get_translation().y;
774 // BadGuy fall below the ground
775 if (base.y > World::current()->get_level()->height * 32) {
780 // Kill us if we landed on spikes
781 if (dying == DYING_NOT
782 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
783 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
784 || isspike(base.x, base.y + base.height)
785 || isspike(base.x + base.width, base.y + base.height)))
787 physic.set_velocity_y(3);
792 /* activate badguys if they're just inside the offscreen_distance around the
793 * screen. Don't activate them inside the screen, since that might have the
794 * effect of badguys suddenly popping up from nowhere
796 if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
797 start_position.x < scroll_x - base.width)
799 else if(start_position.x > scroll_y - Y_OFFSCREEN_DISTANCE &&
800 start_position.y < scroll_y - base.height)
802 else if(start_position.x > scroll_x + screen->w &&
803 start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE)
805 else if(start_position.y > scroll_y + screen->h &&
806 start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
809 if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE
810 || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE
811 || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE
812 || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE) {
814 if(dying != DYING_NOT)
825 action_mriceblock(elapsed_time);
829 action_jumpy(elapsed_time);
833 action_mrbomb(elapsed_time);
837 action_bomb(elapsed_time);
841 action_stalactite(elapsed_time);
845 action_flame(elapsed_time);
849 action_fish(elapsed_time);
852 case BAD_BOUNCINGSNOWBALL:
853 action_bouncingsnowball(elapsed_time);
856 case BAD_FLYINGSNOWBALL:
857 action_flyingsnowball(elapsed_time);
861 action_spiky(elapsed_time);
865 action_snowball(elapsed_time);
873 BadGuy::draw(Camera& viewport, int)
875 float scroll_x = viewport.get_translation().x;
876 float scroll_y = viewport.get_translation().y;
878 // Don't try to draw stuff that is outside of the screen
879 if(base.x <= scroll_x - base.width || base.x >= scroll_x + screen->w)
882 if(sprite_left == 0 || sprite_right == 0)
887 Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right;
888 sprite->draw(viewport.world2screen(Vector(base.x, base.y)));
891 fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75,0,75, 150);
895 BadGuy::set_sprite(Sprite* left, Sprite* right)
904 // FIXME: Using the image size for the physics and collision is
905 // a bad idea, since images should always overlap there physical
908 if(base.width == 0 && base.height == 0) {
909 base.width = left->get_width();
910 base.height = left->get_height();
911 } else if(base.width != left->get_width() || base.height != left->get_height()) {
912 base.x -= (left->get_width() - base.width) / 2;
913 base.y -= left->get_height() - base.height;
914 base.width = left->get_width();
915 base.height = left->get_height();
919 base.width = base.height = 0;
923 animation_offset = 0;
925 sprite_right = right;
931 // these can't be bumped
932 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
933 || kind == BAD_FLYINGSNOWBALL)
936 physic.set_velocity_y(3);
941 BadGuy::make_player_jump(Player* player)
943 player->physic.set_velocity_y(2);
944 player->base.y = base.y - player->base.height - 2;
948 BadGuy::squish_me(Player* player)
950 make_player_jump(player);
952 World::current()->add_score(Vector(base.x, base.y),
953 50 * player_status.score_multiplier);
954 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
955 player_status.score_multiplier++;
957 dying = DYING_SQUISHED;
959 physic.set_velocity(0, 0);
963 BadGuy::squish(Player* player)
965 static const int MAX_ICEBLOCK_SQUICHES = 10;
967 if(kind == BAD_MRBOMB) {
968 // mrbomb transforms into a bomb now
971 make_player_jump(player);
972 World::current()->add_score(Vector(base.x, base.y),
973 50 * player_status.score_multiplier);
974 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
975 player_status.score_multiplier++;
978 } else if (kind == BAD_MRICEBLOCK) {
979 if (mode == NORMAL || mode == KICK)
982 play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
984 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
985 physic.set_velocity_x(0);
988 } else if (mode == FLAT) {
990 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
992 if (player->base.x < base.x + (base.width/2)) {
993 physic.set_velocity_x(5);
996 physic.set_velocity_x(-5);
1001 player->kick_timer.start(KICKING_TIME);
1002 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
1005 make_player_jump(player);
1007 player_status.score_multiplier++;
1009 // check for maximum number of squishes
1011 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
1017 } else if(kind == BAD_FISH) {
1018 // fish can only be killed when falling down
1019 if(physic.get_velocity_y() >= 0)
1022 make_player_jump(player);
1024 World::current()->add_score(Vector(base.x, base.y),
1025 25 * player_status.score_multiplier);
1026 player_status.score_multiplier++;
1028 // simply remove the fish...
1031 } else if(kind == BAD_BOUNCINGSNOWBALL) {
1033 set_sprite(img_bouncingsnowball_squished,img_bouncingsnowball_squished);
1035 } else if(kind == BAD_FLYINGSNOWBALL) {
1037 set_sprite(img_flyingsnowball_squished,img_flyingsnowball_squished);
1039 } else if(kind == BAD_SNOWBALL) {
1041 set_sprite(img_snowball_squished_left, img_snowball_squished_right);
1047 BadGuy::kill_me(int score)
1049 if(kind == BAD_BOMB)
1052 dying = DYING_FALLING;
1053 if(kind == BAD_MRICEBLOCK) {
1054 set_sprite(img_mriceblock_falling_left, img_mriceblock_falling_right);
1057 Player& tux = *World::current()->get_tux();
1058 tux.holding_something = false;
1062 physic.enable_gravity(true);
1064 /* Gain some points: */
1066 World::current()->add_score(Vector(base.x, base.y),
1067 score * player_status.score_multiplier);
1069 /* Play death sound: */
1070 play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
1076 World::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
1081 BadGuy::collision(const MovingObject&, int)
1087 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1089 BadGuy* pbad_c = NULL;
1090 Bullet* pbullet_c = NULL;
1092 if(type == COLLISION_BUMP) {
1097 if(type == COLLISION_SQUISH) {
1098 Player* player = static_cast<Player*>(p_c_object);
1103 /* COLLISION_NORMAL */
1107 pbullet_c = (Bullet*) p_c_object;
1109 if(pbullet_c->kind == FIRE_BULLET)
1111 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME)
1114 else if(pbullet_c->kind == ICE_BULLET)
1116 //if(kind == BAD_FLAME)
1119 frozen_timer.start(FROZEN_TIME);
1124 pbad_c = (BadGuy*) p_c_object;
1126 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1127 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1128 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1130 pbad_c->kill_me(25);
1133 // a held mriceblock kills the enemy too but falls to ground then
1134 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1136 pbad_c->kill_me(25);
1140 /* Kill badguys that run into exploding bomb */
1141 else if (kind == BAD_BOMB && dying == DYING_NOT)
1143 if (pbad_c->kind == BAD_MRBOMB)
1145 // mrbomb transforms into a bomb now
1149 else if (pbad_c->kind != BAD_MRBOMB)
1151 pbad_c->kill_me(50);
1155 /* Kill any badguys that get hit by stalactite */
1156 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1158 if (pbad_c->kind == BAD_MRBOMB)
1160 // mrbomb transforms into a bomb now
1165 pbad_c->kill_me(50);
1168 /* When enemies run into eachother, make them change directions */
1171 // Jumpy, fish, flame, stalactites are exceptions
1172 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1173 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH)
1176 // Bounce off of other badguy if we land on top of him
1177 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1179 if (pbad_c->dir == LEFT)
1182 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1184 else if (pbad_c->dir == RIGHT)
1187 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1192 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1195 if (pbad_c->kind != BAD_FLAME)
1200 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1202 // in case badguys get "jammed"
1203 if (physic.get_velocity_x() != 0)
1204 base.x = pbad_c->base.x + pbad_c->base.width;
1206 else if (dir == RIGHT)
1209 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1218 Player* player = static_cast<Player*>(p_c_object);
1219 /* Get kicked if were flat */
1220 if (mode == FLAT && !dying)
1222 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
1224 // Hit from left side
1225 if (player->base.x < base.x) {
1226 physic.set_velocity_x(5);
1229 // Hit from right side
1231 physic.set_velocity_x(-5);
1236 player->kick_timer.start(KICKING_TIME);
1237 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
1245 //---------------------------------------------------------------------------
1247 void load_badguy_gfx()
1249 img_mriceblock_flat_left = sprite_manager->load("mriceblock-flat-left");
1250 img_mriceblock_flat_right = sprite_manager->load("mriceblock-flat-right");
1251 img_mriceblock_falling_left = sprite_manager->load("mriceblock-falling-left");
1252 img_mriceblock_falling_right = sprite_manager->load("mriceblock-falling-right");
1253 img_mriceblock_left = sprite_manager->load("mriceblock-left");
1254 img_mriceblock_right = sprite_manager->load("mriceblock-right");
1255 img_jumpy_left_up = sprite_manager->load("jumpy-left-up");
1256 img_jumpy_left_down = sprite_manager->load("jumpy-left-down");
1257 img_jumpy_left_middle = sprite_manager->load("jumpy-left-middle");
1258 img_jumpy_left_iced = sprite_manager->load("jumpy-left-iced");
1259 img_mrbomb_left = sprite_manager->load("mrbomb-left");
1260 img_mrbomb_right = sprite_manager->load("mrbomb-right");
1261 img_mrbomb_iced_left = sprite_manager->load("mrbomb-iced-left");
1262 img_mrbomb_iced_right = sprite_manager->load("mrbomb-iced-right");
1263 img_mrbomb_ticking_left = sprite_manager->load("mrbomb-ticking-left");
1264 img_mrbomb_ticking_right = sprite_manager->load("mrbomb-ticking-right");
1265 img_mrbomb_explosion = sprite_manager->load("mrbomb-explosion");
1266 img_stalactite = sprite_manager->load("stalactite");
1267 img_stalactite_broken = sprite_manager->load("stalactite-broken");
1268 img_flame = sprite_manager->load("flame");
1269 img_fish = sprite_manager->load("fish");
1270 img_fish_down = sprite_manager->load("fish-down");
1271 img_fish_iced = sprite_manager->load("fish-iced");
1272 img_fish_iced_down = sprite_manager->load("fish-iced-down");
1273 img_bouncingsnowball_left = sprite_manager->load("bouncingsnowball-left");
1274 img_bouncingsnowball_right = sprite_manager->load("bouncingsnowball-right");
1275 img_bouncingsnowball_squished = sprite_manager->load("bouncingsnowball-squished");
1276 img_flyingsnowball = sprite_manager->load("flyingsnowball");
1277 img_flyingsnowball_squished = sprite_manager->load("flyingsnowball-squished");
1278 img_spiky_left = sprite_manager->load("spiky-left");
1279 img_spiky_right = sprite_manager->load("spiky-right");
1280 img_spiky_iced_left = sprite_manager->load("spiky-iced-left");
1281 img_spiky_iced_right = sprite_manager->load("spiky-iced-right");
1282 img_snowball_left = sprite_manager->load("snowball-left");
1283 img_snowball_right = sprite_manager->load("snowball-right");
1284 img_snowball_squished_left = sprite_manager->load("snowball-squished-left");
1285 img_snowball_squished_right = sprite_manager->load("snowball-squished-right");
1288 void free_badguy_gfx()