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"
39 Sprite* img_mriceblock_flat_left;
40 Sprite* img_mriceblock_flat_right;
41 Sprite* img_mriceblock_falling_left;
42 Sprite* img_mriceblock_falling_right;
43 Sprite* img_mriceblock_left;
44 Sprite* img_mriceblock_right;
45 Sprite* img_jumpy_left_up;
46 Sprite* img_jumpy_left_down;
47 Sprite* img_jumpy_left_middle;
48 Sprite* img_jumpy_left_iced;
49 Sprite* img_mrbomb_left;
50 Sprite* img_mrbomb_right;
51 Sprite* img_mrbomb_iced_left;
52 Sprite* img_mrbomb_iced_right;
53 Sprite* img_mrbomb_ticking_left;
54 Sprite* img_mrbomb_ticking_right;
55 Sprite* img_mrbomb_explosion;
56 Sprite* img_stalactite;
57 Sprite* img_stalactite_broken;
60 Sprite* img_fish_down;
61 Sprite* img_fish_iced;
62 Sprite* img_fish_iced_down;
63 Sprite* img_bouncingsnowball_left;
64 Sprite* img_bouncingsnowball_right;
65 Sprite* img_bouncingsnowball_squished;
66 Sprite* img_flyingsnowball;
67 Sprite* img_flyingsnowball_squished;
68 Sprite* img_spiky_left;
69 Sprite* img_spiky_right;
70 Sprite* img_spiky_iced_left;
71 Sprite* img_spiky_iced_right;
72 Sprite* img_snowball_left;
73 Sprite* img_snowball_right;
74 Sprite* img_snowball_squished_left;
75 Sprite* img_snowball_squished_right;
77 #define BADGUY_WALK_SPEED .8f
79 BadGuyKind badguykind_from_string(const std::string& str)
81 if (str == "money" || str == "jumpy") // was money in old maps
83 else if (str == "laptop" || str == "mriceblock") // was laptop in old maps
84 return BAD_MRICEBLOCK;
85 else if (str == "mrbomb")
87 else if (str == "stalactite")
88 return BAD_STALACTITE;
89 else if (str == "flame")
91 else if (str == "fish")
93 else if (str == "bouncingsnowball")
94 return BAD_BOUNCINGSNOWBALL;
95 else if (str == "flyingsnowball")
96 return BAD_FLYINGSNOWBALL;
97 else if (str == "spiky")
99 else if (str == "snowball" || str == "bsod") // was bsod in old maps
103 printf("Couldn't convert badguy: '%s'\n", str.c_str());
108 std::string badguykind_to_string(BadGuyKind kind)
130 case BAD_BOUNCINGSNOWBALL:
131 return "bouncingsnowball";
133 case BAD_FLYINGSNOWBALL:
134 return "flyingsnowball";
147 BadGuy::BadGuy(DisplayManager& display_manager, BadGuyKind kind_,
148 LispReader& lispreader)
149 : removable(false), squishcount(0)
151 display_manager.add_drawable(this, LAYER_OBJECTS);
155 lispreader.read_float("x", &base.x);
156 lispreader.read_float("y", &base.y);
162 stay_on_platform = false;
163 lispreader.read_bool("stay-on-platform", &stay_on_platform);
168 BadGuy::BadGuy(DisplayManager& display_manager, BadGuyKind kind_,
171 display_manager.add_drawable(this, LAYER_OBJECTS);
177 stay_on_platform = false;
196 frozen_timer.init(true);
197 animation_offset = 0;
198 sprite_left = sprite_right = 0;
202 if(kind == BAD_MRBOMB) {
203 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
204 set_sprite(img_mrbomb_left, img_mrbomb_right);
205 } else if (kind == BAD_MRICEBLOCK) {
206 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
207 set_sprite(img_mriceblock_left, img_mriceblock_right);
208 } else if(kind == BAD_JUMPY) {
209 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
210 } else if(kind == BAD_BOMB) {
211 set_sprite(img_mrbomb_ticking_left, img_mrbomb_ticking_right);
212 // hack so that the bomb doesn't hurt until it expldes...
213 dying = DYING_SQUISHED;
214 } else if(kind == BAD_FLAME) {
216 physic.enable_gravity(false);
217 set_sprite(img_flame, img_flame);
218 } else if(kind == BAD_BOUNCINGSNOWBALL) {
219 physic.set_velocity(-1.3, 0);
220 set_sprite(img_bouncingsnowball_left, img_bouncingsnowball_right);
221 } else if(kind == BAD_STALACTITE) {
222 physic.enable_gravity(false);
223 set_sprite(img_stalactite, img_stalactite);
224 } else if(kind == BAD_FISH) {
225 set_sprite(img_fish, img_fish);
226 physic.enable_gravity(true);
227 } else if(kind == BAD_FLYINGSNOWBALL) {
228 set_sprite(img_flyingsnowball, img_flyingsnowball);
229 physic.enable_gravity(false);
230 } else if(kind == BAD_SPIKY) {
231 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
232 set_sprite(img_spiky_left, img_spiky_right);
233 } else if(kind == BAD_SNOWBALL) {
234 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
235 set_sprite(img_snowball_left, img_snowball_right);
238 // if we're in a solid tile at start correct that now
239 if(kind != BAD_FLAME && kind != BAD_FISH && collision_object_map(base))
241 std::cout << "Warning: badguy started in wall: kind: " << badguykind_to_string(kind)
242 << " pos: (" << base.x << ", " << base.y << ")" << std::endl;
243 while(collision_object_map(base))
249 BadGuy::write(LispWriter& writer)
251 writer.start_list(badguykind_to_string(kind));
253 writer.write_float("x", base.x);
254 writer.write_float("y", base.y);
255 writer.write_bool("stay-on-platform", stay_on_platform);
257 writer.end_list(badguykind_to_string(kind));
261 BadGuy::action_mriceblock(double elapsed_time)
263 Player& tux = *World::current()->get_tux();
268 /* Move left/right: */
272 physic.apply(elapsed_time, base.x, base.y);
273 if (dying != DYING_FALLING)
274 collision_swept_object_map(&old_base,&base);
276 else if (mode == HELD)
277 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
278 /* If we're holding the iceblock */
282 base.x = tux.base.x + 16;
283 base.y = tux.base.y + tux.base.height/1.5 - base.height;
285 else /* facing left */
287 base.x = tux.base.x - 16;
288 base.y = tux.base.y + tux.base.height/1.5 - base.height;
290 if(collision_object_map(base))
293 base.y = tux.base.y + tux.base.height/1.5 - base.height;
296 if(tux.input.fire != DOWN) /* SHOOT! */
305 tux.kick_timer.start(KICKING_TIME);
306 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
307 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
308 play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
315 check_horizontal_bump();
316 if(mode == KICK && changed != dir)
318 /* handle stereo sound (number 10 should be tweaked...)*/
319 if (base.x < scroll_x + screen->w/2 - 10)
320 play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
321 else if (base.x > scroll_x + screen->w/2 + 10)
322 play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
324 play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
328 /* Handle mode timer: */
334 set_sprite(img_mriceblock_left, img_mriceblock_right);
335 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
341 BadGuy::check_horizontal_bump(bool checkcliff)
343 float halfheight = base.height / 2;
344 if (dir == LEFT && issolid( base.x, (int) base.y + halfheight))
346 if (kind == BAD_MRICEBLOCK && mode == KICK)
347 World::current()->trybreakbrick(base.x, (int) base.y + halfheight, false);
350 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
353 if (dir == RIGHT && issolid( base.x + base.width, (int)base.y + halfheight))
355 if (kind == BAD_MRICEBLOCK && mode == KICK)
356 World::current()->trybreakbrick(base.x + base.width, (int) base.y + halfheight, false);
359 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
363 // don't check for cliffs when we're falling
366 if(!issolid(base.x + base.width/2, base.y + base.height))
369 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
372 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
375 if(dir == RIGHT && !issolid(base.x + base.width,
376 (int) base.y + base.height + halfheight))
379 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
387 /* Fall if we get off the ground: */
388 if (dying != DYING_FALLING)
390 if (!issolid(base.x+base.width/2, base.y + base.height))
392 // not solid below us? enable gravity
393 physic.enable_gravity(true);
398 if (physic.get_velocity_y() < 0)
400 base.y = int((base.y + base.height)/32) * 32 - base.height;
401 physic.set_velocity_y(0);
403 // no gravity anymore please
404 physic.enable_gravity(false);
406 if (stay_on_platform && mode == NORMAL)
408 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
409 base.y + base.height))
414 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
419 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
427 physic.enable_gravity(true);
432 BadGuy::action_jumpy(double elapsed_time)
434 if(frozen_timer.check())
436 set_sprite(img_jumpy_left_iced, img_jumpy_left_iced);
440 const float vy = physic.get_velocity_y();
442 // XXX: These tests *should* use location from ground, not velocity
443 if (fabsf(vy) > 5.6f)
444 set_sprite(img_jumpy_left_down, img_jumpy_left_down);
445 else if (fabsf(vy) > 5.3f)
446 set_sprite(img_jumpy_left_middle, img_jumpy_left_middle);
448 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
450 Player& tux = *World::current()->get_tux();
452 static const float JUMPV = 6;
455 // jump when on ground
456 if(dying == DYING_NOT && issolid(base.x, base.y+32))
458 physic.set_velocity_y(JUMPV);
459 physic.enable_gravity(true);
463 else if(mode == JUMPY_JUMP)
468 // set direction based on tux
469 if(tux.base.x > base.x)
475 physic.apply(elapsed_time, base.x, base.y);
476 if(dying == DYING_NOT)
477 collision_swept_object_map(&old_base, &base);
481 BadGuy::action_mrbomb(double elapsed_time)
483 if(frozen_timer.check())
485 set_sprite(img_mrbomb_iced_left, img_mrbomb_iced_right);
489 if (dying == DYING_NOT)
490 check_horizontal_bump(true);
494 physic.apply(elapsed_time, base.x, base.y);
495 if (dying != DYING_FALLING)
496 collision_swept_object_map(&old_base,&base);
500 BadGuy::action_bomb(double elapsed_time)
502 static const int TICKINGTIME = 1000;
503 static const int EXPLODETIME = 1000;
509 timer.start(TICKINGTIME);
510 } else if(!timer.check()) {
511 if(mode == BOMB_TICKING) {
513 set_sprite(img_mrbomb_explosion, img_mrbomb_explosion);
514 dying = DYING_NOT; // now the bomb hurts
515 timer.start(EXPLODETIME);
517 /* play explosion sound */ // FIXME: is the stereo all right? maybe we should use player cordinates...
518 if (base.x < scroll_x + screen->w/2 - 10)
519 play_sound(sounds[SND_EXPLODE], SOUND_LEFT_SPEAKER);
520 else if (base.x > scroll_x + screen->w/2 + 10)
521 play_sound(sounds[SND_EXPLODE], SOUND_RIGHT_SPEAKER);
523 play_sound(sounds[SND_EXPLODE], SOUND_CENTER_SPEAKER);
525 } else if(mode == BOMB_EXPLODE) {
532 physic.apply(elapsed_time, base.x, base.y);
533 collision_swept_object_map(&old_base,&base);
537 BadGuy::action_stalactite(double elapsed_time)
539 Player& tux = *World::current()->get_tux();
541 static const int SHAKETIME = 800;
542 static const int RANGE = 40;
545 // start shaking when tux is below the stalactite and at least 40 pixels
547 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
548 && tux.base.y + tux.base.height > base.y) {
549 timer.start(SHAKETIME);
550 mode = STALACTITE_SHAKING;
552 } if(mode == STALACTITE_SHAKING) {
553 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
555 mode = STALACTITE_FALL;
557 } else if(mode == STALACTITE_FALL) {
559 /* Destroy if we collides with land */
560 if(issolid(base.x+base.width/2, base.y+base.height))
563 dying = DYING_SQUISHED;
565 set_sprite(img_stalactite_broken, img_stalactite_broken);
567 } else if(mode == FLAT) {
572 physic.apply(elapsed_time, base.x, base.y);
574 if(dying == DYING_SQUISHED && !timer.check())
579 BadGuy::action_flame(double elapsed_time)
581 static const float radius = 100;
582 static const float speed = 0.02;
583 base.x = old_base.x + cos(angle) * radius;
584 base.y = old_base.y + sin(angle) * radius;
586 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
590 BadGuy::action_fish(double elapsed_time)
592 if(frozen_timer.check())
594 if(physic.get_velocity_y() < 0)
595 set_sprite(img_fish_iced_down, img_fish_iced_down);
597 set_sprite(img_fish_iced, img_fish_iced);
602 static const float JUMPV = 6;
603 static const int WAITTIME = 1000;
605 // go in wait mode when back in water
606 if(dying == DYING_NOT && gettile(base.x, base.y+ base.height)->water
607 && physic.get_velocity_y() <= 0 && mode == NORMAL)
611 physic.set_velocity(0, 0);
612 physic.enable_gravity(false);
613 timer.start(WAITTIME);
615 else if(mode == FISH_WAIT && !timer.check())
618 set_sprite(img_fish, img_fish);
620 physic.set_velocity(0, JUMPV);
621 physic.enable_gravity(true);
624 physic.apply(elapsed_time, base.x, base.y);
625 if(dying == DYING_NOT)
626 collision_swept_object_map(&old_base, &base);
628 if(physic.get_velocity_y() < 0)
629 set_sprite(img_fish_down, img_fish_down);
633 BadGuy::action_bouncingsnowball(double elapsed_time)
635 static const float JUMPV = 4.5;
639 // jump when on ground
640 if(dying == DYING_NOT && issolid(base.x, base.y+32))
642 physic.set_velocity_y(JUMPV);
643 physic.enable_gravity(true);
650 // check for right/left collisions
651 check_horizontal_bump();
653 physic.apply(elapsed_time, base.x, base.y);
654 if(dying == DYING_NOT)
655 collision_swept_object_map(&old_base, &base);
657 // Handle dying timer:
658 if (dying == DYING_SQUISHED && !timer.check())
660 /* Remove it if time's up: */
667 BadGuy::action_flyingsnowball(double elapsed_time)
669 static const float FLYINGSPEED = 1;
670 static const int DIRCHANGETIME = 1000;
672 // go into flyup mode if none specified yet
673 if(dying == DYING_NOT && mode == NORMAL) {
675 physic.set_velocity_y(FLYINGSPEED);
676 timer.start(DIRCHANGETIME/2);
679 if(dying == DYING_NOT && !timer.check()) {
682 physic.set_velocity_y(-FLYINGSPEED);
683 } else if(mode == FLY_DOWN) {
685 physic.set_velocity_y(FLYINGSPEED);
687 timer.start(DIRCHANGETIME);
690 if(dying != DYING_NOT)
691 physic.enable_gravity(true);
693 physic.apply(elapsed_time, base.x, base.y);
694 if(dying == DYING_NOT || dying == DYING_SQUISHED)
695 collision_swept_object_map(&old_base, &base);
697 // Handle dying timer:
698 if (dying == DYING_SQUISHED && !timer.check())
700 /* Remove it if time's up: */
707 BadGuy::action_spiky(double elapsed_time)
709 if(frozen_timer.check())
711 set_sprite(img_spiky_iced_left, img_spiky_iced_right);
715 if (dying == DYING_NOT)
716 check_horizontal_bump();
720 // jump when we're about to fall
721 if (physic.get_velocity_y() == 0 &&
722 !issolid(base.x+base.width/2, base.y + base.height)) {
723 physic.enable_gravity(true);
724 physic.set_velocity_y(2);
728 physic.apply(elapsed_time, base.x, base.y);
729 if (dying != DYING_FALLING)
730 collision_swept_object_map(&old_base,&base);
734 BadGuy::action_snowball(double elapsed_time)
736 if (dying == DYING_NOT)
737 check_horizontal_bump();
741 physic.apply(elapsed_time, base.x, base.y);
742 if (dying != DYING_FALLING)
743 collision_swept_object_map(&old_base,&base);
747 BadGuy::action(float elapsed_time)
749 // Remove if it's far off the screen:
750 if (base.x < scroll_x - OFFSCREEN_DISTANCE)
756 // BadGuy fall below the ground
757 if (base.y > World::current()->get_level()->height * 32) {
762 // Kill us if we landed on spikes
763 if (dying == DYING_NOT
764 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
765 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
766 || isspike(base.x, base.y + base.height)
767 || isspike(base.x + base.width, base.y + base.height)))
769 physic.set_velocity_y(3);
773 // Once it's on screen, it's activated!
774 if (base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
783 action_mriceblock(elapsed_time);
787 action_jumpy(elapsed_time);
791 action_mrbomb(elapsed_time);
795 action_bomb(elapsed_time);
799 action_stalactite(elapsed_time);
803 action_flame(elapsed_time);
807 action_fish(elapsed_time);
810 case BAD_BOUNCINGSNOWBALL:
811 action_bouncingsnowball(elapsed_time);
814 case BAD_FLYINGSNOWBALL:
815 action_flyingsnowball(elapsed_time);
819 action_spiky(elapsed_time);
823 action_snowball(elapsed_time);
831 BadGuy::draw(ViewPort& viewport, int)
833 float scroll_x = viewport.get_translation().x;
834 float scroll_y = viewport.get_translation().y;
836 // Don't try to draw stuff that is outside of the screen
837 if(base.x <= scroll_x - base.width || base.x >= scroll_x + screen->w)
840 if(sprite_left == 0 || sprite_right == 0)
845 Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right;
846 sprite->draw(viewport.world2screen(Vector(base.x, base.y)));
849 fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75,0,75, 150);
853 BadGuy::set_sprite(Sprite* left, Sprite* right)
862 // FIXME: Using the image size for the physics and collision is
863 // a bad idea, since images should always overlap there physical
866 if(base.width == 0 && base.height == 0) {
867 base.width = left->get_width();
868 base.height = left->get_height();
869 } else if(base.width != left->get_width() || base.height != left->get_height()) {
870 base.x -= (left->get_width() - base.width) / 2;
871 base.y -= left->get_height() - base.height;
872 base.width = left->get_width();
873 base.height = left->get_height();
877 base.width = base.height = 0;
881 animation_offset = 0;
883 sprite_right = right;
889 // these can't be bumped
890 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
891 || kind == BAD_FLYINGSNOWBALL)
894 physic.set_velocity_y(3);
899 BadGuy::make_player_jump(Player* player)
901 player->physic.set_velocity_y(2);
902 player->base.y = base.y - player->base.height - 2;
906 BadGuy::squish_me(Player* player)
908 make_player_jump(player);
910 World::current()->add_score(Vector(base.x, base.y),
911 50 * player_status.score_multiplier);
912 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
913 player_status.score_multiplier++;
915 dying = DYING_SQUISHED;
917 physic.set_velocity(0, 0);
921 BadGuy::squish(Player* player)
923 static const int MAX_ICEBLOCK_SQUICHES = 10;
925 if(kind == BAD_MRBOMB) {
926 // mrbomb transforms into a bomb now
929 make_player_jump(player);
930 World::current()->add_score(Vector(base.x, base.y),
931 50 * player_status.score_multiplier);
932 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
933 player_status.score_multiplier++;
936 } else if (kind == BAD_MRICEBLOCK) {
937 if (mode == NORMAL || mode == KICK)
940 play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
942 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
943 physic.set_velocity_x(0);
946 } else if (mode == FLAT) {
948 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
950 if (player->base.x < base.x + (base.width/2)) {
951 physic.set_velocity_x(5);
954 physic.set_velocity_x(-5);
959 player->kick_timer.start(KICKING_TIME);
960 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
963 make_player_jump(player);
965 player_status.score_multiplier++;
967 // check for maximum number of squiches
969 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
975 } else if(kind == BAD_FISH) {
976 // fish can only be killed when falling down
977 if(physic.get_velocity_y() >= 0)
980 make_player_jump(player);
982 World::current()->add_score(Vector(base.x, base.y),
983 25 * player_status.score_multiplier);
984 player_status.score_multiplier++;
986 // simply remove the fish...
989 } else if(kind == BAD_BOUNCINGSNOWBALL) {
991 set_sprite(img_bouncingsnowball_squished,img_bouncingsnowball_squished);
993 } else if(kind == BAD_FLYINGSNOWBALL) {
995 set_sprite(img_flyingsnowball_squished,img_flyingsnowball_squished);
997 } else if(kind == BAD_SNOWBALL) {
999 set_sprite(img_snowball_squished_left, img_snowball_squished_right);
1005 BadGuy::kill_me(int score)
1007 if(kind == BAD_BOMB)
1010 dying = DYING_FALLING;
1011 if(kind == BAD_MRICEBLOCK) {
1012 set_sprite(img_mriceblock_falling_left, img_mriceblock_falling_right);
1015 Player& tux = *World::current()->get_tux();
1016 tux.holding_something = false;
1020 physic.enable_gravity(true);
1022 /* Gain some points: */
1024 World::current()->add_score(Vector(base.x, base.y),
1025 score * player_status.score_multiplier);
1027 /* Play death sound: */
1028 play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
1034 World::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
1039 BadGuy::collision(const MovingObject&, int)
1045 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
1047 BadGuy* pbad_c = NULL;
1048 Bullet* pbullet_c = NULL;
1050 if(type == COLLISION_BUMP) {
1055 if(type == COLLISION_SQUISH) {
1056 Player* player = static_cast<Player*>(p_c_object);
1061 /* COLLISION_NORMAL */
1065 pbullet_c = (Bullet*) p_c_object;
1067 if(pbullet_c->kind == FIRE_BULLET)
1069 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME)
1072 else if(pbullet_c->kind == ICE_BULLET)
1074 //if(kind == BAD_FLAME)
1077 frozen_timer.start(FROZEN_TIME);
1082 pbad_c = (BadGuy*) p_c_object;
1084 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1085 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1086 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1088 pbad_c->kill_me(25);
1091 // a held mriceblock kills the enemy too but falls to ground then
1092 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1094 pbad_c->kill_me(25);
1098 /* Kill badguys that run into exploding bomb */
1099 else if (kind == BAD_BOMB && dying == DYING_NOT)
1101 if (pbad_c->kind == BAD_MRBOMB)
1103 // mrbomb transforms into a bomb now
1107 else if (pbad_c->kind != BAD_MRBOMB)
1109 pbad_c->kill_me(50);
1113 /* Kill any badguys that get hit by stalactite */
1114 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1116 if (pbad_c->kind == BAD_MRBOMB)
1118 // mrbomb transforms into a bomb now
1123 pbad_c->kill_me(50);
1126 /* When enemies run into eachother, make them change directions */
1129 // Jumpy, fish, flame, stalactites are exceptions
1130 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1131 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH)
1134 // Bounce off of other badguy if we land on top of him
1135 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1137 if (pbad_c->dir == LEFT)
1140 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1142 else if (pbad_c->dir == RIGHT)
1145 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1150 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1153 if (pbad_c->kind != BAD_FLAME)
1158 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1160 // in case badguys get "jammed"
1161 if (physic.get_velocity_x() != 0)
1162 base.x = pbad_c->base.x + pbad_c->base.width;
1164 else if (dir == RIGHT)
1167 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1176 Player* player = static_cast<Player*>(p_c_object);
1177 /* Get kicked if were flat */
1178 if (mode == FLAT && !dying)
1180 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
1182 // Hit from left side
1183 if (player->base.x < base.x) {
1184 physic.set_velocity_x(5);
1187 // Hit from right side
1189 physic.set_velocity_x(-5);
1194 player->kick_timer.start(KICKING_TIME);
1195 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
1203 //---------------------------------------------------------------------------
1205 void load_badguy_gfx()
1207 img_mriceblock_flat_left = sprite_manager->load("mriceblock-flat-left");
1208 img_mriceblock_flat_right = sprite_manager->load("mriceblock-flat-right");
1209 img_mriceblock_falling_left = sprite_manager->load("mriceblock-falling-left");
1210 img_mriceblock_falling_right = sprite_manager->load("mriceblock-falling-right");
1211 img_mriceblock_left = sprite_manager->load("mriceblock-left");
1212 img_mriceblock_right = sprite_manager->load("mriceblock-right");
1213 img_jumpy_left_up = sprite_manager->load("jumpy-left-up");
1214 img_jumpy_left_down = sprite_manager->load("jumpy-left-down");
1215 img_jumpy_left_middle = sprite_manager->load("jumpy-left-middle");
1216 img_jumpy_left_iced = sprite_manager->load("jumpy-left-iced");
1217 img_mrbomb_left = sprite_manager->load("mrbomb-left");
1218 img_mrbomb_right = sprite_manager->load("mrbomb-right");
1219 img_mrbomb_iced_left = sprite_manager->load("mrbomb-iced-left");
1220 img_mrbomb_iced_right = sprite_manager->load("mrbomb-iced-right");
1221 img_mrbomb_ticking_left = sprite_manager->load("mrbomb-ticking-left");
1222 img_mrbomb_ticking_right = sprite_manager->load("mrbomb-ticking-right");
1223 img_mrbomb_explosion = sprite_manager->load("mrbomb-explosion");
1224 img_stalactite = sprite_manager->load("stalactite");
1225 img_stalactite_broken = sprite_manager->load("stalactite-broken");
1226 img_flame = sprite_manager->load("flame");
1227 img_fish = sprite_manager->load("fish");
1228 img_fish_down = sprite_manager->load("fish-down");
1229 img_fish_iced = sprite_manager->load("fish-iced");
1230 img_fish_iced_down = sprite_manager->load("fish-iced-down");
1231 img_bouncingsnowball_left = sprite_manager->load("bouncingsnowball-left");
1232 img_bouncingsnowball_right = sprite_manager->load("bouncingsnowball-right");
1233 img_bouncingsnowball_squished = sprite_manager->load("bouncingsnowball-squished");
1234 img_flyingsnowball = sprite_manager->load("flyingsnowball");
1235 img_flyingsnowball_squished = sprite_manager->load("flyingsnowball-squished");
1236 img_spiky_left = sprite_manager->load("spiky-left");
1237 img_spiky_right = sprite_manager->load("spiky-right");
1238 img_spiky_iced_left = sprite_manager->load("spiky-iced-left");
1239 img_spiky_iced_right = sprite_manager->load("spiky-iced-right");
1240 img_snowball_left = sprite_manager->load("snowball-left");
1241 img_snowball_right = sprite_manager->load("snowball-right");
1242 img_snowball_squished_left = sprite_manager->load("snowball-squished-left");
1243 img_snowball_squished_right = sprite_manager->load("snowball-squished-right");
1246 void free_badguy_gfx()