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 Sprite* img_bsod_squished_left;
37 Sprite* img_bsod_squished_right;
38 Sprite* img_bsod_falling_left;
39 Sprite* img_bsod_falling_right;
40 Sprite* img_laptop_flat_left;
41 Sprite* img_laptop_flat_right;
42 Sprite* img_laptop_falling_left;
43 Sprite* img_laptop_falling_right;
44 Sprite* img_bsod_left;
45 Sprite* img_bsod_right;
46 Sprite* img_laptop_left;
47 Sprite* img_laptop_right;
48 Sprite* img_jumpy_left_up;
49 Sprite* img_jumpy_left_down;
50 Sprite* img_jumpy_left_middle;
51 Sprite* img_mrbomb_left;
52 Sprite* img_mrbomb_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_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_snowball_left;
69 Sprite* img_snowball_right;
70 Sprite* img_snowball_squished_left;
71 Sprite* img_snowball_squished_right;
73 #define BADGUY_WALK_SPEED .8f
75 BadGuyKind badguykind_from_string(const std::string& str)
79 else if (str == "laptop" || str == "mriceblock")
81 else if (str == "bsod")
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")
101 printf("Couldn't convert badguy: '%s'\n", str.c_str());
106 std::string badguykind_to_string(BadGuyKind kind)
131 case BAD_BOUNCINGSNOWBALL:
132 return "bouncingsnowball";
134 case BAD_FLYINGSNOWBALL:
135 return "flyingsnowball";
149 BadGuy::init(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
158 stay_on_platform = stay_on_platform_;
165 animation_offset = 0;
166 sprite_left = sprite_right = 0;
170 if(kind == BAD_BSOD) {
171 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
172 set_sprite(img_bsod_left, img_bsod_right);
173 } else if(kind == BAD_MRBOMB) {
174 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
175 set_sprite(img_mrbomb_left, img_mrbomb_right);
176 } else if (kind == BAD_LAPTOP) {
177 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
178 set_sprite(img_laptop_left, img_laptop_right);
179 } else if(kind == BAD_MONEY) {
180 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
181 } else if(kind == BAD_BOMB) {
182 set_sprite(img_mrbomb_ticking_left, img_mrbomb_ticking_right);
183 // hack so that the bomb doesn't hurt until it expldes...
184 dying = DYING_SQUISHED;
185 } else if(kind == BAD_FLAME) {
186 base.ym = 0; // we misuse base.ym as angle for the flame
187 physic.enable_gravity(false);
188 set_sprite(img_flame, img_flame);
189 } else if(kind == BAD_BOUNCINGSNOWBALL) {
190 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
191 set_sprite(img_bouncingsnowball_left, img_bouncingsnowball_right);
192 } else if(kind == BAD_STALACTITE) {
193 physic.enable_gravity(false);
194 set_sprite(img_stalactite, img_stalactite);
195 } else if(kind == BAD_FISH) {
196 set_sprite(img_fish, img_fish);
197 physic.enable_gravity(true);
198 } else if(kind == BAD_FLYINGSNOWBALL) {
199 set_sprite(img_flyingsnowball, img_flyingsnowball);
200 physic.enable_gravity(false);
201 } else if(kind == BAD_SPIKY) {
202 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
203 set_sprite(img_spiky_left, img_spiky_right);
204 } else if(kind == BAD_SNOWBALL) {
205 physic.set_velocity(-BADGUY_WALK_SPEED, 0);
206 set_sprite(img_snowball_left, img_snowball_right);
209 // if we're in a solid tile at start correct that now
210 if(kind != BAD_FLAME && kind != BAD_FISH && collision_object_map(&base)) {
211 printf("Warning: badguy started in wall!.\n");
212 while(collision_object_map(&base))
218 BadGuy::action_bsod(float frame_ratio)
220 static const float BSODJUMP = 2;
222 if (dying == DYING_NOT)
223 check_horizontal_bump();
227 // jump when we're about to fall
228 if (physic.get_velocity_y() == 0 &&
229 !issolid(base.x+base.width/2, base.y + base.height))
231 physic.enable_gravity(true);
232 physic.set_velocity(physic.get_velocity_x(), BSODJUMP);
235 // Handle dying timer:
236 if (dying == DYING_SQUISHED && !timer.check())
238 /* Remove it if time's up: */
244 physic.apply(frame_ratio, base.x, base.y);
245 if(dying != DYING_FALLING)
246 collision_swept_object_map(&old_base, &base);
250 BadGuy::action_laptop(float frame_ratio)
252 Player& tux = *World::current()->get_tux();
254 if(dying == DYING_NOT)
257 /* Move left/right: */
258 if (mode == NORMAL || mode == KICK)
261 physic.apply(frame_ratio, base.x, base.y);
262 if (dying != DYING_FALLING)
263 collision_swept_object_map(&old_base,&base);
265 else if (mode == HELD)
266 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
267 /* If we're holding the laptop */
271 base.x = tux.base.x + 16;
272 base.y = tux.base.y + tux.base.height/1.5 - base.height;
274 else /* facing left */
276 base.x = tux.base.x - 16;
277 base.y = tux.base.y + tux.base.height/1.5 - base.height;
279 if(collision_object_map(&base))
282 base.y = tux.base.y + tux.base.height/1.5 - base.height;
285 if(tux.input.fire != DOWN) /* SHOOT! */
294 set_sprite(img_laptop_flat_left, img_laptop_flat_right);
295 physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
296 play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
303 check_horizontal_bump();
304 if(mode == KICK && changed != dir)
306 /* handle stereo sound (number 10 should be tweaked...)*/
307 if (base.x < scroll_x + screen->w/2 - 10)
308 play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
309 else if (base.x > scroll_x + screen->w/2 + 10)
310 play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
312 play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
316 /* Handle mode timer: */
322 set_sprite(img_laptop_left, img_laptop_right);
323 physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
329 BadGuy::check_horizontal_bump(bool checkcliff)
331 float halfheight = base.height / 2;
332 if (dir == LEFT && issolid( base.x, (int) base.y + halfheight))
335 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
338 if (dir == RIGHT && issolid( base.x + base.width, (int)base.y + halfheight))
341 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
345 // don't check for cliffs when we're falling
348 if(!issolid(base.x + base.width/2, base.y + base.height))
351 if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
354 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
357 if(dir == RIGHT && !issolid(base.x + base.width,
358 (int) base.y + base.height + halfheight))
361 physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
369 /* Fall if we get off the ground: */
370 if (dying != DYING_FALLING)
372 if (!issolid(base.x+base.width/2, base.y + base.height))
374 // not solid below us? enable gravity
375 physic.enable_gravity(true);
380 if (physic.get_velocity_y() < 0)
382 base.y = int((base.y + base.height)/32) * 32 - base.height;
383 physic.set_velocity_y(0);
385 // no gravity anymore please
386 physic.enable_gravity(false);
388 if (stay_on_platform && mode == NORMAL)
390 if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
391 base.y + base.height))
393 physic.set_velocity_x(-physic.get_velocity_x());
404 physic.enable_gravity(true);
411 for(std::vector<BadGuy>::iterator i = World::current()->bad_guys.begin();
412 i != World::current()->bad_guys.end(); ++i)
414 if( & (*i) == this) {
415 World::current()->bad_guys.erase(i);
422 BadGuy::action_money(float frame_ratio)
424 if (fabsf(physic.get_velocity_y()) < 2.5f)
425 set_sprite(img_jumpy_left_middle, img_jumpy_left_middle);
426 else if (physic.get_velocity_y() < 0)
427 set_sprite(img_jumpy_left_up, img_jumpy_left_up);
429 set_sprite(img_jumpy_left_down, img_jumpy_left_down);
431 Player& tux = *World::current()->get_tux();
433 static const float JUMPV = 6;
436 // jump when on ground
437 if(dying == DYING_NOT && issolid(base.x, base.y+32))
439 physic.set_velocity_y(JUMPV);
440 physic.enable_gravity(true);
444 else if(mode == MONEY_JUMP)
449 // set direction based on tux
450 if(tux.base.x > base.x)
456 physic.apply(frame_ratio, base.x, base.y);
457 if(dying == DYING_NOT)
458 collision_swept_object_map(&old_base, &base);
462 BadGuy::action_mrbomb(float frame_ratio)
464 if (dying == DYING_NOT)
465 check_horizontal_bump(true);
469 physic.apply(frame_ratio, base.x, base.y);
470 if (dying != DYING_FALLING)
471 collision_swept_object_map(&old_base,&base);
475 BadGuy::action_bomb(float frame_ratio)
477 static const int TICKINGTIME = 1000;
478 static const int EXPLODETIME = 1000;
484 timer.start(TICKINGTIME);
485 } else if(!timer.check()) {
486 if(mode == BOMB_TICKING) {
488 set_sprite(img_mrbomb_explosion, img_mrbomb_explosion);
489 dying = DYING_NOT; // now the bomb hurts
490 timer.start(EXPLODETIME);
491 } else if(mode == BOMB_EXPLODE) {
498 physic.apply(frame_ratio, base.x, base.y);
499 collision_swept_object_map(&old_base,&base);
503 BadGuy::action_stalactite(float frame_ratio)
505 Player& tux = *World::current()->get_tux();
507 static const int SHAKETIME = 800;
508 static const int RANGE = 40;
511 // start shaking when tux is below the stalactite and at least 40 pixels
513 if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
514 && tux.base.y + tux.base.height > base.y) {
515 timer.start(SHAKETIME);
516 mode = STALACTITE_SHAKING;
518 } if(mode == STALACTITE_SHAKING) {
519 base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
521 mode = STALACTITE_FALL;
523 } else if(mode == STALACTITE_FALL) {
525 /* Destroy if we collides with land */
526 if(issolid(base.x+base.width/2, base.y+base.height))
529 dying = DYING_SQUISHED;
531 set_sprite(img_stalactite_broken, img_stalactite_broken);
533 } else if(mode == FLAT) {
538 physic.apply(frame_ratio, base.x, base.y);
540 if(dying == DYING_SQUISHED && !timer.check())
545 BadGuy::action_flame(float frame_ratio)
547 static const float radius = 100;
548 static const float speed = 0.02;
549 base.x = old_base.x + cos(base.ym) * radius;
550 base.y = old_base.y + sin(base.ym) * radius;
552 base.ym = fmodf(base.ym + frame_ratio * speed, 2*M_PI);
556 BadGuy::action_fish(float frame_ratio)
558 static const float JUMPV = 6;
559 static const int WAITTIME = 1000;
561 // go in wait mode when back in water
562 if(dying == DYING_NOT && gettile(base.x, base.y+ base.height)->water
563 && physic.get_velocity_y() <= 0 && mode == NORMAL)
567 physic.set_velocity(0, 0);
568 physic.enable_gravity(false);
569 timer.start(WAITTIME);
571 else if(mode == FISH_WAIT && !timer.check())
574 set_sprite(img_fish, img_fish);
576 physic.set_velocity(0, JUMPV);
577 physic.enable_gravity(true);
580 physic.apply(frame_ratio, base.x, base.y);
581 if(dying == DYING_NOT)
582 collision_swept_object_map(&old_base, &base);
584 if(physic.get_velocity_y() < 0)
585 set_sprite(img_fish_down, img_fish_down);
589 BadGuy::action_bouncingsnowball(float frame_ratio)
591 static const float JUMPV = 4.5;
595 // jump when on ground
596 if(dying == DYING_NOT && issolid(base.x, base.y+32))
598 physic.set_velocity_y(JUMPV);
599 physic.enable_gravity(true);
606 // check for right/left collisions
607 check_horizontal_bump();
609 physic.apply(frame_ratio, base.x, base.y);
610 if(dying == DYING_NOT)
611 collision_swept_object_map(&old_base, &base);
613 // Handle dying timer:
614 if (dying == DYING_SQUISHED && !timer.check())
616 /* Remove it if time's up: */
623 BadGuy::action_flyingsnowball(float frame_ratio)
625 static const float FLYINGSPEED = 1;
626 static const int DIRCHANGETIME = 1000;
628 // go into flyup mode if none specified yet
629 if(dying == DYING_NOT && mode == NORMAL) {
631 physic.set_velocity_y(FLYINGSPEED);
632 timer.start(DIRCHANGETIME/2);
635 if(dying == DYING_NOT && !timer.check()) {
638 physic.set_velocity_y(-FLYINGSPEED);
639 } else if(mode == FLY_DOWN) {
641 physic.set_velocity_y(FLYINGSPEED);
643 timer.start(DIRCHANGETIME);
646 if(dying != DYING_NOT)
647 physic.enable_gravity(true);
649 physic.apply(frame_ratio, base.x, base.y);
650 if(dying == DYING_NOT || dying == DYING_SQUISHED)
651 collision_swept_object_map(&old_base, &base);
653 // Handle dying timer:
654 if (dying == DYING_SQUISHED && !timer.check())
656 /* Remove it if time's up: */
663 BadGuy::action_spiky(float frame_ratio)
665 if (dying == DYING_NOT)
666 check_horizontal_bump();
670 // jump when we're about to fall
671 if (physic.get_velocity_y() == 0 &&
672 !issolid(base.x+base.width/2, base.y + base.height)) {
673 physic.enable_gravity(true);
674 physic.set_velocity_y(2);
678 physic.apply(frame_ratio, base.x, base.y);
679 if (dying != DYING_FALLING)
680 collision_swept_object_map(&old_base,&base);
684 BadGuy::action_snowball(float frame_ratio)
686 if (dying == DYING_NOT)
687 check_horizontal_bump();
691 physic.apply(frame_ratio, base.x, base.y);
692 if (dying != DYING_FALLING)
693 collision_swept_object_map(&old_base,&base);
697 BadGuy::action(float frame_ratio)
699 // Remove if it's far off the screen:
700 if (base.x < scroll_x - OFFSCREEN_DISTANCE)
706 // BadGuy fall below the ground
707 if (base.y > screen->h) {
712 // Once it's on screen, it's activated!
713 if (base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
722 action_bsod(frame_ratio);
726 action_laptop(frame_ratio);
730 action_money(frame_ratio);
734 action_mrbomb(frame_ratio);
738 action_bomb(frame_ratio);
742 action_stalactite(frame_ratio);
746 action_flame(frame_ratio);
750 action_fish(frame_ratio);
753 case BAD_BOUNCINGSNOWBALL:
754 action_bouncingsnowball(frame_ratio);
757 case BAD_FLYINGSNOWBALL:
758 action_flyingsnowball(frame_ratio);
762 action_spiky(frame_ratio);
766 action_snowball(frame_ratio);
774 // Don't try to draw stuff that is outside of the screen
775 if(base.x <= scroll_x - base.width || base.x >= scroll_x + screen->w)
778 if(sprite_left == 0 || sprite_right == 0)
783 Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right;
784 sprite->draw(base.x - scroll_x, base.y);
787 fillrect(base.x - scroll_x, base.y, base.width, base.height, 75,0,75, 150);
791 BadGuy::set_sprite(Sprite* left, Sprite* right)
800 // FIXME: Using the image size for the physics and collision is
801 // a bad idea, since images should always overlap there physical
804 if(base.width == 0 && base.height == 0) {
805 base.width = left->get_width();
806 base.height = left->get_height();
807 } else if(base.width != left->get_width() || base.height != left->get_height()) {
808 base.x -= (left->get_width() - base.width) / 2;
809 base.y -= left->get_height() - base.height;
810 base.width = left->get_width();
811 base.height = left->get_height();
815 base.width = base.height = 0;
819 animation_offset = 0;
821 sprite_right = right;
827 if(kind == BAD_BSOD || kind == BAD_LAPTOP || kind == BAD_MRBOMB
828 || kind == BAD_BOUNCINGSNOWBALL) {
834 BadGuy::make_player_jump(Player* player)
836 player->physic.set_velocity_y(2);
837 player->base.y = base.y - player->base.height - 2;
841 BadGuy::squish_me(Player* player)
843 make_player_jump(player);
845 World::current()->add_score(base.x - scroll_x,
846 base.y, 50 * player_status.score_multiplier);
847 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
848 player_status.score_multiplier++;
850 dying = DYING_SQUISHED;
852 physic.set_velocity(0, 0);
856 BadGuy::squish(Player* player)
858 if(kind == BAD_MRBOMB) {
859 // mrbomb transforms into a bomb now
860 World::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
862 make_player_jump(player);
863 World::current()->add_score(base.x - scroll_x, base.y, 50 * player_status.score_multiplier);
864 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
865 player_status.score_multiplier++;
869 } else if(kind == BAD_BSOD) {
871 set_sprite(img_bsod_squished_left, img_bsod_squished_right);
872 physic.set_velocity_x(0);
875 } else if (kind == BAD_LAPTOP) {
876 if (mode == NORMAL || mode == KICK)
879 play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
881 set_sprite(img_laptop_flat_left, img_laptop_flat_right);
882 physic.set_velocity_x(0);
885 } else if (mode == FLAT) {
887 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
889 if (player->base.x < base.x + (base.width/2)) {
890 physic.set_velocity_x(5);
893 physic.set_velocity_x(-5);
898 set_sprite(img_laptop_flat_left, img_laptop_flat_right);
901 make_player_jump(player);
903 World::current()->add_score(base.x - scroll_x, base.y, 25 * player_status.score_multiplier);
904 player_status.score_multiplier++;
906 } else if(kind == BAD_FISH) {
907 // fish can only be killed when falling down
908 if(physic.get_velocity_y() >= 0)
911 make_player_jump(player);
913 World::current()->add_score(base.x - scroll_x, base.y, 25 * player_status.score_multiplier);
914 player_status.score_multiplier++;
916 // simply remove the fish...
919 } else if(kind == BAD_BOUNCINGSNOWBALL) {
921 set_sprite(img_bouncingsnowball_squished,img_bouncingsnowball_squished);
923 } else if(kind == BAD_FLYINGSNOWBALL) {
925 set_sprite(img_flyingsnowball_squished,img_flyingsnowball_squished);
927 } else if(kind == BAD_SNOWBALL) {
929 set_sprite(img_snowball_squished_left, img_snowball_squished_right);
937 if(kind == BAD_BOMB || kind == BAD_STALACTITE || kind == BAD_FLAME)
940 dying = DYING_FALLING;
941 if(kind == BAD_LAPTOP)
942 set_sprite(img_laptop_falling_left, img_laptop_falling_right);
943 else if(kind == BAD_BSOD)
944 set_sprite(img_bsod_falling_left, img_bsod_falling_right);
946 physic.enable_gravity(true);
947 physic.set_velocity_y(0);
949 /* Gain some points: */
950 if (kind == BAD_BSOD)
951 World::current()->add_score(base.x - scroll_x, base.y,
952 50 * player_status.score_multiplier);
954 World::current()->add_score(base.x - scroll_x, base.y,
955 25 * player_status.score_multiplier);
957 /* Play death sound: */
958 play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
962 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
964 BadGuy* pbad_c = NULL;
966 if(type == COLLISION_BUMP) {
970 if(type == COLLISION_SQUISH) {
971 Player* player = static_cast<Player*>(p_c_object);
976 /* COLLISION_NORMAL */
984 pbad_c = (BadGuy*) p_c_object;
986 /* If we're a kicked mriceblock, kill any badguys we hit */
987 if(kind == BAD_LAPTOP && mode == KICK &&
988 pbad_c->kind != BAD_FLAME && pbad_c->kind != BAD_BOMB)
993 /* Kill badguys that run into exploding bomb */
994 else if (kind == BAD_BOMB && dying == DYING_NOT)
996 if (pbad_c->kind == BAD_MRBOMB)
998 // FIXME: this is where other MrBombs *should* explode istead of dying
1001 else if (pbad_c->kind != BAD_BOMB)
1007 /* Kill any badguys that get hit by stalactite */
1008 else if (kind == BAD_STALACTITE && dying == DYING_NOT)
1013 /* When enemies run into eachother, make them change directions */
1016 // Jumpy is an exception
1017 if (pbad_c->kind == BAD_MONEY)
1020 // Bounce off of other badguy if we land on top of him
1021 if (base.y + base.height < pbad_c->base.y + pbad_c->base.height)
1023 Direction old_dir = dir;
1024 if (pbad_c->dir == LEFT)
1026 else if (pbad_c->dir == RIGHT)
1030 physic.inverse_velocity_x();
1032 physic.set_velocity(fabs(physic.get_velocity_x()), 2);
1036 else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height)
1041 else if (dir == RIGHT)
1044 physic.inverse_velocity_x();
1050 Player* player = static_cast<Player*>(p_c_object);
1051 /* Get kicked if were flat */
1052 if (mode == FLAT && !dying)
1054 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
1056 // Hit from left side
1057 if (player->base.x < base.x) {
1058 physic.set_velocity_x(5);
1061 // Hit from right side
1063 physic.set_velocity_x(-5);
1068 set_sprite(img_laptop_flat_left, img_laptop_flat_right);
1075 //---------------------------------------------------------------------------
1077 void load_badguy_gfx()
1079 img_bsod_squished_left = sprite_manager->load("bsod-squished-left");
1080 img_bsod_squished_right = sprite_manager->load("bsod-squished-right");
1081 img_bsod_falling_left = sprite_manager->load("bsod-falling-left");
1082 img_bsod_falling_right = sprite_manager->load("bsod-falling-right");
1083 img_laptop_flat_left = sprite_manager->load("laptop-flat-left");
1084 img_laptop_flat_right = sprite_manager->load("laptop-flat-right");
1085 img_laptop_falling_left = sprite_manager->load("laptop-falling-left");
1086 img_laptop_falling_right = sprite_manager->load("laptop-falling-right");
1087 img_bsod_left = sprite_manager->load("bsod-left");
1088 img_bsod_right = sprite_manager->load("bsod-right");
1089 img_laptop_left = sprite_manager->load("laptop-left");
1090 img_laptop_right = sprite_manager->load("laptop-right");
1091 img_jumpy_left_up = sprite_manager->load("jumpy-left-up");
1092 img_jumpy_left_down = sprite_manager->load("jumpy-left-down");
1093 img_jumpy_left_middle = sprite_manager->load("jumpy-left-middle");
1094 img_mrbomb_left = sprite_manager->load("mrbomb-left");
1095 img_mrbomb_right = sprite_manager->load("mrbomb-right");
1096 img_mrbomb_ticking_left = sprite_manager->load("mrbomb-ticking-left");
1097 img_mrbomb_ticking_right = sprite_manager->load("mrbomb-ticking-right");
1098 img_mrbomb_explosion = sprite_manager->load("mrbomb-explosion");
1099 img_stalactite = sprite_manager->load("stalactite");
1100 img_stalactite_broken = sprite_manager->load("stalactite-broken");
1101 img_flame = sprite_manager->load("flame");
1102 img_fish = sprite_manager->load("fish");
1103 img_fish_down = sprite_manager->load("fish-down");
1104 img_bouncingsnowball_left = sprite_manager->load("bouncingsnowball-left");
1105 img_bouncingsnowball_right = sprite_manager->load("bouncingsnowball-right");
1106 img_bouncingsnowball_squished = sprite_manager->load("bouncingsnowball-squished");
1107 img_flyingsnowball = sprite_manager->load("flyingsnowball");
1108 img_flyingsnowball_squished = sprite_manager->load("flyingsnowball-squished");
1109 img_spiky_left = sprite_manager->load("spiky-left");
1110 img_spiky_right = sprite_manager->load("spiky-right");
1111 img_snowball_left = sprite_manager->load("snowball-left");
1112 img_snowball_right = sprite_manager->load("snowball-right");
1113 img_snowball_squished_left = sprite_manager->load("snowball-squished-left");
1114 img_snowball_squished_right = sprite_manager->load("snowball-squished-right");
1117 img_bsod_left[0] = new Surface(datadir + "/images/shared/bsod-left-0.png", USE_ALPHA);
1119 img_bsod_left[1] = new Surface(datadir +
1120 "/images/shared/bsod-left-1.png",
1123 img_bsod_left[2] = new Surface(datadir +
1124 "/images/shared/bsod-left-2.png",
1127 img_bsod_left[3] = new Surface(datadir +
1128 "/images/shared/bsod-left-3.png",
1131 img_bsod_right[0] = new Surface(datadir +
1132 "/images/shared/bsod-right-0.png",
1135 img_bsod_right[1] = new Surface(datadir +
1136 "/images/shared/bsod-right-1.png",
1139 img_bsod_right[2] = new Surface(datadir +
1140 "/images/shared/bsod-right-2.png",
1143 img_bsod_right[3] = new Surface(datadir +
1144 "/images/shared/bsod-right-3.png",
1147 img_bsod_squished_left[0] = new Surface(datadir +
1148 "/images/shared/bsod-squished-left.png",
1151 img_bsod_squished_right[0] = new Surface(datadir +
1152 "/images/shared/bsod-squished-right.png",
1155 img_bsod_falling_left[0] = new Surface(datadir +
1156 "/images/shared/bsod-falling-left.png",
1159 img_bsod_falling_right[0] = new Surface(datadir +
1160 "/images/shared/bsod-falling-right.png",
1166 img_laptop_left[0] = new Surface(datadir + "/images/shared/mriceblock-left-0.png", USE_ALPHA);
1167 img_laptop_left[1] = new Surface(datadir + "/images/shared/mriceblock-left-1.png", USE_ALPHA);
1168 img_laptop_left[2] = new Surface(datadir + "/images/shared/mriceblock-left-2.png", USE_ALPHA);
1169 img_laptop_left[3] = new Surface(datadir + "/images/shared/mriceblock-left-1.png", USE_ALPHA);
1171 img_laptop_right[0] = new Surface(datadir + "/images/shared/mriceblock-right-0.png", USE_ALPHA);
1172 img_laptop_right[1] = new Surface(datadir + "/images/shared/mriceblock-right-1.png", USE_ALPHA);
1173 img_laptop_right[2] = new Surface(datadir + "/images/shared/mriceblock-right-2.png", USE_ALPHA);
1174 img_laptop_right[3] = new Surface(datadir + "/images/shared/mriceblock-right-1.png", USE_ALPHA);
1176 img_laptop_flat_left[0] = new Surface(
1177 datadir + "/images/shared/laptop-flat-left.png",
1180 img_laptop_flat_right[0] = new Surface(datadir +
1181 "/images/shared/laptop-flat-right.png",
1184 img_laptop_falling_left[0] = new Surface(datadir +
1185 "/images/shared/laptop-falling-left.png",
1188 img_laptop_falling_right[0] = new Surface(datadir +
1189 "/images/shared/laptop-falling-right.png",
1194 img_jumpy_left_up = new Surface(datadir +
1195 "/images/shared/jumpy-left-up-0.png",
1197 img_jumpy_left_down = new Surface(datadir +
1198 "/images/shared/jumpy-left-down-0.png",
1200 img_jumpy_left_middle = new Surface(datadir +
1201 "/images/shared/jumpy-left-middle-0.png",
1205 for(int i=0; i<4; ++i) {
1207 snprintf(num, 4, "%d", i);
1208 img_mrbomb_left[i] = new Surface(
1209 datadir + "/images/shared/mrbomb-left-" + num + ".png", USE_ALPHA);
1210 img_mrbomb_right[i] = new Surface(
1211 datadir + "/images/shared/mrbomb-right-" + num + ".png", USE_ALPHA);
1213 img_mrbomb_ticking_left[0] = new Surface(
1214 datadir + "/images/shared/mrbombx-left-0.png", USE_ALPHA);
1215 img_mrbomb_ticking_right[0] = new Surface(
1216 datadir + "/images/shared/mrbombx-right-0.png", USE_ALPHA);
1217 img_mrbomb_explosion[0] = new Surface(
1218 datadir + "/images/shared/mrbomb-explosion.png", USE_ALPHA);
1221 img_stalactite[0] = new Surface(
1222 datadir + "/images/shared/stalactite.png", USE_ALPHA);
1223 img_stalactite_broken[0] = new Surface(
1224 datadir + "/images/shared/stalactite-broken.png", USE_ALPHA);
1227 img_flame[0] = new Surface(
1228 datadir + "/images/shared/flame-0.png", USE_ALPHA);
1229 img_flame[1] = new Surface(
1230 datadir + "/images/shared/flame-1.png", USE_ALPHA);
1233 img_fish[0] = new Surface(
1234 datadir + "/images/shared/fish-left-0.png", USE_ALPHA);
1235 img_fish[1] = new Surface(
1236 datadir + "/images/shared/fish-left-1.png", USE_ALPHA);
1237 img_fish_down[0] = new Surface(
1238 datadir + "/images/shared/fish-down-0.png", USE_ALPHA);
1240 /* bouncing snowball */
1241 for(int i=0; i<6; ++i) {
1243 snprintf(num, 4, "%d", i);
1244 img_bouncingsnowball_left[i] = new Surface(
1245 datadir + "/images/shared/bouncingsnowball-left-" + num + ".png",
1247 img_bouncingsnowball_right[i] = new Surface(
1248 datadir + "/images/shared/bouncingsnowball-right-" + num + ".png",
1251 img_bouncingsnowball_squished[0] = new Surface(
1252 datadir + "/images/shared/bsod-squished-left.png", USE_ALPHA);
1254 /* flying snowball */
1255 img_flyingsnowball[0] = new Surface(
1256 datadir + "/images/shared/flyingsnowball-left-0.png", USE_ALPHA);
1257 img_flyingsnowball[1] = new Surface(
1258 datadir + "/images/shared/flyingsnowball-left-1.png", USE_ALPHA);
1259 img_flyingsnowball_squished[0] = new Surface(
1260 datadir + "/images/shared/bsod-squished-left.png", USE_ALPHA);
1263 for(int i = 0; i < 3; ++i) {
1265 snprintf(num, 4, "%d", i);
1266 img_spiky_left[i] = new Surface(
1267 datadir + "/images/shared/spiky-left-" + num + ".png",
1269 img_spiky_right[i] = new Surface(
1270 datadir + "/images/shared/spiky-right-" + num + ".png",
1275 img_snowball_left[0] = new Surface(datadir + "/images/shared/snowball-left-0.png", USE_ALPHA);
1276 img_snowball_left[1] = new Surface(datadir + "/images/shared/snowball-left-1.png", USE_ALPHA);
1277 img_snowball_left[2] = new Surface(datadir + "/images/shared/snowball-left-2.png", USE_ALPHA);
1278 img_snowball_left[3] = new Surface(datadir + "/images/shared/snowball-left-1.png", USE_ALPHA);
1280 img_snowball_right[0] = new Surface(datadir + "/images/shared/snowball-right-0.png", USE_ALPHA);
1281 img_snowball_right[1] = new Surface(datadir + "/images/shared/snowball-right-1.png", USE_ALPHA);
1282 img_snowball_right[2] = new Surface(datadir + "/images/shared/snowball-right-2.png", USE_ALPHA);
1283 img_snowball_right[3] = new Surface(datadir + "/images/shared/snowball-right-1.png", USE_ALPHA);
1285 img_snowball_squished_left[0] = new Surface(
1286 datadir + "/images/shared/bsod-squished-left.png", USE_ALPHA);
1287 img_snowball_squished_right[0] = new Surface(
1288 datadir + "/images/shared/bsod-squished-right.png", USE_ALPHA);
1292 void free_badguy_gfx()