7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - December 28, 2003
22 #include <sys/types.h>
32 #include "high_scores.h"
60 char * soundfilenames[NUM_SOUNDS] = {
61 DATA_PREFIX "/sounds/jump.wav",
62 DATA_PREFIX "/sounds/bigjump.wav",
63 DATA_PREFIX "/sounds/skid.wav",
64 DATA_PREFIX "/sounds/distro.wav",
65 DATA_PREFIX "/sounds/herring.wav",
66 DATA_PREFIX "/sounds/brick.wav",
67 DATA_PREFIX "/sounds/hurt.wav",
68 DATA_PREFIX "/sounds/squish.wav",
69 DATA_PREFIX "/sounds/fall.wav",
70 DATA_PREFIX "/sounds/ricochet.wav",
71 DATA_PREFIX "/sounds/bump-upgrade.wav",
72 DATA_PREFIX "/sounds/upgrade.wav",
73 DATA_PREFIX "/sounds/excellent.wav",
74 DATA_PREFIX "/sounds/coffee.wav",
75 DATA_PREFIX "/sounds/shoot.wav",
76 DATA_PREFIX "/sounds/lifeup.wav"
80 /* Local variables: */
82 int score, highscore, distros, level, lives, scroll_x, next_level, game_pause,
83 done, quit, tux_dir, tux_size, tux_duck, tux_x, tux_xm, tux_y, tux_ym,
84 tux_dying, tux_safe, jumping, jump_counter, frame, score_multiplier,
85 tux_frame_main, tux_frame, tux_got_coffee, tux_skidding,
86 super_bkgd_time, time_left, tux_invincible_time, endpos,
87 counting_distros, distro_counter;
88 int bkgd_red, bkgd_green, bkgd_blue, level_width;
89 int left, right, up, down, fire, old_fire;
90 SDL_Surface * img_brick[2], * img_solid[4], * img_distro[4],
91 * img_waves[3], * img_water, * img_pole, * img_poletop, * img_flag[2];
92 SDL_Surface * img_bkgd[2][4];
93 SDL_Surface * img_golden_herring;
94 SDL_Surface * img_bsod_left[4], * img_bsod_right[4],
95 * img_laptop_left[3], * img_laptop_right[3],
96 * img_money_left[2], * img_money_right[2];
97 SDL_Surface * img_bsod_squished_left, * img_bsod_squished_right,
98 * img_bsod_falling_left, * img_bsod_falling_right,
99 * img_laptop_flat_left, * img_laptop_flat_right,
100 * img_laptop_falling_left, * img_laptop_falling_right;
101 SDL_Surface * img_box_full, * img_box_empty, * img_mints, * img_coffee,
102 * img_super_bkgd, * img_bullet, * img_red_glow;
103 SDL_Surface * img_cloud[2][4];
104 SDL_Surface * tux_right[3], * tux_left[3],
105 * bigtux_right[3], * bigtux_left[3],
106 * bigtux_right_jump, * bigtux_left_jump,
107 * cape_right[2], * cape_left[2],
108 * bigcape_right[2], * bigcape_left[2],
109 * ducktux_right, * ducktux_left,
110 * skidtux_right, * skidtux_left, * tux_life;
114 unsigned char * tiles[15];
115 bouncy_distro_type bouncy_distros[NUM_BOUNCY_DISTROS];
116 broken_brick_type broken_bricks[NUM_BROKEN_BRICKS];
117 bouncy_brick_type bouncy_bricks[NUM_BOUNCY_BRICKS];
118 bad_guy_type bad_guys[NUM_BAD_GUYS];
119 floating_score_type floating_scores[NUM_FLOATING_SCORES];
120 upgrade_type upgrades[NUM_UPGRADES];
121 bullet_type bullets[NUM_BULLETS];
128 /* Local function prototypes: */
131 void loadlevel(void);
132 void loadlevelgfx(void);
133 void loadlevelsong(void);
134 void unloadlevelgfx(void);
135 void unloadlevelsong(void);
136 void loadshared(void);
137 void unloadshared(void);
138 void drawshape(int x, int y, unsigned char c);
140 unsigned char shape(int x, int y, int sx);
141 int issolid(int x, int y, int sx);
142 int isbrick(int x, int y, int sx);
143 int isice(int x, int y, int sx);
144 int isfullbox(int x, int y, int sx);
145 void change(int x, int y, int sx, unsigned char c);
146 void trybreakbrick(int x, int y, int sx);
147 void bumpbrick(int x, int y, int sx);
148 void tryemptybox(int x, int y, int sx);
149 void trygrabdistro(int x, int y, int sx, int bounciness);
150 void add_bouncy_distro(int x, int y);
151 void add_broken_brick(int x, int y);
152 void add_broken_brick_piece(int x, int y, int xm, int ym);
153 void add_bouncy_brick(int x, int y);
154 void add_bad_guy(int x, int y, int kind);
155 void add_score(int x, int y, int s);
156 void trybumpbadguy(int x, int y, int sx);
157 void add_upgrade(int x, int y, int kind);
158 void killtux(int mode);
159 void add_bullet(int x, int y, int dir, int xm);
160 void drawendscreen(void);
161 void drawresultscreen(void);
163 /* --- GAME EVENT! --- */
165 void game_event(void)
168 while (SDL_PollEvent(&event))
171 if (event.type == SDL_QUIT)
173 /* Quit event - quit: */
177 else if (event.type == SDL_KEYDOWN)
181 key = event.key.keysym.sym;
183 /* Check for menu-events, if the menu is shown */
187 if (key == SDLK_ESCAPE)
189 /* Escape: Open/Close the menu: */
198 else if (key == SDLK_RIGHT)
202 else if (key == SDLK_LEFT)
206 else if (key == SDLK_UP)
210 else if (key == SDLK_DOWN)
214 else if (key == SDLK_LCTRL)
219 else if (event.type == SDL_KEYUP)
223 key = event.key.keysym.sym;
225 if (key == SDLK_RIGHT)
229 else if (key == SDLK_LEFT)
233 else if (key == SDLK_UP)
237 else if (key == SDLK_DOWN)
241 else if (key == SDLK_LCTRL)
245 else if (key == SDLK_p)
255 else if (key == SDLK_TAB && debug_mode == YES)
257 tux_size = !tux_size;
259 else if (key == SDLK_END && debug_mode == YES)
263 else if (key == SDLK_SPACE && debug_mode == YES)
269 else if (event.type == SDL_JOYAXISMOTION)
271 if (event.jaxis.axis == JOY_X)
273 if (event.jaxis.value < -256)
278 if (event.jaxis.value > 256)
283 else if (event.jaxis.axis == JOY_Y)
285 if (event.jaxis.value > 256)
290 /* Handle joystick for the menu */
294 menuaction = MN_DOWN;
300 else if (event.type == SDL_JOYBUTTONDOWN)
302 if (event.jbutton.button == JOY_A)
304 else if (event.jbutton.button == JOY_B)
307 else if (event.type == SDL_JOYBUTTONUP)
309 if (event.jbutton.button == JOY_A)
311 else if (event.jbutton.button == JOY_B)
324 /* --- GAME ACTION! --- */
326 int game_action(void)
330 /* --- HANDLE TUX! --- */
332 /* Handle key and joystick state: */
334 if (!(tux_dying || next_level))
336 if (right == DOWN && left == UP)
340 if (tux_xm < -SKID_XM && !tux_skidding &&
343 tux_skidding = SKID_TIME;
345 play_sound(sounds[SND_SKID]);
351 if (tux_xm < 0 && !isice(tux_x, tux_y + 32, scroll_x) &&
359 if (tux_dir == RIGHT)
361 /* Facing the direction we're jumping? Go full-speed: */
365 tux_xm = tux_xm + WALK_SPEED;
367 if (tux_xm > MAX_WALK_XM)
368 tux_xm = MAX_WALK_XM;
370 else if (fire == DOWN)
372 tux_xm = tux_xm + RUN_SPEED;
374 if (tux_xm > MAX_RUN_XM)
380 /* Not facing the direction we're jumping?
383 tux_xm = tux_xm + WALK_SPEED / 2;
385 if (tux_xm > MAX_WALK_XM / 2)
386 tux_xm = MAX_WALK_XM / 2;
390 else if (left == DOWN && right == UP)
394 if (tux_xm > SKID_XM && !tux_skidding &&
397 tux_skidding = SKID_TIME;
398 play_sound(sounds[SND_SKID]);
403 if (tux_xm > 0 && !isice(tux_x, tux_y + 32, scroll_x) &&
413 /* Facing the direction we're jumping? Go full-speed: */
417 tux_xm = tux_xm - WALK_SPEED;
419 if (tux_xm < -MAX_WALK_XM)
420 tux_xm = -MAX_WALK_XM;
422 else if (fire == DOWN)
424 tux_xm = tux_xm - RUN_SPEED;
426 if (tux_xm < -MAX_RUN_XM)
427 tux_xm = -MAX_RUN_XM;
432 /* Not facing the direction we're jumping?
435 tux_xm = tux_xm - WALK_SPEED / 2;
437 if (tux_xm < -MAX_WALK_XM / 2)
438 tux_xm = -MAX_WALK_XM / 2;
446 if (tux_x >= endpos && endpos != 0)
456 if (jump_counter == 0)
460 if (!issolid(tux_x, tux_y + 32, scroll_x) ||
463 /* If they're not on the ground, or are currently moving
464 vertically, don't jump! */
466 jump_counter = MAX_JUMP_COUNT;
470 /* Make sure we're not standing back up into a solid! */
472 if (tux_size == SMALL || tux_duck == NO ||
473 !issolid(tux_x, tux_y, scroll_x))
477 if (tux_size == SMALL)
478 play_sound(sounds[SND_JUMP]);
480 play_sound(sounds[SND_BIGJUMP]);
486 /* Keep jumping for a while: */
488 if (jump_counter < MAX_JUMP_COUNT)
490 tux_ym = tux_ym - JUMP_SPEED;
500 if (fire == DOWN && old_fire == UP && tux_got_coffee)
502 add_bullet(tux_x + scroll_x, tux_y, tux_dir, tux_xm);
515 if (tux_size == BIG && tux_duck == YES)
517 /* Make sure we're not standing back up into a solid! */
519 if (!issolid(tux_x, tux_y - 32, scroll_x))
525 } /* (tux_dying || next_level) */
528 /* Tux either died, or reached the end of a level! */
537 /* End of a level! */
545 tux_ym = tux_ym + GRAVITY;
553 /* No more lives!? */
559 if (score > highscore)
566 } /* if (lives < 0) */
569 /* Either way, (re-)load the (next) level... */
580 tux_x = tux_x + tux_xm;
581 tux_y = tux_y + tux_ym;
584 /* Keep tux in bounds: */
587 else if (tux_x < 160 && scroll_x > 0 && debug_mode == YES)
589 scroll_x = scroll_x - ( 160 - tux_x);
596 else if (tux_x > 320 && scroll_x < ((level_width * 32) - 640))
598 /* Scroll the screen in past center: */
600 scroll_x = scroll_x + (tux_x - 320);
603 if (scroll_x > ((level_width * 32) - 640))
604 scroll_x = ((level_width * 32) - 640);
606 else if (tux_x > 608)
608 /* ... unless there's no more to scroll! */
618 if (issolid(tux_x, tux_y + 31, scroll_x) &&
619 !issolid(tux_x - tux_xm, tux_y + 31, scroll_x))
621 while (issolid(tux_x, tux_y + 31, scroll_x))
632 if (issolid(tux_x, tux_y, scroll_x) &&
633 !issolid(tux_x - tux_xm, tux_y, scroll_x))
635 while (issolid(tux_x, tux_y, scroll_x))
646 if (issolid(tux_x, tux_y + 31, scroll_x))
648 /* Set down properly: */
650 while (issolid(tux_x, tux_y + 31, scroll_x))
659 /* Reset score multiplier (for mutli-hits): */
662 score_multiplier = 1;
672 /* Bump into things: */
674 if (issolid(tux_x, tux_y, scroll_x) ||
675 (tux_size == BIG && !tux_duck &&
676 (issolid(tux_x, tux_y - 32, scroll_x))))
678 if (!issolid(tux_x - tux_xm, tux_y, scroll_x) &&
679 (tux_size == SMALL || tux_duck ||
680 !issolid(tux_x - tux_xm, tux_y - 32, scroll_x)))
682 tux_x = tux_x - tux_xm;
685 else if (!issolid(tux_x, tux_y - tux_ym, scroll_x) &&
686 (tux_size == SMALL || tux_duck ||
687 !issolid(tux_x, tux_y - 32 - tux_ym, scroll_x)))
695 /* Break bricks and empty boxes: */
699 if (isbrick(tux_x, tux_y - 32, scroll_x) ||
700 isfullbox(tux_x, tux_y - 32, scroll_x))
702 trygrabdistro(tux_x, tux_y - 64, scroll_x,
704 trybumpbadguy(tux_x, tux_y - 96, scroll_x);
706 if (isfullbox(tux_x, tux_y - 32,
709 bumpbrick(tux_x, tux_y - 32,
713 trybreakbrick(tux_x, tux_y - 32, scroll_x);
714 tryemptybox(tux_x, tux_y - 32, scroll_x);
717 if (isbrick(tux_x + 31, tux_y - 32, scroll_x) ||
718 isfullbox(tux_x + 31, tux_y - 32, scroll_x))
720 trygrabdistro(tux_x + 31,
724 trybumpbadguy(tux_x + 31,
728 if (isfullbox(tux_x + 31, tux_y - 32,
731 bumpbrick(tux_x + 31, tux_y - 32,
735 trybreakbrick(tux_x + 31,
738 tryemptybox(tux_x + 31,
745 if (isbrick(tux_x, tux_y, scroll_x) ||
746 isfullbox(tux_x, tux_y, scroll_x))
748 trygrabdistro(tux_x, tux_y - 32, scroll_x,
750 trybumpbadguy(tux_x, tux_y - 64, scroll_x);
751 if (isfullbox(tux_x, tux_y, scroll_x))
752 bumpbrick(tux_x, tux_y, scroll_x);
753 trybreakbrick(tux_x, tux_y, scroll_x);
754 tryemptybox(tux_x, tux_y, scroll_x);
757 if (isbrick(tux_x + 31, tux_y, scroll_x) ||
758 isfullbox(tux_x + 31, tux_y, scroll_x))
760 trygrabdistro(tux_x + 31,
764 trybumpbadguy(tux_x + 31,
767 if (isfullbox(tux_x + 31, tux_y, scroll_x))
768 bumpbrick(tux_x + 31, tux_y, scroll_x);
769 trybreakbrick(tux_x + 31, tux_y, scroll_x);
770 tryemptybox(tux_x + 31, tux_y, scroll_x);
776 /* It's a brick and we're small, make the brick
777 bounce, and grab any distros above it: */
779 if (isbrick(tux_x, tux_y, scroll_x) ||
780 isfullbox(tux_x, tux_y, scroll_x))
782 trygrabdistro(tux_x, tux_y - 32, scroll_x,
784 trybumpbadguy(tux_x, tux_y - 64, scroll_x);
785 bumpbrick(tux_x, tux_y, scroll_x);
786 tryemptybox(tux_x, tux_y, scroll_x);
789 if (isbrick(tux_x + 31, tux_y, scroll_x) ||
790 isfullbox(tux_x + 31, tux_y, scroll_x))
792 trygrabdistro(tux_x + 31, tux_y - 32, scroll_x,
794 trybumpbadguy(tux_x + 31, tux_y - 64, scroll_x);
795 bumpbrick(tux_x + 31, tux_y, scroll_x);
796 tryemptybox(tux_x + 31, tux_y, scroll_x);
800 /* Get a distro from a brick? */
802 if (shape(tux_x, tux_y, scroll_x) == 'x' ||
803 shape(tux_x, tux_y, scroll_x) == 'y')
805 add_bouncy_distro(((tux_x + scroll_x + 1)
809 if (counting_distros == NO)
811 counting_distros = YES;
812 distro_counter = 100;
815 if (distro_counter <= 0)
816 change(tux_x, tux_y, scroll_x, 'a');
818 play_sound(sounds[SND_DISTRO]);
819 score = score + SCORE_DISTRO;
822 else if (shape(tux_x + 31, tux_y, scroll_x) == 'x' ||
823 shape(tux_x + 31, tux_y, scroll_x) == 'y')
825 add_bouncy_distro(((tux_x + scroll_x + 1 + 31)
829 if (counting_distros == NO)
831 counting_distros = YES;
832 distro_counter = 100;
835 if (distro_counter <= 0)
836 change(tux_x + 31, tux_y, scroll_x, 'a');
838 play_sound(sounds[SND_DISTRO]);
839 score = score + SCORE_DISTRO;
847 tux_y = (tux_y / 32) * 32 + 30;
853 tux_y = (tux_y / 32) * 32 - 32;
858 jump_counter = MAX_JUMP_COUNT;
868 trygrabdistro(tux_x, tux_y, scroll_x, NO_BOUNCE);
869 trygrabdistro(tux_x + 31, tux_y, scroll_x, NO_BOUNCE);
871 if (tux_size == BIG && !tux_duck)
873 trygrabdistro(tux_x, tux_y - 32, scroll_x, NO_BOUNCE);
874 trygrabdistro(tux_x + 31, tux_y - 32, scroll_x, NO_BOUNCE);
879 /* Enough distros for a One-up? */
881 if (distros >= DISTROS_LIFEUP)
883 distros = distros - DISTROS_LIFEUP;
884 if(lives < MAX_LIVES)
886 play_sound(sounds[SND_LIFEUP]); /*We want to hear the sound even, if MAX_LIVES is reached*/
890 /* Keep in-bounds, vertically: */
894 else if (tux_y > 480)
900 /* Slow down horizontally: */
904 if (right == UP && left == UP)
906 if (isice(tux_x, tux_y + 32, scroll_x) ||
907 !issolid(tux_x, tux_y + 32, scroll_x))
909 /* Slowly on ice or in air: */
918 /* Quickly, otherwise: */
925 /* Drop vertically: */
927 if (!issolid(tux_x, tux_y + 32, scroll_x))
929 tux_ym = tux_ym + GRAVITY;
941 /* ---- DONE HANDLING TUX! --- */
944 /* Handle bouncy distros: */
946 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
948 if (bouncy_distros[i].alive)
950 bouncy_distros[i].y = bouncy_distros[i].y + bouncy_distros[i].ym;
952 bouncy_distros[i].ym++;
954 if (bouncy_distros[i].ym >= 0)
955 bouncy_distros[i].alive = NO;
960 /* Handle broken bricks: */
962 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
964 if (broken_bricks[i].alive)
966 broken_bricks[i].x = broken_bricks[i].x + broken_bricks[i].xm;
967 broken_bricks[i].y = broken_bricks[i].y + broken_bricks[i].ym;
969 broken_bricks[i].ym++;
971 if (broken_bricks[i].ym >= 0)
972 broken_bricks[i].alive = NO;
977 /* Handle distro counting: */
979 if (counting_distros == YES)
983 if (distro_counter <= 0)
984 counting_distros = -1;
988 /* Handle bouncy bricks: */
990 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
992 if (bouncy_bricks[i].alive)
994 bouncy_bricks[i].offset = (bouncy_bricks[i].offset +
995 bouncy_bricks[i].offset_m);
999 if (bouncy_bricks[i].offset < -BOUNCY_BRICK_MAX_OFFSET)
1000 bouncy_bricks[i].offset_m = BOUNCY_BRICK_SPEED;
1003 /* Stop bouncing? */
1005 if (bouncy_bricks[i].offset == 0)
1006 bouncy_bricks[i].alive = NO;
1011 /* Handle floating scores: */
1013 for (i = 0; i < NUM_FLOATING_SCORES; i++)
1015 if (floating_scores[i].alive)
1017 floating_scores[i].y = floating_scores[i].y - 2;
1018 floating_scores[i].timer--;
1020 if (floating_scores[i].timer <= 0)
1021 floating_scores[i].alive = NO;
1026 /* Handle bullets: */
1028 for (i = 0; i < NUM_BULLETS; i++)
1030 if (bullets[i].alive)
1032 bullets[i].x = bullets[i].x + bullets[i].xm;
1033 bullets[i].y = bullets[i].y + bullets[i].ym;
1035 if (issolid(bullets[i].x, bullets[i].y, 0))
1037 if (issolid(bullets[i].x, bullets[i].y - bullets[i].ym, 0))
1038 bullets[i].alive = NO;
1041 if (bullets[i].ym >= 0)
1043 bullets[i].y = (bullets[i].y / 32) * 32 - 8;
1045 bullets[i].ym = -bullets[i].ym;
1049 bullets[i].ym = bullets[i].ym + GRAVITY;
1051 if (bullets[i].x < scroll_x ||
1052 bullets[i].x > scroll_x + 640)
1054 bullets[i].alive = NO;
1059 if (bullets[i].alive)
1061 for (j = 0; j < NUM_BAD_GUYS; j++)
1063 if (bad_guys[j].alive && !bad_guys[j].dying)
1065 if (bullets[i].x >= bad_guys[j].x - 4 &&
1066 bullets[i].x <= bad_guys[j].x + 32 + 4 &&
1067 bullets[i].y >= bad_guys[j].y - 4 &&
1068 bullets[i].y <= bad_guys[j].y + 32 + 4)
1070 /* Kill the bad guy! */
1072 bullets[i].alive = 0;
1073 bad_guys[j].dying = FALLING;
1074 bad_guys[j].ym = -8;
1077 /* Gain some points: */
1079 if (bad_guys[j].kind == BAD_BSOD)
1081 add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
1082 50 * score_multiplier);
1084 else if (bad_guys[j].kind == BAD_LAPTOP)
1086 add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
1087 25 * score_multiplier);
1091 /* Play death sound: */
1092 play_sound(sounds[SND_FALL]);
1100 /* Handle background timer: */
1102 if (super_bkgd_time)
1106 /* Handle invincibility timer: */
1109 if (tux_invincible_time > 50)
1111 tux_invincible_time--;
1114 if (!playing_music())
1115 play_music( herring_song, 1 );
1119 if (current_music == HERRING_MUSIC)
1121 /* stop the herring_song, now play the level_song ! */
1122 current_music = LEVEL_MUSIC;
1126 if (!playing_music())
1128 play_music( level_song, 1 );
1131 if (tux_invincible_time > 0)
1132 tux_invincible_time--;
1136 /* Handle upgrades: */
1138 for (i = 0; i < NUM_UPGRADES; i++)
1140 if (upgrades[i].alive)
1142 if (upgrades[i].height < 32)
1146 upgrades[i].height++;
1152 if (upgrades[i].kind == UPGRADE_MINTS ||
1153 upgrades[i].kind == UPGRADE_HERRING)
1155 upgrades[i].x = upgrades[i].x + upgrades[i].xm;
1156 upgrades[i].y = upgrades[i].y + upgrades[i].ym;
1158 if (issolid(upgrades[i].x, upgrades[i].y + 31, 0) ||
1159 issolid(upgrades[i].x + 31, upgrades[i].y + 31, 0))
1161 if (upgrades[i].ym > 0)
1163 if (upgrades[i].kind == UPGRADE_MINTS)
1167 else if (upgrades[i].kind == UPGRADE_HERRING)
1169 upgrades[i].ym = -24;
1172 upgrades[i].y = (upgrades[i].y / 32) * 32;
1176 upgrades[i].ym = upgrades[i].ym + GRAVITY;
1178 if (issolid(upgrades[i].x, upgrades[i].y, 0))
1180 upgrades[i].xm = -upgrades[i].xm;
1185 /* Off the screen? Kill it! */
1187 if (upgrades[i].x < scroll_x)
1188 upgrades[i].alive = NO;
1191 /* Did the player grab it? */
1193 if (tux_x + scroll_x >= upgrades[i].x - 32 &&
1194 tux_x + scroll_x <= upgrades[i].x + 32 &&
1195 tux_y >= upgrades[i].y - 32 &&
1196 tux_y <= upgrades[i].y + 32)
1198 /* Remove the upgrade: */
1200 upgrades[i].alive = NO;
1203 /* Affect the player: */
1205 if (upgrades[i].kind == UPGRADE_MINTS)
1207 play_sound(sounds[SND_EXCELLENT]);
1209 super_bkgd_time = 8;
1211 else if (upgrades[i].kind == UPGRADE_COFFEE)
1213 play_sound(sounds[SND_COFFEE]);
1214 tux_got_coffee = YES;
1215 super_bkgd_time = 4;
1217 else if (upgrades[i].kind == UPGRADE_HERRING)
1219 play_sound(sounds[SND_HERRING]);
1220 tux_invincible_time = TUX_INVINCIBLE_TIME;
1221 super_bkgd_time = 4;
1222 /* play the herring song ^^ */
1223 current_music = HERRING_MUSIC;
1224 if (playing_music())
1226 play_music( herring_song, 1 );
1234 /* Handle bad guys: */
1236 for (i = 0; i < NUM_BAD_GUYS; i++)
1238 if (bad_guys[i].alive)
1240 if (bad_guys[i].seen)
1242 if (bad_guys[i].kind == BAD_BSOD)
1244 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
1246 /* Move left/right: */
1248 if (bad_guys[i].dying == NO ||
1249 bad_guys[i].dying == FALLING)
1251 if (bad_guys[i].dir == RIGHT)
1252 bad_guys[i].x = bad_guys[i].x + 4;
1253 else if (bad_guys[i].dir == LEFT)
1254 bad_guys[i].x = bad_guys[i].x - 4;
1258 /* Move vertically: */
1260 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1263 /* Bump into things horizontally: */
1265 if (!bad_guys[i].dying)
1267 if (issolid(bad_guys[i].x, bad_guys[i].y, 0))
1268 bad_guys[i].dir = !bad_guys[i].dir;
1272 /* Bump into other bad guys: */
1274 for (j = 0; j < NUM_BAD_GUYS; j++)
1276 if (j != i && bad_guys[j].alive &&
1277 !bad_guys[j].dying && !bad_guys[i].dying &&
1278 bad_guys[i].x >= bad_guys[j].x - 32 &&
1279 bad_guys[i].x <= bad_guys[j].x + 32 &&
1280 bad_guys[i].y >= bad_guys[j].y - 32 &&
1281 bad_guys[i].y <= bad_guys[j].y + 32)
1283 bad_guys[i].dir = !bad_guys[i].dir;
1288 /* Fall if we get off the ground: */
1290 if (bad_guys[i].dying != FALLING)
1292 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0) &&
1293 bad_guys[i].ym < MAX_YM)
1295 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1301 if (bad_guys[i].ym > 0)
1303 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1309 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1311 if (bad_guys[i].y > 480)
1312 bad_guys[i].alive = NO;
1314 else if (bad_guys[i].kind == BAD_LAPTOP)
1316 /* --- LAPTOP MONSTER: --- */
1318 /* Move left/right: */
1320 if (bad_guys[i].mode != FLAT && bad_guys[i].mode != KICK)
1322 if (bad_guys[i].dying == NO ||
1323 bad_guys[i].dying == FALLING)
1325 if (bad_guys[i].dir == RIGHT)
1326 bad_guys[i].x = bad_guys[i].x + 4;
1327 else if (bad_guys[i].dir == LEFT)
1328 bad_guys[i].x = bad_guys[i].x - 4;
1331 else if (bad_guys[i].mode == KICK)
1333 if (bad_guys[i].dir == RIGHT)
1334 bad_guys[i].x = bad_guys[i].x + 16;
1335 else if (bad_guys[i].dir == LEFT)
1336 bad_guys[i].x = bad_guys[i].x - 16;
1340 /* Move vertically: */
1342 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1345 /* Bump into things horizontally: */
1347 if (!bad_guys[i].dying)
1349 if (issolid(bad_guys[i].x, bad_guys[i].y, 0))
1351 bad_guys[i].dir = !bad_guys[i].dir;
1353 if (bad_guys[i].mode == KICK)
1354 play_sound(sounds[SND_RICOCHET]);
1359 /* Bump into other bad guys: */
1361 for (j = 0; j < NUM_BAD_GUYS; j++)
1363 if (j != i && bad_guys[j].alive &&
1364 !bad_guys[j].dying && !bad_guys[i].dying &&
1365 bad_guys[i].x >= bad_guys[j].x - 32 &&
1366 bad_guys[i].x <= bad_guys[j].x + 32 &&
1367 bad_guys[i].y >= bad_guys[j].y - 32 &&
1368 bad_guys[i].y <= bad_guys[j].y + 32)
1370 if (bad_guys[i].mode != KICK)
1371 bad_guys[i].dir = !bad_guys[i].dir;
1374 /* We're in kick mode, kill the other guy: */
1376 bad_guys[j].dying = FALLING;
1377 bad_guys[j].ym = -8;
1378 play_sound(sounds[SND_FALL]);
1380 add_score(bad_guys[i].x - scroll_x,
1381 bad_guys[i].y, 100);
1387 /* Fall if we get off the ground: */
1389 if (bad_guys[i].dying != FALLING)
1391 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0) &&
1392 bad_guys[i].ym < MAX_YM)
1394 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1400 if (bad_guys[i].ym > 0)
1402 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1408 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1410 if (bad_guys[i].y > 480)
1411 bad_guys[i].alive = NO;
1413 else if (bad_guys[i].kind == BAD_MONEY)
1415 /* --- MONEY BAGS: --- */
1418 /* Move vertically: */
1420 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1423 /* Fall if we get off the ground: */
1425 if (bad_guys[i].dying != FALLING)
1427 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0))
1429 if (bad_guys[i].ym < MAX_YM)
1431 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1438 if (bad_guys[i].ym > 0)
1440 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1441 bad_guys[i].ym = -MAX_YM;
1446 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1448 if (bad_guys[i].y > 480)
1449 bad_guys[i].alive = NO;
1451 else if (bad_guys[i].kind == -1)
1455 /* Kill it if the player jumped on it: */
1457 if (!bad_guys[i].dying && !tux_dying && !tux_safe &&
1458 tux_x + scroll_x >= bad_guys[i].x - 32 &&
1459 tux_x + scroll_x <= bad_guys[i].x + 32 &&
1460 tux_y >= bad_guys[i].y - 32 &&
1461 tux_y <= bad_guys[i].y - 8
1465 if (bad_guys[i].kind == BAD_BSOD)
1467 bad_guys[i].dying = SQUISHED;
1468 bad_guys[i].timer = 16;
1469 tux_ym = -KILL_BOUNCE_YM;
1471 add_score(bad_guys[i].x - scroll_x, bad_guys[i].y,
1472 50 * score_multiplier);
1474 play_sound(sounds[SND_SQUISH]);
1476 else if (bad_guys[i].kind == BAD_LAPTOP)
1478 if (bad_guys[i].mode != FLAT)
1482 bad_guys[i].mode = FLAT;
1484 bad_guys[i].timer = 64;
1492 bad_guys[i].mode = KICK;
1494 if (tux_x + scroll_x <= bad_guys[i].x)
1495 bad_guys[i].dir = RIGHT;
1497 bad_guys[i].dir = LEFT;
1499 bad_guys[i].timer = 8;
1502 tux_ym = -KILL_BOUNCE_YM;
1504 add_score(bad_guys[i].x - scroll_x,
1506 25 * score_multiplier);
1508 /* play_sound(sounds[SND_SQUISH]); */
1510 else if (bad_guys[i].kind == -1)
1517 /* Hurt the player if he just touched it: */
1519 if (!bad_guys[i].dying && !tux_dying &&
1521 tux_x + scroll_x >= bad_guys[i].x - 32 &&
1522 tux_x + scroll_x <= bad_guys[i].x + 32 &&
1523 tux_y >= bad_guys[i].y - 32 &&
1524 tux_y <= bad_guys[i].y + 32)
1526 if (bad_guys[i].mode == FLAT)
1530 bad_guys[i].mode = KICK;
1532 if (tux_x + scroll_x <= bad_guys[i].x)
1534 bad_guys[i].dir = RIGHT;
1535 bad_guys[i].x = bad_guys[i].x + 16;
1539 bad_guys[i].dir = LEFT;
1540 bad_guys[i].x = bad_guys[i].x - 16;
1543 bad_guys[i].timer = 8;
1545 else if (bad_guys[i].mode == KICK)
1547 if (tux_y < bad_guys[i].y - 16 &&
1548 bad_guys[i].timer == 0)
1550 /* Step on (stop being kicked) */
1552 bad_guys[i].mode = FLAT;
1553 bad_guys[i].timer = 64;
1557 /* Hurt if you get hit by kicked laptop: */
1559 if (bad_guys[i].timer == 0)
1561 if (tux_invincible_time == 0)
1567 bad_guys[i].dying = FALLING;
1568 bad_guys[i].ym = -8;
1569 play_sound(sounds[SND_FALL]);
1576 if (tux_invincible_time == 0)
1582 bad_guys[i].dying = FALLING;
1583 bad_guys[i].ym = -8;
1584 play_sound(sounds[SND_FALL]);
1590 /* Handle mode timer: */
1592 if (bad_guys[i].mode == FLAT)
1594 bad_guys[i].timer--;
1596 if (bad_guys[i].timer <= 0)
1597 bad_guys[i].mode = NORMAL;
1599 else if (bad_guys[i].mode == KICK)
1601 if (bad_guys[i].timer > 0)
1602 bad_guys[i].timer--;
1606 /* Handle dying timer: */
1608 if (bad_guys[i].dying == SQUISHED)
1610 bad_guys[i].timer--;
1613 /* Remove it if time's up: */
1615 if (bad_guys[i].timer <= 0)
1616 bad_guys[i].alive = NO;
1620 /* Remove if it's far off the screen: */
1622 if (bad_guys[i].x < scroll_x - OFFSCREEN_DISTANCE)
1623 bad_guys[i].alive = NO;
1627 /* Once it's on screen, it's activated! */
1629 if (bad_guys[i].x <= scroll_x + 640 + OFFSCREEN_DISTANCE)
1630 bad_guys[i].seen = YES;
1636 /* Handle skidding: */
1638 if (tux_skidding > 0)
1646 /* --- GAME DRAW! --- */
1654 if (tux_dying && (frame % 4) == 0)
1655 clearscreen(255, 255, 255);
1658 if (super_bkgd_time == 0)
1659 clearscreen(bkgd_red, bkgd_green, bkgd_blue);
1661 drawimage(img_super_bkgd, 0, 0, NO_UPDATE);
1665 /* Draw background: */
1667 for (y = 0; y < 15; y++)
1669 for (x = 0; x < 21; x++)
1671 drawshape(x * 32 - (scroll_x % 32), y * 32,
1672 tiles[y][x + (scroll_x / 32)]);
1677 /* (Bouncy bricks): */
1679 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
1681 if (bouncy_bricks[i].alive)
1683 if (bouncy_bricks[i].x >= scroll_x - 32 &&
1684 bouncy_bricks[i].x <= scroll_x + 640)
1686 dest.x = bouncy_bricks[i].x - scroll_x;
1687 dest.y = bouncy_bricks[i].y;
1691 SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format,
1696 drawshape(bouncy_bricks[i].x - scroll_x,
1697 bouncy_bricks[i].y + bouncy_bricks[i].offset,
1698 bouncy_bricks[i].shape);
1706 for (i = 0; i < NUM_BAD_GUYS; i++)
1708 if (bad_guys[i].alive &&
1709 bad_guys[i].x > scroll_x - 32 &&
1710 bad_guys[i].x < scroll_x + 640)
1712 if (bad_guys[i].kind == BAD_BSOD)
1714 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
1716 if (bad_guys[i].dying == NO)
1720 if (bad_guys[i].dir == LEFT)
1722 drawimage(img_bsod_left[(frame / 5) % 4],
1723 bad_guys[i].x - scroll_x,
1729 drawimage(img_bsod_right[(frame / 5) % 4],
1730 bad_guys[i].x - scroll_x,
1735 else if (bad_guys[i].dying == FALLING)
1739 if (bad_guys[i].dir == LEFT)
1741 drawimage(img_bsod_falling_left,
1742 bad_guys[i].x - scroll_x,
1748 drawimage(img_bsod_falling_right,
1749 bad_guys[i].x - scroll_x,
1754 else if (bad_guys[i].dying == SQUISHED)
1756 /* Dying - Squished: */
1758 if (bad_guys[i].dir == LEFT)
1760 drawimage(img_bsod_squished_left,
1761 bad_guys[i].x - scroll_x,
1767 drawimage(img_bsod_squished_right,
1768 bad_guys[i].x - scroll_x,
1774 else if (bad_guys[i].kind == BAD_LAPTOP)
1776 /* --- LAPTOP MONSTER: --- */
1778 if (bad_guys[i].dying == NO)
1782 if (bad_guys[i].mode == NORMAL)
1786 if (bad_guys[i].dir == LEFT)
1788 drawimage(img_laptop_left[(frame / 5) % 3],
1789 bad_guys[i].x - scroll_x,
1795 drawimage(img_laptop_right[(frame / 5) % 3],
1796 bad_guys[i].x - scroll_x,
1805 if (bad_guys[i].dir == LEFT)
1807 drawimage(img_laptop_flat_left,
1808 bad_guys[i].x - scroll_x,
1814 drawimage(img_laptop_flat_right,
1815 bad_guys[i].x - scroll_x,
1821 else if (bad_guys[i].dying == FALLING)
1825 if (bad_guys[i].dir == LEFT)
1827 drawimage(img_laptop_falling_left,
1828 bad_guys[i].x - scroll_x,
1834 drawimage(img_laptop_falling_right,
1835 bad_guys[i].x - scroll_x,
1841 else if (bad_guys[i].kind == BAD_MONEY)
1843 if (bad_guys[i].ym > -16)
1845 if (bad_guys[i].dir == LEFT)
1847 drawimage(img_money_left[0],
1848 bad_guys[i].x - scroll_x,
1854 drawimage(img_money_right[0],
1855 bad_guys[i].x - scroll_x,
1862 if (bad_guys[i].dir == LEFT)
1864 drawimage(img_money_left[1],
1865 bad_guys[i].x - scroll_x,
1871 drawimage(img_money_right[1],
1872 bad_guys[i].x - scroll_x,
1878 else if (bad_guys[i].kind == -1)
1886 if (right == UP && left == UP)
1893 if ((fire == DOWN && (frame % 2) == 0) ||
1895 tux_frame_main = (tux_frame_main + 1) % 4;
1897 tux_frame = tux_frame_main;
1904 if (tux_got_coffee && (frame % 2) == 1)
1908 drawimage(img_red_glow, tux_x - 8, tux_y - 32, NO_UPDATE);
1912 if (tux_safe == 0 || (frame % 2) == 0)
1914 if (tux_size == SMALL)
1916 if (tux_invincible_time)
1920 if (tux_dir == RIGHT)
1922 drawimage(cape_right[frame % 2],
1928 drawimage(cape_left[frame % 2],
1935 if (tux_dir == RIGHT)
1937 drawimage(tux_right[tux_frame], tux_x, tux_y, NO_UPDATE);
1941 drawimage(tux_left[tux_frame], tux_x, tux_y, NO_UPDATE);
1946 if (tux_invincible_time)
1950 if (tux_dir == RIGHT)
1952 drawimage(bigcape_right[frame % 2],
1953 tux_x - 8 - 16, tux_y - 32,
1958 drawimage(bigcape_left[frame % 2],
1959 tux_x - 8, tux_y - 32,
1968 if (!jumping || tux_ym > 0)
1970 if (tux_dir == RIGHT)
1972 drawimage(bigtux_right[tux_frame],
1973 tux_x - 8, tux_y - 32,
1978 drawimage(bigtux_left[tux_frame],
1979 tux_x - 8, tux_y - 32,
1985 if (tux_dir == RIGHT)
1987 drawimage(bigtux_right_jump,
1988 tux_x - 8, tux_y - 32,
1993 drawimage(bigtux_left_jump,
1994 tux_x - 8, tux_y - 32,
2001 if (tux_dir == RIGHT)
2003 drawimage(skidtux_right,
2004 tux_x - 8, tux_y - 32,
2009 drawimage(skidtux_left,
2010 tux_x - 8, tux_y - 32,
2017 if (tux_dir == RIGHT)
2019 drawimage(ducktux_right, tux_x - 8, tux_y - 16,
2024 drawimage(ducktux_left, tux_x - 8, tux_y - 16,
2034 for (i = 0; i < NUM_BULLETS; i++)
2036 if (bullets[i].alive &&
2037 bullets[i].x >= scroll_x - 4 &&
2038 bullets[i].x <= scroll_x + 640)
2040 drawimage(img_bullet, bullets[i].x - scroll_x, bullets[i].y,
2046 /* (Floating scores): */
2048 for (i = 0; i < NUM_FLOATING_SCORES; i++)
2050 if (floating_scores[i].alive)
2052 sprintf(str, "%d", floating_scores[i].value);
2054 floating_scores[i].x + 16 - strlen(str) * 8,
2055 floating_scores[i].y,
2056 letters_gold, NO_UPDATE);
2063 for (i = 0; i < NUM_UPGRADES; i++)
2065 if (upgrades[i].alive)
2067 if (upgrades[i].height < 32)
2071 dest.x = upgrades[i].x - scroll_x;
2072 dest.y = upgrades[i].y + 32 - upgrades[i].height;
2074 dest.h = upgrades[i].height;
2079 src.h = upgrades[i].height;
2081 if (upgrades[i].kind == UPGRADE_MINTS)
2082 SDL_BlitSurface(img_mints, &src, screen, &dest);
2083 else if (upgrades[i].kind == UPGRADE_COFFEE)
2084 SDL_BlitSurface(img_coffee, &src, screen, &dest);
2085 else if (upgrades[i].kind == UPGRADE_HERRING)
2086 SDL_BlitSurface(img_golden_herring, &src, screen, &dest);
2090 if (upgrades[i].kind == UPGRADE_MINTS)
2092 drawimage(img_mints,
2093 upgrades[i].x - scroll_x, upgrades[i].y,
2096 else if (upgrades[i].kind == UPGRADE_COFFEE)
2098 drawimage(img_coffee,
2099 upgrades[i].x - scroll_x, upgrades[i].y,
2102 else if (upgrades[i].kind == UPGRADE_HERRING)
2104 drawimage(img_golden_herring,
2105 upgrades[i].x - scroll_x, upgrades[i].y,
2113 /* (Bouncy distros): */
2115 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
2117 if (bouncy_distros[i].alive)
2119 drawimage(img_distro[0],
2120 bouncy_distros[i].x - scroll_x,
2121 bouncy_distros[i].y,
2127 /* (Broken bricks): */
2129 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
2131 if (broken_bricks[i].alive)
2133 src.x = rand() % 16;
2134 src.y = rand() % 16;
2138 dest.x = broken_bricks[i].x - scroll_x;
2139 dest.y = broken_bricks[i].y;
2143 SDL_BlitSurface(img_brick[0], &src, screen, &dest);
2150 sprintf(str, "%d", score);
2151 drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE);
2152 drawtext(str, 96, 0, letters_gold, NO_UPDATE);
2154 sprintf(str, "%d", highscore);
2155 drawtext("HIGH", 0, 20, letters_blue, NO_UPDATE);
2156 drawtext(str, 96, 20, letters_gold, NO_UPDATE);
2158 if (time_left >= 50 || (frame % 10) < 5)
2160 sprintf(str, "%d", time_left);
2161 drawtext("TIME", 224, 0, letters_blue, NO_UPDATE);
2162 drawtext(str, 304, 0, letters_gold, NO_UPDATE);
2165 sprintf(str, "%d", distros);
2166 drawtext("DISTROS", 480, 0, letters_blue, NO_UPDATE);
2167 drawtext(str, 608, 0, letters_gold, NO_UPDATE);
2169 drawtext("LIVES", 480, 20, letters_blue, NO_UPDATE);
2171 for(i=0; i < lives; ++i)
2173 drawimage(tux_life,565+(18*i),20,NO_UPDATE);
2177 drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE);
2182 /* (Update it all!) */
2189 /* --- GAME LOOP! --- */
2194 Uint32 last_time, now_time;
2198 clearscreen(0, 0, 0);
2202 /* Init the game: */
2210 highscore = load_hs();
2213 /* --- MAIN GAME LOOP!!! --- */
2225 last_time = SDL_GetTicks();
2229 /* Handle events: */
2235 /* Handle actions: */
2237 if(!game_pause && !show_menu)
2239 if (game_action() == 0)
2241 /* == 0: no more lives */
2242 /* == -1: continues */
2249 /*Draw the current scene to the screen */
2252 /* Keep playing music: */
2255 if (!playing_music())
2257 switch (current_music)
2260 play_music(level_song, 1);
2263 play_music(herring_song, 1);
2265 case HURRYUP_MUSIC: // keep the compiler happy
2266 case NO_MUSIC: // keep the compiler happy for the moment :-)
2272 /* Time stops in pause mode */
2273 if(game_pause || show_menu )
2278 /* Pause til next frame: */
2280 now_time = SDL_GetTicks();
2281 if (now_time < last_time + FPS)
2282 SDL_Delay(last_time + FPS - now_time);
2287 if ((frame % 10) == 0 && time_left > 0)
2295 while (!done && !quit);
2297 if (playing_music())
2308 /* Initialize the game stuff: */
2320 /* Load data for this level: */
2322 void loadlevel(void)
2333 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
2334 bouncy_distros[i].alive = NO;
2336 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
2337 broken_bricks[i].alive = NO;
2339 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
2340 bouncy_bricks[i].alive = NO;
2342 for (i = 0; i < NUM_BAD_GUYS; i++)
2343 bad_guys[i].alive = NO;
2345 for (i = 0; i < NUM_FLOATING_SCORES; i++)
2346 floating_scores[i].alive = NO;
2348 for (i = 0; i < NUM_UPGRADES; i++)
2349 upgrades[i].alive = NO;
2351 for (i = 0; i < NUM_BULLETS; i++)
2352 bullets[i].alive = NO;
2355 /* Load data file: */
2357 filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20));
2358 sprintf(filename, "%s/levels/level%d.dat", DATA_PREFIX, level);
2359 fi = fopen(filename, "r");
2370 /* Load header info: */
2375 strcpy(levelname, str);
2376 levelname[strlen(levelname)-1] = '\0';
2380 strcpy(leveltheme, str);
2381 leveltheme[strlen(leveltheme)-1] = '\0';
2385 /* (Time to beat level) */
2387 time_left = atoi(str);
2389 /* (Song file for this level) */
2391 strcpy(song_title, str);
2392 song_title[strlen(song_title)-1] = '\0';
2396 /* (Level background color) */
2398 bkgd_red = atoi(str);
2400 bkgd_green= atoi(str);
2402 bkgd_blue = atoi(str);
2406 level_width = atoi(str);
2409 /* Allocate some space for the line-reading! */
2411 line = (char *) malloc(sizeof(char) * (level_width + 5));
2414 fprintf(stderr, "Couldn't allocate space to load level data!");
2419 /* Load the level lines: */
2421 for (y = 0; y < 15; y++)
2423 if(fgets(line, level_width + 5, fi) == NULL)
2425 fprintf(stderr, "Level %s isn't complete!\n",levelname);
2428 line[strlen(line) - 1] = '\0';
2429 tiles[y] = strdup(line);
2435 /* Activate bad guys: */
2437 for (y = 0; y < 15; y++)
2439 for (x = 0; x < level_width; x++)
2441 if (tiles[y][x] >= '0' && tiles[y][x] <= '9')
2443 add_bad_guy(x * 32, y * 32, tiles[y][x] - '0');
2458 tux_got_coffee = NO;
2459 tux_invincible_time = 0;
2463 tux_safe = TUX_SAFE_TIME;
2479 score_multiplier = 1;
2480 super_bkgd_time = 0;
2482 counting_distros = NO;
2487 /* set current song/music */
2488 current_music = LEVEL_MUSIC;
2492 clearscreen(0, 0, 0);
2494 sprintf(str, "LEVEL %d", level);
2495 drawcenteredtext(str, 200, letters_red, NO_UPDATE);
2497 sprintf(str, "%s", levelname);
2498 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
2500 sprintf(str, "TUX x %d", lives);
2501 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
2511 /* Load a level-specific graphic... */
2513 SDL_Surface * load_level_image(char * file, int use_alpha)
2517 snprintf(fname, 1024, "%s/images/%s/%s", DATA_PREFIX, leveltheme, file);
2519 return(load_image(fname, use_alpha));
2523 /* Load graphics: */
2525 void loadlevelgfx(void)
2527 img_brick[0] = load_level_image("brick0.png", IGNORE_ALPHA);
2528 img_brick[1] = load_level_image("brick1.png", IGNORE_ALPHA);
2530 img_solid[0] = load_level_image("solid0.png", USE_ALPHA);
2531 img_solid[1] = load_level_image("solid1.png", USE_ALPHA);
2532 img_solid[2] = load_level_image("solid2.png", USE_ALPHA);
2533 img_solid[3] = load_level_image("solid3.png", USE_ALPHA);
2535 img_bkgd[0][0] = load_level_image("bkgd-00.png", USE_ALPHA);
2536 img_bkgd[0][1] = load_level_image("bkgd-01.png", USE_ALPHA);
2537 img_bkgd[0][2] = load_level_image("bkgd-02.png", USE_ALPHA);
2538 img_bkgd[0][3] = load_level_image("bkgd-03.png", USE_ALPHA);
2540 img_bkgd[1][0] = load_level_image("bkgd-10.png", USE_ALPHA);
2541 img_bkgd[1][1] = load_level_image("bkgd-11.png", USE_ALPHA);
2542 img_bkgd[1][2] = load_level_image("bkgd-12.png", USE_ALPHA);
2543 img_bkgd[1][3] = load_level_image("bkgd-13.png", USE_ALPHA);
2549 void loadlevelsong(void)
2554 song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
2555 strlen(song_title) + 8));
2557 sprintf(song_path, "%s/music/%s", DATA_PREFIX, song_title);
2559 level_song = load_song(song_path);
2565 /* Free graphics data for this level: */
2567 void unloadlevelgfx(void)
2571 for (i = 0; i < 2; i++)
2573 SDL_FreeSurface(img_brick[i]);
2575 for (i = 0; i < 4; i++)
2577 SDL_FreeSurface(img_solid[i]);
2578 SDL_FreeSurface(img_bkgd[0][i]);
2579 SDL_FreeSurface(img_bkgd[1][i]);
2584 /* Free music data for this level: */
2586 void unloadlevelsong(void)
2588 free_music(level_song);
2592 /* Load graphics/sounds shared between all levels: */
2594 void loadshared(void)
2597 char * herring_song_path; /* for loading herring song*/
2601 tux_right[0] = load_image(DATA_PREFIX "/images/shared/tux-right-0.png",
2604 tux_right[1] = load_image(DATA_PREFIX "/images/shared/tux-right-1.png",
2607 tux_right[2] = load_image(DATA_PREFIX "/images/shared/tux-right-2.png",
2610 tux_left[0] = load_image(DATA_PREFIX "/images/shared/tux-left-0.png",
2613 tux_left[1] = load_image(DATA_PREFIX "/images/shared/tux-left-1.png",
2616 tux_left[2] = load_image(DATA_PREFIX "/images/shared/tux-left-2.png",
2619 cape_right[0] = load_image(DATA_PREFIX "/images/shared/cape-right-0.png",
2622 cape_right[1] = load_image(DATA_PREFIX "/images/shared/cape-right-1.png",
2625 cape_left[0] = load_image(DATA_PREFIX "/images/shared/cape-left-0.png",
2628 cape_left[1] = load_image(DATA_PREFIX "/images/shared/cape-left-1.png",
2631 bigtux_right[0] = load_image(DATA_PREFIX "/images/shared/bigtux-right-0.png",
2634 bigtux_right[1] = load_image(DATA_PREFIX "/images/shared/bigtux-right-1.png",
2637 bigtux_right[2] = load_image(DATA_PREFIX "/images/shared/bigtux-right-2.png",
2641 load_image(DATA_PREFIX "/images/shared/bigtux-right-jump.png", USE_ALPHA);
2643 bigtux_left[0] = load_image(DATA_PREFIX "/images/shared/bigtux-left-0.png",
2646 bigtux_left[1] = load_image(DATA_PREFIX "/images/shared/bigtux-left-1.png",
2649 bigtux_left[2] = load_image(DATA_PREFIX "/images/shared/bigtux-left-2.png",
2653 load_image(DATA_PREFIX "/images/shared/bigtux-left-jump.png", USE_ALPHA);
2656 load_image(DATA_PREFIX "/images/shared/bigcape-right-0.png",
2660 load_image(DATA_PREFIX "/images/shared/bigcape-right-1.png",
2664 load_image(DATA_PREFIX "/images/shared/bigcape-left-0.png",
2668 load_image(DATA_PREFIX "/images/shared/bigcape-left-1.png",
2671 ducktux_right = load_image(DATA_PREFIX
2672 "/images/shared/ducktux-right.png",
2675 ducktux_left = load_image(DATA_PREFIX
2676 "/images/shared/ducktux-left.png",
2679 skidtux_right = load_image(DATA_PREFIX
2680 "/images/shared/skidtux-right.png",
2683 skidtux_left = load_image(DATA_PREFIX
2684 "/images/shared/skidtux-left.png",
2690 img_box_full = load_image(DATA_PREFIX "/images/shared/box-full.png",
2692 img_box_empty = load_image(DATA_PREFIX "/images/shared/box-empty.png",
2699 img_water = load_image(DATA_PREFIX "/images/shared/water.png", IGNORE_ALPHA);
2701 img_waves[0] = load_image(DATA_PREFIX "/images/shared/waves-0.png",
2704 img_waves[1] = load_image(DATA_PREFIX "/images/shared/waves-1.png",
2707 img_waves[2] = load_image(DATA_PREFIX "/images/shared/waves-2.png",
2713 img_pole = load_image(DATA_PREFIX "/images/shared/pole.png", USE_ALPHA);
2714 img_poletop = load_image(DATA_PREFIX "/images/shared/poletop.png",
2720 img_flag[0] = load_image(DATA_PREFIX "/images/shared/flag-0.png",
2722 img_flag[1] = load_image(DATA_PREFIX "/images/shared/flag-1.png",
2728 img_cloud[0][0] = load_image(DATA_PREFIX "/images/shared/cloud-00.png",
2731 img_cloud[0][1] = load_image(DATA_PREFIX "/images/shared/cloud-01.png",
2734 img_cloud[0][2] = load_image(DATA_PREFIX "/images/shared/cloud-02.png",
2737 img_cloud[0][3] = load_image(DATA_PREFIX "/images/shared/cloud-03.png",
2741 img_cloud[1][0] = load_image(DATA_PREFIX "/images/shared/cloud-10.png",
2744 img_cloud[1][1] = load_image(DATA_PREFIX "/images/shared/cloud-11.png",
2747 img_cloud[1][2] = load_image(DATA_PREFIX "/images/shared/cloud-12.png",
2750 img_cloud[1][3] = load_image(DATA_PREFIX "/images/shared/cloud-13.png",
2758 img_bsod_left[0] = load_image(DATA_PREFIX
2759 "/images/shared/bsod-left-0.png",
2762 img_bsod_left[1] = load_image(DATA_PREFIX
2763 "/images/shared/bsod-left-1.png",
2766 img_bsod_left[2] = load_image(DATA_PREFIX
2767 "/images/shared/bsod-left-2.png",
2770 img_bsod_left[3] = load_image(DATA_PREFIX
2771 "/images/shared/bsod-left-3.png",
2774 img_bsod_right[0] = load_image(DATA_PREFIX
2775 "/images/shared/bsod-right-0.png",
2778 img_bsod_right[1] = load_image(DATA_PREFIX
2779 "/images/shared/bsod-right-1.png",
2782 img_bsod_right[2] = load_image(DATA_PREFIX
2783 "/images/shared/bsod-right-2.png",
2786 img_bsod_right[3] = load_image(DATA_PREFIX
2787 "/images/shared/bsod-right-3.png",
2790 img_bsod_squished_left = load_image(DATA_PREFIX
2791 "/images/shared/bsod-squished-left.png",
2794 img_bsod_squished_right = load_image(DATA_PREFIX
2795 "/images/shared/bsod-squished-right.png",
2798 img_bsod_falling_left = load_image(DATA_PREFIX
2799 "/images/shared/bsod-falling-left.png",
2802 img_bsod_falling_right = load_image(DATA_PREFIX
2803 "/images/shared/bsod-falling-right.png",
2809 img_laptop_left[0] = load_image(DATA_PREFIX
2810 "/images/shared/laptop-left-0.png",
2813 img_laptop_left[1] = load_image(DATA_PREFIX
2814 "/images/shared/laptop-left-1.png",
2817 img_laptop_left[2] = load_image(DATA_PREFIX
2818 "/images/shared/laptop-left-2.png",
2821 img_laptop_right[0] = load_image(DATA_PREFIX
2822 "/images/shared/laptop-right-0.png",
2825 img_laptop_right[1] = load_image(DATA_PREFIX
2826 "/images/shared/laptop-right-1.png",
2829 img_laptop_right[2] = load_image(DATA_PREFIX
2830 "/images/shared/laptop-right-2.png",
2833 img_laptop_flat_left = load_image(DATA_PREFIX
2834 "/images/shared/laptop-flat-left.png",
2837 img_laptop_flat_right = load_image(DATA_PREFIX
2838 "/images/shared/laptop-flat-right.png",
2841 img_laptop_falling_left =
2842 load_image(DATA_PREFIX
2843 "/images/shared/laptop-falling-left.png",
2846 img_laptop_falling_right =
2847 load_image(DATA_PREFIX
2848 "/images/shared/laptop-falling-right.png",
2854 img_money_left[0] = load_image(DATA_PREFIX
2855 "/images/shared/bag-left-0.png",
2858 img_money_left[1] = load_image(DATA_PREFIX
2859 "/images/shared/bag-left-1.png",
2862 img_money_right[0] = load_image(DATA_PREFIX
2863 "/images/shared/bag-right-0.png",
2866 img_money_right[1] = load_image(DATA_PREFIX
2867 "/images/shared/bag-right-1.png",
2874 img_mints = load_image(DATA_PREFIX "/images/shared/mints.png", USE_ALPHA);
2875 img_coffee = load_image(DATA_PREFIX "/images/shared/coffee.png", USE_ALPHA);
2880 img_bullet = load_image(DATA_PREFIX "/images/shared/bullet.png", USE_ALPHA);
2882 img_red_glow = load_image(DATA_PREFIX "/images/shared/red-glow.png",
2888 img_distro[0] = load_image(DATA_PREFIX "/images/shared/distro-0.png",
2891 img_distro[1] = load_image(DATA_PREFIX "/images/shared/distro-1.png",
2894 img_distro[2] = load_image(DATA_PREFIX "/images/shared/distro-2.png",
2897 img_distro[3] = load_image(DATA_PREFIX "/images/shared/distro-3.png",
2902 tux_life = load_image(DATA_PREFIX "/images/shared/tux-life.png",
2907 img_golden_herring =
2908 load_image(DATA_PREFIX "/images/shared/golden-herring.png",
2912 /* Super background: */
2914 img_super_bkgd = load_image(DATA_PREFIX "/images/shared/super-bkgd.png",
2918 /* Sound effects: */
2920 /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
2921 // initialize sounds[i] with the correct pointer's value:
2922 // NULL or something else. And it will be dangerous to
2923 // play with not-initialized pointers.
2924 // This is also true with if (use_music)
2925 Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
2927 for (i = 0; i < NUM_SOUNDS; i++)
2928 sounds[i] = load_sound(soundfilenames[i]);
2931 herring_song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
2932 strlen("SALCON.MOD") + 8)); /* FIXME: We need a real herring_song! Thats a fake.:) */
2934 sprintf(herring_song_path, "%s/music/%s", DATA_PREFIX, "SALCON.MOD");
2936 herring_song = load_song(herring_song_path);
2938 free(herring_song_path);
2943 /* Free shared data: */
2945 void unloadshared(void)
2949 for (i = 0; i < 3; i++)
2951 SDL_FreeSurface(tux_right[i]);
2952 SDL_FreeSurface(tux_left[i]);
2953 SDL_FreeSurface(bigtux_right[i]);
2954 SDL_FreeSurface(bigtux_left[i]);
2957 SDL_FreeSurface(bigtux_right_jump);
2958 SDL_FreeSurface(bigtux_left_jump);
2960 for (i = 0; i < 2; i++)
2962 SDL_FreeSurface(cape_right[i]);
2963 SDL_FreeSurface(cape_left[i]);
2964 SDL_FreeSurface(bigcape_right[i]);
2965 SDL_FreeSurface(bigcape_left[i]);
2968 SDL_FreeSurface(ducktux_left);
2969 SDL_FreeSurface(ducktux_right);
2971 SDL_FreeSurface(skidtux_left);
2972 SDL_FreeSurface(skidtux_right);
2974 for (i = 0; i < 4; i++)
2976 SDL_FreeSurface(img_bsod_left[i]);
2977 SDL_FreeSurface(img_bsod_right[i]);
2980 SDL_FreeSurface(img_bsod_squished_left);
2981 SDL_FreeSurface(img_bsod_squished_right);
2983 SDL_FreeSurface(img_bsod_falling_left);
2984 SDL_FreeSurface(img_bsod_falling_right);
2986 for (i = 0; i < 3; i++)
2988 SDL_FreeSurface(img_laptop_left[i]);
2989 SDL_FreeSurface(img_laptop_right[i]);
2992 SDL_FreeSurface(img_laptop_flat_left);
2993 SDL_FreeSurface(img_laptop_flat_right);
2995 SDL_FreeSurface(img_laptop_falling_left);
2996 SDL_FreeSurface(img_laptop_falling_right);
2998 for (i = 0; i < 2; i++)
3000 SDL_FreeSurface(img_money_left[i]);
3001 SDL_FreeSurface(img_money_right[i]);
3004 SDL_FreeSurface(img_box_full);
3005 SDL_FreeSurface(img_box_empty);
3007 SDL_FreeSurface(img_water);
3008 for (i = 0; i < 3; i++)
3009 SDL_FreeSurface(img_waves[i]);
3011 SDL_FreeSurface(img_pole);
3012 SDL_FreeSurface(img_poletop);
3014 for (i = 0; i < 2; i++)
3015 SDL_FreeSurface(img_flag[i]);
3017 SDL_FreeSurface(img_mints);
3018 SDL_FreeSurface(img_coffee);
3020 for (i = 0; i < 4; i++)
3022 SDL_FreeSurface(img_distro[i]);
3023 SDL_FreeSurface(img_cloud[0][i]);
3024 SDL_FreeSurface(img_cloud[1][i]);
3027 SDL_FreeSurface(img_golden_herring);
3029 for (i = 0; i < NUM_SOUNDS; i++)
3030 free_chunk(sounds[i]);
3032 /* free the herring song */
3033 free_music( herring_song );
3037 /* Draw a tile on the screen: */
3039 void drawshape(int x, int y, unsigned char c)
3043 if (c == 'X' || c == 'x')
3044 drawimage(img_brick[0], x, y, NO_UPDATE);
3045 else if (c == 'Y' || c == 'y')
3046 drawimage(img_brick[1], x, y, NO_UPDATE);
3047 else if (c == 'A' || c =='B' || c == '!')
3048 drawimage(img_box_full, x, y, NO_UPDATE);
3050 drawimage(img_box_empty, x, y, NO_UPDATE);
3051 else if (c >= 'C' && c <= 'F')
3052 drawimage(img_cloud[0][c - 'C'], x, y, NO_UPDATE);
3053 else if (c >= 'c' && c <= 'f')
3054 drawimage(img_cloud[1][c - 'c'], x, y, NO_UPDATE);
3055 else if (c >= 'G' && c <= 'J')
3056 drawimage(img_bkgd[0][c - 'G'], x, y, NO_UPDATE);
3057 else if (c >= 'g' && c <= 'j')
3058 drawimage(img_bkgd[1][c - 'g'], x, y, NO_UPDATE);
3060 drawimage(img_solid[0], x, y, NO_UPDATE);
3062 drawimage(img_solid[1], x, y, NO_UPDATE);
3064 drawimage(img_solid[2], x, y, NO_UPDATE);
3066 drawimage(img_solid[3], x, y, NO_UPDATE);
3069 z = (frame / 2) % 6;
3072 drawimage(img_distro[z], x, y, NO_UPDATE);
3074 drawimage(img_distro[2], x, y, NO_UPDATE);
3076 drawimage(img_distro[1], x, y, NO_UPDATE);
3080 z = (frame / 3) % 3;
3082 drawimage(img_waves[z], x, y, NO_UPDATE);
3085 drawimage(img_poletop, x, y, NO_UPDATE);
3088 drawimage(img_pole, x, y, NO_UPDATE);
3090 /* Mark this as the end position of the level! */
3096 z = (frame / 3) % 2;
3098 drawimage(img_flag[z], x + 16, y, NO_UPDATE);
3101 drawimage(img_water, x, y, NO_UPDATE);
3105 /* What shape is at some position? */
3107 unsigned char shape(int x, int y, int sx)
3113 xx = ((x + sx) / 32);
3115 if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
3126 int issolid(int x, int y, int sx)
3132 if (isbrick(x, y, sx) ||
3133 isbrick(x + 31, y, sx) ||
3135 isice(x + 31, y, sx) ||
3136 (shape(x, y, sx) == '[' ||
3137 shape(x + 31, y, sx) == '[') ||
3138 (shape(x, y, sx) == '=' ||
3139 shape(x + 31, y, sx) == '=') ||
3140 (shape(x, y, sx) == ']' ||
3141 shape(x + 31, y, sx) == ']') ||
3142 (shape(x, y, sx) == 'A' ||
3143 shape(x + 31, y, sx) == 'A') ||
3144 (shape(x, y, sx) == 'B' ||
3145 shape(x + 31, y, sx) == 'B') ||
3146 (shape(x, y, sx) == '!' ||
3147 shape(x + 31, y, sx) == '!') ||
3148 (shape(x, y, sx) == 'a' ||
3149 shape(x + 31, y, sx) == 'a'))
3158 /* Is it a brick? */
3160 int isbrick(int x, int y, int sx)
3166 if (shape(x, y, sx) == 'X' ||
3167 shape(x, y, sx) == 'x' ||
3168 shape(x, y, sx) == 'Y' ||
3169 shape(x, y, sx) == 'y')
3180 int isice(int x, int y, int sx)
3186 if (shape(x, y, sx) == '#')
3195 /* Is it a full box? */
3197 int isfullbox(int x, int y, int sx)
3203 if (shape(x, y, sx) == 'A' ||
3204 shape(x, y, sx) == 'B' ||
3205 shape(x, y, sx) == '!')
3214 /* Edit a piece of the map! */
3216 void change(int x, int y, int sx, unsigned char c)
3221 xx = ((x + sx) / 32);
3223 if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
3228 /* Break a brick: */
3230 void trybreakbrick(int x, int y, int sx)
3232 if (isbrick(x, y, sx))
3234 if (shape(x, y, sx) == 'x' || shape(x, y, sx) == 'y')
3236 /* Get a distro from it: */
3238 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3241 if (counting_distros == NO)
3243 counting_distros = YES;
3244 distro_counter = 50;
3247 if (distro_counter <= 0)
3248 change(x, y, sx, 'a');
3250 play_sound(sounds[SND_DISTRO]);
3251 score = score + SCORE_DISTRO;
3256 /* Get rid of it: */
3258 change(x, y, sx, '.');
3262 /* Replace it with broken bits: */
3264 add_broken_brick(((x + sx + 1) / 32) * 32,
3268 /* Get some score: */
3270 play_sound(sounds[SND_BRICK]);
3271 score = score + SCORE_BRICK;
3276 /* Bounce a brick: */
3278 void bumpbrick(int x, int y, int sx)
3280 add_bouncy_brick(((x + sx + 1) / 32) * 32,
3283 play_sound(sounds[SND_BRICK]);
3289 void tryemptybox(int x, int y, int sx)
3291 if (isfullbox(x, y, sx))
3293 if (shape(x, y, sx) == 'A')
3295 /* Box with a distro! */
3297 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3298 (y / 32) * 32 - 32);
3300 play_sound(sounds[SND_DISTRO]);
3301 score = score + SCORE_DISTRO;
3304 else if (shape(x, y, sx) == 'B')
3306 /* Add an upgrade! */
3308 if (tux_size == SMALL)
3310 /* Tux is small, add mints! */
3312 add_upgrade(((x + sx + 1) / 32) * 32,
3318 /* Tux is big, add coffee: */
3320 add_upgrade(((x + sx + 1) / 32) * 32,
3325 play_sound(sounds[SND_UPGRADE]);
3327 else if (shape(x, y, sx) == '!')
3329 /* Add a golden herring */
3331 add_upgrade(((x + sx + 1) / 32) * 32,
3336 /* Empty the box: */
3338 change(x, y, sx, 'a');
3343 /* Try to grab a distro: */
3345 void trygrabdistro(int x, int y, int sx, int bounciness)
3347 if (shape(x, y, sx) == '$')
3349 change(x, y, sx, '.');
3350 play_sound(sounds[SND_DISTRO]);
3352 if (bounciness == BOUNCE)
3354 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3358 score = score + SCORE_DISTRO;
3364 /* Add a bouncy distro: */
3366 void add_bouncy_distro(int x, int y)
3372 for (i = 0; i < NUM_BOUNCY_DISTROS && found == -1; i++)
3374 if (!bouncy_distros[i].alive)
3380 bouncy_distros[found].alive = YES;
3381 bouncy_distros[found].x = x;
3382 bouncy_distros[found].y = y;
3383 bouncy_distros[found].ym = -6;
3388 /* Add broken brick pieces: */
3390 void add_broken_brick(int x, int y)
3392 add_broken_brick_piece(x, y, -4, -16);
3393 add_broken_brick_piece(x, y + 16, -6, -12);
3395 add_broken_brick_piece(x + 16, y, 4, -16);
3396 add_broken_brick_piece(x + 16, y + 16, 6, -12);
3400 /* Add a broken brick piece: */
3402 void add_broken_brick_piece(int x, int y, int xm, int ym)
3408 for (i = 0; i < NUM_BROKEN_BRICKS && found == -1; i++)
3410 if (!broken_bricks[i].alive)
3416 broken_bricks[found].alive = YES;
3417 broken_bricks[found].x = x;
3418 broken_bricks[found].y = y;
3419 broken_bricks[found].xm = xm;
3420 broken_bricks[found].ym = ym;
3425 /* Add a bouncy brick piece: */
3427 void add_bouncy_brick(int x, int y)
3433 for (i = 0; i < NUM_BOUNCY_BRICKS && found == -1; i++)
3435 if (!bouncy_bricks[i].alive)
3441 bouncy_bricks[found].alive = YES;
3442 bouncy_bricks[found].x = x;
3443 bouncy_bricks[found].y = y;
3444 bouncy_bricks[found].offset = 0;
3445 bouncy_bricks[found].offset_m = -BOUNCY_BRICK_SPEED;
3446 bouncy_bricks[found].shape = shape(x, y, 0);
3451 /* Add a bad guy: */
3453 void add_bad_guy(int x, int y, int kind)
3459 for (i = 0; i < NUM_BAD_GUYS && found == -1; i++)
3461 if (!bad_guys[i].alive)
3467 bad_guys[found].alive = YES;
3468 bad_guys[found].mode = NORMAL;
3469 bad_guys[found].dying = NO;
3470 bad_guys[found].timer = 0;
3471 bad_guys[found].kind = kind;
3472 bad_guys[found].x = x;
3473 bad_guys[found].y = y;
3474 bad_guys[found].xm = 0;
3475 bad_guys[found].ym = 0;
3476 bad_guys[found].dir = LEFT;
3477 bad_guys[found].seen = NO;
3484 void add_score(int x, int y, int s)
3489 /* Add the score: */
3494 /* Add a floating score thing to the game: */
3498 for (i = 0; i < NUM_FLOATING_SCORES && found == -1; i++)
3500 if (!floating_scores[i].alive)
3507 floating_scores[found].alive = YES;
3508 floating_scores[found].x = x;
3509 floating_scores[found].y = y - 16;
3510 floating_scores[found].timer = 8;
3511 floating_scores[found].value = s;
3516 /* Try to bump a bad guy from below: */
3518 void trybumpbadguy(int x, int y, int sx)
3525 for (i = 0; i < NUM_BAD_GUYS; i++)
3527 if (bad_guys[i].alive &&
3528 bad_guys[i].x >= x + sx - 32 && bad_guys[i].x <= x + sx + 32 &&
3529 bad_guys[i].y >= y - 16 && bad_guys[i].y <= y + 16)
3531 if (bad_guys[i].kind == BAD_BSOD ||
3532 bad_guys[i].kind == BAD_LAPTOP)
3534 bad_guys[i].dying = FALLING;
3535 bad_guys[i].ym = -8;
3536 play_sound(sounds[SND_FALL]);
3544 for (i = 0; i < NUM_UPGRADES; i++)
3546 if (upgrades[i].alive && upgrades[i].height == 32 &&
3547 upgrades[i].x >= x + sx - 32 && upgrades[i].x <= x + sx + 32 &&
3548 upgrades[i].y >= y - 16 && upgrades[i].y <= y + 16)
3550 upgrades[i].xm = -upgrades[i].xm;
3551 upgrades[i].ym = -8;
3552 play_sound(sounds[SND_BUMP_UPGRADE]);
3558 /* Add an upgrade: */
3560 void add_upgrade(int x, int y, int kind)
3566 for (i = 0; i < NUM_UPGRADES && found == -1; i++)
3568 if (!upgrades[i].alive)
3574 upgrades[found].alive = YES;
3575 upgrades[found].kind = kind;
3576 upgrades[found].x = x;
3577 upgrades[found].y = y;
3578 upgrades[found].xm = 4;
3579 upgrades[found].ym = -4;
3580 upgrades[found].height = 0;
3587 void killtux(int mode)
3591 play_sound(sounds[SND_HURT]);
3593 if (tux_dir == RIGHT)
3595 else if (tux_dir == LEFT)
3598 if (mode == SHRINK && tux_size == BIG)
3601 tux_got_coffee = NO;
3605 tux_safe = TUX_SAFE_TIME;
3616 void add_bullet(int x, int y, int dir, int xm)
3622 for (i = 0; i < NUM_BULLETS && found == -1; i++)
3624 if (!bullets[i].alive)
3630 bullets[found].alive = YES;
3634 bullets[found].x = x + 32;
3635 bullets[found].xm = BULLET_XM + xm;
3639 bullets[found].x = x;
3640 bullets[found].xm = -BULLET_XM + xm;
3643 bullets[found].y = y;
3644 bullets[found].ym = BULLET_STARTING_YM;
3646 play_sound(sounds[SND_SHOOT]);
3651 void drawendscreen(void)
3655 clearscreen(0, 0, 0);
3657 drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE);
3659 sprintf(str, "SCORE: %d", score);
3660 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
3662 sprintf(str, "DISTROS: %d", distros);
3663 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
3669 void drawresultscreen(void)
3673 clearscreen(0, 0, 0);
3675 drawcenteredtext("Result:", 200, letters_red, NO_UPDATE);
3677 sprintf(str, "SCORE: %d", score);
3678 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
3680 sprintf(str, "DISTROS: %d", distros);
3681 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
3684 /*SDL_Delay(2000);*/