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);
156 lispreader.read_float("x", &base.x);
157 lispreader.read_float("y", &base.y);
163 stay_on_platform = false;
164 lispreader.read_bool("stay-on-platform", &stay_on_platform);
169 BadGuy::BadGuy(DisplayManager& display_manager, BadGuyKind kind_,
172 display_manager.add_drawable(this, LAYER_OBJECTS);
178 stay_on_platform = false;
197 frozen_timer.init(true);
198 animation_offset = 0;
199 sprite_left = sprite_right = 0;
203 if(kind == BAD_MRBOMB) {
204 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
205 set_sprite(img_mrbomb_left, img_mrbomb_right);
206 } else if (kind == BAD_MRICEBLOCK) {
207 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
208 set_sprite(img_mriceblock_left, img_mriceblock_right);
209 } else if(kind == BAD_JUMPY) {
210 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
211 } else if(kind == BAD_BOMB) {
212 set_sprite(img_mrbomb_ticking_left, img_mrbomb_ticking_right);
213 // hack so that the bomb doesn't hurt until it expldes...
214 dying = DYING_SQUISHED;
215 } else if(kind == BAD_FLAME) {
217 physic.enable_gravity(false);
218 set_sprite(img_flame, img_flame);
219 } else if(kind == BAD_BOUNCINGSNOWBALL) {
220 physic.set_velocity(-1.3, 0);
221 set_sprite(img_bouncingsnowball_left, img_bouncingsnowball_right);
222 } else if(kind == BAD_STALACTITE) {
223 physic.enable_gravity(false);
224 set_sprite(img_stalactite, img_stalactite);
225 } else if(kind == BAD_FISH) {
226 set_sprite(img_fish, img_fish);
227 physic.enable_gravity(true);
228 } else if(kind == BAD_FLYINGSNOWBALL) {
229 set_sprite(img_flyingsnowball, img_flyingsnowball);
230 physic.enable_gravity(false);
231 } else if(kind == BAD_SPIKY) {
232 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
233 set_sprite(img_spiky_left, img_spiky_right);
234 } else if(kind == BAD_SNOWBALL) {
235 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
236 set_sprite(img_snowball_left, img_snowball_right);
239 // if we're in a solid tile at start correct that now
240 if(kind != BAD_FLAME && kind != BAD_FISH && collision_object_map(base))
242 std::cout << "Warning: badguy started in wall: kind: " << badguykind_to_string(kind)
243 << " pos: (" << base.x << ", " << base.y << ")" << std::endl;
244 while(collision_object_map(base))
250 BadGuy::write(LispWriter& writer)
252 writer.start_list(badguykind_to_string(kind));
254 writer.write_float("x", base.x);
255 writer.write_float("y", base.y);
256 writer.write_bool("stay-on-platform", stay_on_platform);
258 writer.end_list(badguykind_to_string(kind));
262 BadGuy::action_mriceblock(double elapsed_time)
264 Player& tux = *World::current()->get_tux();
269 /* Move left/right: */
273 physic.apply(elapsed_time, base.x, base.y);
274 if (dying != DYING_FALLING)
275 collision_swept_object_map(&old_base,&base);
277 else if (mode == HELD)
278 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
279 /* If we're holding the iceblock */
283 base.x = tux.base.x + 16;
284 base.y = tux.base.y + tux.base.height/1.5 - base.height;
286 else /* facing left */
288 base.x = tux.base.x - 16;
289 base.y = tux.base.y + tux.base.height/1.5 - base.height;
291 if(collision_object_map(base))
294 base.y = tux.base.y + tux.base.height/1.5 - base.height;
297 if(tux.input.fire != DOWN) /* SHOOT! */
306 tux.kick_timer.start(KICKING_TIME);
307 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
308 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
309 play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
316 check_horizontal_bump();
317 if(mode == KICK && changed != dir)
319 float scroll_x = World::current()->camera->get_translation().x;
321 /* handle stereo sound (number 10 should be tweaked...)*/
322 if (base.x < scroll_x + screen->w/2 - 10)
323 play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
324 else if (base.x > scroll_x + screen->w/2 + 10)
325 play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
327 play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
331 /* Handle mode timer: */
337 set_sprite(img_mriceblock_left, img_mriceblock_right);
338 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
344 BadGuy::check_horizontal_bump(bool checkcliff)
346 float halfheight = base.height / 2;
347 if (dir == LEFT && issolid( base.x, (int) base.y + halfheight))
349 if (kind == BAD_MRICEBLOCK && mode == KICK)
350 World::current()->trybreakbrick(base.x, (int) base.y + halfheight, false);
353 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
356 if (dir == RIGHT && issolid( base.x + base.width, (int)base.y + halfheight))
358 if (kind == BAD_MRICEBLOCK && mode == KICK)
359 World::current()->trybreakbrick(base.x + base.width, (int) base.y + halfheight, false);
362 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
366 // don't check for cliffs when we're falling
369 if(!issolid(base.x + base.width/2, base.y + base.height))
372 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
375 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
378 if(dir == RIGHT && !issolid(base.x + base.width,
379 (int) base.y + base.height + halfheight))
382 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
390 /* Fall if we get off the ground: */
391 if (dying != DYING_FALLING)
393 if (!issolid(base.x+base.width/2, base.y + base.height))
395 // not solid below us? enable gravity
396 physic.enable_gravity(true);
401 if (physic.get_velocity_y() < 0)
403 base.y = int((base.y + base.height)/32) * 32 - base.height;
404 physic.set_velocity_y(0);
406 // no gravity anymore please
407 physic.enable_gravity(false);
409 if (stay_on_platform && mode == NORMAL)
411 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
412 base.y + base.height))
417 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
422 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
430 physic.enable_gravity(true);
435 BadGuy::action_jumpy(double elapsed_time)
437 if(frozen_timer.check())
439 set_sprite(img_jumpy_left_iced, img_jumpy_left_iced);
443 const float vy = physic.get_velocity_y();
445 // XXX: These tests *should* use location from ground, not velocity
446 if (fabsf(vy) > 5.6f)
447 set_sprite(img_jumpy_left_down, img_jumpy_left_down);
448 else if (fabsf(vy) > 5.3f)
449 set_sprite(img_jumpy_left_middle, img_jumpy_left_middle);
451 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
453 Player& tux = *World::current()->get_tux();
455 static const float JUMPV = 6;
458 // jump when on ground
459 if(dying == DYING_NOT && issolid(base.x, base.y+32))
461 physic.set_velocity_y(JUMPV);
462 physic.enable_gravity(true);
466 else if(mode == JUMPY_JUMP)
471 // set direction based on tux
472 if(tux.base.x > base.x)
478 physic.apply(elapsed_time, base.x, base.y);
479 if(dying == DYING_NOT)
480 collision_swept_object_map(&old_base, &base);
484 BadGuy::action_mrbomb(double elapsed_time)
486 if(frozen_timer.check())
488 set_sprite(img_mrbomb_iced_left, img_mrbomb_iced_right);
492 if (dying == DYING_NOT)
493 check_horizontal_bump(true);
497 physic.apply(elapsed_time, base.x, base.y);
498 if (dying != DYING_FALLING)
499 collision_swept_object_map(&old_base,&base);
503 BadGuy::action_bomb(double elapsed_time)
505 static const int TICKINGTIME = 1000;
506 static const int EXPLODETIME = 1000;
512 timer.start(TICKINGTIME);
513 } else if(!timer.check()) {
514 if(mode == BOMB_TICKING) {
516 set_sprite(img_mrbomb_explosion, img_mrbomb_explosion);
517 dying = DYING_NOT; // now the bomb hurts
518 timer.start(EXPLODETIME);
520 float scroll_x = World::current()->camera->get_translation().x;
522 /* play explosion sound */ // FIXME: is the stereo all right? maybe we should use player cordinates...
523 if (base.x < scroll_x + screen->w/2 - 10)
524 play_sound(sounds[SND_EXPLODE], SOUND_LEFT_SPEAKER);
525 else if (base.x > scroll_x + screen->w/2 + 10)
526 play_sound(sounds[SND_EXPLODE], SOUND_RIGHT_SPEAKER);
528 play_sound(sounds[SND_EXPLODE], SOUND_CENTER_SPEAKER);
530 } else if(mode == BOMB_EXPLODE) {
537 physic.apply(elapsed_time, base.x, base.y);
538 collision_swept_object_map(&old_base,&base);
542 BadGuy::action_stalactite(double elapsed_time)
544 Player& tux = *World::current()->get_tux();
546 static const int SHAKETIME = 800;
547 static const int RANGE = 40;
550 // start shaking when tux is below the stalactite and at least 40 pixels
552 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
553 && tux.base.y + tux.base.height > base.y) {
554 timer.start(SHAKETIME);
555 mode = STALACTITE_SHAKING;
557 } if(mode == STALACTITE_SHAKING) {
558 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
560 mode = STALACTITE_FALL;
562 } else if(mode == STALACTITE_FALL) {
564 /* Destroy if we collides with land */
565 if(issolid(base.x+base.width/2, base.y+base.height))
568 dying = DYING_SQUISHED;
570 set_sprite(img_stalactite_broken, img_stalactite_broken);
572 } else if(mode == FLAT) {
577 physic.apply(elapsed_time, base.x, base.y);
579 if(dying == DYING_SQUISHED && !timer.check())
584 BadGuy::action_flame(double elapsed_time)
586 static const float radius = 100;
587 static const float speed = 0.02;
588 base.x = old_base.x + cos(angle) * radius;
589 base.y = old_base.y + sin(angle) * radius;
591 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
595 BadGuy::action_fish(double elapsed_time)
597 if(frozen_timer.check())
599 if(physic.get_velocity_y() < 0)
600 set_sprite(img_fish_iced_down, img_fish_iced_down);
602 set_sprite(img_fish_iced, img_fish_iced);
607 static const float JUMPV = 6;
608 static const int WAITTIME = 1000;
610 // go in wait mode when back in water
611 if(dying == DYING_NOT && gettile(base.x, base.y+ base.height)->water
612 && physic.get_velocity_y() <= 0 && mode == NORMAL)
616 physic.set_velocity(0, 0);
617 physic.enable_gravity(false);
618 timer.start(WAITTIME);
620 else if(mode == FISH_WAIT && !timer.check())
623 set_sprite(img_fish, img_fish);
625 physic.set_velocity(0, JUMPV);
626 physic.enable_gravity(true);
629 physic.apply(elapsed_time, base.x, base.y);
630 if(dying == DYING_NOT)
631 collision_swept_object_map(&old_base, &base);
633 if(physic.get_velocity_y() < 0)
634 set_sprite(img_fish_down, img_fish_down);
638 BadGuy::action_bouncingsnowball(double elapsed_time)
640 static const float JUMPV = 4.5;
644 // jump when on ground
645 if(dying == DYING_NOT && issolid(base.x, base.y+32))
647 physic.set_velocity_y(JUMPV);
648 physic.enable_gravity(true);
655 // check for right/left collisions
656 check_horizontal_bump();
658 physic.apply(elapsed_time, base.x, base.y);
659 if(dying == DYING_NOT)
660 collision_swept_object_map(&old_base, &base);
662 // Handle dying timer:
663 if (dying == DYING_SQUISHED && !timer.check())
665 /* Remove it if time's up: */
672 BadGuy::action_flyingsnowball(double elapsed_time)
674 static const float FLYINGSPEED = 1;
675 static const int DIRCHANGETIME = 1000;
677 // go into flyup mode if none specified yet
678 if(dying == DYING_NOT && mode == NORMAL) {
680 physic.set_velocity_y(FLYINGSPEED);
681 timer.start(DIRCHANGETIME/2);
684 if(dying == DYING_NOT && !timer.check()) {
687 physic.set_velocity_y(-FLYINGSPEED);
688 } else if(mode == FLY_DOWN) {
690 physic.set_velocity_y(FLYINGSPEED);
692 timer.start(DIRCHANGETIME);
695 if(dying != DYING_NOT)
696 physic.enable_gravity(true);
698 physic.apply(elapsed_time, base.x, base.y);
699 if(dying == DYING_NOT || dying == DYING_SQUISHED)
700 collision_swept_object_map(&old_base, &base);
702 // Handle dying timer:
703 if (dying == DYING_SQUISHED && !timer.check())
705 /* Remove it if time's up: */
712 BadGuy::action_spiky(double elapsed_time)
714 if(frozen_timer.check())
716 set_sprite(img_spiky_iced_left, img_spiky_iced_right);
720 if (dying == DYING_NOT)
721 check_horizontal_bump();
725 // jump when we're about to fall
726 if (physic.get_velocity_y() == 0 &&
727 !issolid(base.x+base.width/2, base.y + base.height)) {
728 physic.enable_gravity(true);
729 physic.set_velocity_y(2);
733 physic.apply(elapsed_time, base.x, base.y);
734 if (dying != DYING_FALLING)
735 collision_swept_object_map(&old_base,&base);
739 BadGuy::action_snowball(double elapsed_time)
741 if (dying == DYING_NOT)
742 check_horizontal_bump();
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(float elapsed_time)
754 float scroll_x = World::current()->camera->get_translation().x;
755 float scroll_y = World::current()->camera->get_translation().y;
757 // BadGuy fall below the ground
758 if (base.y > World::current()->get_level()->height * 32) {
763 // Kill us if we landed on spikes
764 if (dying == DYING_NOT
765 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
766 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
767 || isspike(base.x, base.y + base.height)
768 || isspike(base.x + base.width, base.y + base.height)))
770 physic.set_velocity_y(3);
774 // Once it's on screen, it's activated!
775 if (base.x > scroll_x - X_OFFSCREEN_DISTANCE &&
776 base.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
777 base.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
778 base.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
787 action_mriceblock(elapsed_time);
791 action_jumpy(elapsed_time);
795 action_mrbomb(elapsed_time);
799 action_bomb(elapsed_time);
803 action_stalactite(elapsed_time);
807 action_flame(elapsed_time);
811 action_fish(elapsed_time);
814 case BAD_BOUNCINGSNOWBALL:
815 action_bouncingsnowball(elapsed_time);
818 case BAD_FLYINGSNOWBALL:
819 action_flyingsnowball(elapsed_time);
823 action_spiky(elapsed_time);
827 action_snowball(elapsed_time);
835 BadGuy::draw(Camera& viewport, int)
837 float scroll_x = viewport.get_translation().x;
838 float scroll_y = viewport.get_translation().y;
840 // Don't try to draw stuff that is outside of the screen
841 if(base.x <= scroll_x - base.width || base.x >= scroll_x + screen->w)
844 if(sprite_left == 0 || sprite_right == 0)
849 Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right;
850 sprite->draw(viewport.world2screen(Vector(base.x, base.y)));
853 fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75,0,75, 150);
857 BadGuy::set_sprite(Sprite* left, Sprite* right)
866 // FIXME: Using the image size for the physics and collision is
867 // a bad idea, since images should always overlap there physical
870 if(base.width == 0 && base.height == 0) {
871 base.width = left->get_width();
872 base.height = left->get_height();
873 } else if(base.width != left->get_width() || base.height != left->get_height()) {
874 base.x -= (left->get_width() - base.width) / 2;
875 base.y -= left->get_height() - base.height;
876 base.width = left->get_width();
877 base.height = left->get_height();
881 base.width = base.height = 0;
885 animation_offset = 0;
887 sprite_right = right;
893 // these can't be bumped
894 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
895 || kind == BAD_FLYINGSNOWBALL)
898 physic.set_velocity_y(3);
903 BadGuy::make_player_jump(Player* player)
905 player->physic.set_velocity_y(2);
906 player->base.y = base.y - player->base.height - 2;
910 BadGuy::squish_me(Player* player)
912 make_player_jump(player);
914 World::current()->add_score(Vector(base.x, base.y),
915 50 * player_status.score_multiplier);
916 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
917 player_status.score_multiplier++;
919 dying = DYING_SQUISHED;
921 physic.set_velocity(0, 0);
925 BadGuy::squish(Player* player)
927 static const int MAX_ICEBLOCK_SQUICHES = 10;
929 if(kind == BAD_MRBOMB) {
930 // mrbomb transforms into a bomb now
933 make_player_jump(player);
934 World::current()->add_score(Vector(base.x, base.y),
935 50 * player_status.score_multiplier);
936 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
937 player_status.score_multiplier++;
940 } else if (kind == BAD_MRICEBLOCK) {
941 if (mode == NORMAL || mode == KICK)
944 play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
946 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
947 physic.set_velocity_x(0);
950 } else if (mode == FLAT) {
952 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
954 if (player->base.x < base.x + (base.width/2)) {
955 physic.set_velocity_x(5);
958 physic.set_velocity_x(-5);
963 player->kick_timer.start(KICKING_TIME);
964 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
967 make_player_jump(player);
969 player_status.score_multiplier++;
971 // check for maximum number of squiches
973 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
979 } else if(kind == BAD_FISH) {
980 // fish can only be killed when falling down
981 if(physic.get_velocity_y() >= 0)
984 make_player_jump(player);
986 World::current()->add_score(Vector(base.x, base.y),
987 25 * player_status.score_multiplier);
988 player_status.score_multiplier++;
990 // simply remove the fish...
993 } else if(kind == BAD_BOUNCINGSNOWBALL) {
995 set_sprite(img_bouncingsnowball_squished,img_bouncingsnowball_squished);
997 } else if(kind == BAD_FLYINGSNOWBALL) {
999 set_sprite(img_flyingsnowball_squished,img_flyingsnowball_squished);
1001 } else if(kind == BAD_SNOWBALL) {
1003 set_sprite(img_snowball_squished_left, img_snowball_squished_right);
1009 BadGuy::kill_me(int score)
1011 if(kind == BAD_BOMB)
1014 dying = DYING_FALLING;
1015 if(kind == BAD_MRICEBLOCK) {
1016 set_sprite(img_mriceblock_falling_left, img_mriceblock_falling_right);
1019 Player& tux = *World::current()->get_tux();
1020 tux.holding_something = false;
1024 physic.enable_gravity(true);
1026 /* Gain some points: */
1028 World::current()->add_score(Vector(base.x, base.y),
1029 score * player_status.score_multiplier);
1031 /* Play death sound: */
1032 play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
1038 World::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
1043 BadGuy::collision(const MovingObject&, int)
1049 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1051 BadGuy* pbad_c = NULL;
1052 Bullet* pbullet_c = NULL;
1054 if(type == COLLISION_BUMP) {
1059 if(type == COLLISION_SQUISH) {
1060 Player* player = static_cast<Player*>(p_c_object);
1065 /* COLLISION_NORMAL */
1069 pbullet_c = (Bullet*) p_c_object;
1071 if(pbullet_c->kind == FIRE_BULLET)
1073 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME)
1076 else if(pbullet_c->kind == ICE_BULLET)
1078 //if(kind == BAD_FLAME)
1081 frozen_timer.start(FROZEN_TIME);
1086 pbad_c = (BadGuy*) p_c_object;
1088 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1089 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1090 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1092 pbad_c->kill_me(25);
1095 // a held mriceblock kills the enemy too but falls to ground then
1096 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1098 pbad_c->kill_me(25);
1102 /* Kill badguys that run into exploding bomb */
1103 else if (kind == BAD_BOMB && dying == DYING_NOT)
1105 if (pbad_c->kind == BAD_MRBOMB)
1107 // mrbomb transforms into a bomb now
1111 else if (pbad_c->kind != BAD_MRBOMB)
1113 pbad_c->kill_me(50);
1117 /* Kill any badguys that get hit by stalactite */
1118 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1120 if (pbad_c->kind == BAD_MRBOMB)
1122 // mrbomb transforms into a bomb now
1127 pbad_c->kill_me(50);
1130 /* When enemies run into eachother, make them change directions */
1133 // Jumpy, fish, flame, stalactites are exceptions
1134 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1135 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH)
1138 // Bounce off of other badguy if we land on top of him
1139 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1141 if (pbad_c->dir == LEFT)
1144 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1146 else if (pbad_c->dir == RIGHT)
1149 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1154 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1157 if (pbad_c->kind != BAD_FLAME)
1162 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1164 // in case badguys get "jammed"
1165 if (physic.get_velocity_x() != 0)
1166 base.x = pbad_c->base.x + pbad_c->base.width;
1168 else if (dir == RIGHT)
1171 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1180 Player* player = static_cast<Player*>(p_c_object);
1181 /* Get kicked if were flat */
1182 if (mode == FLAT && !dying)
1184 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
1186 // Hit from left side
1187 if (player->base.x < base.x) {
1188 physic.set_velocity_x(5);
1191 // Hit from right side
1193 physic.set_velocity_x(-5);
1198 player->kick_timer.start(KICKING_TIME);
1199 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
1207 //---------------------------------------------------------------------------
1209 void load_badguy_gfx()
1211 img_mriceblock_flat_left = sprite_manager->load("mriceblock-flat-left");
1212 img_mriceblock_flat_right = sprite_manager->load("mriceblock-flat-right");
1213 img_mriceblock_falling_left = sprite_manager->load("mriceblock-falling-left");
1214 img_mriceblock_falling_right = sprite_manager->load("mriceblock-falling-right");
1215 img_mriceblock_left = sprite_manager->load("mriceblock-left");
1216 img_mriceblock_right = sprite_manager->load("mriceblock-right");
1217 img_jumpy_left_up = sprite_manager->load("jumpy-left-up");
1218 img_jumpy_left_down = sprite_manager->load("jumpy-left-down");
1219 img_jumpy_left_middle = sprite_manager->load("jumpy-left-middle");
1220 img_jumpy_left_iced = sprite_manager->load("jumpy-left-iced");
1221 img_mrbomb_left = sprite_manager->load("mrbomb-left");
1222 img_mrbomb_right = sprite_manager->load("mrbomb-right");
1223 img_mrbomb_iced_left = sprite_manager->load("mrbomb-iced-left");
1224 img_mrbomb_iced_right = sprite_manager->load("mrbomb-iced-right");
1225 img_mrbomb_ticking_left = sprite_manager->load("mrbomb-ticking-left");
1226 img_mrbomb_ticking_right = sprite_manager->load("mrbomb-ticking-right");
1227 img_mrbomb_explosion = sprite_manager->load("mrbomb-explosion");
1228 img_stalactite = sprite_manager->load("stalactite");
1229 img_stalactite_broken = sprite_manager->load("stalactite-broken");
1230 img_flame = sprite_manager->load("flame");
1231 img_fish = sprite_manager->load("fish");
1232 img_fish_down = sprite_manager->load("fish-down");
1233 img_fish_iced = sprite_manager->load("fish-iced");
1234 img_fish_iced_down = sprite_manager->load("fish-iced-down");
1235 img_bouncingsnowball_left = sprite_manager->load("bouncingsnowball-left");
1236 img_bouncingsnowball_right = sprite_manager->load("bouncingsnowball-right");
1237 img_bouncingsnowball_squished = sprite_manager->load("bouncingsnowball-squished");
1238 img_flyingsnowball = sprite_manager->load("flyingsnowball");
1239 img_flyingsnowball_squished = sprite_manager->load("flyingsnowball-squished");
1240 img_spiky_left = sprite_manager->load("spiky-left");
1241 img_spiky_right = sprite_manager->load("spiky-right");
1242 img_spiky_iced_left = sprite_manager->load("spiky-iced-left");
1243 img_spiky_iced_right = sprite_manager->load("spiky-iced-right");
1244 img_snowball_left = sprite_manager->load("snowball-left");
1245 img_snowball_right = sprite_manager->load("snowball-right");
1246 img_snowball_squished_left = sprite_manager->load("snowball-squished-left");
1247 img_snowball_squished_right = sprite_manager->load("snowball-squished-right");
1250 void free_badguy_gfx()