7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - December 9, 2003
22 #include <sys/types.h>
32 #include "high_scores.h"
58 char * soundfilenames[NUM_SOUNDS] = {
59 DATA_PREFIX "/sounds/jump.wav",
60 DATA_PREFIX "/sounds/bigjump.wav",
61 DATA_PREFIX "/sounds/skid.wav",
62 DATA_PREFIX "/sounds/distro.wav",
63 DATA_PREFIX "/sounds/herring.wav",
64 DATA_PREFIX "/sounds/brick.wav",
65 DATA_PREFIX "/sounds/hurt.wav",
66 DATA_PREFIX "/sounds/squish.wav",
67 DATA_PREFIX "/sounds/fall.wav",
68 DATA_PREFIX "/sounds/ricochet.wav",
69 DATA_PREFIX "/sounds/bump-upgrade.wav",
70 DATA_PREFIX "/sounds/upgrade.wav",
71 DATA_PREFIX "/sounds/excellent.wav",
72 DATA_PREFIX "/sounds/coffee.wav",
73 DATA_PREFIX "/sounds/shoot.wav",
74 DATA_PREFIX "/sounds/lifeup.wav"
78 /* Local variables: */
80 int score, highscore, distros, level, lives, scroll_x, next_level, game_pause,
81 done, quit, tux_dir, tux_size, tux_duck, tux_x, tux_xm, tux_y, tux_ym,
82 tux_dying, tux_safe, jumping, jump_counter, frame, score_multiplier,
83 tux_frame_main, tux_frame, tux_got_coffee, tux_skidding,
84 super_bkgd_time, time_left, tux_invincible_time, endpos,
85 counting_distros, distro_counter;
86 int bkgd_red, bkgd_green, bkgd_blue, level_width;
87 int left, right, up, down, fire, old_fire;
88 SDL_Surface * img_brick[2], * img_solid[4], * img_distro[4],
89 * img_waves[3], * img_water, * img_pole, * img_poletop, * img_flag[2];
90 SDL_Surface * img_bkgd[2][4];
91 SDL_Surface * img_golden_herring;
92 SDL_Surface * img_bsod_left[4], * img_bsod_right[4],
93 * img_laptop_left[3], * img_laptop_right[3],
94 * img_money_left[2], * img_money_right[2];
95 SDL_Surface * img_bsod_squished_left, * img_bsod_squished_right,
96 * img_bsod_falling_left, * img_bsod_falling_right,
97 * img_laptop_flat_left, * img_laptop_flat_right,
98 * img_laptop_falling_left, * img_laptop_falling_right;
99 SDL_Surface * img_box_full, * img_box_empty, * img_mints, * img_coffee,
100 * img_super_bkgd, * img_bullet, * img_red_glow;
101 SDL_Surface * img_cloud[2][4];
102 SDL_Surface * tux_right[3], * tux_left[3],
103 * bigtux_right[3], * bigtux_left[3],
104 * bigtux_right_jump, * bigtux_left_jump,
105 * cape_right[2], * cape_left[2],
106 * bigcape_right[2], * bigcape_left[2],
107 * ducktux_right, * ducktux_left,
108 * skidtux_right, * skidtux_left;
112 unsigned char * tiles[15];
113 bouncy_distro_type bouncy_distros[NUM_BOUNCY_DISTROS];
114 broken_brick_type broken_bricks[NUM_BROKEN_BRICKS];
115 bouncy_brick_type bouncy_bricks[NUM_BOUNCY_BRICKS];
116 bad_guy_type bad_guys[NUM_BAD_GUYS];
117 floating_score_type floating_scores[NUM_FLOATING_SCORES];
118 upgrade_type upgrades[NUM_UPGRADES];
119 bullet_type bullets[NUM_BULLETS];
125 /* Local function prototypes: */
128 void loadlevel(void);
129 void loadlevelgfx(void);
130 void loadlevelsong(void);
131 void unloadlevelgfx(void);
132 void unloadlevelsong(void);
133 void loadshared(void);
134 void unloadshared(void);
135 void drawshape(int x, int y, unsigned char c);
136 unsigned char shape(int x, int y, int sx);
137 int issolid(int x, int y, int sx);
138 int isbrick(int x, int y, int sx);
139 int isice(int x, int y, int sx);
140 int isfullbox(int x, int y, int sx);
141 void change(int x, int y, int sx, unsigned char c);
142 void trybreakbrick(int x, int y, int sx);
143 void bumpbrick(int x, int y, int sx);
144 void tryemptybox(int x, int y, int sx);
145 void trygrabdistro(int x, int y, int sx, int bounciness);
146 void add_bouncy_distro(int x, int y);
147 void add_broken_brick(int x, int y);
148 void add_broken_brick_piece(int x, int y, int xm, int ym);
149 void add_bouncy_brick(int x, int y);
150 void add_bad_guy(int x, int y, int kind);
151 void add_score(int x, int y, int s);
152 void trybumpbadguy(int x, int y, int sx);
153 void add_upgrade(int x, int y, int kind);
154 void killtux(int mode);
155 void add_bullet(int x, int y, int dir, int xm);
156 void drawendscreen(void);
157 void drawresultscreen(void);
159 /* --- GAME EVENT! --- */
161 void game_event(void)
164 while (SDL_PollEvent(&event))
167 if (event.type == SDL_QUIT)
169 /* Quit event - quit: */
173 else if (event.type == SDL_KEYDOWN)
177 key = event.key.keysym.sym;
179 if (key == SDLK_ESCAPE)
181 /* Escape: Open/Close the menu: */
190 else if (key == SDLK_RIGHT)
194 else if (key == SDLK_LEFT)
198 else if (key == SDLK_UP)
202 else if (key == SDLK_DOWN)
206 else if (key == SDLK_LCTRL)
211 else if (event.type == SDL_KEYUP)
215 key = event.key.keysym.sym;
217 /* Check for menu-events, if the menu is shown */
221 if (key == SDLK_RIGHT)
225 else if (key == SDLK_LEFT)
229 else if (key == SDLK_UP)
233 else if (key == SDLK_DOWN)
237 else if (key == SDLK_LCTRL)
241 else if (key == SDLK_p)
251 else if (key == SDLK_TAB)
253 tux_size = !tux_size;
255 else if (key == SDLK_END)
259 else if (key == SDLK_SPACE)
265 else if (event.type == SDL_JOYAXISMOTION)
267 if (event.jaxis.axis == JOY_X)
269 if (event.jaxis.value < -256)
274 if (event.jaxis.value > 256)
279 else if (event.jaxis.axis == JOY_Y)
281 if (event.jaxis.value > 256)
286 /* Handle joystick for the menu */
290 menuaction = MN_DOWN;
296 else if (event.type == SDL_JOYBUTTONDOWN)
298 if (event.jbutton.button == JOY_A)
300 else if (event.jbutton.button == JOY_B)
303 else if (event.type == SDL_JOYBUTTONUP)
305 if (event.jbutton.button == JOY_A)
307 else if (event.jbutton.button == JOY_B)
320 /* --- GAME ACTION! --- */
322 int game_action(void)
326 /* --- HANDLE TUX! --- */
328 /* Handle key and joystick state: */
330 if (!(tux_dying || next_level))
332 if (right == DOWN && left == UP)
336 if (tux_xm < -SKID_XM && !tux_skidding &&
339 tux_skidding = SKID_TIME;
341 play_sound(sounds[SND_SKID]);
347 if (tux_xm < 0 && !isice(tux_x, tux_y + 32, scroll_x) &&
355 if (tux_dir == RIGHT)
357 /* Facing the direction we're jumping? Go full-speed: */
361 tux_xm = tux_xm + WALK_SPEED;
363 if (tux_xm > MAX_WALK_XM)
364 tux_xm = MAX_WALK_XM;
366 else if (fire == DOWN)
368 tux_xm = tux_xm + RUN_SPEED;
370 if (tux_xm > MAX_RUN_XM)
376 /* Not facing the direction we're jumping?
379 tux_xm = tux_xm + WALK_SPEED / 2;
381 if (tux_xm > MAX_WALK_XM / 2)
382 tux_xm = MAX_WALK_XM / 2;
386 else if (left == DOWN && right == UP)
390 if (tux_xm > SKID_XM && !tux_skidding &&
393 tux_skidding = SKID_TIME;
394 play_sound(sounds[SND_SKID]);
399 if (tux_xm > 0 && !isice(tux_x, tux_y + 32, scroll_x) &&
409 /* Facing the direction we're jumping? Go full-speed: */
413 tux_xm = tux_xm - WALK_SPEED;
415 if (tux_xm < -MAX_WALK_XM)
416 tux_xm = -MAX_WALK_XM;
418 else if (fire == DOWN)
420 tux_xm = tux_xm - RUN_SPEED;
422 if (tux_xm < -MAX_RUN_XM)
423 tux_xm = -MAX_RUN_XM;
428 /* Not facing the direction we're jumping?
431 tux_xm = tux_xm - WALK_SPEED / 2;
433 if (tux_xm < -MAX_WALK_XM / 2)
434 tux_xm = -MAX_WALK_XM / 2;
442 if (tux_x >= endpos && endpos != 0)
452 if (jump_counter == 0)
456 if (!issolid(tux_x, tux_y + 32, scroll_x) ||
459 /* If they're not on the ground, or are currently moving
460 vertically, don't jump! */
462 jump_counter = MAX_JUMP_COUNT;
466 /* Make sure we're not standing back up into a solid! */
468 if (tux_size == SMALL || tux_duck == NO ||
469 !issolid(tux_x, tux_y, scroll_x))
473 if (tux_size == SMALL)
474 play_sound(sounds[SND_JUMP]);
476 play_sound(sounds[SND_BIGJUMP]);
482 /* Keep jumping for a while: */
484 if (jump_counter < MAX_JUMP_COUNT)
486 tux_ym = tux_ym - JUMP_SPEED;
496 if (fire == DOWN && old_fire == UP && tux_got_coffee)
498 add_bullet(tux_x + scroll_x, tux_y, tux_dir, tux_xm);
511 if (tux_size == BIG && tux_duck == YES)
513 /* Make sure we're not standing back up into a solid! */
515 if (!issolid(tux_x, tux_y - 32, scroll_x))
521 } /* (tux_dying || next_level) */
524 /* Tux either died, or reached the end of a level! */
533 /* End of a level! */
541 tux_ym = tux_ym + GRAVITY;
549 /* No more lives!? */
555 if (score > highscore)
559 } /* if (lives < 0) */
562 /* Either way, (re-)load the (next) level... */
573 tux_x = tux_x + tux_xm;
574 tux_y = tux_y + tux_ym;
577 /* Keep tux in bounds: */
581 else if (tux_x > 320 && scroll_x < ((level_width * 32) - 640))
583 /* Scroll the screen in past center: */
585 scroll_x = scroll_x + (tux_x - 320);
588 if (scroll_x > ((level_width * 32) - 640))
589 scroll_x = ((level_width * 32) - 640);
591 else if (tux_x > 608)
593 /* ... unless there's no more to scroll! */
603 if (issolid(tux_x, tux_y + 31, scroll_x) &&
604 !issolid(tux_x - tux_xm, tux_y + 31, scroll_x))
606 while (issolid(tux_x, tux_y + 31, scroll_x))
617 if (issolid(tux_x, tux_y, scroll_x) &&
618 !issolid(tux_x - tux_xm, tux_y, scroll_x))
620 while (issolid(tux_x, tux_y, scroll_x))
631 if (issolid(tux_x, tux_y + 31, scroll_x))
633 /* Set down properly: */
635 while (issolid(tux_x, tux_y + 31, scroll_x))
644 /* Reset score multiplier (for mutli-hits): */
647 score_multiplier = 1;
657 /* Bump into things: */
659 if (issolid(tux_x, tux_y, scroll_x) ||
660 (tux_size == BIG && !tux_duck &&
661 (issolid(tux_x, tux_y - 32, scroll_x))))
663 if (!issolid(tux_x - tux_xm, tux_y, scroll_x) &&
664 (tux_size == SMALL || tux_duck ||
665 !issolid(tux_x - tux_xm, tux_y - 32, scroll_x)))
667 tux_x = tux_x - tux_xm;
670 else if (!issolid(tux_x, tux_y - tux_ym, scroll_x) &&
671 (tux_size == SMALL || tux_duck ||
672 !issolid(tux_x, tux_y - 32 - tux_ym, scroll_x)))
680 /* Break bricks and empty boxes: */
684 if (isbrick(tux_x, tux_y - 32, scroll_x) ||
685 isfullbox(tux_x, tux_y - 32, scroll_x))
687 trygrabdistro(tux_x, tux_y - 64, scroll_x,
689 trybumpbadguy(tux_x, tux_y - 96, scroll_x);
691 if (isfullbox(tux_x, tux_y - 32,
694 bumpbrick(tux_x, tux_y - 32,
698 trybreakbrick(tux_x, tux_y - 32, scroll_x);
699 tryemptybox(tux_x, tux_y - 32, scroll_x);
702 if (isbrick(tux_x + 31, tux_y - 32, scroll_x) ||
703 isfullbox(tux_x + 31, tux_y - 32, scroll_x))
705 trygrabdistro(tux_x + 31,
709 trybumpbadguy(tux_x + 31,
713 if (isfullbox(tux_x + 31, tux_y - 32,
716 bumpbrick(tux_x + 31, tux_y - 32,
720 trybreakbrick(tux_x + 31,
723 tryemptybox(tux_x + 31,
730 if (isbrick(tux_x, tux_y, scroll_x) ||
731 isfullbox(tux_x, tux_y, scroll_x))
733 trygrabdistro(tux_x, tux_y - 32, scroll_x,
735 trybumpbadguy(tux_x, tux_y - 64, scroll_x);
736 if (isfullbox(tux_x, tux_y, scroll_x))
737 bumpbrick(tux_x, tux_y, scroll_x);
738 trybreakbrick(tux_x, tux_y, scroll_x);
739 tryemptybox(tux_x, tux_y, scroll_x);
742 if (isbrick(tux_x + 31, tux_y, scroll_x) ||
743 isfullbox(tux_x + 31, tux_y, scroll_x))
745 trygrabdistro(tux_x + 31,
749 trybumpbadguy(tux_x + 31,
752 if (isfullbox(tux_x + 31, tux_y, scroll_x))
753 bumpbrick(tux_x + 31, tux_y, scroll_x);
754 trybreakbrick(tux_x + 31, tux_y, scroll_x);
755 tryemptybox(tux_x + 31, tux_y, scroll_x);
761 /* It's a brick and we're small, make the brick
762 bounce, and grab any distros above it: */
764 if (isbrick(tux_x, tux_y, scroll_x) ||
765 isfullbox(tux_x, tux_y, scroll_x))
767 trygrabdistro(tux_x, tux_y - 32, scroll_x,
769 trybumpbadguy(tux_x, tux_y - 64, scroll_x);
770 bumpbrick(tux_x, tux_y, scroll_x);
771 tryemptybox(tux_x, tux_y, scroll_x);
774 if (isbrick(tux_x + 31, tux_y, scroll_x) ||
775 isfullbox(tux_x + 31, tux_y, scroll_x))
777 trygrabdistro(tux_x + 31, tux_y - 32, scroll_x,
779 trybumpbadguy(tux_x + 31, tux_y - 64, scroll_x);
780 bumpbrick(tux_x + 31, tux_y, scroll_x);
781 tryemptybox(tux_x + 31, tux_y, scroll_x);
785 /* Get a distro from a brick? */
787 if (shape(tux_x, tux_y, scroll_x) == 'x' ||
788 shape(tux_x, tux_y, scroll_x) == 'y')
790 add_bouncy_distro(((tux_x + scroll_x + 1)
794 if (counting_distros == NO)
796 counting_distros = YES;
797 distro_counter = 100;
800 if (distro_counter <= 0)
801 change(tux_x, tux_y, scroll_x, 'a');
803 play_sound(sounds[SND_DISTRO]);
804 score = score + SCORE_DISTRO;
807 else if (shape(tux_x + 31, tux_y, scroll_x) == 'x' ||
808 shape(tux_x + 31, tux_y, scroll_x) == 'y')
810 add_bouncy_distro(((tux_x + scroll_x + 1 + 31)
814 if (counting_distros == NO)
816 counting_distros = YES;
817 distro_counter = 100;
820 if (distro_counter <= 0)
821 change(tux_x + 31, tux_y, scroll_x, 'a');
823 play_sound(sounds[SND_DISTRO]);
824 score = score + SCORE_DISTRO;
832 tux_y = (tux_y / 32) * 32 + 30;
838 tux_y = (tux_y / 32) * 32 - 32;
843 jump_counter = MAX_JUMP_COUNT;
853 trygrabdistro(tux_x, tux_y, scroll_x, NO_BOUNCE);
854 trygrabdistro(tux_x + 31, tux_y, scroll_x, NO_BOUNCE);
856 if (tux_size == BIG && !tux_duck)
858 trygrabdistro(tux_x, tux_y - 32, scroll_x, NO_BOUNCE);
859 trygrabdistro(tux_x + 31, tux_y - 32, scroll_x, NO_BOUNCE);
864 /* Enough distros for a One-up? */
866 if (distros >= DISTROS_LIFEUP)
868 distros = distros - DISTROS_LIFEUP;
869 if(lives < MAX_LIVES)
871 play_sound(sounds[SND_LIFEUP]); /*We want to hear the sound even, if MAX_LIVES is reached*/
875 /* Keep in-bounds, vertically: */
879 else if (tux_y > 480)
885 /* Slow down horizontally: */
889 if (right == UP && left == UP)
891 if (isice(tux_x, tux_y + 32, scroll_x) ||
892 !issolid(tux_x, tux_y + 32, scroll_x))
894 /* Slowly on ice or in air: */
903 /* Quickly, otherwise: */
910 /* Drop vertically: */
912 if (!issolid(tux_x, tux_y + 32, scroll_x))
914 tux_ym = tux_ym + GRAVITY;
926 /* ---- DONE HANDLING TUX! --- */
929 /* Handle bouncy distros: */
931 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
933 if (bouncy_distros[i].alive)
935 bouncy_distros[i].y = bouncy_distros[i].y + bouncy_distros[i].ym;
937 bouncy_distros[i].ym++;
939 if (bouncy_distros[i].ym >= 0)
940 bouncy_distros[i].alive = NO;
945 /* Handle broken bricks: */
947 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
949 if (broken_bricks[i].alive)
951 broken_bricks[i].x = broken_bricks[i].x + broken_bricks[i].xm;
952 broken_bricks[i].y = broken_bricks[i].y + broken_bricks[i].ym;
954 broken_bricks[i].ym++;
956 if (broken_bricks[i].ym >= 0)
957 broken_bricks[i].alive = NO;
962 /* Handle distro counting: */
964 if (counting_distros == YES)
968 if (distro_counter <= 0)
969 counting_distros = -1;
973 /* Handle bouncy bricks: */
975 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
977 if (bouncy_bricks[i].alive)
979 bouncy_bricks[i].offset = (bouncy_bricks[i].offset +
980 bouncy_bricks[i].offset_m);
984 if (bouncy_bricks[i].offset < -BOUNCY_BRICK_MAX_OFFSET)
985 bouncy_bricks[i].offset_m = BOUNCY_BRICK_SPEED;
990 if (bouncy_bricks[i].offset == 0)
991 bouncy_bricks[i].alive = NO;
996 /* Handle floating scores: */
998 for (i = 0; i < NUM_FLOATING_SCORES; i++)
1000 if (floating_scores[i].alive)
1002 floating_scores[i].y = floating_scores[i].y - 2;
1003 floating_scores[i].timer--;
1005 if (floating_scores[i].timer <= 0)
1006 floating_scores[i].alive = NO;
1011 /* Handle bullets: */
1013 for (i = 0; i < NUM_BULLETS; i++)
1015 if (bullets[i].alive)
1017 bullets[i].x = bullets[i].x + bullets[i].xm;
1018 bullets[i].y = bullets[i].y + bullets[i].ym;
1020 if (issolid(bullets[i].x, bullets[i].y, 0))
1022 if (issolid(bullets[i].x, bullets[i].y - bullets[i].ym, 0))
1023 bullets[i].alive = NO;
1026 if (bullets[i].ym >= 0)
1028 bullets[i].y = (bullets[i].y / 32) * 32 - 8;
1030 bullets[i].ym = -bullets[i].ym;
1034 bullets[i].ym = bullets[i].ym + GRAVITY;
1036 if (bullets[i].x < scroll_x ||
1037 bullets[i].x > scroll_x + 640)
1039 bullets[i].alive = NO;
1044 if (bullets[i].alive)
1046 for (j = 0; j < NUM_BAD_GUYS; j++)
1048 if (bad_guys[j].alive && !bad_guys[j].dying)
1050 if (bullets[i].x >= bad_guys[j].x - 4 &&
1051 bullets[i].x <= bad_guys[j].x + 32 + 4 &&
1052 bullets[i].y >= bad_guys[j].y - 4 &&
1053 bullets[i].y <= bad_guys[j].y + 32 + 4)
1055 /* Kill the bad guy! */
1057 bullets[i].alive = 0;
1058 bad_guys[j].dying = FALLING;
1059 bad_guys[j].ym = -8;
1062 /* Gain some points: */
1064 if (bad_guys[j].kind == BAD_BSOD)
1066 add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
1067 50 * score_multiplier);
1069 else if (bad_guys[j].kind == BAD_LAPTOP)
1071 add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
1072 25 * score_multiplier);
1076 /* Play death sound: */
1077 play_sound(sounds[SND_FALL]);
1085 /* Handle background timer: */
1087 if (super_bkgd_time)
1091 /* Handle invincibility timer: */
1094 if (tux_invincible_time > 50)
1096 tux_invincible_time--;
1099 if (!playing_music())
1100 play_music( herring_song, 1 );
1104 if (current_music == HERRING_MUSIC)
1106 /* stop the herring_song, now play the level_song ! */
1107 current_music = LEVEL_MUSIC;
1110 if (!playing_music())
1111 play_music( level_song, 1 );
1112 if (tux_invincible_time > 0)
1113 tux_invincible_time--;
1117 /* Handle upgrades: */
1119 for (i = 0; i < NUM_UPGRADES; i++)
1121 if (upgrades[i].alive)
1123 if (upgrades[i].height < 32)
1127 upgrades[i].height++;
1133 if (upgrades[i].kind == UPGRADE_MINTS ||
1134 upgrades[i].kind == UPGRADE_HERRING)
1136 upgrades[i].x = upgrades[i].x + upgrades[i].xm;
1137 upgrades[i].y = upgrades[i].y + upgrades[i].ym;
1139 if (issolid(upgrades[i].x, upgrades[i].y + 31, 0) ||
1140 issolid(upgrades[i].x + 31, upgrades[i].y + 31, 0))
1142 if (upgrades[i].ym > 0)
1144 if (upgrades[i].kind == UPGRADE_MINTS)
1148 else if (upgrades[i].kind == UPGRADE_HERRING)
1150 upgrades[i].ym = -24;
1153 upgrades[i].y = (upgrades[i].y / 32) * 32;
1157 upgrades[i].ym = upgrades[i].ym + GRAVITY;
1159 if (issolid(upgrades[i].x, upgrades[i].y, 0))
1161 upgrades[i].xm = -upgrades[i].xm;
1166 /* Off the screen? Kill it! */
1168 if (upgrades[i].x < scroll_x)
1169 upgrades[i].alive = NO;
1172 /* Did the player grab it? */
1174 if (tux_x + scroll_x >= upgrades[i].x - 32 &&
1175 tux_x + scroll_x <= upgrades[i].x + 32 &&
1176 tux_y >= upgrades[i].y - 32 &&
1177 tux_y <= upgrades[i].y + 32)
1179 /* Remove the upgrade: */
1181 upgrades[i].alive = NO;
1184 /* Affect the player: */
1186 if (upgrades[i].kind == UPGRADE_MINTS)
1188 play_sound(sounds[SND_EXCELLENT]);
1190 super_bkgd_time = 8;
1192 else if (upgrades[i].kind == UPGRADE_COFFEE)
1194 play_sound(sounds[SND_COFFEE]);
1195 tux_got_coffee = YES;
1196 super_bkgd_time = 4;
1198 else if (upgrades[i].kind == UPGRADE_HERRING)
1200 play_sound(sounds[SND_HERRING]);
1201 tux_invincible_time = TUX_INVINCIBLE_TIME;
1202 super_bkgd_time = 4;
1203 /* play the herring song ^^ */
1204 current_music = HERRING_MUSIC;
1205 if (playing_music())
1207 play_music( herring_song, 1 );
1215 /* Handle bad guys: */
1217 for (i = 0; i < NUM_BAD_GUYS; i++)
1219 if (bad_guys[i].alive)
1221 if (bad_guys[i].seen)
1223 if (bad_guys[i].kind == BAD_BSOD)
1225 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
1227 /* Move left/right: */
1229 if (bad_guys[i].dying == NO ||
1230 bad_guys[i].dying == FALLING)
1232 if (bad_guys[i].dir == RIGHT)
1233 bad_guys[i].x = bad_guys[i].x + 4;
1234 else if (bad_guys[i].dir == LEFT)
1235 bad_guys[i].x = bad_guys[i].x - 4;
1239 /* Move vertically: */
1241 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1244 /* Bump into things horizontally: */
1246 if (!bad_guys[i].dying)
1248 if (issolid(bad_guys[i].x, bad_guys[i].y, 0))
1249 bad_guys[i].dir = !bad_guys[i].dir;
1253 /* Bump into other bad guys: */
1255 for (j = 0; j < NUM_BAD_GUYS; j++)
1257 if (j != i && bad_guys[j].alive &&
1258 !bad_guys[j].dying && !bad_guys[i].dying &&
1259 bad_guys[i].x >= bad_guys[j].x - 32 &&
1260 bad_guys[i].x <= bad_guys[j].x + 32 &&
1261 bad_guys[i].y >= bad_guys[j].y - 32 &&
1262 bad_guys[i].y <= bad_guys[j].y + 32)
1264 bad_guys[i].dir = !bad_guys[i].dir;
1269 /* Fall if we get off the ground: */
1271 if (bad_guys[i].dying != FALLING)
1273 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0) &&
1274 bad_guys[i].ym < MAX_YM)
1276 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1282 if (bad_guys[i].ym > 0)
1284 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1290 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1292 if (bad_guys[i].y > 480)
1293 bad_guys[i].alive = NO;
1295 else if (bad_guys[i].kind == BAD_LAPTOP)
1297 /* --- LAPTOP MONSTER: --- */
1299 /* Move left/right: */
1301 if (bad_guys[i].mode != FLAT && bad_guys[i].mode != KICK)
1303 if (bad_guys[i].dying == NO ||
1304 bad_guys[i].dying == FALLING)
1306 if (bad_guys[i].dir == RIGHT)
1307 bad_guys[i].x = bad_guys[i].x + 4;
1308 else if (bad_guys[i].dir == LEFT)
1309 bad_guys[i].x = bad_guys[i].x - 4;
1312 else if (bad_guys[i].mode == KICK)
1314 if (bad_guys[i].dir == RIGHT)
1315 bad_guys[i].x = bad_guys[i].x + 16;
1316 else if (bad_guys[i].dir == LEFT)
1317 bad_guys[i].x = bad_guys[i].x - 16;
1321 /* Move vertically: */
1323 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1326 /* Bump into things horizontally: */
1328 if (!bad_guys[i].dying)
1330 if (issolid(bad_guys[i].x, bad_guys[i].y, 0))
1332 bad_guys[i].dir = !bad_guys[i].dir;
1334 if (bad_guys[i].mode == KICK)
1335 play_sound(sounds[SND_RICOCHET]);
1340 /* Bump into other bad guys: */
1342 for (j = 0; j < NUM_BAD_GUYS; j++)
1344 if (j != i && bad_guys[j].alive &&
1345 !bad_guys[j].dying && !bad_guys[i].dying &&
1346 bad_guys[i].x >= bad_guys[j].x - 32 &&
1347 bad_guys[i].x <= bad_guys[j].x + 32 &&
1348 bad_guys[i].y >= bad_guys[j].y - 32 &&
1349 bad_guys[i].y <= bad_guys[j].y + 32)
1351 if (bad_guys[i].mode != KICK)
1352 bad_guys[i].dir = !bad_guys[i].dir;
1355 /* We're in kick mode, kill the other guy: */
1357 bad_guys[j].dying = FALLING;
1358 bad_guys[j].ym = -8;
1359 play_sound(sounds[SND_FALL]);
1361 add_score(bad_guys[i].x - scroll_x,
1362 bad_guys[i].y, 100);
1368 /* Fall if we get off the ground: */
1370 if (bad_guys[i].dying != FALLING)
1372 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0) &&
1373 bad_guys[i].ym < MAX_YM)
1375 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1381 if (bad_guys[i].ym > 0)
1383 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1389 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1391 if (bad_guys[i].y > 480)
1392 bad_guys[i].alive = NO;
1394 else if (bad_guys[i].kind == BAD_MONEY)
1396 /* --- MONEY BAGS: --- */
1399 /* Move vertically: */
1401 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1404 /* Fall if we get off the ground: */
1406 if (bad_guys[i].dying != FALLING)
1408 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0))
1410 if (bad_guys[i].ym < MAX_YM)
1412 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1419 if (bad_guys[i].ym > 0)
1421 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1422 bad_guys[i].ym = -MAX_YM;
1427 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1429 if (bad_guys[i].y > 480)
1430 bad_guys[i].alive = NO;
1432 else if (bad_guys[i].kind == -1)
1436 /* Kill it if the player jumped on it: */
1438 if (!bad_guys[i].dying && !tux_dying && !tux_safe &&
1439 tux_x + scroll_x >= bad_guys[i].x - 32 &&
1440 tux_x + scroll_x <= bad_guys[i].x + 32 &&
1441 tux_y >= bad_guys[i].y - 32 &&
1442 tux_y <= bad_guys[i].y - 8
1446 if (bad_guys[i].kind == BAD_BSOD)
1448 bad_guys[i].dying = SQUISHED;
1449 bad_guys[i].timer = 16;
1450 tux_ym = -KILL_BOUNCE_YM;
1452 add_score(bad_guys[i].x - scroll_x, bad_guys[i].y,
1453 50 * score_multiplier);
1455 play_sound(sounds[SND_SQUISH]);
1457 else if (bad_guys[i].kind == BAD_LAPTOP)
1459 if (bad_guys[i].mode != FLAT)
1463 bad_guys[i].mode = FLAT;
1465 bad_guys[i].timer = 64;
1473 bad_guys[i].mode = KICK;
1475 if (tux_x + scroll_x <= bad_guys[i].x)
1476 bad_guys[i].dir = RIGHT;
1478 bad_guys[i].dir = LEFT;
1480 bad_guys[i].timer = 8;
1483 tux_ym = -KILL_BOUNCE_YM;
1485 add_score(bad_guys[i].x - scroll_x,
1487 25 * score_multiplier);
1489 /* play_sound(sounds[SND_SQUISH]); */
1491 else if (bad_guys[i].kind == -1)
1498 /* Hurt the player if he just touched it: */
1500 if (!bad_guys[i].dying && !tux_dying &&
1502 tux_x + scroll_x >= bad_guys[i].x - 32 &&
1503 tux_x + scroll_x <= bad_guys[i].x + 32 &&
1504 tux_y >= bad_guys[i].y - 32 &&
1505 tux_y <= bad_guys[i].y + 32)
1507 if (bad_guys[i].mode == FLAT)
1511 bad_guys[i].mode = KICK;
1513 if (tux_x + scroll_x <= bad_guys[i].x)
1515 bad_guys[i].dir = RIGHT;
1516 bad_guys[i].x = bad_guys[i].x + 16;
1520 bad_guys[i].dir = LEFT;
1521 bad_guys[i].x = bad_guys[i].x - 16;
1524 bad_guys[i].timer = 8;
1526 else if (bad_guys[i].mode == KICK)
1528 if (tux_y < bad_guys[i].y - 16 &&
1529 bad_guys[i].timer == 0)
1531 /* Step on (stop being kicked) */
1533 bad_guys[i].mode = FLAT;
1534 bad_guys[i].timer = 64;
1538 /* Hurt if you get hit by kicked laptop: */
1540 if (bad_guys[i].timer == 0)
1542 if (tux_invincible_time == 0)
1548 bad_guys[i].dying = FALLING;
1549 bad_guys[i].ym = -8;
1550 play_sound(sounds[SND_FALL]);
1557 if (tux_invincible_time == 0)
1563 bad_guys[i].dying = FALLING;
1564 bad_guys[i].ym = -8;
1565 play_sound(sounds[SND_FALL]);
1571 /* Handle mode timer: */
1573 if (bad_guys[i].mode == FLAT)
1575 bad_guys[i].timer--;
1577 if (bad_guys[i].timer <= 0)
1578 bad_guys[i].mode = NORMAL;
1580 else if (bad_guys[i].mode == KICK)
1582 if (bad_guys[i].timer > 0)
1583 bad_guys[i].timer--;
1587 /* Handle dying timer: */
1589 if (bad_guys[i].dying == SQUISHED)
1591 bad_guys[i].timer--;
1594 /* Remove it if time's up: */
1596 if (bad_guys[i].timer <= 0)
1597 bad_guys[i].alive = NO;
1601 /* Remove if it's far off the screen: */
1603 if (bad_guys[i].x < scroll_x - OFFSCREEN_DISTANCE)
1604 bad_guys[i].alive = NO;
1608 /* Once it's on screen, it's activated! */
1610 if (bad_guys[i].x <= scroll_x + 640 + OFFSCREEN_DISTANCE)
1611 bad_guys[i].seen = YES;
1617 /* Handle skidding: */
1619 if (tux_skidding > 0)
1627 /* --- GAME DRAW! --- */
1635 if (tux_dying && (frame % 4) == 0)
1636 clearscreen(255, 255, 255);
1639 if (super_bkgd_time == 0)
1640 clearscreen(bkgd_red, bkgd_green, bkgd_blue);
1642 drawimage(img_super_bkgd, 0, 0, NO_UPDATE);
1646 /* Draw background: */
1648 for (y = 0; y < 15; y++)
1650 for (x = 0; x < 21; x++)
1652 drawshape(x * 32 - (scroll_x % 32), y * 32,
1653 tiles[y][x + (scroll_x / 32)]);
1658 /* (Bouncy bricks): */
1660 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
1662 if (bouncy_bricks[i].alive)
1664 if (bouncy_bricks[i].x >= scroll_x - 32 &&
1665 bouncy_bricks[i].x <= scroll_x + 640)
1667 dest.x = bouncy_bricks[i].x - scroll_x;
1668 dest.y = bouncy_bricks[i].y;
1672 SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format,
1677 drawshape(bouncy_bricks[i].x - scroll_x,
1678 bouncy_bricks[i].y + bouncy_bricks[i].offset,
1679 bouncy_bricks[i].shape);
1687 for (i = 0; i < NUM_BAD_GUYS; i++)
1689 if (bad_guys[i].alive &&
1690 bad_guys[i].x > scroll_x - 32 &&
1691 bad_guys[i].x < scroll_x + 640)
1693 if (bad_guys[i].kind == BAD_BSOD)
1695 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
1697 if (bad_guys[i].dying == NO)
1701 if (bad_guys[i].dir == LEFT)
1703 drawimage(img_bsod_left[(frame / 5) % 4],
1704 bad_guys[i].x - scroll_x,
1710 drawimage(img_bsod_right[(frame / 5) % 4],
1711 bad_guys[i].x - scroll_x,
1716 else if (bad_guys[i].dying == FALLING)
1720 if (bad_guys[i].dir == LEFT)
1722 drawimage(img_bsod_falling_left,
1723 bad_guys[i].x - scroll_x,
1729 drawimage(img_bsod_falling_right,
1730 bad_guys[i].x - scroll_x,
1735 else if (bad_guys[i].dying == SQUISHED)
1737 /* Dying - Squished: */
1739 if (bad_guys[i].dir == LEFT)
1741 drawimage(img_bsod_squished_left,
1742 bad_guys[i].x - scroll_x,
1748 drawimage(img_bsod_squished_right,
1749 bad_guys[i].x - scroll_x,
1755 else if (bad_guys[i].kind == BAD_LAPTOP)
1757 /* --- LAPTOP MONSTER: --- */
1759 if (bad_guys[i].dying == NO)
1763 if (bad_guys[i].mode == NORMAL)
1767 if (bad_guys[i].dir == LEFT)
1769 drawimage(img_laptop_left[(frame / 5) % 3],
1770 bad_guys[i].x - scroll_x,
1776 drawimage(img_laptop_right[(frame / 5) % 3],
1777 bad_guys[i].x - scroll_x,
1786 if (bad_guys[i].dir == LEFT)
1788 drawimage(img_laptop_flat_left,
1789 bad_guys[i].x - scroll_x,
1795 drawimage(img_laptop_flat_right,
1796 bad_guys[i].x - scroll_x,
1802 else if (bad_guys[i].dying == FALLING)
1806 if (bad_guys[i].dir == LEFT)
1808 drawimage(img_laptop_falling_left,
1809 bad_guys[i].x - scroll_x,
1815 drawimage(img_laptop_falling_right,
1816 bad_guys[i].x - scroll_x,
1822 else if (bad_guys[i].kind == BAD_MONEY)
1824 if (bad_guys[i].ym > -16)
1826 if (bad_guys[i].dir == LEFT)
1828 drawimage(img_money_left[0],
1829 bad_guys[i].x - scroll_x,
1835 drawimage(img_money_right[0],
1836 bad_guys[i].x - scroll_x,
1843 if (bad_guys[i].dir == LEFT)
1845 drawimage(img_money_left[1],
1846 bad_guys[i].x - scroll_x,
1852 drawimage(img_money_right[1],
1853 bad_guys[i].x - scroll_x,
1859 else if (bad_guys[i].kind == -1)
1867 if (right == UP && left == UP)
1874 if ((fire == DOWN && (frame % 2) == 0) ||
1876 tux_frame_main = (tux_frame_main + 1) % 4;
1878 tux_frame = tux_frame_main;
1885 if (tux_got_coffee && (frame % 2) == 1)
1889 drawimage(img_red_glow, tux_x - 8, tux_y - 32, NO_UPDATE);
1893 if (tux_safe == 0 || (frame % 2) == 0)
1895 if (tux_size == SMALL)
1897 if (tux_invincible_time)
1901 if (tux_dir == RIGHT)
1903 drawimage(cape_right[frame % 2],
1909 drawimage(cape_left[frame % 2],
1916 if (tux_dir == RIGHT)
1918 drawimage(tux_right[tux_frame], tux_x, tux_y, NO_UPDATE);
1922 drawimage(tux_left[tux_frame], tux_x, tux_y, NO_UPDATE);
1927 if (tux_invincible_time)
1931 if (tux_dir == RIGHT)
1933 drawimage(bigcape_right[frame % 2],
1934 tux_x - 8 - 16, tux_y - 32,
1939 drawimage(bigcape_left[frame % 2],
1940 tux_x - 8, tux_y - 32,
1949 if (!jumping || tux_ym > 0)
1951 if (tux_dir == RIGHT)
1953 drawimage(bigtux_right[tux_frame],
1954 tux_x - 8, tux_y - 32,
1959 drawimage(bigtux_left[tux_frame],
1960 tux_x - 8, tux_y - 32,
1966 if (tux_dir == RIGHT)
1968 drawimage(bigtux_right_jump,
1969 tux_x - 8, tux_y - 32,
1974 drawimage(bigtux_left_jump,
1975 tux_x - 8, tux_y - 32,
1982 if (tux_dir == RIGHT)
1984 drawimage(skidtux_right,
1985 tux_x - 8, tux_y - 32,
1990 drawimage(skidtux_left,
1991 tux_x - 8, tux_y - 32,
1998 if (tux_dir == RIGHT)
2000 drawimage(ducktux_right, tux_x - 8, tux_y - 16,
2005 drawimage(ducktux_left, tux_x - 8, tux_y - 16,
2015 for (i = 0; i < NUM_BULLETS; i++)
2017 if (bullets[i].alive &&
2018 bullets[i].x >= scroll_x - 4 &&
2019 bullets[i].x <= scroll_x + 640)
2021 drawimage(img_bullet, bullets[i].x - scroll_x, bullets[i].y,
2027 /* (Floating scores): */
2029 for (i = 0; i < NUM_FLOATING_SCORES; i++)
2031 if (floating_scores[i].alive)
2033 sprintf(str, "%d", floating_scores[i].value);
2035 floating_scores[i].x + 16 - strlen(str) * 8,
2036 floating_scores[i].y,
2037 letters_gold, NO_UPDATE);
2044 for (i = 0; i < NUM_UPGRADES; i++)
2046 if (upgrades[i].alive)
2048 if (upgrades[i].height < 32)
2052 dest.x = upgrades[i].x - scroll_x;
2053 dest.y = upgrades[i].y + 32 - upgrades[i].height;
2055 dest.h = upgrades[i].height;
2060 src.h = upgrades[i].height;
2062 if (upgrades[i].kind == UPGRADE_MINTS)
2063 SDL_BlitSurface(img_mints, &src, screen, &dest);
2064 else if (upgrades[i].kind == UPGRADE_COFFEE)
2065 SDL_BlitSurface(img_coffee, &src, screen, &dest);
2066 else if (upgrades[i].kind == UPGRADE_HERRING)
2067 SDL_BlitSurface(img_golden_herring, &src, screen, &dest);
2071 if (upgrades[i].kind == UPGRADE_MINTS)
2073 drawimage(img_mints,
2074 upgrades[i].x - scroll_x, upgrades[i].y,
2077 else if (upgrades[i].kind == UPGRADE_COFFEE)
2079 drawimage(img_coffee,
2080 upgrades[i].x - scroll_x, upgrades[i].y,
2083 else if (upgrades[i].kind == UPGRADE_HERRING)
2085 drawimage(img_golden_herring,
2086 upgrades[i].x - scroll_x, upgrades[i].y,
2094 /* (Bouncy distros): */
2096 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
2098 if (bouncy_distros[i].alive)
2100 drawimage(img_distro[0],
2101 bouncy_distros[i].x - scroll_x,
2102 bouncy_distros[i].y,
2108 /* (Broken bricks): */
2110 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
2112 if (broken_bricks[i].alive)
2114 src.x = rand() % 16;
2115 src.y = rand() % 16;
2119 dest.x = broken_bricks[i].x - scroll_x;
2120 dest.y = broken_bricks[i].y;
2124 SDL_BlitSurface(img_brick[0], &src, screen, &dest);
2131 sprintf(str, "%d", score);
2132 drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE);
2133 drawtext(str, 96, 0, letters_gold, NO_UPDATE);
2135 sprintf(str, "%d", highscore);
2136 drawtext("HIGH", 0, 20, letters_blue, NO_UPDATE);
2137 drawtext(str, 96, 20, letters_gold, NO_UPDATE);
2139 if (time_left >= 50 || (frame % 10) < 5)
2141 sprintf(str, "%d", time_left);
2142 drawtext("TIME", 224, 0, letters_blue, NO_UPDATE);
2143 drawtext(str, 304, 0, letters_gold, NO_UPDATE);
2146 sprintf(str, "%d", distros);
2147 drawtext("DISTROS", 480, 0, letters_blue, NO_UPDATE);
2148 drawtext(str, 608, 0, letters_gold, NO_UPDATE);
2151 drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE);
2156 /* (Update it all!) */
2163 /* --- GAME LOOP! --- */
2168 Uint32 last_time, now_time;
2172 clearscreen(0, 0, 0);
2176 /* Init the game: */
2184 highscore = load_hs();
2187 /* --- MAIN GAME LOOP!!! --- */
2199 last_time = SDL_GetTicks();
2203 /* Handle events: */
2209 /* Handle actions: */
2211 if(!game_pause && !show_menu)
2213 if (game_action() == 0)
2215 /* == 0: no more lives */
2216 /* == -1: continues */
2223 /*Draw the current scene to the screen */
2226 /* Keep playing music: */
2229 if (!playing_music())
2231 switch (current_music)
2234 play_music(level_song, 1);
2237 play_music(herring_song, 1);
2239 case HURRYUP_MUSIC: // keep the compiler happy
2240 case NO_MUSIC: // keep the compiler happy for the moment :-)
2246 /* Time stops in pause mode */
2247 if(game_pause || show_menu )
2252 /* Pause til next frame: */
2254 now_time = SDL_GetTicks();
2255 if (now_time < last_time + FPS)
2256 SDL_Delay(last_time + FPS - now_time);
2261 if ((frame % 10) == 0 && time_left > 0)
2269 while (!done && !quit);
2271 if (playing_music())
2282 /* Initialize the game stuff: */
2294 /* Load data for this level: */
2296 void loadlevel(void)
2307 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
2308 bouncy_distros[i].alive = NO;
2310 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
2311 broken_bricks[i].alive = NO;
2313 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
2314 bouncy_bricks[i].alive = NO;
2316 for (i = 0; i < NUM_BAD_GUYS; i++)
2317 bad_guys[i].alive = NO;
2319 for (i = 0; i < NUM_FLOATING_SCORES; i++)
2320 floating_scores[i].alive = NO;
2322 for (i = 0; i < NUM_UPGRADES; i++)
2323 upgrades[i].alive = NO;
2325 for (i = 0; i < NUM_BULLETS; i++)
2326 bullets[i].alive = NO;
2329 /* Load data file: */
2331 filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20));
2332 sprintf(filename, "%s/levels/level%d.dat", DATA_PREFIX, level);
2333 fi = fopen(filename, "r");
2344 /* Load header info: */
2349 strcpy(levelname, str);
2350 levelname[strlen(levelname)-1] = '\0';
2354 strcpy(leveltheme, str);
2355 leveltheme[strlen(leveltheme)-1] = '\0';
2359 /* (Time to beat level) */
2361 time_left = atoi(str);
2363 /* (Song file for this level) */
2365 strcpy(song_title, str);
2366 song_title[strlen(song_title)-1] = '\0';
2370 /* (Level background color) */
2372 bkgd_red = atoi(str);
2374 bkgd_green= atoi(str);
2376 bkgd_blue = atoi(str);
2380 level_width = atoi(str);
2383 /* Allocate some space for the line-reading! */
2385 line = (char *) malloc(sizeof(char) * (level_width + 5));
2388 fprintf(stderr, "Couldn't allocate space to load level data!");
2393 /* Load the level lines: */
2395 for (y = 0; y < 15; y++)
2397 if(fgets(line, level_width + 5, fi) == NULL)
2399 fprintf(stderr, "Level %s isn't complete!\n",levelname);
2402 line[strlen(line) - 1] = '\0';
2403 tiles[y] = strdup(line);
2409 /* Activate bad guys: */
2411 for (y = 0; y < 15; y++)
2413 for (x = 0; x < level_width; x++)
2415 if (tiles[y][x] >= '0' && tiles[y][x] <= '9')
2417 add_bad_guy(x * 32, y * 32, tiles[y][x] - '0');
2432 tux_got_coffee = NO;
2433 tux_invincible_time = 0;
2437 tux_safe = TUX_SAFE_TIME;
2453 score_multiplier = 1;
2454 super_bkgd_time = 0;
2456 counting_distros = NO;
2461 /* set current song/music */
2462 current_music = LEVEL_MUSIC;
2466 clearscreen(0, 0, 0);
2468 sprintf(str, "LEVEL %d", level);
2469 drawcenteredtext(str, 200, letters_red, NO_UPDATE);
2471 sprintf(str, "%s", levelname);
2472 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
2474 sprintf(str, "TUX x %d", lives);
2475 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
2485 /* Load a level-specific graphic... */
2487 SDL_Surface * load_level_image(char * file, int use_alpha)
2491 snprintf(fname, 1024, "%s/images/%s/%s", DATA_PREFIX, leveltheme, file);
2493 return(load_image(fname, use_alpha));
2497 /* Load graphics: */
2499 void loadlevelgfx(void)
2501 img_brick[0] = load_level_image("brick0.png", IGNORE_ALPHA);
2502 img_brick[1] = load_level_image("brick1.png", IGNORE_ALPHA);
2504 img_solid[0] = load_level_image("solid0.png", USE_ALPHA);
2505 img_solid[1] = load_level_image("solid1.png", USE_ALPHA);
2506 img_solid[2] = load_level_image("solid2.png", USE_ALPHA);
2507 img_solid[3] = load_level_image("solid3.png", USE_ALPHA);
2509 img_bkgd[0][0] = load_level_image("bkgd-00.png", USE_ALPHA);
2510 img_bkgd[0][1] = load_level_image("bkgd-01.png", USE_ALPHA);
2511 img_bkgd[0][2] = load_level_image("bkgd-02.png", USE_ALPHA);
2512 img_bkgd[0][3] = load_level_image("bkgd-03.png", USE_ALPHA);
2514 img_bkgd[1][0] = load_level_image("bkgd-10.png", USE_ALPHA);
2515 img_bkgd[1][1] = load_level_image("bkgd-11.png", USE_ALPHA);
2516 img_bkgd[1][2] = load_level_image("bkgd-12.png", USE_ALPHA);
2517 img_bkgd[1][3] = load_level_image("bkgd-13.png", USE_ALPHA);
2523 void loadlevelsong(void)
2528 song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
2529 strlen(song_title) + 8));
2531 sprintf(song_path, "%s/music/%s", DATA_PREFIX, song_title);
2533 level_song = load_song(song_path);
2539 /* Free graphics data for this level: */
2541 void unloadlevelgfx(void)
2545 for (i = 0; i < 2; i++)
2547 SDL_FreeSurface(img_brick[i]);
2549 for (i = 0; i < 4; i++)
2551 SDL_FreeSurface(img_solid[i]);
2552 SDL_FreeSurface(img_bkgd[0][i]);
2553 SDL_FreeSurface(img_bkgd[1][i]);
2558 /* Free music data for this level: */
2560 void unloadlevelsong(void)
2562 free_music(level_song);
2566 /* Load graphics/sounds shared between all levels: */
2568 void loadshared(void)
2571 char * herring_song_path; /* for loading herring song*/
2575 tux_right[0] = load_image(DATA_PREFIX "/images/shared/tux-right-0.png",
2578 tux_right[1] = load_image(DATA_PREFIX "/images/shared/tux-right-1.png",
2581 tux_right[2] = load_image(DATA_PREFIX "/images/shared/tux-right-2.png",
2584 tux_left[0] = load_image(DATA_PREFIX "/images/shared/tux-left-0.png",
2587 tux_left[1] = load_image(DATA_PREFIX "/images/shared/tux-left-1.png",
2590 tux_left[2] = load_image(DATA_PREFIX "/images/shared/tux-left-2.png",
2593 cape_right[0] = load_image(DATA_PREFIX "/images/shared/cape-right-0.png",
2596 cape_right[1] = load_image(DATA_PREFIX "/images/shared/cape-right-1.png",
2599 cape_left[0] = load_image(DATA_PREFIX "/images/shared/cape-left-0.png",
2602 cape_left[1] = load_image(DATA_PREFIX "/images/shared/cape-left-1.png",
2605 bigtux_right[0] = load_image(DATA_PREFIX "/images/shared/bigtux-right-0.png",
2608 bigtux_right[1] = load_image(DATA_PREFIX "/images/shared/bigtux-right-1.png",
2611 bigtux_right[2] = load_image(DATA_PREFIX "/images/shared/bigtux-right-2.png",
2615 load_image(DATA_PREFIX "/images/shared/bigtux-right-jump.png", USE_ALPHA);
2617 bigtux_left[0] = load_image(DATA_PREFIX "/images/shared/bigtux-left-0.png",
2620 bigtux_left[1] = load_image(DATA_PREFIX "/images/shared/bigtux-left-1.png",
2623 bigtux_left[2] = load_image(DATA_PREFIX "/images/shared/bigtux-left-2.png",
2627 load_image(DATA_PREFIX "/images/shared/bigtux-left-jump.png", USE_ALPHA);
2630 load_image(DATA_PREFIX "/images/shared/bigcape-right-0.png",
2634 load_image(DATA_PREFIX "/images/shared/bigcape-right-1.png",
2638 load_image(DATA_PREFIX "/images/shared/bigcape-left-0.png",
2642 load_image(DATA_PREFIX "/images/shared/bigcape-left-1.png",
2645 ducktux_right = load_image(DATA_PREFIX
2646 "/images/shared/ducktux-right.png",
2649 ducktux_left = load_image(DATA_PREFIX
2650 "/images/shared/ducktux-left.png",
2653 skidtux_right = load_image(DATA_PREFIX
2654 "/images/shared/skidtux-right.png",
2657 skidtux_left = load_image(DATA_PREFIX
2658 "/images/shared/skidtux-left.png",
2664 img_box_full = load_image(DATA_PREFIX "/images/shared/box-full.png",
2666 img_box_empty = load_image(DATA_PREFIX "/images/shared/box-empty.png",
2673 img_water = load_image(DATA_PREFIX "/images/shared/water.png", IGNORE_ALPHA);
2675 img_waves[0] = load_image(DATA_PREFIX "/images/shared/waves-0.png",
2678 img_waves[1] = load_image(DATA_PREFIX "/images/shared/waves-1.png",
2681 img_waves[2] = load_image(DATA_PREFIX "/images/shared/waves-2.png",
2687 img_pole = load_image(DATA_PREFIX "/images/shared/pole.png", USE_ALPHA);
2688 img_poletop = load_image(DATA_PREFIX "/images/shared/poletop.png",
2694 img_flag[0] = load_image(DATA_PREFIX "/images/shared/flag-0.png",
2696 img_flag[1] = load_image(DATA_PREFIX "/images/shared/flag-1.png",
2702 img_cloud[0][0] = load_image(DATA_PREFIX "/images/shared/cloud-00.png",
2705 img_cloud[0][1] = load_image(DATA_PREFIX "/images/shared/cloud-01.png",
2708 img_cloud[0][2] = load_image(DATA_PREFIX "/images/shared/cloud-02.png",
2711 img_cloud[0][3] = load_image(DATA_PREFIX "/images/shared/cloud-03.png",
2715 img_cloud[1][0] = load_image(DATA_PREFIX "/images/shared/cloud-10.png",
2718 img_cloud[1][1] = load_image(DATA_PREFIX "/images/shared/cloud-11.png",
2721 img_cloud[1][2] = load_image(DATA_PREFIX "/images/shared/cloud-12.png",
2724 img_cloud[1][3] = load_image(DATA_PREFIX "/images/shared/cloud-13.png",
2732 img_bsod_left[0] = load_image(DATA_PREFIX
2733 "/images/shared/bsod-left-0.png",
2736 img_bsod_left[1] = load_image(DATA_PREFIX
2737 "/images/shared/bsod-left-1.png",
2740 img_bsod_left[2] = load_image(DATA_PREFIX
2741 "/images/shared/bsod-left-2.png",
2744 img_bsod_left[3] = load_image(DATA_PREFIX
2745 "/images/shared/bsod-left-3.png",
2748 img_bsod_right[0] = load_image(DATA_PREFIX
2749 "/images/shared/bsod-right-0.png",
2752 img_bsod_right[1] = load_image(DATA_PREFIX
2753 "/images/shared/bsod-right-1.png",
2756 img_bsod_right[2] = load_image(DATA_PREFIX
2757 "/images/shared/bsod-right-2.png",
2760 img_bsod_right[3] = load_image(DATA_PREFIX
2761 "/images/shared/bsod-right-3.png",
2764 img_bsod_squished_left = load_image(DATA_PREFIX
2765 "/images/shared/bsod-squished-left.png",
2768 img_bsod_squished_right = load_image(DATA_PREFIX
2769 "/images/shared/bsod-squished-right.png",
2772 img_bsod_falling_left = load_image(DATA_PREFIX
2773 "/images/shared/bsod-falling-left.png",
2776 img_bsod_falling_right = load_image(DATA_PREFIX
2777 "/images/shared/bsod-falling-right.png",
2783 img_laptop_left[0] = load_image(DATA_PREFIX
2784 "/images/shared/laptop-left-0.png",
2787 img_laptop_left[1] = load_image(DATA_PREFIX
2788 "/images/shared/laptop-left-1.png",
2791 img_laptop_left[2] = load_image(DATA_PREFIX
2792 "/images/shared/laptop-left-2.png",
2795 img_laptop_right[0] = load_image(DATA_PREFIX
2796 "/images/shared/laptop-right-0.png",
2799 img_laptop_right[1] = load_image(DATA_PREFIX
2800 "/images/shared/laptop-right-1.png",
2803 img_laptop_right[2] = load_image(DATA_PREFIX
2804 "/images/shared/laptop-right-2.png",
2807 img_laptop_flat_left = load_image(DATA_PREFIX
2808 "/images/shared/laptop-flat-left.png",
2811 img_laptop_flat_right = load_image(DATA_PREFIX
2812 "/images/shared/laptop-flat-right.png",
2815 img_laptop_falling_left =
2816 load_image(DATA_PREFIX
2817 "/images/shared/laptop-falling-left.png",
2820 img_laptop_falling_right =
2821 load_image(DATA_PREFIX
2822 "/images/shared/laptop-falling-right.png",
2828 img_money_left[0] = load_image(DATA_PREFIX
2829 "/images/shared/bag-left-0.png",
2832 img_money_left[1] = load_image(DATA_PREFIX
2833 "/images/shared/bag-left-1.png",
2836 img_money_right[0] = load_image(DATA_PREFIX
2837 "/images/shared/bag-right-0.png",
2840 img_money_right[1] = load_image(DATA_PREFIX
2841 "/images/shared/bag-right-1.png",
2848 img_mints = load_image(DATA_PREFIX "/images/shared/mints.png", USE_ALPHA);
2849 img_coffee = load_image(DATA_PREFIX "/images/shared/coffee.png", USE_ALPHA);
2854 img_bullet = load_image(DATA_PREFIX "/images/shared/bullet.png", USE_ALPHA);
2856 img_red_glow = load_image(DATA_PREFIX "/images/shared/red-glow.png",
2862 img_distro[0] = load_image(DATA_PREFIX "/images/shared/distro-0.png",
2865 img_distro[1] = load_image(DATA_PREFIX "/images/shared/distro-1.png",
2868 img_distro[2] = load_image(DATA_PREFIX "/images/shared/distro-2.png",
2871 img_distro[3] = load_image(DATA_PREFIX "/images/shared/distro-3.png",
2877 img_golden_herring =
2878 load_image(DATA_PREFIX "/images/shared/golden-herring.png",
2882 /* Super background: */
2884 img_super_bkgd = load_image(DATA_PREFIX "/images/shared/super-bkgd.png",
2888 /* Sound effects: */
2890 /* if (use_sound) // this can help speeding up a little, but
2891 we shouldn't take care about "use_sound" here, it's load_sound's job
2892 / Send a mail to neoneurone@users.sf.net, if you have another opinion. :)
2894 for (i = 0; i < NUM_SOUNDS; i++)
2895 sounds[i] = load_sound(soundfilenames[i]);
2898 herring_song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
2899 strlen("SALCON.MOD") + 8)); /* FIXME: We need a real herring_song! Thats a fake.:) */
2901 sprintf(herring_song_path, "%s/music/%s", DATA_PREFIX, "SALCON.MOD");
2903 herring_song = load_song(herring_song_path);
2905 free(herring_song_path);
2910 /* Free shared data: */
2912 void unloadshared(void)
2916 for (i = 0; i < 3; i++)
2918 SDL_FreeSurface(tux_right[i]);
2919 SDL_FreeSurface(tux_left[i]);
2920 SDL_FreeSurface(bigtux_right[i]);
2921 SDL_FreeSurface(bigtux_left[i]);
2924 SDL_FreeSurface(bigtux_right_jump);
2925 SDL_FreeSurface(bigtux_left_jump);
2927 for (i = 0; i < 2; i++)
2929 SDL_FreeSurface(cape_right[i]);
2930 SDL_FreeSurface(cape_left[i]);
2931 SDL_FreeSurface(bigcape_right[i]);
2932 SDL_FreeSurface(bigcape_left[i]);
2935 SDL_FreeSurface(ducktux_left);
2936 SDL_FreeSurface(ducktux_right);
2938 SDL_FreeSurface(skidtux_left);
2939 SDL_FreeSurface(skidtux_right);
2941 for (i = 0; i < 4; i++)
2943 SDL_FreeSurface(img_bsod_left[i]);
2944 SDL_FreeSurface(img_bsod_right[i]);
2947 SDL_FreeSurface(img_bsod_squished_left);
2948 SDL_FreeSurface(img_bsod_squished_right);
2950 SDL_FreeSurface(img_bsod_falling_left);
2951 SDL_FreeSurface(img_bsod_falling_right);
2953 for (i = 0; i < 3; i++)
2955 SDL_FreeSurface(img_laptop_left[i]);
2956 SDL_FreeSurface(img_laptop_right[i]);
2959 SDL_FreeSurface(img_laptop_flat_left);
2960 SDL_FreeSurface(img_laptop_flat_right);
2962 SDL_FreeSurface(img_laptop_falling_left);
2963 SDL_FreeSurface(img_laptop_falling_right);
2965 for (i = 0; i < 2; i++)
2967 SDL_FreeSurface(img_money_left[i]);
2968 SDL_FreeSurface(img_money_right[i]);
2971 SDL_FreeSurface(img_box_full);
2972 SDL_FreeSurface(img_box_empty);
2974 SDL_FreeSurface(img_water);
2975 for (i = 0; i < 3; i++)
2976 SDL_FreeSurface(img_waves[i]);
2978 SDL_FreeSurface(img_pole);
2979 SDL_FreeSurface(img_poletop);
2981 for (i = 0; i < 2; i++)
2982 SDL_FreeSurface(img_flag[i]);
2984 SDL_FreeSurface(img_mints);
2985 SDL_FreeSurface(img_coffee);
2987 for (i = 0; i < 4; i++)
2989 SDL_FreeSurface(img_distro[i]);
2990 SDL_FreeSurface(img_cloud[0][i]);
2991 SDL_FreeSurface(img_cloud[1][i]);
2994 SDL_FreeSurface(img_golden_herring);
2996 for (i = 0; i < NUM_SOUNDS; i++)
2997 free_chunk(sounds[i]);
2999 /* free the herring song */
3000 free_music( herring_song );
3004 /* Draw a tile on the screen: */
3006 void drawshape(int x, int y, unsigned char c)
3010 if (c == 'X' || c == 'x')
3011 drawimage(img_brick[0], x, y, NO_UPDATE);
3012 else if (c == 'Y' || c == 'y')
3013 drawimage(img_brick[1], x, y, NO_UPDATE);
3014 else if (c == 'A' || c =='B' || c == '!')
3015 drawimage(img_box_full, x, y, NO_UPDATE);
3017 drawimage(img_box_empty, x, y, NO_UPDATE);
3018 else if (c >= 'C' && c <= 'F')
3019 drawimage(img_cloud[0][c - 'C'], x, y, NO_UPDATE);
3020 else if (c >= 'c' && c <= 'f')
3021 drawimage(img_cloud[1][c - 'c'], x, y, NO_UPDATE);
3022 else if (c >= 'G' && c <= 'J')
3023 drawimage(img_bkgd[0][c - 'G'], x, y, NO_UPDATE);
3024 else if (c >= 'g' && c <= 'j')
3025 drawimage(img_bkgd[1][c - 'g'], x, y, NO_UPDATE);
3027 drawimage(img_solid[0], x, y, NO_UPDATE);
3029 drawimage(img_solid[1], x, y, NO_UPDATE);
3031 drawimage(img_solid[2], x, y, NO_UPDATE);
3033 drawimage(img_solid[3], x, y, NO_UPDATE);
3036 z = (frame / 2) % 6;
3039 drawimage(img_distro[z], x, y, NO_UPDATE);
3041 drawimage(img_distro[2], x, y, NO_UPDATE);
3043 drawimage(img_distro[1], x, y, NO_UPDATE);
3047 z = (frame / 3) % 3;
3049 drawimage(img_waves[z], x, y, NO_UPDATE);
3052 drawimage(img_poletop, x, y, NO_UPDATE);
3055 drawimage(img_pole, x, y, NO_UPDATE);
3057 /* Mark this as the end position of the level! */
3063 z = (frame / 3) % 2;
3065 drawimage(img_flag[z], x + 16, y, NO_UPDATE);
3068 drawimage(img_water, x, y, NO_UPDATE);
3072 /* What shape is at some position? */
3074 unsigned char shape(int x, int y, int sx)
3080 xx = ((x + sx) / 32);
3082 if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
3093 int issolid(int x, int y, int sx)
3099 if (isbrick(x, y, sx) ||
3100 isbrick(x + 31, y, sx) ||
3102 isice(x + 31, y, sx) ||
3103 (shape(x, y, sx) == '[' ||
3104 shape(x + 31, y, sx) == '[') ||
3105 (shape(x, y, sx) == '=' ||
3106 shape(x + 31, y, sx) == '=') ||
3107 (shape(x, y, sx) == ']' ||
3108 shape(x + 31, y, sx) == ']') ||
3109 (shape(x, y, sx) == 'A' ||
3110 shape(x + 31, y, sx) == 'A') ||
3111 (shape(x, y, sx) == 'B' ||
3112 shape(x + 31, y, sx) == 'B') ||
3113 (shape(x, y, sx) == '!' ||
3114 shape(x + 31, y, sx) == '!') ||
3115 (shape(x, y, sx) == 'a' ||
3116 shape(x + 31, y, sx) == 'a'))
3125 /* Is it a brick? */
3127 int isbrick(int x, int y, int sx)
3133 if (shape(x, y, sx) == 'X' ||
3134 shape(x, y, sx) == 'x' ||
3135 shape(x, y, sx) == 'Y' ||
3136 shape(x, y, sx) == 'y')
3147 int isice(int x, int y, int sx)
3153 if (shape(x, y, sx) == '#')
3162 /* Is it a full box? */
3164 int isfullbox(int x, int y, int sx)
3170 if (shape(x, y, sx) == 'A' ||
3171 shape(x, y, sx) == 'B' ||
3172 shape(x, y, sx) == '!')
3181 /* Edit a piece of the map! */
3183 void change(int x, int y, int sx, unsigned char c)
3188 xx = ((x + sx) / 32);
3190 if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
3195 /* Break a brick: */
3197 void trybreakbrick(int x, int y, int sx)
3199 if (isbrick(x, y, sx))
3201 if (shape(x, y, sx) == 'x' || shape(x, y, sx) == 'y')
3203 /* Get a distro from it: */
3205 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3208 if (counting_distros == NO)
3210 counting_distros = YES;
3211 distro_counter = 50;
3214 if (distro_counter <= 0)
3215 change(x, y, sx, 'a');
3217 play_sound(sounds[SND_DISTRO]);
3218 score = score + SCORE_DISTRO;
3223 /* Get rid of it: */
3225 change(x, y, sx, '.');
3229 /* Replace it with broken bits: */
3231 add_broken_brick(((x + sx + 1) / 32) * 32,
3235 /* Get some score: */
3237 play_sound(sounds[SND_BRICK]);
3238 score = score + SCORE_BRICK;
3243 /* Bounce a brick: */
3245 void bumpbrick(int x, int y, int sx)
3247 add_bouncy_brick(((x + sx + 1) / 32) * 32,
3250 play_sound(sounds[SND_BRICK]);
3256 void tryemptybox(int x, int y, int sx)
3258 if (isfullbox(x, y, sx))
3260 if (shape(x, y, sx) == 'A')
3262 /* Box with a distro! */
3264 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3265 (y / 32) * 32 - 32);
3267 play_sound(sounds[SND_DISTRO]);
3268 score = score + SCORE_DISTRO;
3271 else if (shape(x, y, sx) == 'B')
3273 /* Add an upgrade! */
3275 if (tux_size == SMALL)
3277 /* Tux is small, add mints! */
3279 add_upgrade(((x + sx + 1) / 32) * 32,
3285 /* Tux is big, add coffee: */
3287 add_upgrade(((x + sx + 1) / 32) * 32,
3292 play_sound(sounds[SND_UPGRADE]);
3294 else if (shape(x, y, sx) == '!')
3296 /* Add a golden herring */
3298 add_upgrade(((x + sx + 1) / 32) * 32,
3303 /* Empty the box: */
3305 change(x, y, sx, 'a');
3310 /* Try to grab a distro: */
3312 void trygrabdistro(int x, int y, int sx, int bounciness)
3314 if (shape(x, y, sx) == '$')
3316 change(x, y, sx, '.');
3317 play_sound(sounds[SND_DISTRO]);
3319 if (bounciness == BOUNCE)
3321 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3325 score = score + SCORE_DISTRO;
3331 /* Add a bouncy distro: */
3333 void add_bouncy_distro(int x, int y)
3339 for (i = 0; i < NUM_BOUNCY_DISTROS && found == -1; i++)
3341 if (!bouncy_distros[i].alive)
3347 bouncy_distros[found].alive = YES;
3348 bouncy_distros[found].x = x;
3349 bouncy_distros[found].y = y;
3350 bouncy_distros[found].ym = -6;
3355 /* Add broken brick pieces: */
3357 void add_broken_brick(int x, int y)
3359 add_broken_brick_piece(x, y, -4, -16);
3360 add_broken_brick_piece(x, y + 16, -6, -12);
3362 add_broken_brick_piece(x + 16, y, 4, -16);
3363 add_broken_brick_piece(x + 16, y + 16, 6, -12);
3367 /* Add a broken brick piece: */
3369 void add_broken_brick_piece(int x, int y, int xm, int ym)
3375 for (i = 0; i < NUM_BROKEN_BRICKS && found == -1; i++)
3377 if (!broken_bricks[i].alive)
3383 broken_bricks[found].alive = YES;
3384 broken_bricks[found].x = x;
3385 broken_bricks[found].y = y;
3386 broken_bricks[found].xm = xm;
3387 broken_bricks[found].ym = ym;
3392 /* Add a bouncy brick piece: */
3394 void add_bouncy_brick(int x, int y)
3400 for (i = 0; i < NUM_BOUNCY_BRICKS && found == -1; i++)
3402 if (!bouncy_bricks[i].alive)
3408 bouncy_bricks[found].alive = YES;
3409 bouncy_bricks[found].x = x;
3410 bouncy_bricks[found].y = y;
3411 bouncy_bricks[found].offset = 0;
3412 bouncy_bricks[found].offset_m = -BOUNCY_BRICK_SPEED;
3413 bouncy_bricks[found].shape = shape(x, y, 0);
3418 /* Add a bad guy: */
3420 void add_bad_guy(int x, int y, int kind)
3426 for (i = 0; i < NUM_BAD_GUYS && found == -1; i++)
3428 if (!bad_guys[i].alive)
3434 bad_guys[found].alive = YES;
3435 bad_guys[found].mode = NORMAL;
3436 bad_guys[found].dying = NO;
3437 bad_guys[found].timer = 0;
3438 bad_guys[found].kind = kind;
3439 bad_guys[found].x = x;
3440 bad_guys[found].y = y;
3441 bad_guys[found].xm = 0;
3442 bad_guys[found].ym = 0;
3443 bad_guys[found].dir = LEFT;
3444 bad_guys[found].seen = NO;
3451 void add_score(int x, int y, int s)
3456 /* Add the score: */
3461 /* Add a floating score thing to the game: */
3465 for (i = 0; i < NUM_FLOATING_SCORES && found == -1; i++)
3467 if (!floating_scores[i].alive)
3474 floating_scores[found].alive = YES;
3475 floating_scores[found].x = x;
3476 floating_scores[found].y = y - 16;
3477 floating_scores[found].timer = 8;
3478 floating_scores[found].value = s;
3483 /* Try to bump a bad guy from below: */
3485 void trybumpbadguy(int x, int y, int sx)
3492 for (i = 0; i < NUM_BAD_GUYS; i++)
3494 if (bad_guys[i].alive &&
3495 bad_guys[i].x >= x + sx - 32 && bad_guys[i].x <= x + sx + 32 &&
3496 bad_guys[i].y >= y - 16 && bad_guys[i].y <= y + 16)
3498 if (bad_guys[i].kind == BAD_BSOD ||
3499 bad_guys[i].kind == BAD_LAPTOP)
3501 bad_guys[i].dying = FALLING;
3502 bad_guys[i].ym = -8;
3503 play_sound(sounds[SND_FALL]);
3511 for (i = 0; i < NUM_UPGRADES; i++)
3513 if (upgrades[i].alive && upgrades[i].height == 32 &&
3514 upgrades[i].x >= x + sx - 32 && upgrades[i].x <= x + sx + 32 &&
3515 upgrades[i].y >= y - 16 && upgrades[i].y <= y + 16)
3517 upgrades[i].xm = -upgrades[i].xm;
3518 upgrades[i].ym = -8;
3519 play_sound(sounds[SND_BUMP_UPGRADE]);
3525 /* Add an upgrade: */
3527 void add_upgrade(int x, int y, int kind)
3533 for (i = 0; i < NUM_UPGRADES && found == -1; i++)
3535 if (!upgrades[i].alive)
3541 upgrades[found].alive = YES;
3542 upgrades[found].kind = kind;
3543 upgrades[found].x = x;
3544 upgrades[found].y = y;
3545 upgrades[found].xm = 4;
3546 upgrades[found].ym = -4;
3547 upgrades[found].height = 0;
3554 void killtux(int mode)
3558 play_sound(sounds[SND_HURT]);
3560 if (tux_dir == RIGHT)
3562 else if (tux_dir == LEFT)
3565 if (mode == SHRINK && tux_size == BIG)
3568 tux_got_coffee = NO;
3572 tux_safe = TUX_SAFE_TIME;
3583 void add_bullet(int x, int y, int dir, int xm)
3589 for (i = 0; i < NUM_BULLETS && found == -1; i++)
3591 if (!bullets[i].alive)
3597 bullets[found].alive = YES;
3601 bullets[found].x = x + 32;
3602 bullets[found].xm = BULLET_XM + xm;
3606 bullets[found].x = x;
3607 bullets[found].xm = -BULLET_XM + xm;
3610 bullets[found].y = y;
3611 bullets[found].ym = BULLET_STARTING_YM;
3613 play_sound(sounds[SND_SHOOT]);
3618 void drawendscreen(void)
3622 clearscreen(0, 0, 0);
3624 drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE);
3626 sprintf(str, "SCORE: %d", score);
3627 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
3629 sprintf(str, "DISTROS: %d", distros);
3630 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
3636 void drawresultscreen(void)
3640 clearscreen(0, 0, 0);
3642 drawcenteredtext("Result:", 200, letters_red, NO_UPDATE);
3644 sprintf(str, "SCORE: %d", score);
3645 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
3647 sprintf(str, "DISTROS: %d", distros);
3648 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
3651 /*SDL_Delay(2000);*/