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"
37 Sprite* img_mriceblock_flat_left;
38 Sprite* img_mriceblock_flat_right;
39 Sprite* img_mriceblock_falling_left;
40 Sprite* img_mriceblock_falling_right;
41 Sprite* img_mriceblock_left;
42 Sprite* img_mriceblock_right;
43 Sprite* img_jumpy_left_up;
44 Sprite* img_jumpy_left_down;
45 Sprite* img_jumpy_left_middle;
46 Sprite* img_jumpy_left_iced;
47 Sprite* img_mrbomb_left;
48 Sprite* img_mrbomb_right;
49 Sprite* img_mrbomb_iced_left;
50 Sprite* img_mrbomb_iced_right;
51 Sprite* img_mrbomb_ticking_left;
52 Sprite* img_mrbomb_ticking_right;
53 Sprite* img_mrbomb_explosion;
54 Sprite* img_stalactite;
55 Sprite* img_stalactite_broken;
58 Sprite* img_fish_down;
59 Sprite* img_fish_iced;
60 Sprite* img_fish_iced_down;
61 Sprite* img_bouncingsnowball_left;
62 Sprite* img_bouncingsnowball_right;
63 Sprite* img_bouncingsnowball_squished;
64 Sprite* img_flyingsnowball;
65 Sprite* img_flyingsnowball_squished;
66 Sprite* img_spiky_left;
67 Sprite* img_spiky_right;
68 Sprite* img_spiky_iced_left;
69 Sprite* img_spiky_iced_right;
70 Sprite* img_snowball_left;
71 Sprite* img_snowball_right;
72 Sprite* img_snowball_squished_left;
73 Sprite* img_snowball_squished_right;
75 #define BADGUY_WALK_SPEED .8f
77 BadGuyKind badguykind_from_string(const std::string& str)
79 if (str == "money" || str == "jumpy") // was money in old maps
81 else if (str == "laptop" || str == "mriceblock") // was laptop in old maps
82 return BAD_MRICEBLOCK;
83 else if (str == "mrbomb")
85 else if (str == "stalactite")
86 return BAD_STALACTITE;
87 else if (str == "flame")
89 else if (str == "fish")
91 else if (str == "bouncingsnowball")
92 return BAD_BOUNCINGSNOWBALL;
93 else if (str == "flyingsnowball")
94 return BAD_FLYINGSNOWBALL;
95 else if (str == "spiky")
97 else if (str == "snowball" || str == "bsod") // was bsod in old maps
101 printf("Couldn't convert badguy: '%s'\n", str.c_str());
106 std::string badguykind_to_string(BadGuyKind kind)
128 case BAD_BOUNCINGSNOWBALL:
129 return "bouncingsnowball";
131 case BAD_FLYINGSNOWBALL:
132 return "flyingsnowball";
145 BadGuy::BadGuy(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
146 : removable(false), squishcount(0)
155 stay_on_platform = stay_on_platform_;
162 frozen_timer.init(true);
163 animation_offset = 0;
164 sprite_left = sprite_right = 0;
168 if(kind == BAD_MRBOMB) {
169 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
170 set_sprite(img_mrbomb_left, img_mrbomb_right);
171 } else if (kind == BAD_MRICEBLOCK) {
172 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
173 set_sprite(img_mriceblock_left, img_mriceblock_right);
174 } else if(kind == BAD_JUMPY) {
175 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
176 } else if(kind == BAD_BOMB) {
177 set_sprite(img_mrbomb_ticking_left, img_mrbomb_ticking_right);
178 // hack so that the bomb doesn't hurt until it expldes...
179 dying = DYING_SQUISHED;
180 } else if(kind == BAD_FLAME) {
181 base.ym = 0; // we misuse base.ym as angle for the flame
182 physic.enable_gravity(false);
183 set_sprite(img_flame, img_flame);
184 } else if(kind == BAD_BOUNCINGSNOWBALL) {
185 physic.set_velocity(-1.3, 0);
186 set_sprite(img_bouncingsnowball_left, img_bouncingsnowball_right);
187 } else if(kind == BAD_STALACTITE) {
188 physic.enable_gravity(false);
189 set_sprite(img_stalactite, img_stalactite);
190 } else if(kind == BAD_FISH) {
191 set_sprite(img_fish, img_fish);
192 physic.enable_gravity(true);
193 } else if(kind == BAD_FLYINGSNOWBALL) {
194 set_sprite(img_flyingsnowball, img_flyingsnowball);
195 physic.enable_gravity(false);
196 } else if(kind == BAD_SPIKY) {
197 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
198 set_sprite(img_spiky_left, img_spiky_right);
199 } else if(kind == BAD_SNOWBALL) {
200 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
201 set_sprite(img_snowball_left, img_snowball_right);
204 // if we're in a solid tile at start correct that now
205 if(kind != BAD_FLAME && kind != BAD_FISH && collision_object_map(base))
207 std::cout << "Warning: badguy started in wall: kind: " << badguykind_to_string(kind)
208 << " pos: (" << base.x << ", " << base.y << ")" << std::endl;
209 while(collision_object_map(base))
215 BadGuy::action_mriceblock(double frame_ratio)
217 Player& tux = *World::current()->get_tux();
222 /* Move left/right: */
226 physic.apply(frame_ratio, base.x, base.y);
227 if (dying != DYING_FALLING)
228 collision_swept_object_map(&old_base,&base);
230 else if (mode == HELD)
231 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
232 /* If we're holding the iceblock */
236 base.x = tux.base.x + 16;
237 base.y = tux.base.y + tux.base.height/1.5 - base.height;
239 else /* facing left */
241 base.x = tux.base.x - 16;
242 base.y = tux.base.y + tux.base.height/1.5 - base.height;
244 if(collision_object_map(base))
247 base.y = tux.base.y + tux.base.height/1.5 - base.height;
250 if(tux.input.fire != DOWN) /* SHOOT! */
259 tux.kick_timer.start(KICKING_TIME);
260 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
261 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
262 play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
269 check_horizontal_bump();
270 if(mode == KICK && changed != dir)
272 /* handle stereo sound (number 10 should be tweaked...)*/
273 if (base.x < scroll_x + screen->w/2 - 10)
274 play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
275 else if (base.x > scroll_x + screen->w/2 + 10)
276 play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
278 play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
282 /* Handle mode timer: */
288 set_sprite(img_mriceblock_left, img_mriceblock_right);
289 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
295 BadGuy::check_horizontal_bump(bool checkcliff)
297 float halfheight = base.height / 2;
298 if (dir == LEFT && issolid( base.x, (int) base.y + halfheight))
300 if (kind == BAD_MRICEBLOCK && mode == KICK)
301 World::current()->trybreakbrick(base.x, (int) base.y + halfheight, false);
304 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
307 if (dir == RIGHT && issolid( base.x + base.width, (int)base.y + halfheight))
309 if (kind == BAD_MRICEBLOCK && mode == KICK)
310 World::current()->trybreakbrick(base.x + base.width, (int) base.y + halfheight, false);
313 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
317 // don't check for cliffs when we're falling
320 if(!issolid(base.x + base.width/2, base.y + base.height))
323 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
326 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
329 if(dir == RIGHT && !issolid(base.x + base.width,
330 (int) base.y + base.height + halfheight))
333 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
341 /* Fall if we get off the ground: */
342 if (dying != DYING_FALLING)
344 if (!issolid(base.x+base.width/2, base.y + base.height))
346 // not solid below us? enable gravity
347 physic.enable_gravity(true);
352 if (physic.get_velocity_y() < 0)
354 base.y = int((base.y + base.height)/32) * 32 - base.height;
355 physic.set_velocity_y(0);
357 // no gravity anymore please
358 physic.enable_gravity(false);
360 if (stay_on_platform && mode == NORMAL)
362 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
363 base.y + base.height))
368 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
373 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
381 physic.enable_gravity(true);
392 BadGuy::action_jumpy(double frame_ratio)
394 if(frozen_timer.check())
396 set_sprite(img_jumpy_left_iced, img_jumpy_left_iced);
400 const float vy = physic.get_velocity_y();
402 // XXX: These tests *should* use location from ground, not velocity
403 if (fabsf(vy) > 5.6f)
404 set_sprite(img_jumpy_left_down, img_jumpy_left_down);
405 else if (fabsf(vy) > 5.3f)
406 set_sprite(img_jumpy_left_middle, img_jumpy_left_middle);
408 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
410 Player& tux = *World::current()->get_tux();
412 static const float JUMPV = 6;
415 // jump when on ground
416 if(dying == DYING_NOT && issolid(base.x, base.y+32))
418 physic.set_velocity_y(JUMPV);
419 physic.enable_gravity(true);
423 else if(mode == JUMPY_JUMP)
428 // set direction based on tux
429 if(tux.base.x > base.x)
435 physic.apply(frame_ratio, base.x, base.y);
436 if(dying == DYING_NOT)
437 collision_swept_object_map(&old_base, &base);
441 BadGuy::action_mrbomb(double frame_ratio)
443 if(frozen_timer.check())
445 set_sprite(img_mrbomb_iced_left, img_mrbomb_iced_right);
449 if (dying == DYING_NOT)
450 check_horizontal_bump(true);
454 physic.apply(frame_ratio, base.x, base.y);
455 if (dying != DYING_FALLING)
456 collision_swept_object_map(&old_base,&base);
460 BadGuy::action_bomb(double frame_ratio)
462 static const int TICKINGTIME = 1000;
463 static const int EXPLODETIME = 1000;
469 timer.start(TICKINGTIME);
470 } else if(!timer.check()) {
471 if(mode == BOMB_TICKING) {
473 set_sprite(img_mrbomb_explosion, img_mrbomb_explosion);
474 dying = DYING_NOT; // now the bomb hurts
475 timer.start(EXPLODETIME);
477 /* play explosion sound */ // FIXME: is the stereo all right? maybe we should use player cordinates...
478 if (base.x < scroll_x + screen->w/2 - 10)
479 play_sound(sounds[SND_EXPLODE], SOUND_LEFT_SPEAKER);
480 else if (base.x > scroll_x + screen->w/2 + 10)
481 play_sound(sounds[SND_EXPLODE], SOUND_RIGHT_SPEAKER);
483 play_sound(sounds[SND_EXPLODE], SOUND_CENTER_SPEAKER);
485 } else if(mode == BOMB_EXPLODE) {
492 physic.apply(frame_ratio, base.x, base.y);
493 collision_swept_object_map(&old_base,&base);
497 BadGuy::action_stalactite(double frame_ratio)
499 Player& tux = *World::current()->get_tux();
501 static const int SHAKETIME = 800;
502 static const int RANGE = 40;
505 // start shaking when tux is below the stalactite and at least 40 pixels
507 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
508 && tux.base.y + tux.base.height > base.y) {
509 timer.start(SHAKETIME);
510 mode = STALACTITE_SHAKING;
512 } if(mode == STALACTITE_SHAKING) {
513 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
515 mode = STALACTITE_FALL;
517 } else if(mode == STALACTITE_FALL) {
519 /* Destroy if we collides with land */
520 if(issolid(base.x+base.width/2, base.y+base.height))
523 dying = DYING_SQUISHED;
525 set_sprite(img_stalactite_broken, img_stalactite_broken);
527 } else if(mode == FLAT) {
532 physic.apply(frame_ratio, base.x, base.y);
534 if(dying == DYING_SQUISHED && !timer.check())
539 BadGuy::action_flame(double frame_ratio)
541 static const float radius = 100;
542 static const float speed = 0.02;
543 base.x = old_base.x + cos(base.ym) * radius;
544 base.y = old_base.y + sin(base.ym) * radius;
546 base.ym = fmodf(base.ym + frame_ratio * speed, 2*M_PI);
550 BadGuy::action_fish(double frame_ratio)
552 if(frozen_timer.check())
554 if(physic.get_velocity_y() < 0)
555 set_sprite(img_fish_iced_down, img_fish_iced_down);
557 set_sprite(img_fish_iced, img_fish_iced);
562 static const float JUMPV = 6;
563 static const int WAITTIME = 1000;
565 // go in wait mode when back in water
566 if(dying == DYING_NOT && gettile(base.x, base.y+ base.height)->water
567 && physic.get_velocity_y() <= 0 && mode == NORMAL)
571 physic.set_velocity(0, 0);
572 physic.enable_gravity(false);
573 timer.start(WAITTIME);
575 else if(mode == FISH_WAIT && !timer.check())
578 set_sprite(img_fish, img_fish);
580 physic.set_velocity(0, JUMPV);
581 physic.enable_gravity(true);
584 physic.apply(frame_ratio, base.x, base.y);
585 if(dying == DYING_NOT)
586 collision_swept_object_map(&old_base, &base);
588 if(physic.get_velocity_y() < 0)
589 set_sprite(img_fish_down, img_fish_down);
593 BadGuy::action_bouncingsnowball(double frame_ratio)
595 static const float JUMPV = 4.5;
599 // jump when on ground
600 if(dying == DYING_NOT && issolid(base.x, base.y+32))
602 physic.set_velocity_y(JUMPV);
603 physic.enable_gravity(true);
610 // check for right/left collisions
611 check_horizontal_bump();
613 physic.apply(frame_ratio, base.x, base.y);
614 if(dying == DYING_NOT)
615 collision_swept_object_map(&old_base, &base);
617 // Handle dying timer:
618 if (dying == DYING_SQUISHED && !timer.check())
620 /* Remove it if time's up: */
627 BadGuy::action_flyingsnowball(double frame_ratio)
629 static const float FLYINGSPEED = 1;
630 static const int DIRCHANGETIME = 1000;
632 // go into flyup mode if none specified yet
633 if(dying == DYING_NOT && mode == NORMAL) {
635 physic.set_velocity_y(FLYINGSPEED);
636 timer.start(DIRCHANGETIME/2);
639 if(dying == DYING_NOT && !timer.check()) {
642 physic.set_velocity_y(-FLYINGSPEED);
643 } else if(mode == FLY_DOWN) {
645 physic.set_velocity_y(FLYINGSPEED);
647 timer.start(DIRCHANGETIME);
650 if(dying != DYING_NOT)
651 physic.enable_gravity(true);
653 physic.apply(frame_ratio, base.x, base.y);
654 if(dying == DYING_NOT || dying == DYING_SQUISHED)
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_spiky(double frame_ratio)
669 if(frozen_timer.check())
671 set_sprite(img_spiky_iced_left, img_spiky_iced_right);
675 if (dying == DYING_NOT)
676 check_horizontal_bump();
680 // jump when we're about to fall
681 if (physic.get_velocity_y() == 0 &&
682 !issolid(base.x+base.width/2, base.y + base.height)) {
683 physic.enable_gravity(true);
684 physic.set_velocity_y(2);
688 physic.apply(frame_ratio, base.x, base.y);
689 if (dying != DYING_FALLING)
690 collision_swept_object_map(&old_base,&base);
694 BadGuy::action_snowball(double frame_ratio)
696 if (dying == DYING_NOT)
697 check_horizontal_bump();
701 physic.apply(frame_ratio, base.x, base.y);
702 if (dying != DYING_FALLING)
703 collision_swept_object_map(&old_base,&base);
707 BadGuy::action(double frame_ratio)
709 // Remove if it's far off the screen:
710 if (base.x < scroll_x - OFFSCREEN_DISTANCE)
716 // BadGuy fall below the ground
717 if (base.y > World::current()->get_level()->height * 32) {
722 // Kill us if we landed on spikes
723 if (dying == DYING_NOT
724 && (kind != BAD_STALACTITE && kind != BAD_FLAME && kind != BAD_BOMB)
725 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
726 || isspike(base.x, base.y + base.height)
727 || isspike(base.x + base.width, base.y + base.height)))
729 physic.set_velocity_y(3);
733 // Once it's on screen, it's activated!
734 if (base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
743 action_mriceblock(frame_ratio);
747 action_jumpy(frame_ratio);
751 action_mrbomb(frame_ratio);
755 action_bomb(frame_ratio);
759 action_stalactite(frame_ratio);
763 action_flame(frame_ratio);
767 action_fish(frame_ratio);
770 case BAD_BOUNCINGSNOWBALL:
771 action_bouncingsnowball(frame_ratio);
774 case BAD_FLYINGSNOWBALL:
775 action_flyingsnowball(frame_ratio);
779 action_spiky(frame_ratio);
783 action_snowball(frame_ratio);
793 // Don't try to draw stuff that is outside of the screen
794 if(base.x <= scroll_x - base.width || base.x >= scroll_x + screen->w)
797 if(sprite_left == 0 || sprite_right == 0)
802 Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right;
803 sprite->draw(base.x, base.y);
806 fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75,0,75, 150);
810 BadGuy::set_sprite(Sprite* left, Sprite* right)
819 // FIXME: Using the image size for the physics and collision is
820 // a bad idea, since images should always overlap there physical
823 if(base.width == 0 && base.height == 0) {
824 base.width = left->get_width();
825 base.height = left->get_height();
826 } else if(base.width != left->get_width() || base.height != left->get_height()) {
827 base.x -= (left->get_width() - base.width) / 2;
828 base.y -= left->get_height() - base.height;
829 base.width = left->get_width();
830 base.height = left->get_height();
834 base.width = base.height = 0;
838 animation_offset = 0;
840 sprite_right = right;
846 // these can't be bumped
847 if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
848 || kind == BAD_FLYINGSNOWBALL)
851 physic.set_velocity_y(3);
856 BadGuy::make_player_jump(Player* player)
858 player->physic.set_velocity_y(2);
859 player->base.y = base.y - player->base.height - 2;
863 BadGuy::squish_me(Player* player)
865 make_player_jump(player);
867 World::current()->add_score(base.x,
868 base.y, 50 * player_status.score_multiplier);
869 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
870 player_status.score_multiplier++;
872 dying = DYING_SQUISHED;
874 physic.set_velocity(0, 0);
878 BadGuy::squish(Player* player)
880 static const int MAX_ICEBLOCK_SQUICHES = 10;
882 if(kind == BAD_MRBOMB) {
883 // mrbomb transforms into a bomb now
884 World::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
886 make_player_jump(player);
887 World::current()->add_score(base.x, base.y, 50 * player_status.score_multiplier);
888 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
889 player_status.score_multiplier++;
893 } else if (kind == BAD_MRICEBLOCK) {
894 if (mode == NORMAL || mode == KICK)
897 play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
899 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
900 physic.set_velocity_x(0);
903 } else if (mode == FLAT) {
905 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
907 if (player->base.x < base.x + (base.width/2)) {
908 physic.set_velocity_x(5);
911 physic.set_velocity_x(-5);
916 player->kick_timer.start(KICKING_TIME);
917 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
920 make_player_jump(player);
922 player_status.score_multiplier++;
924 // check for maximum number of squiches
926 if(squishcount >= MAX_ICEBLOCK_SQUICHES) {
932 } else if(kind == BAD_FISH) {
933 // fish can only be killed when falling down
934 if(physic.get_velocity_y() >= 0)
937 make_player_jump(player);
939 World::current()->add_score(base.x, base.y, 25 * player_status.score_multiplier);
940 player_status.score_multiplier++;
942 // simply remove the fish...
945 } else if(kind == BAD_BOUNCINGSNOWBALL) {
947 set_sprite(img_bouncingsnowball_squished,img_bouncingsnowball_squished);
949 } else if(kind == BAD_FLYINGSNOWBALL) {
951 set_sprite(img_flyingsnowball_squished,img_flyingsnowball_squished);
953 } else if(kind == BAD_SNOWBALL) {
955 set_sprite(img_snowball_squished_left, img_snowball_squished_right);
961 BadGuy::kill_me(int score)
966 dying = DYING_FALLING;
967 if(kind == BAD_MRICEBLOCK) {
968 set_sprite(img_mriceblock_falling_left, img_mriceblock_falling_right);
971 Player& tux = *World::current()->get_tux();
972 tux.holding_something = false;
976 physic.enable_gravity(true);
978 /* Gain some points: */
980 World::current()->add_score(base.x, base.y,
981 score * player_status.score_multiplier);
983 /* Play death sound: */
984 play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
987 void BadGuy::explode(BadGuy *badguy)
989 World::current()->add_bad_guy(badguy->base.x, badguy->base.y, BAD_BOMB);
994 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
996 BadGuy* pbad_c = NULL;
997 Bullet* pbullet_c = NULL;
999 if(type == COLLISION_BUMP) {
1004 if(type == COLLISION_SQUISH) {
1005 Player* player = static_cast<Player*>(p_c_object);
1010 /* COLLISION_NORMAL */
1014 pbullet_c = (Bullet*) p_c_object;
1016 if(pbullet_c->kind == FIRE_BULLET)
1018 if (kind != BAD_BOMB && kind != BAD_STALACTITE && kind != BAD_FLAME)
1021 else if(pbullet_c->kind == ICE_BULLET)
1023 //if(kind == BAD_FLAME)
1026 frozen_timer.start(FROZEN_TIME);
1031 pbad_c = (BadGuy*) p_c_object;
1033 /* If we're a kicked mriceblock, kill [almost] any badguys we hit */
1034 if(kind == BAD_MRICEBLOCK && mode == KICK &&
1035 kind != BAD_FLAME && kind != BAD_BOMB && kind != BAD_STALACTITE)
1037 pbad_c->kill_me(25);
1040 // a held mriceblock kills the enemy too but falls to ground then
1041 else if(kind == BAD_MRICEBLOCK && mode == HELD)
1043 pbad_c->kill_me(25);
1047 /* Kill badguys that run into exploding bomb */
1048 else if (kind == BAD_BOMB && dying == DYING_NOT)
1050 if (pbad_c->kind == BAD_MRBOMB)
1052 // mrbomb transforms into a bomb now
1056 else if (pbad_c->kind != BAD_MRBOMB)
1058 pbad_c->kill_me(50);
1062 /* Kill any badguys that get hit by stalactite */
1063 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1065 if (pbad_c->kind == BAD_MRBOMB)
1067 // mrbomb transforms into a bomb now
1072 pbad_c->kill_me(50);
1075 /* When enemies run into eachother, make them change directions */
1078 // Jumpy, fish, flame, stalactites are exceptions
1079 if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME
1080 || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH)
1083 // Bounce off of other badguy if we land on top of him
1084 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1086 if (pbad_c->dir == LEFT)
1089 physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
1091 else if (pbad_c->dir == RIGHT)
1094 physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
1099 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1102 if (pbad_c->kind != BAD_FLAME)
1107 physic.set_velocity_x(fabsf(physic.get_velocity_x()));
1109 // in case badguys get "jammed"
1110 if (physic.get_velocity_x() != 0)
1111 base.x = pbad_c->base.x + pbad_c->base.width;
1113 else if (dir == RIGHT)
1116 physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
1125 Player* player = static_cast<Player*>(p_c_object);
1126 /* Get kicked if were flat */
1127 if (mode == FLAT && !dying)
1129 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
1131 // Hit from left side
1132 if (player->base.x < base.x) {
1133 physic.set_velocity_x(5);
1136 // Hit from right side
1138 physic.set_velocity_x(-5);
1143 player->kick_timer.start(KICKING_TIME);
1144 set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
1152 //---------------------------------------------------------------------------
1154 void load_badguy_gfx()
1156 img_mriceblock_flat_left = sprite_manager->load("mriceblock-flat-left");
1157 img_mriceblock_flat_right = sprite_manager->load("mriceblock-flat-right");
1158 img_mriceblock_falling_left = sprite_manager->load("mriceblock-falling-left");
1159 img_mriceblock_falling_right = sprite_manager->load("mriceblock-falling-right");
1160 img_mriceblock_left = sprite_manager->load("mriceblock-left");
1161 img_mriceblock_right = sprite_manager->load("mriceblock-right");
1162 img_jumpy_left_up = sprite_manager->load("jumpy-left-up");
1163 img_jumpy_left_down = sprite_manager->load("jumpy-left-down");
1164 img_jumpy_left_middle = sprite_manager->load("jumpy-left-middle");
1165 img_jumpy_left_iced = sprite_manager->load("jumpy-left-iced");
1166 img_mrbomb_left = sprite_manager->load("mrbomb-left");
1167 img_mrbomb_right = sprite_manager->load("mrbomb-right");
1168 img_mrbomb_iced_left = sprite_manager->load("mrbomb-iced-left");
1169 img_mrbomb_iced_right = sprite_manager->load("mrbomb-iced-right");
1170 img_mrbomb_ticking_left = sprite_manager->load("mrbomb-ticking-left");
1171 img_mrbomb_ticking_right = sprite_manager->load("mrbomb-ticking-right");
1172 img_mrbomb_explosion = sprite_manager->load("mrbomb-explosion");
1173 img_stalactite = sprite_manager->load("stalactite");
1174 img_stalactite_broken = sprite_manager->load("stalactite-broken");
1175 img_flame = sprite_manager->load("flame");
1176 img_fish = sprite_manager->load("fish");
1177 img_fish_down = sprite_manager->load("fish-down");
1178 img_fish_iced = sprite_manager->load("fish-iced");
1179 img_fish_iced_down = sprite_manager->load("fish-iced-down");
1180 img_bouncingsnowball_left = sprite_manager->load("bouncingsnowball-left");
1181 img_bouncingsnowball_right = sprite_manager->load("bouncingsnowball-right");
1182 img_bouncingsnowball_squished = sprite_manager->load("bouncingsnowball-squished");
1183 img_flyingsnowball = sprite_manager->load("flyingsnowball");
1184 img_flyingsnowball_squished = sprite_manager->load("flyingsnowball-squished");
1185 img_spiky_left = sprite_manager->load("spiky-left");
1186 img_spiky_right = sprite_manager->load("spiky-right");
1187 img_spiky_iced_left = sprite_manager->load("spiky-iced-left");
1188 img_spiky_iced_right = sprite_manager->load("spiky-iced-right");
1189 img_snowball_left = sprite_manager->load("snowball-left");
1190 img_snowball_right = sprite_manager->load("snowball-right");
1191 img_snowball_squished_left = sprite_manager->load("snowball-squished-left");
1192 img_snowball_squished_right = sprite_manager->load("snowball-squished-right");
1195 void free_badguy_gfx()
1199 //---------------------------------------------------------------------------
1201 BadGuyManager::BadGuyManager()
1203 std::string filename = datadir + "/images/tilesets/supertux.stbg";
1204 load_badguys(filename);
1207 BadGuyManager::~BadGuyManager()
1209 for(std::vector<BadGuy*>::iterator i = badguys.begin(); i != badguys.end(); ++i) {
1214 void BadGuyManager::load_badguys(std::string filename)
1217 lisp_object_t* root_obj = lisp_read_from_file(filename);
1220 st_abort("Couldn't load file", filename);
1222 if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-badguys") == 0)
1224 lisp_object_t* cur = lisp_cdr(root_obj);
1226 while(!lisp_nil_p(cur))
1228 lisp_object_t* element = lisp_car(cur);
1230 if (strcmp(lisp_symbol(lisp_car(element)), "badguy") == 0)
1234 Tile* tile = new Tile;
1236 tile->solid = false;
1237 tile->brick = false;
1239 tile->water = false;
1240 tile->fullbox = false;
1241 tile->distro = false;
1244 tile->next_tile = 0;
1245 tile->anim_speed = 25;
1247 LispReader reader(lisp_cdr(element));
1248 assert(reader.read_int("id", &tile->id));
1249 reader.read_bool("solid", &tile->solid);
1250 reader.read_bool("brick", &tile->brick);
1251 reader.read_bool("ice", &tile->ice);
1252 reader.read_bool("water", &tile->water);
1253 reader.read_bool("fullbox", &tile->fullbox);
1254 reader.read_bool("distro", &tile->distro);
1255 reader.read_bool("goal", &tile->goal);
1256 reader.read_int("data", &tile->data);
1257 reader.read_int("anim-speed", &tile->anim_speed);
1258 reader.read_int("next-tile", &tile->next_tile);
1259 reader.read_string_vector("images", &tile->filenames);
1260 reader.read_string_vector("editor-images", &tile->editor_filenames);
1262 for(std::vector<std::string>::iterator it = tile->
1264 it != tile->filenames.end();
1268 tile->images.push_back(cur_image);
1269 tile->images[tile->images.size()-1] = new Surface(
1270 datadir + "/images/tilesets/" + (*it),
1273 for(std::vector<std::string>::iterator it = tile->editor_filenames.begin();
1274 it != tile->editor_filenames.end();
1278 tile->editor_images.push_back(cur_image);
1279 tile->editor_images[tile->editor_images.size()-1] = new Surface(
1280 datadir + "/images/tilesets/" + (*it),
1284 if (tile->id + tileset_id >= int(tiles.size())
1286 tiles.resize(tile->id + tileset_id+1);
1288 tiles[tile->id + tileset_id] = tile;
1290 else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0)
1292 LispReader reader(lisp_cdr(element));
1293 std::string filename;
1294 reader.read_string("file", &filename);
1295 filename = datadir + "/images/tilesets/" + filename;
1296 load_tileset(filename);
1298 else if (strcmp(lisp_symbol(lisp_car(element)), "tilegroup") == 0)
1301 LispReader reader(lisp_cdr(element));
1302 reader.read_string("name", &new_.name);
1303 reader.read_int_vector("tiles", &new_.tiles);
1305 tilegroups_ = new std::set<TileGroup>;
1306 tilegroups_->insert(new_).first;
1308 else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
1310 LispReader reader(lisp_cdr(element));
1311 reader.read_int("id", &tileset_id);
1316 puts("Unhandled symbol");
1319 cur = lisp_cdr(cur);
1327 lisp_free(root_obj);