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"
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];
127 /* Local function prototypes: */
130 void loadlevel(void);
131 void loadlevelgfx(void);
132 void loadlevelsong(void);
133 void unloadlevelgfx(void);
134 void unloadlevelsong(void);
135 void loadshared(void);
136 void unloadshared(void);
137 void drawshape(int x, int y, unsigned char c);
139 unsigned char shape(int x, int y, int sx);
140 int issolid(int x, int y, int sx);
141 int isbrick(int x, int y, int sx);
142 int isice(int x, int y, int sx);
143 int isfullbox(int x, int y, int sx);
144 void change(int x, int y, int sx, unsigned char c);
145 void trybreakbrick(int x, int y, int sx);
146 void bumpbrick(int x, int y, int sx);
147 void tryemptybox(int x, int y, int sx);
148 void trygrabdistro(int x, int y, int sx, int bounciness);
149 void add_bouncy_distro(int x, int y);
150 void add_broken_brick(int x, int y);
151 void add_broken_brick_piece(int x, int y, int xm, int ym);
152 void add_bouncy_brick(int x, int y);
153 void add_bad_guy(int x, int y, int kind);
154 void add_score(int x, int y, int s);
155 void trybumpbadguy(int x, int y, int sx);
156 void add_upgrade(int x, int y, int kind);
157 void killtux(int mode);
158 void add_bullet(int x, int y, int dir, int xm);
159 void drawendscreen(void);
160 void drawresultscreen(void);
162 /* --- GAME EVENT! --- */
164 void game_event(void)
167 while (SDL_PollEvent(&event))
170 if (event.type == SDL_QUIT)
172 /* Quit event - quit: */
176 else if (event.type == SDL_KEYDOWN)
180 key = event.key.keysym.sym;
182 /* Check for menu-events, if the menu is shown */
186 if (key == SDLK_ESCAPE)
188 /* Escape: Open/Close the menu: */
197 else if (key == SDLK_RIGHT)
201 else if (key == SDLK_LEFT)
205 else if (key == SDLK_UP)
209 else if (key == SDLK_DOWN)
213 else if (key == SDLK_LCTRL)
218 else if (event.type == SDL_KEYUP)
222 key = event.key.keysym.sym;
224 if (key == SDLK_RIGHT)
228 else if (key == SDLK_LEFT)
232 else if (key == SDLK_UP)
236 else if (key == SDLK_DOWN)
240 else if (key == SDLK_LCTRL)
244 else if (key == SDLK_p)
254 else if (key == SDLK_TAB)
256 tux_size = !tux_size;
258 else if (key == SDLK_END)
262 else if (key == SDLK_SPACE)
268 else if (event.type == SDL_JOYAXISMOTION)
270 if (event.jaxis.axis == JOY_X)
272 if (event.jaxis.value < -256)
277 if (event.jaxis.value > 256)
282 else if (event.jaxis.axis == JOY_Y)
284 if (event.jaxis.value > 256)
289 /* Handle joystick for the menu */
293 menuaction = MN_DOWN;
299 else if (event.type == SDL_JOYBUTTONDOWN)
301 if (event.jbutton.button == JOY_A)
303 else if (event.jbutton.button == JOY_B)
306 else if (event.type == SDL_JOYBUTTONUP)
308 if (event.jbutton.button == JOY_A)
310 else if (event.jbutton.button == JOY_B)
323 /* --- GAME ACTION! --- */
325 int game_action(void)
329 /* --- HANDLE TUX! --- */
331 /* Handle key and joystick state: */
333 if (!(tux_dying || next_level))
335 if (right == DOWN && left == UP)
339 if (tux_xm < -SKID_XM && !tux_skidding &&
342 tux_skidding = SKID_TIME;
344 play_sound(sounds[SND_SKID]);
350 if (tux_xm < 0 && !isice(tux_x, tux_y + 32, scroll_x) &&
358 if (tux_dir == RIGHT)
360 /* Facing the direction we're jumping? Go full-speed: */
364 tux_xm = tux_xm + WALK_SPEED;
366 if (tux_xm > MAX_WALK_XM)
367 tux_xm = MAX_WALK_XM;
369 else if (fire == DOWN)
371 tux_xm = tux_xm + RUN_SPEED;
373 if (tux_xm > MAX_RUN_XM)
379 /* Not facing the direction we're jumping?
382 tux_xm = tux_xm + WALK_SPEED / 2;
384 if (tux_xm > MAX_WALK_XM / 2)
385 tux_xm = MAX_WALK_XM / 2;
389 else if (left == DOWN && right == UP)
393 if (tux_xm > SKID_XM && !tux_skidding &&
396 tux_skidding = SKID_TIME;
397 play_sound(sounds[SND_SKID]);
402 if (tux_xm > 0 && !isice(tux_x, tux_y + 32, scroll_x) &&
412 /* Facing the direction we're jumping? Go full-speed: */
416 tux_xm = tux_xm - WALK_SPEED;
418 if (tux_xm < -MAX_WALK_XM)
419 tux_xm = -MAX_WALK_XM;
421 else if (fire == DOWN)
423 tux_xm = tux_xm - RUN_SPEED;
425 if (tux_xm < -MAX_RUN_XM)
426 tux_xm = -MAX_RUN_XM;
431 /* Not facing the direction we're jumping?
434 tux_xm = tux_xm - WALK_SPEED / 2;
436 if (tux_xm < -MAX_WALK_XM / 2)
437 tux_xm = -MAX_WALK_XM / 2;
445 if (tux_x >= endpos && endpos != 0)
455 if (jump_counter == 0)
459 if (!issolid(tux_x, tux_y + 32, scroll_x) ||
462 /* If they're not on the ground, or are currently moving
463 vertically, don't jump! */
465 jump_counter = MAX_JUMP_COUNT;
469 /* Make sure we're not standing back up into a solid! */
471 if (tux_size == SMALL || tux_duck == NO ||
472 !issolid(tux_x, tux_y, scroll_x))
476 if (tux_size == SMALL)
477 play_sound(sounds[SND_JUMP]);
479 play_sound(sounds[SND_BIGJUMP]);
485 /* Keep jumping for a while: */
487 if (jump_counter < MAX_JUMP_COUNT)
489 tux_ym = tux_ym - JUMP_SPEED;
499 if (fire == DOWN && old_fire == UP && tux_got_coffee)
501 add_bullet(tux_x + scroll_x, tux_y, tux_dir, tux_xm);
514 if (tux_size == BIG && tux_duck == YES)
516 /* Make sure we're not standing back up into a solid! */
518 if (!issolid(tux_x, tux_y - 32, scroll_x))
524 } /* (tux_dying || next_level) */
527 /* Tux either died, or reached the end of a level! */
536 /* End of a level! */
544 tux_ym = tux_ym + GRAVITY;
552 /* No more lives!? */
558 if (score > highscore)
565 } /* if (lives < 0) */
568 /* Either way, (re-)load the (next) level... */
579 tux_x = tux_x + tux_xm;
580 tux_y = tux_y + tux_ym;
583 /* Keep tux in bounds: */
587 else if (tux_x > 320 && scroll_x < ((level_width * 32) - 640))
589 /* Scroll the screen in past center: */
591 scroll_x = scroll_x + (tux_x - 320);
594 if (scroll_x > ((level_width * 32) - 640))
595 scroll_x = ((level_width * 32) - 640);
597 else if (tux_x > 608)
599 /* ... unless there's no more to scroll! */
609 if (issolid(tux_x, tux_y + 31, scroll_x) &&
610 !issolid(tux_x - tux_xm, tux_y + 31, scroll_x))
612 while (issolid(tux_x, tux_y + 31, scroll_x))
623 if (issolid(tux_x, tux_y, scroll_x) &&
624 !issolid(tux_x - tux_xm, tux_y, scroll_x))
626 while (issolid(tux_x, tux_y, scroll_x))
637 if (issolid(tux_x, tux_y + 31, scroll_x))
639 /* Set down properly: */
641 while (issolid(tux_x, tux_y + 31, scroll_x))
650 /* Reset score multiplier (for mutli-hits): */
653 score_multiplier = 1;
663 /* Bump into things: */
665 if (issolid(tux_x, tux_y, scroll_x) ||
666 (tux_size == BIG && !tux_duck &&
667 (issolid(tux_x, tux_y - 32, scroll_x))))
669 if (!issolid(tux_x - tux_xm, tux_y, scroll_x) &&
670 (tux_size == SMALL || tux_duck ||
671 !issolid(tux_x - tux_xm, tux_y - 32, scroll_x)))
673 tux_x = tux_x - tux_xm;
676 else if (!issolid(tux_x, tux_y - tux_ym, scroll_x) &&
677 (tux_size == SMALL || tux_duck ||
678 !issolid(tux_x, tux_y - 32 - tux_ym, scroll_x)))
686 /* Break bricks and empty boxes: */
690 if (isbrick(tux_x, tux_y - 32, scroll_x) ||
691 isfullbox(tux_x, tux_y - 32, scroll_x))
693 trygrabdistro(tux_x, tux_y - 64, scroll_x,
695 trybumpbadguy(tux_x, tux_y - 96, scroll_x);
697 if (isfullbox(tux_x, tux_y - 32,
700 bumpbrick(tux_x, tux_y - 32,
704 trybreakbrick(tux_x, tux_y - 32, scroll_x);
705 tryemptybox(tux_x, tux_y - 32, scroll_x);
708 if (isbrick(tux_x + 31, tux_y - 32, scroll_x) ||
709 isfullbox(tux_x + 31, tux_y - 32, scroll_x))
711 trygrabdistro(tux_x + 31,
715 trybumpbadguy(tux_x + 31,
719 if (isfullbox(tux_x + 31, tux_y - 32,
722 bumpbrick(tux_x + 31, tux_y - 32,
726 trybreakbrick(tux_x + 31,
729 tryemptybox(tux_x + 31,
736 if (isbrick(tux_x, tux_y, scroll_x) ||
737 isfullbox(tux_x, tux_y, scroll_x))
739 trygrabdistro(tux_x, tux_y - 32, scroll_x,
741 trybumpbadguy(tux_x, tux_y - 64, scroll_x);
742 if (isfullbox(tux_x, tux_y, scroll_x))
743 bumpbrick(tux_x, tux_y, scroll_x);
744 trybreakbrick(tux_x, tux_y, scroll_x);
745 tryemptybox(tux_x, tux_y, scroll_x);
748 if (isbrick(tux_x + 31, tux_y, scroll_x) ||
749 isfullbox(tux_x + 31, tux_y, scroll_x))
751 trygrabdistro(tux_x + 31,
755 trybumpbadguy(tux_x + 31,
758 if (isfullbox(tux_x + 31, tux_y, scroll_x))
759 bumpbrick(tux_x + 31, tux_y, scroll_x);
760 trybreakbrick(tux_x + 31, tux_y, scroll_x);
761 tryemptybox(tux_x + 31, tux_y, scroll_x);
767 /* It's a brick and we're small, make the brick
768 bounce, and grab any distros above it: */
770 if (isbrick(tux_x, tux_y, scroll_x) ||
771 isfullbox(tux_x, tux_y, scroll_x))
773 trygrabdistro(tux_x, tux_y - 32, scroll_x,
775 trybumpbadguy(tux_x, tux_y - 64, scroll_x);
776 bumpbrick(tux_x, tux_y, scroll_x);
777 tryemptybox(tux_x, tux_y, scroll_x);
780 if (isbrick(tux_x + 31, tux_y, scroll_x) ||
781 isfullbox(tux_x + 31, tux_y, scroll_x))
783 trygrabdistro(tux_x + 31, tux_y - 32, scroll_x,
785 trybumpbadguy(tux_x + 31, tux_y - 64, scroll_x);
786 bumpbrick(tux_x + 31, tux_y, scroll_x);
787 tryemptybox(tux_x + 31, tux_y, scroll_x);
791 /* Get a distro from a brick? */
793 if (shape(tux_x, tux_y, scroll_x) == 'x' ||
794 shape(tux_x, tux_y, scroll_x) == 'y')
796 add_bouncy_distro(((tux_x + scroll_x + 1)
800 if (counting_distros == NO)
802 counting_distros = YES;
803 distro_counter = 100;
806 if (distro_counter <= 0)
807 change(tux_x, tux_y, scroll_x, 'a');
809 play_sound(sounds[SND_DISTRO]);
810 score = score + SCORE_DISTRO;
813 else if (shape(tux_x + 31, tux_y, scroll_x) == 'x' ||
814 shape(tux_x + 31, tux_y, scroll_x) == 'y')
816 add_bouncy_distro(((tux_x + scroll_x + 1 + 31)
820 if (counting_distros == NO)
822 counting_distros = YES;
823 distro_counter = 100;
826 if (distro_counter <= 0)
827 change(tux_x + 31, tux_y, scroll_x, 'a');
829 play_sound(sounds[SND_DISTRO]);
830 score = score + SCORE_DISTRO;
838 tux_y = (tux_y / 32) * 32 + 30;
844 tux_y = (tux_y / 32) * 32 - 32;
849 jump_counter = MAX_JUMP_COUNT;
859 trygrabdistro(tux_x, tux_y, scroll_x, NO_BOUNCE);
860 trygrabdistro(tux_x + 31, tux_y, scroll_x, NO_BOUNCE);
862 if (tux_size == BIG && !tux_duck)
864 trygrabdistro(tux_x, tux_y - 32, scroll_x, NO_BOUNCE);
865 trygrabdistro(tux_x + 31, tux_y - 32, scroll_x, NO_BOUNCE);
870 /* Enough distros for a One-up? */
872 if (distros >= DISTROS_LIFEUP)
874 distros = distros - DISTROS_LIFEUP;
875 if(lives < MAX_LIVES)
877 play_sound(sounds[SND_LIFEUP]); /*We want to hear the sound even, if MAX_LIVES is reached*/
881 /* Keep in-bounds, vertically: */
885 else if (tux_y > 480)
891 /* Slow down horizontally: */
895 if (right == UP && left == UP)
897 if (isice(tux_x, tux_y + 32, scroll_x) ||
898 !issolid(tux_x, tux_y + 32, scroll_x))
900 /* Slowly on ice or in air: */
909 /* Quickly, otherwise: */
916 /* Drop vertically: */
918 if (!issolid(tux_x, tux_y + 32, scroll_x))
920 tux_ym = tux_ym + GRAVITY;
932 /* ---- DONE HANDLING TUX! --- */
935 /* Handle bouncy distros: */
937 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
939 if (bouncy_distros[i].alive)
941 bouncy_distros[i].y = bouncy_distros[i].y + bouncy_distros[i].ym;
943 bouncy_distros[i].ym++;
945 if (bouncy_distros[i].ym >= 0)
946 bouncy_distros[i].alive = NO;
951 /* Handle broken bricks: */
953 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
955 if (broken_bricks[i].alive)
957 broken_bricks[i].x = broken_bricks[i].x + broken_bricks[i].xm;
958 broken_bricks[i].y = broken_bricks[i].y + broken_bricks[i].ym;
960 broken_bricks[i].ym++;
962 if (broken_bricks[i].ym >= 0)
963 broken_bricks[i].alive = NO;
968 /* Handle distro counting: */
970 if (counting_distros == YES)
974 if (distro_counter <= 0)
975 counting_distros = -1;
979 /* Handle bouncy bricks: */
981 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
983 if (bouncy_bricks[i].alive)
985 bouncy_bricks[i].offset = (bouncy_bricks[i].offset +
986 bouncy_bricks[i].offset_m);
990 if (bouncy_bricks[i].offset < -BOUNCY_BRICK_MAX_OFFSET)
991 bouncy_bricks[i].offset_m = BOUNCY_BRICK_SPEED;
996 if (bouncy_bricks[i].offset == 0)
997 bouncy_bricks[i].alive = NO;
1002 /* Handle floating scores: */
1004 for (i = 0; i < NUM_FLOATING_SCORES; i++)
1006 if (floating_scores[i].alive)
1008 floating_scores[i].y = floating_scores[i].y - 2;
1009 floating_scores[i].timer--;
1011 if (floating_scores[i].timer <= 0)
1012 floating_scores[i].alive = NO;
1017 /* Handle bullets: */
1019 for (i = 0; i < NUM_BULLETS; i++)
1021 if (bullets[i].alive)
1023 bullets[i].x = bullets[i].x + bullets[i].xm;
1024 bullets[i].y = bullets[i].y + bullets[i].ym;
1026 if (issolid(bullets[i].x, bullets[i].y, 0))
1028 if (issolid(bullets[i].x, bullets[i].y - bullets[i].ym, 0))
1029 bullets[i].alive = NO;
1032 if (bullets[i].ym >= 0)
1034 bullets[i].y = (bullets[i].y / 32) * 32 - 8;
1036 bullets[i].ym = -bullets[i].ym;
1040 bullets[i].ym = bullets[i].ym + GRAVITY;
1042 if (bullets[i].x < scroll_x ||
1043 bullets[i].x > scroll_x + 640)
1045 bullets[i].alive = NO;
1050 if (bullets[i].alive)
1052 for (j = 0; j < NUM_BAD_GUYS; j++)
1054 if (bad_guys[j].alive && !bad_guys[j].dying)
1056 if (bullets[i].x >= bad_guys[j].x - 4 &&
1057 bullets[i].x <= bad_guys[j].x + 32 + 4 &&
1058 bullets[i].y >= bad_guys[j].y - 4 &&
1059 bullets[i].y <= bad_guys[j].y + 32 + 4)
1061 /* Kill the bad guy! */
1063 bullets[i].alive = 0;
1064 bad_guys[j].dying = FALLING;
1065 bad_guys[j].ym = -8;
1068 /* Gain some points: */
1070 if (bad_guys[j].kind == BAD_BSOD)
1072 add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
1073 50 * score_multiplier);
1075 else if (bad_guys[j].kind == BAD_LAPTOP)
1077 add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
1078 25 * score_multiplier);
1082 /* Play death sound: */
1083 play_sound(sounds[SND_FALL]);
1091 /* Handle background timer: */
1093 if (super_bkgd_time)
1097 /* Handle invincibility timer: */
1100 if (tux_invincible_time > 50)
1102 tux_invincible_time--;
1105 if (!playing_music())
1106 play_music( herring_song, 1 );
1110 if (current_music == HERRING_MUSIC)
1112 /* stop the herring_song, now play the level_song ! */
1113 current_music = LEVEL_MUSIC;
1116 if (!playing_music())
1117 play_music( level_song, 1 );
1118 if (tux_invincible_time > 0)
1119 tux_invincible_time--;
1123 /* Handle upgrades: */
1125 for (i = 0; i < NUM_UPGRADES; i++)
1127 if (upgrades[i].alive)
1129 if (upgrades[i].height < 32)
1133 upgrades[i].height++;
1139 if (upgrades[i].kind == UPGRADE_MINTS ||
1140 upgrades[i].kind == UPGRADE_HERRING)
1142 upgrades[i].x = upgrades[i].x + upgrades[i].xm;
1143 upgrades[i].y = upgrades[i].y + upgrades[i].ym;
1145 if (issolid(upgrades[i].x, upgrades[i].y + 31, 0) ||
1146 issolid(upgrades[i].x + 31, upgrades[i].y + 31, 0))
1148 if (upgrades[i].ym > 0)
1150 if (upgrades[i].kind == UPGRADE_MINTS)
1154 else if (upgrades[i].kind == UPGRADE_HERRING)
1156 upgrades[i].ym = -24;
1159 upgrades[i].y = (upgrades[i].y / 32) * 32;
1163 upgrades[i].ym = upgrades[i].ym + GRAVITY;
1165 if (issolid(upgrades[i].x, upgrades[i].y, 0))
1167 upgrades[i].xm = -upgrades[i].xm;
1172 /* Off the screen? Kill it! */
1174 if (upgrades[i].x < scroll_x)
1175 upgrades[i].alive = NO;
1178 /* Did the player grab it? */
1180 if (tux_x + scroll_x >= upgrades[i].x - 32 &&
1181 tux_x + scroll_x <= upgrades[i].x + 32 &&
1182 tux_y >= upgrades[i].y - 32 &&
1183 tux_y <= upgrades[i].y + 32)
1185 /* Remove the upgrade: */
1187 upgrades[i].alive = NO;
1190 /* Affect the player: */
1192 if (upgrades[i].kind == UPGRADE_MINTS)
1194 play_sound(sounds[SND_EXCELLENT]);
1196 super_bkgd_time = 8;
1198 else if (upgrades[i].kind == UPGRADE_COFFEE)
1200 play_sound(sounds[SND_COFFEE]);
1201 tux_got_coffee = YES;
1202 super_bkgd_time = 4;
1204 else if (upgrades[i].kind == UPGRADE_HERRING)
1206 play_sound(sounds[SND_HERRING]);
1207 tux_invincible_time = TUX_INVINCIBLE_TIME;
1208 super_bkgd_time = 4;
1209 /* play the herring song ^^ */
1210 current_music = HERRING_MUSIC;
1211 if (playing_music())
1213 play_music( herring_song, 1 );
1221 /* Handle bad guys: */
1223 for (i = 0; i < NUM_BAD_GUYS; i++)
1225 if (bad_guys[i].alive)
1227 if (bad_guys[i].seen)
1229 if (bad_guys[i].kind == BAD_BSOD)
1231 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
1233 /* Move left/right: */
1235 if (bad_guys[i].dying == NO ||
1236 bad_guys[i].dying == FALLING)
1238 if (bad_guys[i].dir == RIGHT)
1239 bad_guys[i].x = bad_guys[i].x + 4;
1240 else if (bad_guys[i].dir == LEFT)
1241 bad_guys[i].x = bad_guys[i].x - 4;
1245 /* Move vertically: */
1247 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1250 /* Bump into things horizontally: */
1252 if (!bad_guys[i].dying)
1254 if (issolid(bad_guys[i].x, bad_guys[i].y, 0))
1255 bad_guys[i].dir = !bad_guys[i].dir;
1259 /* Bump into other bad guys: */
1261 for (j = 0; j < NUM_BAD_GUYS; j++)
1263 if (j != i && bad_guys[j].alive &&
1264 !bad_guys[j].dying && !bad_guys[i].dying &&
1265 bad_guys[i].x >= bad_guys[j].x - 32 &&
1266 bad_guys[i].x <= bad_guys[j].x + 32 &&
1267 bad_guys[i].y >= bad_guys[j].y - 32 &&
1268 bad_guys[i].y <= bad_guys[j].y + 32)
1270 bad_guys[i].dir = !bad_guys[i].dir;
1275 /* Fall if we get off the ground: */
1277 if (bad_guys[i].dying != FALLING)
1279 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0) &&
1280 bad_guys[i].ym < MAX_YM)
1282 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1288 if (bad_guys[i].ym > 0)
1290 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1296 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1298 if (bad_guys[i].y > 480)
1299 bad_guys[i].alive = NO;
1301 else if (bad_guys[i].kind == BAD_LAPTOP)
1303 /* --- LAPTOP MONSTER: --- */
1305 /* Move left/right: */
1307 if (bad_guys[i].mode != FLAT && bad_guys[i].mode != KICK)
1309 if (bad_guys[i].dying == NO ||
1310 bad_guys[i].dying == FALLING)
1312 if (bad_guys[i].dir == RIGHT)
1313 bad_guys[i].x = bad_guys[i].x + 4;
1314 else if (bad_guys[i].dir == LEFT)
1315 bad_guys[i].x = bad_guys[i].x - 4;
1318 else if (bad_guys[i].mode == KICK)
1320 if (bad_guys[i].dir == RIGHT)
1321 bad_guys[i].x = bad_guys[i].x + 16;
1322 else if (bad_guys[i].dir == LEFT)
1323 bad_guys[i].x = bad_guys[i].x - 16;
1327 /* Move vertically: */
1329 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1332 /* Bump into things horizontally: */
1334 if (!bad_guys[i].dying)
1336 if (issolid(bad_guys[i].x, bad_guys[i].y, 0))
1338 bad_guys[i].dir = !bad_guys[i].dir;
1340 if (bad_guys[i].mode == KICK)
1341 play_sound(sounds[SND_RICOCHET]);
1346 /* Bump into other bad guys: */
1348 for (j = 0; j < NUM_BAD_GUYS; j++)
1350 if (j != i && bad_guys[j].alive &&
1351 !bad_guys[j].dying && !bad_guys[i].dying &&
1352 bad_guys[i].x >= bad_guys[j].x - 32 &&
1353 bad_guys[i].x <= bad_guys[j].x + 32 &&
1354 bad_guys[i].y >= bad_guys[j].y - 32 &&
1355 bad_guys[i].y <= bad_guys[j].y + 32)
1357 if (bad_guys[i].mode != KICK)
1358 bad_guys[i].dir = !bad_guys[i].dir;
1361 /* We're in kick mode, kill the other guy: */
1363 bad_guys[j].dying = FALLING;
1364 bad_guys[j].ym = -8;
1365 play_sound(sounds[SND_FALL]);
1367 add_score(bad_guys[i].x - scroll_x,
1368 bad_guys[i].y, 100);
1374 /* Fall if we get off the ground: */
1376 if (bad_guys[i].dying != FALLING)
1378 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0) &&
1379 bad_guys[i].ym < MAX_YM)
1381 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1387 if (bad_guys[i].ym > 0)
1389 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1395 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1397 if (bad_guys[i].y > 480)
1398 bad_guys[i].alive = NO;
1400 else if (bad_guys[i].kind == BAD_MONEY)
1402 /* --- MONEY BAGS: --- */
1405 /* Move vertically: */
1407 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1410 /* Fall if we get off the ground: */
1412 if (bad_guys[i].dying != FALLING)
1414 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0))
1416 if (bad_guys[i].ym < MAX_YM)
1418 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1425 if (bad_guys[i].ym > 0)
1427 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1428 bad_guys[i].ym = -MAX_YM;
1433 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1435 if (bad_guys[i].y > 480)
1436 bad_guys[i].alive = NO;
1438 else if (bad_guys[i].kind == -1)
1442 /* Kill it if the player jumped on it: */
1444 if (!bad_guys[i].dying && !tux_dying && !tux_safe &&
1445 tux_x + scroll_x >= bad_guys[i].x - 32 &&
1446 tux_x + scroll_x <= bad_guys[i].x + 32 &&
1447 tux_y >= bad_guys[i].y - 32 &&
1448 tux_y <= bad_guys[i].y - 8
1452 if (bad_guys[i].kind == BAD_BSOD)
1454 bad_guys[i].dying = SQUISHED;
1455 bad_guys[i].timer = 16;
1456 tux_ym = -KILL_BOUNCE_YM;
1458 add_score(bad_guys[i].x - scroll_x, bad_guys[i].y,
1459 50 * score_multiplier);
1461 play_sound(sounds[SND_SQUISH]);
1463 else if (bad_guys[i].kind == BAD_LAPTOP)
1465 if (bad_guys[i].mode != FLAT)
1469 bad_guys[i].mode = FLAT;
1471 bad_guys[i].timer = 64;
1479 bad_guys[i].mode = KICK;
1481 if (tux_x + scroll_x <= bad_guys[i].x)
1482 bad_guys[i].dir = RIGHT;
1484 bad_guys[i].dir = LEFT;
1486 bad_guys[i].timer = 8;
1489 tux_ym = -KILL_BOUNCE_YM;
1491 add_score(bad_guys[i].x - scroll_x,
1493 25 * score_multiplier);
1495 /* play_sound(sounds[SND_SQUISH]); */
1497 else if (bad_guys[i].kind == -1)
1504 /* Hurt the player if he just touched it: */
1506 if (!bad_guys[i].dying && !tux_dying &&
1508 tux_x + scroll_x >= bad_guys[i].x - 32 &&
1509 tux_x + scroll_x <= bad_guys[i].x + 32 &&
1510 tux_y >= bad_guys[i].y - 32 &&
1511 tux_y <= bad_guys[i].y + 32)
1513 if (bad_guys[i].mode == FLAT)
1517 bad_guys[i].mode = KICK;
1519 if (tux_x + scroll_x <= bad_guys[i].x)
1521 bad_guys[i].dir = RIGHT;
1522 bad_guys[i].x = bad_guys[i].x + 16;
1526 bad_guys[i].dir = LEFT;
1527 bad_guys[i].x = bad_guys[i].x - 16;
1530 bad_guys[i].timer = 8;
1532 else if (bad_guys[i].mode == KICK)
1534 if (tux_y < bad_guys[i].y - 16 &&
1535 bad_guys[i].timer == 0)
1537 /* Step on (stop being kicked) */
1539 bad_guys[i].mode = FLAT;
1540 bad_guys[i].timer = 64;
1544 /* Hurt if you get hit by kicked laptop: */
1546 if (bad_guys[i].timer == 0)
1548 if (tux_invincible_time == 0)
1554 bad_guys[i].dying = FALLING;
1555 bad_guys[i].ym = -8;
1556 play_sound(sounds[SND_FALL]);
1563 if (tux_invincible_time == 0)
1569 bad_guys[i].dying = FALLING;
1570 bad_guys[i].ym = -8;
1571 play_sound(sounds[SND_FALL]);
1577 /* Handle mode timer: */
1579 if (bad_guys[i].mode == FLAT)
1581 bad_guys[i].timer--;
1583 if (bad_guys[i].timer <= 0)
1584 bad_guys[i].mode = NORMAL;
1586 else if (bad_guys[i].mode == KICK)
1588 if (bad_guys[i].timer > 0)
1589 bad_guys[i].timer--;
1593 /* Handle dying timer: */
1595 if (bad_guys[i].dying == SQUISHED)
1597 bad_guys[i].timer--;
1600 /* Remove it if time's up: */
1602 if (bad_guys[i].timer <= 0)
1603 bad_guys[i].alive = NO;
1607 /* Remove if it's far off the screen: */
1609 if (bad_guys[i].x < scroll_x - OFFSCREEN_DISTANCE)
1610 bad_guys[i].alive = NO;
1614 /* Once it's on screen, it's activated! */
1616 if (bad_guys[i].x <= scroll_x + 640 + OFFSCREEN_DISTANCE)
1617 bad_guys[i].seen = YES;
1623 /* Handle skidding: */
1625 if (tux_skidding > 0)
1633 /* --- GAME DRAW! --- */
1641 if (tux_dying && (frame % 4) == 0)
1642 clearscreen(255, 255, 255);
1645 if (super_bkgd_time == 0)
1646 clearscreen(bkgd_red, bkgd_green, bkgd_blue);
1648 drawimage(img_super_bkgd, 0, 0, NO_UPDATE);
1652 /* Draw background: */
1654 for (y = 0; y < 15; y++)
1656 for (x = 0; x < 21; x++)
1658 drawshape(x * 32 - (scroll_x % 32), y * 32,
1659 tiles[y][x + (scroll_x / 32)]);
1664 /* (Bouncy bricks): */
1666 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
1668 if (bouncy_bricks[i].alive)
1670 if (bouncy_bricks[i].x >= scroll_x - 32 &&
1671 bouncy_bricks[i].x <= scroll_x + 640)
1673 dest.x = bouncy_bricks[i].x - scroll_x;
1674 dest.y = bouncy_bricks[i].y;
1678 SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format,
1683 drawshape(bouncy_bricks[i].x - scroll_x,
1684 bouncy_bricks[i].y + bouncy_bricks[i].offset,
1685 bouncy_bricks[i].shape);
1693 for (i = 0; i < NUM_BAD_GUYS; i++)
1695 if (bad_guys[i].alive &&
1696 bad_guys[i].x > scroll_x - 32 &&
1697 bad_guys[i].x < scroll_x + 640)
1699 if (bad_guys[i].kind == BAD_BSOD)
1701 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
1703 if (bad_guys[i].dying == NO)
1707 if (bad_guys[i].dir == LEFT)
1709 drawimage(img_bsod_left[(frame / 5) % 4],
1710 bad_guys[i].x - scroll_x,
1716 drawimage(img_bsod_right[(frame / 5) % 4],
1717 bad_guys[i].x - scroll_x,
1722 else if (bad_guys[i].dying == FALLING)
1726 if (bad_guys[i].dir == LEFT)
1728 drawimage(img_bsod_falling_left,
1729 bad_guys[i].x - scroll_x,
1735 drawimage(img_bsod_falling_right,
1736 bad_guys[i].x - scroll_x,
1741 else if (bad_guys[i].dying == SQUISHED)
1743 /* Dying - Squished: */
1745 if (bad_guys[i].dir == LEFT)
1747 drawimage(img_bsod_squished_left,
1748 bad_guys[i].x - scroll_x,
1754 drawimage(img_bsod_squished_right,
1755 bad_guys[i].x - scroll_x,
1761 else if (bad_guys[i].kind == BAD_LAPTOP)
1763 /* --- LAPTOP MONSTER: --- */
1765 if (bad_guys[i].dying == NO)
1769 if (bad_guys[i].mode == NORMAL)
1773 if (bad_guys[i].dir == LEFT)
1775 drawimage(img_laptop_left[(frame / 5) % 3],
1776 bad_guys[i].x - scroll_x,
1782 drawimage(img_laptop_right[(frame / 5) % 3],
1783 bad_guys[i].x - scroll_x,
1792 if (bad_guys[i].dir == LEFT)
1794 drawimage(img_laptop_flat_left,
1795 bad_guys[i].x - scroll_x,
1801 drawimage(img_laptop_flat_right,
1802 bad_guys[i].x - scroll_x,
1808 else if (bad_guys[i].dying == FALLING)
1812 if (bad_guys[i].dir == LEFT)
1814 drawimage(img_laptop_falling_left,
1815 bad_guys[i].x - scroll_x,
1821 drawimage(img_laptop_falling_right,
1822 bad_guys[i].x - scroll_x,
1828 else if (bad_guys[i].kind == BAD_MONEY)
1830 if (bad_guys[i].ym > -16)
1832 if (bad_guys[i].dir == LEFT)
1834 drawimage(img_money_left[0],
1835 bad_guys[i].x - scroll_x,
1841 drawimage(img_money_right[0],
1842 bad_guys[i].x - scroll_x,
1849 if (bad_guys[i].dir == LEFT)
1851 drawimage(img_money_left[1],
1852 bad_guys[i].x - scroll_x,
1858 drawimage(img_money_right[1],
1859 bad_guys[i].x - scroll_x,
1865 else if (bad_guys[i].kind == -1)
1873 if (right == UP && left == UP)
1880 if ((fire == DOWN && (frame % 2) == 0) ||
1882 tux_frame_main = (tux_frame_main + 1) % 4;
1884 tux_frame = tux_frame_main;
1891 if (tux_got_coffee && (frame % 2) == 1)
1895 drawimage(img_red_glow, tux_x - 8, tux_y - 32, NO_UPDATE);
1899 if (tux_safe == 0 || (frame % 2) == 0)
1901 if (tux_size == SMALL)
1903 if (tux_invincible_time)
1907 if (tux_dir == RIGHT)
1909 drawimage(cape_right[frame % 2],
1915 drawimage(cape_left[frame % 2],
1922 if (tux_dir == RIGHT)
1924 drawimage(tux_right[tux_frame], tux_x, tux_y, NO_UPDATE);
1928 drawimage(tux_left[tux_frame], tux_x, tux_y, NO_UPDATE);
1933 if (tux_invincible_time)
1937 if (tux_dir == RIGHT)
1939 drawimage(bigcape_right[frame % 2],
1940 tux_x - 8 - 16, tux_y - 32,
1945 drawimage(bigcape_left[frame % 2],
1946 tux_x - 8, tux_y - 32,
1955 if (!jumping || tux_ym > 0)
1957 if (tux_dir == RIGHT)
1959 drawimage(bigtux_right[tux_frame],
1960 tux_x - 8, tux_y - 32,
1965 drawimage(bigtux_left[tux_frame],
1966 tux_x - 8, tux_y - 32,
1972 if (tux_dir == RIGHT)
1974 drawimage(bigtux_right_jump,
1975 tux_x - 8, tux_y - 32,
1980 drawimage(bigtux_left_jump,
1981 tux_x - 8, tux_y - 32,
1988 if (tux_dir == RIGHT)
1990 drawimage(skidtux_right,
1991 tux_x - 8, tux_y - 32,
1996 drawimage(skidtux_left,
1997 tux_x - 8, tux_y - 32,
2004 if (tux_dir == RIGHT)
2006 drawimage(ducktux_right, tux_x - 8, tux_y - 16,
2011 drawimage(ducktux_left, tux_x - 8, tux_y - 16,
2021 for (i = 0; i < NUM_BULLETS; i++)
2023 if (bullets[i].alive &&
2024 bullets[i].x >= scroll_x - 4 &&
2025 bullets[i].x <= scroll_x + 640)
2027 drawimage(img_bullet, bullets[i].x - scroll_x, bullets[i].y,
2033 /* (Floating scores): */
2035 for (i = 0; i < NUM_FLOATING_SCORES; i++)
2037 if (floating_scores[i].alive)
2039 sprintf(str, "%d", floating_scores[i].value);
2041 floating_scores[i].x + 16 - strlen(str) * 8,
2042 floating_scores[i].y,
2043 letters_gold, NO_UPDATE);
2050 for (i = 0; i < NUM_UPGRADES; i++)
2052 if (upgrades[i].alive)
2054 if (upgrades[i].height < 32)
2058 dest.x = upgrades[i].x - scroll_x;
2059 dest.y = upgrades[i].y + 32 - upgrades[i].height;
2061 dest.h = upgrades[i].height;
2066 src.h = upgrades[i].height;
2068 if (upgrades[i].kind == UPGRADE_MINTS)
2069 SDL_BlitSurface(img_mints, &src, screen, &dest);
2070 else if (upgrades[i].kind == UPGRADE_COFFEE)
2071 SDL_BlitSurface(img_coffee, &src, screen, &dest);
2072 else if (upgrades[i].kind == UPGRADE_HERRING)
2073 SDL_BlitSurface(img_golden_herring, &src, screen, &dest);
2077 if (upgrades[i].kind == UPGRADE_MINTS)
2079 drawimage(img_mints,
2080 upgrades[i].x - scroll_x, upgrades[i].y,
2083 else if (upgrades[i].kind == UPGRADE_COFFEE)
2085 drawimage(img_coffee,
2086 upgrades[i].x - scroll_x, upgrades[i].y,
2089 else if (upgrades[i].kind == UPGRADE_HERRING)
2091 drawimage(img_golden_herring,
2092 upgrades[i].x - scroll_x, upgrades[i].y,
2100 /* (Bouncy distros): */
2102 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
2104 if (bouncy_distros[i].alive)
2106 drawimage(img_distro[0],
2107 bouncy_distros[i].x - scroll_x,
2108 bouncy_distros[i].y,
2114 /* (Broken bricks): */
2116 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
2118 if (broken_bricks[i].alive)
2120 src.x = rand() % 16;
2121 src.y = rand() % 16;
2125 dest.x = broken_bricks[i].x - scroll_x;
2126 dest.y = broken_bricks[i].y;
2130 SDL_BlitSurface(img_brick[0], &src, screen, &dest);
2137 sprintf(str, "%d", score);
2138 drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE);
2139 drawtext(str, 96, 0, letters_gold, NO_UPDATE);
2141 sprintf(str, "%d", highscore);
2142 drawtext("HIGH", 0, 20, letters_blue, NO_UPDATE);
2143 drawtext(str, 96, 20, letters_gold, NO_UPDATE);
2145 if (time_left >= 50 || (frame % 10) < 5)
2147 sprintf(str, "%d", time_left);
2148 drawtext("TIME", 224, 0, letters_blue, NO_UPDATE);
2149 drawtext(str, 304, 0, letters_gold, NO_UPDATE);
2152 sprintf(str, "%d", distros);
2153 drawtext("DISTROS", 480, 0, letters_blue, NO_UPDATE);
2154 drawtext(str, 608, 0, letters_gold, NO_UPDATE);
2156 drawtext("LIVES", 480, 20, letters_blue, NO_UPDATE);
2158 for(i=0; i < lives; ++i)
2160 drawimage(tux_life,565+(18*i),20,NO_UPDATE);
2164 drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE);
2169 /* (Update it all!) */
2176 /* --- GAME LOOP! --- */
2181 Uint32 last_time, now_time;
2185 clearscreen(0, 0, 0);
2189 /* Init the game: */
2197 highscore = load_hs();
2200 /* --- MAIN GAME LOOP!!! --- */
2212 last_time = SDL_GetTicks();
2216 /* Handle events: */
2222 /* Handle actions: */
2224 if(!game_pause && !show_menu)
2226 if (game_action() == 0)
2228 /* == 0: no more lives */
2229 /* == -1: continues */
2236 /*Draw the current scene to the screen */
2239 /* Keep playing music: */
2242 if (!playing_music())
2244 switch (current_music)
2247 play_music(level_song, 1);
2250 play_music(herring_song, 1);
2252 case HURRYUP_MUSIC: // keep the compiler happy
2253 case NO_MUSIC: // keep the compiler happy for the moment :-)
2259 /* Time stops in pause mode */
2260 if(game_pause || show_menu )
2265 /* Pause til next frame: */
2267 now_time = SDL_GetTicks();
2268 if (now_time < last_time + FPS)
2269 SDL_Delay(last_time + FPS - now_time);
2274 if ((frame % 10) == 0 && time_left > 0)
2282 while (!done && !quit);
2284 if (playing_music())
2295 /* Initialize the game stuff: */
2307 /* Load data for this level: */
2309 void loadlevel(void)
2320 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
2321 bouncy_distros[i].alive = NO;
2323 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
2324 broken_bricks[i].alive = NO;
2326 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
2327 bouncy_bricks[i].alive = NO;
2329 for (i = 0; i < NUM_BAD_GUYS; i++)
2330 bad_guys[i].alive = NO;
2332 for (i = 0; i < NUM_FLOATING_SCORES; i++)
2333 floating_scores[i].alive = NO;
2335 for (i = 0; i < NUM_UPGRADES; i++)
2336 upgrades[i].alive = NO;
2338 for (i = 0; i < NUM_BULLETS; i++)
2339 bullets[i].alive = NO;
2342 /* Load data file: */
2344 filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20));
2345 sprintf(filename, "%s/levels/level%d.dat", DATA_PREFIX, level);
2346 fi = fopen(filename, "r");
2357 /* Load header info: */
2362 strcpy(levelname, str);
2363 levelname[strlen(levelname)-1] = '\0';
2367 strcpy(leveltheme, str);
2368 leveltheme[strlen(leveltheme)-1] = '\0';
2372 /* (Time to beat level) */
2374 time_left = atoi(str);
2376 /* (Song file for this level) */
2378 strcpy(song_title, str);
2379 song_title[strlen(song_title)-1] = '\0';
2383 /* (Level background color) */
2385 bkgd_red = atoi(str);
2387 bkgd_green= atoi(str);
2389 bkgd_blue = atoi(str);
2393 level_width = atoi(str);
2396 /* Allocate some space for the line-reading! */
2398 line = (char *) malloc(sizeof(char) * (level_width + 5));
2401 fprintf(stderr, "Couldn't allocate space to load level data!");
2406 /* Load the level lines: */
2408 for (y = 0; y < 15; y++)
2410 if(fgets(line, level_width + 5, fi) == NULL)
2412 fprintf(stderr, "Level %s isn't complete!\n",levelname);
2415 line[strlen(line) - 1] = '\0';
2416 tiles[y] = strdup(line);
2422 /* Activate bad guys: */
2424 for (y = 0; y < 15; y++)
2426 for (x = 0; x < level_width; x++)
2428 if (tiles[y][x] >= '0' && tiles[y][x] <= '9')
2430 add_bad_guy(x * 32, y * 32, tiles[y][x] - '0');
2445 tux_got_coffee = NO;
2446 tux_invincible_time = 0;
2450 tux_safe = TUX_SAFE_TIME;
2466 score_multiplier = 1;
2467 super_bkgd_time = 0;
2469 counting_distros = NO;
2474 /* set current song/music */
2475 current_music = LEVEL_MUSIC;
2479 clearscreen(0, 0, 0);
2481 sprintf(str, "LEVEL %d", level);
2482 drawcenteredtext(str, 200, letters_red, NO_UPDATE);
2484 sprintf(str, "%s", levelname);
2485 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
2487 sprintf(str, "TUX x %d", lives);
2488 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
2498 /* Load a level-specific graphic... */
2500 SDL_Surface * load_level_image(char * file, int use_alpha)
2504 snprintf(fname, 1024, "%s/images/%s/%s", DATA_PREFIX, leveltheme, file);
2506 return(load_image(fname, use_alpha));
2510 /* Load graphics: */
2512 void loadlevelgfx(void)
2514 img_brick[0] = load_level_image("brick0.png", IGNORE_ALPHA);
2515 img_brick[1] = load_level_image("brick1.png", IGNORE_ALPHA);
2517 img_solid[0] = load_level_image("solid0.png", USE_ALPHA);
2518 img_solid[1] = load_level_image("solid1.png", USE_ALPHA);
2519 img_solid[2] = load_level_image("solid2.png", USE_ALPHA);
2520 img_solid[3] = load_level_image("solid3.png", USE_ALPHA);
2522 img_bkgd[0][0] = load_level_image("bkgd-00.png", USE_ALPHA);
2523 img_bkgd[0][1] = load_level_image("bkgd-01.png", USE_ALPHA);
2524 img_bkgd[0][2] = load_level_image("bkgd-02.png", USE_ALPHA);
2525 img_bkgd[0][3] = load_level_image("bkgd-03.png", USE_ALPHA);
2527 img_bkgd[1][0] = load_level_image("bkgd-10.png", USE_ALPHA);
2528 img_bkgd[1][1] = load_level_image("bkgd-11.png", USE_ALPHA);
2529 img_bkgd[1][2] = load_level_image("bkgd-12.png", USE_ALPHA);
2530 img_bkgd[1][3] = load_level_image("bkgd-13.png", USE_ALPHA);
2536 void loadlevelsong(void)
2541 song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
2542 strlen(song_title) + 8));
2544 sprintf(song_path, "%s/music/%s", DATA_PREFIX, song_title);
2546 level_song = load_song(song_path);
2552 /* Free graphics data for this level: */
2554 void unloadlevelgfx(void)
2558 for (i = 0; i < 2; i++)
2560 SDL_FreeSurface(img_brick[i]);
2562 for (i = 0; i < 4; i++)
2564 SDL_FreeSurface(img_solid[i]);
2565 SDL_FreeSurface(img_bkgd[0][i]);
2566 SDL_FreeSurface(img_bkgd[1][i]);
2571 /* Free music data for this level: */
2573 void unloadlevelsong(void)
2575 free_music(level_song);
2579 /* Load graphics/sounds shared between all levels: */
2581 void loadshared(void)
2584 char * herring_song_path; /* for loading herring song*/
2588 tux_right[0] = load_image(DATA_PREFIX "/images/shared/tux-right-0.png",
2591 tux_right[1] = load_image(DATA_PREFIX "/images/shared/tux-right-1.png",
2594 tux_right[2] = load_image(DATA_PREFIX "/images/shared/tux-right-2.png",
2597 tux_left[0] = load_image(DATA_PREFIX "/images/shared/tux-left-0.png",
2600 tux_left[1] = load_image(DATA_PREFIX "/images/shared/tux-left-1.png",
2603 tux_left[2] = load_image(DATA_PREFIX "/images/shared/tux-left-2.png",
2606 cape_right[0] = load_image(DATA_PREFIX "/images/shared/cape-right-0.png",
2609 cape_right[1] = load_image(DATA_PREFIX "/images/shared/cape-right-1.png",
2612 cape_left[0] = load_image(DATA_PREFIX "/images/shared/cape-left-0.png",
2615 cape_left[1] = load_image(DATA_PREFIX "/images/shared/cape-left-1.png",
2618 bigtux_right[0] = load_image(DATA_PREFIX "/images/shared/bigtux-right-0.png",
2621 bigtux_right[1] = load_image(DATA_PREFIX "/images/shared/bigtux-right-1.png",
2624 bigtux_right[2] = load_image(DATA_PREFIX "/images/shared/bigtux-right-2.png",
2628 load_image(DATA_PREFIX "/images/shared/bigtux-right-jump.png", USE_ALPHA);
2630 bigtux_left[0] = load_image(DATA_PREFIX "/images/shared/bigtux-left-0.png",
2633 bigtux_left[1] = load_image(DATA_PREFIX "/images/shared/bigtux-left-1.png",
2636 bigtux_left[2] = load_image(DATA_PREFIX "/images/shared/bigtux-left-2.png",
2640 load_image(DATA_PREFIX "/images/shared/bigtux-left-jump.png", USE_ALPHA);
2643 load_image(DATA_PREFIX "/images/shared/bigcape-right-0.png",
2647 load_image(DATA_PREFIX "/images/shared/bigcape-right-1.png",
2651 load_image(DATA_PREFIX "/images/shared/bigcape-left-0.png",
2655 load_image(DATA_PREFIX "/images/shared/bigcape-left-1.png",
2658 ducktux_right = load_image(DATA_PREFIX
2659 "/images/shared/ducktux-right.png",
2662 ducktux_left = load_image(DATA_PREFIX
2663 "/images/shared/ducktux-left.png",
2666 skidtux_right = load_image(DATA_PREFIX
2667 "/images/shared/skidtux-right.png",
2670 skidtux_left = load_image(DATA_PREFIX
2671 "/images/shared/skidtux-left.png",
2677 img_box_full = load_image(DATA_PREFIX "/images/shared/box-full.png",
2679 img_box_empty = load_image(DATA_PREFIX "/images/shared/box-empty.png",
2686 img_water = load_image(DATA_PREFIX "/images/shared/water.png", IGNORE_ALPHA);
2688 img_waves[0] = load_image(DATA_PREFIX "/images/shared/waves-0.png",
2691 img_waves[1] = load_image(DATA_PREFIX "/images/shared/waves-1.png",
2694 img_waves[2] = load_image(DATA_PREFIX "/images/shared/waves-2.png",
2700 img_pole = load_image(DATA_PREFIX "/images/shared/pole.png", USE_ALPHA);
2701 img_poletop = load_image(DATA_PREFIX "/images/shared/poletop.png",
2707 img_flag[0] = load_image(DATA_PREFIX "/images/shared/flag-0.png",
2709 img_flag[1] = load_image(DATA_PREFIX "/images/shared/flag-1.png",
2715 img_cloud[0][0] = load_image(DATA_PREFIX "/images/shared/cloud-00.png",
2718 img_cloud[0][1] = load_image(DATA_PREFIX "/images/shared/cloud-01.png",
2721 img_cloud[0][2] = load_image(DATA_PREFIX "/images/shared/cloud-02.png",
2724 img_cloud[0][3] = load_image(DATA_PREFIX "/images/shared/cloud-03.png",
2728 img_cloud[1][0] = load_image(DATA_PREFIX "/images/shared/cloud-10.png",
2731 img_cloud[1][1] = load_image(DATA_PREFIX "/images/shared/cloud-11.png",
2734 img_cloud[1][2] = load_image(DATA_PREFIX "/images/shared/cloud-12.png",
2737 img_cloud[1][3] = load_image(DATA_PREFIX "/images/shared/cloud-13.png",
2745 img_bsod_left[0] = load_image(DATA_PREFIX
2746 "/images/shared/bsod-left-0.png",
2749 img_bsod_left[1] = load_image(DATA_PREFIX
2750 "/images/shared/bsod-left-1.png",
2753 img_bsod_left[2] = load_image(DATA_PREFIX
2754 "/images/shared/bsod-left-2.png",
2757 img_bsod_left[3] = load_image(DATA_PREFIX
2758 "/images/shared/bsod-left-3.png",
2761 img_bsod_right[0] = load_image(DATA_PREFIX
2762 "/images/shared/bsod-right-0.png",
2765 img_bsod_right[1] = load_image(DATA_PREFIX
2766 "/images/shared/bsod-right-1.png",
2769 img_bsod_right[2] = load_image(DATA_PREFIX
2770 "/images/shared/bsod-right-2.png",
2773 img_bsod_right[3] = load_image(DATA_PREFIX
2774 "/images/shared/bsod-right-3.png",
2777 img_bsod_squished_left = load_image(DATA_PREFIX
2778 "/images/shared/bsod-squished-left.png",
2781 img_bsod_squished_right = load_image(DATA_PREFIX
2782 "/images/shared/bsod-squished-right.png",
2785 img_bsod_falling_left = load_image(DATA_PREFIX
2786 "/images/shared/bsod-falling-left.png",
2789 img_bsod_falling_right = load_image(DATA_PREFIX
2790 "/images/shared/bsod-falling-right.png",
2796 img_laptop_left[0] = load_image(DATA_PREFIX
2797 "/images/shared/laptop-left-0.png",
2800 img_laptop_left[1] = load_image(DATA_PREFIX
2801 "/images/shared/laptop-left-1.png",
2804 img_laptop_left[2] = load_image(DATA_PREFIX
2805 "/images/shared/laptop-left-2.png",
2808 img_laptop_right[0] = load_image(DATA_PREFIX
2809 "/images/shared/laptop-right-0.png",
2812 img_laptop_right[1] = load_image(DATA_PREFIX
2813 "/images/shared/laptop-right-1.png",
2816 img_laptop_right[2] = load_image(DATA_PREFIX
2817 "/images/shared/laptop-right-2.png",
2820 img_laptop_flat_left = load_image(DATA_PREFIX
2821 "/images/shared/laptop-flat-left.png",
2824 img_laptop_flat_right = load_image(DATA_PREFIX
2825 "/images/shared/laptop-flat-right.png",
2828 img_laptop_falling_left =
2829 load_image(DATA_PREFIX
2830 "/images/shared/laptop-falling-left.png",
2833 img_laptop_falling_right =
2834 load_image(DATA_PREFIX
2835 "/images/shared/laptop-falling-right.png",
2841 img_money_left[0] = load_image(DATA_PREFIX
2842 "/images/shared/bag-left-0.png",
2845 img_money_left[1] = load_image(DATA_PREFIX
2846 "/images/shared/bag-left-1.png",
2849 img_money_right[0] = load_image(DATA_PREFIX
2850 "/images/shared/bag-right-0.png",
2853 img_money_right[1] = load_image(DATA_PREFIX
2854 "/images/shared/bag-right-1.png",
2861 img_mints = load_image(DATA_PREFIX "/images/shared/mints.png", USE_ALPHA);
2862 img_coffee = load_image(DATA_PREFIX "/images/shared/coffee.png", USE_ALPHA);
2867 img_bullet = load_image(DATA_PREFIX "/images/shared/bullet.png", USE_ALPHA);
2869 img_red_glow = load_image(DATA_PREFIX "/images/shared/red-glow.png",
2875 img_distro[0] = load_image(DATA_PREFIX "/images/shared/distro-0.png",
2878 img_distro[1] = load_image(DATA_PREFIX "/images/shared/distro-1.png",
2881 img_distro[2] = load_image(DATA_PREFIX "/images/shared/distro-2.png",
2884 img_distro[3] = load_image(DATA_PREFIX "/images/shared/distro-3.png",
2889 tux_life = load_image(DATA_PREFIX "/images/shared/tux-life.png",
2894 img_golden_herring =
2895 load_image(DATA_PREFIX "/images/shared/golden-herring.png",
2899 /* Super background: */
2901 img_super_bkgd = load_image(DATA_PREFIX "/images/shared/super-bkgd.png",
2905 /* Sound effects: */
2907 /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
2908 // initialize sounds[i] with the correct pointer's value:
2909 // NULL or something else. And it will be dangerous to
2910 // play with not-initialized pointers.
2911 // This is also true with if (use_music)
2912 Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
2914 for (i = 0; i < NUM_SOUNDS; i++)
2915 sounds[i] = load_sound(soundfilenames[i]);
2918 herring_song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
2919 strlen("SALCON.MOD") + 8)); /* FIXME: We need a real herring_song! Thats a fake.:) */
2921 sprintf(herring_song_path, "%s/music/%s", DATA_PREFIX, "SALCON.MOD");
2923 herring_song = load_song(herring_song_path);
2925 free(herring_song_path);
2930 /* Free shared data: */
2932 void unloadshared(void)
2936 for (i = 0; i < 3; i++)
2938 SDL_FreeSurface(tux_right[i]);
2939 SDL_FreeSurface(tux_left[i]);
2940 SDL_FreeSurface(bigtux_right[i]);
2941 SDL_FreeSurface(bigtux_left[i]);
2944 SDL_FreeSurface(bigtux_right_jump);
2945 SDL_FreeSurface(bigtux_left_jump);
2947 for (i = 0; i < 2; i++)
2949 SDL_FreeSurface(cape_right[i]);
2950 SDL_FreeSurface(cape_left[i]);
2951 SDL_FreeSurface(bigcape_right[i]);
2952 SDL_FreeSurface(bigcape_left[i]);
2955 SDL_FreeSurface(ducktux_left);
2956 SDL_FreeSurface(ducktux_right);
2958 SDL_FreeSurface(skidtux_left);
2959 SDL_FreeSurface(skidtux_right);
2961 for (i = 0; i < 4; i++)
2963 SDL_FreeSurface(img_bsod_left[i]);
2964 SDL_FreeSurface(img_bsod_right[i]);
2967 SDL_FreeSurface(img_bsod_squished_left);
2968 SDL_FreeSurface(img_bsod_squished_right);
2970 SDL_FreeSurface(img_bsod_falling_left);
2971 SDL_FreeSurface(img_bsod_falling_right);
2973 for (i = 0; i < 3; i++)
2975 SDL_FreeSurface(img_laptop_left[i]);
2976 SDL_FreeSurface(img_laptop_right[i]);
2979 SDL_FreeSurface(img_laptop_flat_left);
2980 SDL_FreeSurface(img_laptop_flat_right);
2982 SDL_FreeSurface(img_laptop_falling_left);
2983 SDL_FreeSurface(img_laptop_falling_right);
2985 for (i = 0; i < 2; i++)
2987 SDL_FreeSurface(img_money_left[i]);
2988 SDL_FreeSurface(img_money_right[i]);
2991 SDL_FreeSurface(img_box_full);
2992 SDL_FreeSurface(img_box_empty);
2994 SDL_FreeSurface(img_water);
2995 for (i = 0; i < 3; i++)
2996 SDL_FreeSurface(img_waves[i]);
2998 SDL_FreeSurface(img_pole);
2999 SDL_FreeSurface(img_poletop);
3001 for (i = 0; i < 2; i++)
3002 SDL_FreeSurface(img_flag[i]);
3004 SDL_FreeSurface(img_mints);
3005 SDL_FreeSurface(img_coffee);
3007 for (i = 0; i < 4; i++)
3009 SDL_FreeSurface(img_distro[i]);
3010 SDL_FreeSurface(img_cloud[0][i]);
3011 SDL_FreeSurface(img_cloud[1][i]);
3014 SDL_FreeSurface(img_golden_herring);
3016 for (i = 0; i < NUM_SOUNDS; i++)
3017 free_chunk(sounds[i]);
3019 /* free the herring song */
3020 free_music( herring_song );
3024 /* Draw a tile on the screen: */
3026 void drawshape(int x, int y, unsigned char c)
3030 if (c == 'X' || c == 'x')
3031 drawimage(img_brick[0], x, y, NO_UPDATE);
3032 else if (c == 'Y' || c == 'y')
3033 drawimage(img_brick[1], x, y, NO_UPDATE);
3034 else if (c == 'A' || c =='B' || c == '!')
3035 drawimage(img_box_full, x, y, NO_UPDATE);
3037 drawimage(img_box_empty, x, y, NO_UPDATE);
3038 else if (c >= 'C' && c <= 'F')
3039 drawimage(img_cloud[0][c - 'C'], x, y, NO_UPDATE);
3040 else if (c >= 'c' && c <= 'f')
3041 drawimage(img_cloud[1][c - 'c'], x, y, NO_UPDATE);
3042 else if (c >= 'G' && c <= 'J')
3043 drawimage(img_bkgd[0][c - 'G'], x, y, NO_UPDATE);
3044 else if (c >= 'g' && c <= 'j')
3045 drawimage(img_bkgd[1][c - 'g'], x, y, NO_UPDATE);
3047 drawimage(img_solid[0], x, y, NO_UPDATE);
3049 drawimage(img_solid[1], x, y, NO_UPDATE);
3051 drawimage(img_solid[2], x, y, NO_UPDATE);
3053 drawimage(img_solid[3], x, y, NO_UPDATE);
3056 z = (frame / 2) % 6;
3059 drawimage(img_distro[z], x, y, NO_UPDATE);
3061 drawimage(img_distro[2], x, y, NO_UPDATE);
3063 drawimage(img_distro[1], x, y, NO_UPDATE);
3067 z = (frame / 3) % 3;
3069 drawimage(img_waves[z], x, y, NO_UPDATE);
3072 drawimage(img_poletop, x, y, NO_UPDATE);
3075 drawimage(img_pole, x, y, NO_UPDATE);
3077 /* Mark this as the end position of the level! */
3083 z = (frame / 3) % 2;
3085 drawimage(img_flag[z], x + 16, y, NO_UPDATE);
3088 drawimage(img_water, x, y, NO_UPDATE);
3092 /* What shape is at some position? */
3094 unsigned char shape(int x, int y, int sx)
3100 xx = ((x + sx) / 32);
3102 if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
3113 int issolid(int x, int y, int sx)
3119 if (isbrick(x, y, sx) ||
3120 isbrick(x + 31, y, sx) ||
3122 isice(x + 31, y, sx) ||
3123 (shape(x, y, sx) == '[' ||
3124 shape(x + 31, y, sx) == '[') ||
3125 (shape(x, y, sx) == '=' ||
3126 shape(x + 31, y, sx) == '=') ||
3127 (shape(x, y, sx) == ']' ||
3128 shape(x + 31, y, sx) == ']') ||
3129 (shape(x, y, sx) == 'A' ||
3130 shape(x + 31, y, sx) == 'A') ||
3131 (shape(x, y, sx) == 'B' ||
3132 shape(x + 31, y, sx) == 'B') ||
3133 (shape(x, y, sx) == '!' ||
3134 shape(x + 31, y, sx) == '!') ||
3135 (shape(x, y, sx) == 'a' ||
3136 shape(x + 31, y, sx) == 'a'))
3145 /* Is it a brick? */
3147 int isbrick(int x, int y, int sx)
3153 if (shape(x, y, sx) == 'X' ||
3154 shape(x, y, sx) == 'x' ||
3155 shape(x, y, sx) == 'Y' ||
3156 shape(x, y, sx) == 'y')
3167 int isice(int x, int y, int sx)
3173 if (shape(x, y, sx) == '#')
3182 /* Is it a full box? */
3184 int isfullbox(int x, int y, int sx)
3190 if (shape(x, y, sx) == 'A' ||
3191 shape(x, y, sx) == 'B' ||
3192 shape(x, y, sx) == '!')
3201 /* Edit a piece of the map! */
3203 void change(int x, int y, int sx, unsigned char c)
3208 xx = ((x + sx) / 32);
3210 if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
3215 /* Break a brick: */
3217 void trybreakbrick(int x, int y, int sx)
3219 if (isbrick(x, y, sx))
3221 if (shape(x, y, sx) == 'x' || shape(x, y, sx) == 'y')
3223 /* Get a distro from it: */
3225 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3228 if (counting_distros == NO)
3230 counting_distros = YES;
3231 distro_counter = 50;
3234 if (distro_counter <= 0)
3235 change(x, y, sx, 'a');
3237 play_sound(sounds[SND_DISTRO]);
3238 score = score + SCORE_DISTRO;
3243 /* Get rid of it: */
3245 change(x, y, sx, '.');
3249 /* Replace it with broken bits: */
3251 add_broken_brick(((x + sx + 1) / 32) * 32,
3255 /* Get some score: */
3257 play_sound(sounds[SND_BRICK]);
3258 score = score + SCORE_BRICK;
3263 /* Bounce a brick: */
3265 void bumpbrick(int x, int y, int sx)
3267 add_bouncy_brick(((x + sx + 1) / 32) * 32,
3270 play_sound(sounds[SND_BRICK]);
3276 void tryemptybox(int x, int y, int sx)
3278 if (isfullbox(x, y, sx))
3280 if (shape(x, y, sx) == 'A')
3282 /* Box with a distro! */
3284 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3285 (y / 32) * 32 - 32);
3287 play_sound(sounds[SND_DISTRO]);
3288 score = score + SCORE_DISTRO;
3291 else if (shape(x, y, sx) == 'B')
3293 /* Add an upgrade! */
3295 if (tux_size == SMALL)
3297 /* Tux is small, add mints! */
3299 add_upgrade(((x + sx + 1) / 32) * 32,
3305 /* Tux is big, add coffee: */
3307 add_upgrade(((x + sx + 1) / 32) * 32,
3312 play_sound(sounds[SND_UPGRADE]);
3314 else if (shape(x, y, sx) == '!')
3316 /* Add a golden herring */
3318 add_upgrade(((x + sx + 1) / 32) * 32,
3323 /* Empty the box: */
3325 change(x, y, sx, 'a');
3330 /* Try to grab a distro: */
3332 void trygrabdistro(int x, int y, int sx, int bounciness)
3334 if (shape(x, y, sx) == '$')
3336 change(x, y, sx, '.');
3337 play_sound(sounds[SND_DISTRO]);
3339 if (bounciness == BOUNCE)
3341 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3345 score = score + SCORE_DISTRO;
3351 /* Add a bouncy distro: */
3353 void add_bouncy_distro(int x, int y)
3359 for (i = 0; i < NUM_BOUNCY_DISTROS && found == -1; i++)
3361 if (!bouncy_distros[i].alive)
3367 bouncy_distros[found].alive = YES;
3368 bouncy_distros[found].x = x;
3369 bouncy_distros[found].y = y;
3370 bouncy_distros[found].ym = -6;
3375 /* Add broken brick pieces: */
3377 void add_broken_brick(int x, int y)
3379 add_broken_brick_piece(x, y, -4, -16);
3380 add_broken_brick_piece(x, y + 16, -6, -12);
3382 add_broken_brick_piece(x + 16, y, 4, -16);
3383 add_broken_brick_piece(x + 16, y + 16, 6, -12);
3387 /* Add a broken brick piece: */
3389 void add_broken_brick_piece(int x, int y, int xm, int ym)
3395 for (i = 0; i < NUM_BROKEN_BRICKS && found == -1; i++)
3397 if (!broken_bricks[i].alive)
3403 broken_bricks[found].alive = YES;
3404 broken_bricks[found].x = x;
3405 broken_bricks[found].y = y;
3406 broken_bricks[found].xm = xm;
3407 broken_bricks[found].ym = ym;
3412 /* Add a bouncy brick piece: */
3414 void add_bouncy_brick(int x, int y)
3420 for (i = 0; i < NUM_BOUNCY_BRICKS && found == -1; i++)
3422 if (!bouncy_bricks[i].alive)
3428 bouncy_bricks[found].alive = YES;
3429 bouncy_bricks[found].x = x;
3430 bouncy_bricks[found].y = y;
3431 bouncy_bricks[found].offset = 0;
3432 bouncy_bricks[found].offset_m = -BOUNCY_BRICK_SPEED;
3433 bouncy_bricks[found].shape = shape(x, y, 0);
3438 /* Add a bad guy: */
3440 void add_bad_guy(int x, int y, int kind)
3446 for (i = 0; i < NUM_BAD_GUYS && found == -1; i++)
3448 if (!bad_guys[i].alive)
3454 bad_guys[found].alive = YES;
3455 bad_guys[found].mode = NORMAL;
3456 bad_guys[found].dying = NO;
3457 bad_guys[found].timer = 0;
3458 bad_guys[found].kind = kind;
3459 bad_guys[found].x = x;
3460 bad_guys[found].y = y;
3461 bad_guys[found].xm = 0;
3462 bad_guys[found].ym = 0;
3463 bad_guys[found].dir = LEFT;
3464 bad_guys[found].seen = NO;
3471 void add_score(int x, int y, int s)
3476 /* Add the score: */
3481 /* Add a floating score thing to the game: */
3485 for (i = 0; i < NUM_FLOATING_SCORES && found == -1; i++)
3487 if (!floating_scores[i].alive)
3494 floating_scores[found].alive = YES;
3495 floating_scores[found].x = x;
3496 floating_scores[found].y = y - 16;
3497 floating_scores[found].timer = 8;
3498 floating_scores[found].value = s;
3503 /* Try to bump a bad guy from below: */
3505 void trybumpbadguy(int x, int y, int sx)
3512 for (i = 0; i < NUM_BAD_GUYS; i++)
3514 if (bad_guys[i].alive &&
3515 bad_guys[i].x >= x + sx - 32 && bad_guys[i].x <= x + sx + 32 &&
3516 bad_guys[i].y >= y - 16 && bad_guys[i].y <= y + 16)
3518 if (bad_guys[i].kind == BAD_BSOD ||
3519 bad_guys[i].kind == BAD_LAPTOP)
3521 bad_guys[i].dying = FALLING;
3522 bad_guys[i].ym = -8;
3523 play_sound(sounds[SND_FALL]);
3531 for (i = 0; i < NUM_UPGRADES; i++)
3533 if (upgrades[i].alive && upgrades[i].height == 32 &&
3534 upgrades[i].x >= x + sx - 32 && upgrades[i].x <= x + sx + 32 &&
3535 upgrades[i].y >= y - 16 && upgrades[i].y <= y + 16)
3537 upgrades[i].xm = -upgrades[i].xm;
3538 upgrades[i].ym = -8;
3539 play_sound(sounds[SND_BUMP_UPGRADE]);
3545 /* Add an upgrade: */
3547 void add_upgrade(int x, int y, int kind)
3553 for (i = 0; i < NUM_UPGRADES && found == -1; i++)
3555 if (!upgrades[i].alive)
3561 upgrades[found].alive = YES;
3562 upgrades[found].kind = kind;
3563 upgrades[found].x = x;
3564 upgrades[found].y = y;
3565 upgrades[found].xm = 4;
3566 upgrades[found].ym = -4;
3567 upgrades[found].height = 0;
3574 void killtux(int mode)
3578 play_sound(sounds[SND_HURT]);
3580 if (tux_dir == RIGHT)
3582 else if (tux_dir == LEFT)
3585 if (mode == SHRINK && tux_size == BIG)
3588 tux_got_coffee = NO;
3592 tux_safe = TUX_SAFE_TIME;
3603 void add_bullet(int x, int y, int dir, int xm)
3609 for (i = 0; i < NUM_BULLETS && found == -1; i++)
3611 if (!bullets[i].alive)
3617 bullets[found].alive = YES;
3621 bullets[found].x = x + 32;
3622 bullets[found].xm = BULLET_XM + xm;
3626 bullets[found].x = x;
3627 bullets[found].xm = -BULLET_XM + xm;
3630 bullets[found].y = y;
3631 bullets[found].ym = BULLET_STARTING_YM;
3633 play_sound(sounds[SND_SHOOT]);
3638 void drawendscreen(void)
3642 clearscreen(0, 0, 0);
3644 drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE);
3646 sprintf(str, "SCORE: %d", score);
3647 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
3649 sprintf(str, "DISTROS: %d", distros);
3650 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
3656 void drawresultscreen(void)
3660 clearscreen(0, 0, 0);
3662 drawcenteredtext("Result:", 200, letters_red, NO_UPDATE);
3664 sprintf(str, "SCORE: %d", score);
3665 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
3667 sprintf(str, "DISTROS: %d", distros);
3668 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
3671 /*SDL_Delay(2000);*/