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"
39 /* Local variables: */
41 int score, highscore, distros, level, lives, scroll_x, next_level, game_pause,
42 done, quit, tux_dir, tux_size, tux_duck, tux_x, tux_xm, tux_y, tux_ym,
43 tux_dying, tux_safe, jumping, jump_counter, frame, score_multiplier,
44 tux_frame_main, tux_frame, tux_got_coffee, tux_skidding,
45 super_bkgd_time, time_left, tux_invincible_time, endpos,
46 counting_distros, distro_counter;
47 int bkgd_red, bkgd_green, bkgd_blue, level_width;
48 int left, right, up, down, fire, old_fire;
49 SDL_Surface * img_brick[2], * img_solid[4], * img_distro[4],
50 * img_waves[3], * img_water, * img_pole, * img_poletop, * img_flag[2];
51 SDL_Surface * img_bkgd[2][4];
52 SDL_Surface * img_golden_herring;
53 SDL_Surface * img_bsod_left[4], * img_bsod_right[4],
54 * img_laptop_left[3], * img_laptop_right[3],
55 * img_money_left[2], * img_money_right[2];
56 SDL_Surface * img_bsod_squished_left, * img_bsod_squished_right,
57 * img_bsod_falling_left, * img_bsod_falling_right,
58 * img_laptop_flat_left, * img_laptop_flat_right,
59 * img_laptop_falling_left, * img_laptop_falling_right;
60 SDL_Surface * img_box_full, * img_box_empty, * img_mints, * img_coffee,
61 * img_super_bkgd, * img_bullet, * img_red_glow;
62 SDL_Surface * img_cloud[2][4];
63 SDL_Surface * tux_life,
64 * tux_right[3], * tux_left[3],
65 * bigtux_right[3], * bigtux_left[3],
66 * bigtux_right_jump, * bigtux_left_jump,
67 * ducktux_right, * ducktux_left,
68 * skidtux_right, * skidtux_left,
69 * firetux_right[3], * firetux_left[3],
70 * bigfiretux_right[3], * bigfiretux_left[3],
71 * bigfiretux_right_jump, * bigfiretux_left_jump,
72 * duckfiretux_right, * duckfiretux_left,
73 * skidfiretux_right, * skidfiretux_left,
74 * cape_right[2], * cape_left[2],
75 * bigcape_right[2], * bigcape_left[2];
79 unsigned char * tiles[15];
80 bouncy_distro_type bouncy_distros[NUM_BOUNCY_DISTROS];
81 broken_brick_type broken_bricks[NUM_BROKEN_BRICKS];
82 bouncy_brick_type bouncy_bricks[NUM_BOUNCY_BRICKS];
83 bad_guy_type bad_guys[NUM_BAD_GUYS];
84 floating_score_type floating_scores[NUM_FLOATING_SCORES];
85 upgrade_type upgrades[NUM_UPGRADES];
86 bullet_type bullets[NUM_BULLETS];
93 /* Local function prototypes: */
97 void loadlevelgfx(void);
98 void loadlevelsong(void);
99 void unloadlevelgfx(void);
100 void unloadlevelsong(void);
101 void loadshared(void);
102 void unloadshared(void);
103 void drawshape(int x, int y, unsigned char c);
105 unsigned char shape(int x, int y, int sx);
106 int issolid(int x, int y, int sx);
107 int isbrick(int x, int y, int sx);
108 int isice(int x, int y, int sx);
109 int isfullbox(int x, int y, int sx);
110 void change(int x, int y, int sx, unsigned char c);
111 void trybreakbrick(int x, int y, int sx);
112 void bumpbrick(int x, int y, int sx);
113 void tryemptybox(int x, int y, int sx);
114 void trygrabdistro(int x, int y, int sx, int bounciness);
115 void add_bouncy_distro(int x, int y);
116 void add_broken_brick(int x, int y);
117 void add_broken_brick_piece(int x, int y, int xm, int ym);
118 void add_bouncy_brick(int x, int y);
119 void add_bad_guy(int x, int y, int kind);
120 void add_score(int x, int y, int s);
121 void trybumpbadguy(int x, int y, int sx);
122 void add_upgrade(int x, int y, int kind);
123 void killtux(int mode);
124 void add_bullet(int x, int y, int dir, int xm);
125 void drawendscreen(void);
126 void drawresultscreen(void);
128 /* --- GAME EVENT! --- */
130 void game_event(void)
133 while (SDL_PollEvent(&event))
136 if (event.type == SDL_QUIT)
138 /* Quit event - quit: */
142 else if (event.type == SDL_KEYDOWN)
146 key = event.key.keysym.sym;
148 /* Check for menu-events, if the menu is shown */
152 if (key == SDLK_ESCAPE)
154 /* Escape: Open/Close the menu: */
163 else if (key == SDLK_RIGHT)
167 else if (key == SDLK_LEFT)
171 else if (key == SDLK_UP)
175 else if (key == SDLK_DOWN)
179 else if (key == SDLK_LCTRL)
184 else if (event.type == SDL_KEYUP)
188 key = event.key.keysym.sym;
190 if (key == SDLK_RIGHT)
194 else if (key == SDLK_LEFT)
198 else if (key == SDLK_UP)
202 else if (key == SDLK_DOWN)
206 else if (key == SDLK_LCTRL)
210 else if (key == SDLK_p)
220 else if (key == SDLK_TAB && debug_mode == YES)
222 tux_size = !tux_size;
224 else if (key == SDLK_END && debug_mode == YES)
228 else if (key == SDLK_SPACE && debug_mode == YES)
234 else if (event.type == SDL_JOYAXISMOTION)
236 if (event.jaxis.axis == JOY_X)
238 if (event.jaxis.value < -256)
243 if (event.jaxis.value > 256)
248 else if (event.jaxis.axis == JOY_Y)
250 if (event.jaxis.value > 256)
255 /* Handle joystick for the menu */
259 menuaction = MN_DOWN;
265 else if (event.type == SDL_JOYBUTTONDOWN)
267 if (event.jbutton.button == JOY_A)
269 else if (event.jbutton.button == JOY_B)
272 else if (event.type == SDL_JOYBUTTONUP)
274 if (event.jbutton.button == JOY_A)
276 else if (event.jbutton.button == JOY_B)
289 /* --- GAME ACTION! --- */
291 int game_action(void)
295 /* --- HANDLE TUX! --- */
297 /* Handle key and joystick state: */
299 if (!(tux_dying || next_level))
301 if (right == DOWN && left == UP)
305 if (tux_xm < -SKID_XM && !tux_skidding &&
308 tux_skidding = SKID_TIME;
310 play_sound(sounds[SND_SKID]);
316 if (tux_xm < 0 && !isice(tux_x, tux_y + 32, scroll_x) &&
324 if (tux_dir == RIGHT)
326 /* Facing the direction we're jumping? Go full-speed: */
330 tux_xm = tux_xm + WALK_SPEED;
332 if (tux_xm > MAX_WALK_XM)
333 tux_xm = MAX_WALK_XM;
335 else if (fire == DOWN)
337 tux_xm = tux_xm + RUN_SPEED;
339 if (tux_xm > MAX_RUN_XM)
345 /* Not facing the direction we're jumping?
348 tux_xm = tux_xm + WALK_SPEED / 2;
350 if (tux_xm > MAX_WALK_XM / 2)
351 tux_xm = MAX_WALK_XM / 2;
355 else if (left == DOWN && right == UP)
359 if (tux_xm > SKID_XM && !tux_skidding &&
362 tux_skidding = SKID_TIME;
363 play_sound(sounds[SND_SKID]);
368 if (tux_xm > 0 && !isice(tux_x, tux_y + 32, scroll_x) &&
378 /* Facing the direction we're jumping? Go full-speed: */
382 tux_xm = tux_xm - WALK_SPEED;
384 if (tux_xm < -MAX_WALK_XM)
385 tux_xm = -MAX_WALK_XM;
387 else if (fire == DOWN)
389 tux_xm = tux_xm - RUN_SPEED;
391 if (tux_xm < -MAX_RUN_XM)
392 tux_xm = -MAX_RUN_XM;
397 /* Not facing the direction we're jumping?
400 tux_xm = tux_xm - WALK_SPEED / 2;
402 if (tux_xm < -MAX_WALK_XM / 2)
403 tux_xm = -MAX_WALK_XM / 2;
411 if (tux_x >= endpos && endpos != 0)
421 if (jump_counter == 0)
425 if (!issolid(tux_x, tux_y + 32, scroll_x) ||
428 /* If they're not on the ground, or are currently moving
429 vertically, don't jump! */
431 jump_counter = MAX_JUMP_COUNT;
435 /* Make sure we're not standing back up into a solid! */
437 if (tux_size == SMALL || tux_duck == NO ||
438 !issolid(tux_x, tux_y, scroll_x))
442 if (tux_size == SMALL)
443 play_sound(sounds[SND_JUMP]);
445 play_sound(sounds[SND_BIGJUMP]);
451 /* Keep jumping for a while: */
453 if (jump_counter < MAX_JUMP_COUNT)
455 tux_ym = tux_ym - JUMP_SPEED;
465 if (fire == DOWN && old_fire == UP && tux_got_coffee)
467 add_bullet(tux_x + scroll_x, tux_y, tux_dir, tux_xm);
480 if (tux_size == BIG && tux_duck == YES)
482 /* Make sure we're not standing back up into a solid! */
484 if (!issolid(tux_x, tux_y - 32, scroll_x))
490 } /* (tux_dying || next_level) */
493 /* Tux either died, or reached the end of a level! */
502 /* End of a level! */
510 tux_ym = tux_ym + GRAVITY;
518 /* No more lives!? */
524 if (score > highscore)
531 } /* if (lives < 0) */
534 /* Either way, (re-)load the (next) level... */
545 tux_x = tux_x + tux_xm;
546 tux_y = tux_y + tux_ym;
549 /* Keep tux in bounds: */
552 else if (tux_x < 160 && scroll_x > 0 && debug_mode == YES)
554 scroll_x = scroll_x - ( 160 - tux_x);
561 else if (tux_x > 320 && scroll_x < ((level_width * 32) - 640))
563 /* Scroll the screen in past center: */
565 scroll_x = scroll_x + (tux_x - 320);
568 if (scroll_x > ((level_width * 32) - 640))
569 scroll_x = ((level_width * 32) - 640);
571 else if (tux_x > 608)
573 /* ... unless there's no more to scroll! */
583 if (issolid(tux_x, tux_y + 31, scroll_x) &&
584 !issolid(tux_x - tux_xm, tux_y + 31, scroll_x))
586 while (issolid(tux_x, tux_y + 31, scroll_x))
597 if (issolid(tux_x, tux_y, scroll_x) &&
598 !issolid(tux_x - tux_xm, tux_y, scroll_x))
600 while (issolid(tux_x, tux_y, scroll_x))
611 if (issolid(tux_x, tux_y + 31, scroll_x))
613 /* Set down properly: */
615 while (issolid(tux_x, tux_y + 31, scroll_x))
624 /* Reset score multiplier (for mutli-hits): */
627 score_multiplier = 1;
637 /* Bump into things: */
639 if (issolid(tux_x, tux_y, scroll_x) ||
640 (tux_size == BIG && !tux_duck &&
641 (issolid(tux_x, tux_y - 32, scroll_x))))
643 if (!issolid(tux_x - tux_xm, tux_y, scroll_x) &&
644 (tux_size == SMALL || tux_duck ||
645 !issolid(tux_x - tux_xm, tux_y - 32, scroll_x)))
647 tux_x = tux_x - tux_xm;
650 else if (!issolid(tux_x, tux_y - tux_ym, scroll_x) &&
651 (tux_size == SMALL || tux_duck ||
652 !issolid(tux_x, tux_y - 32 - tux_ym, scroll_x)))
660 /* Break bricks and empty boxes: */
664 if (isbrick(tux_x, tux_y - 32, scroll_x) ||
665 isfullbox(tux_x, tux_y - 32, scroll_x))
667 trygrabdistro(tux_x, tux_y - 64, scroll_x,
669 trybumpbadguy(tux_x, tux_y - 96, scroll_x);
671 if (isfullbox(tux_x, tux_y - 32,
674 bumpbrick(tux_x, tux_y - 32,
678 trybreakbrick(tux_x, tux_y - 32, scroll_x);
679 tryemptybox(tux_x, tux_y - 32, scroll_x);
682 if (isbrick(tux_x + 31, tux_y - 32, scroll_x) ||
683 isfullbox(tux_x + 31, tux_y - 32, scroll_x))
685 trygrabdistro(tux_x + 31,
689 trybumpbadguy(tux_x + 31,
693 if (isfullbox(tux_x + 31, tux_y - 32,
696 bumpbrick(tux_x + 31, tux_y - 32,
700 trybreakbrick(tux_x + 31,
703 tryemptybox(tux_x + 31,
710 if (isbrick(tux_x, tux_y, scroll_x) ||
711 isfullbox(tux_x, tux_y, scroll_x))
713 trygrabdistro(tux_x, tux_y - 32, scroll_x,
715 trybumpbadguy(tux_x, tux_y - 64, scroll_x);
716 if (isfullbox(tux_x, tux_y, scroll_x))
717 bumpbrick(tux_x, tux_y, scroll_x);
718 trybreakbrick(tux_x, tux_y, scroll_x);
719 tryemptybox(tux_x, tux_y, scroll_x);
722 if (isbrick(tux_x + 31, tux_y, scroll_x) ||
723 isfullbox(tux_x + 31, tux_y, scroll_x))
725 trygrabdistro(tux_x + 31,
729 trybumpbadguy(tux_x + 31,
732 if (isfullbox(tux_x + 31, tux_y, scroll_x))
733 bumpbrick(tux_x + 31, tux_y, scroll_x);
734 trybreakbrick(tux_x + 31, tux_y, scroll_x);
735 tryemptybox(tux_x + 31, tux_y, scroll_x);
741 /* It's a brick and we're small, make the brick
742 bounce, and grab any distros above it: */
744 if (isbrick(tux_x, tux_y, scroll_x) ||
745 isfullbox(tux_x, tux_y, scroll_x))
747 trygrabdistro(tux_x, tux_y - 32, scroll_x,
749 trybumpbadguy(tux_x, tux_y - 64, scroll_x);
750 bumpbrick(tux_x, tux_y, scroll_x);
751 tryemptybox(tux_x, tux_y, scroll_x);
754 if (isbrick(tux_x + 31, tux_y, scroll_x) ||
755 isfullbox(tux_x + 31, tux_y, scroll_x))
757 trygrabdistro(tux_x + 31, tux_y - 32, scroll_x,
759 trybumpbadguy(tux_x + 31, tux_y - 64, scroll_x);
760 bumpbrick(tux_x + 31, tux_y, scroll_x);
761 tryemptybox(tux_x + 31, tux_y, scroll_x);
765 /* Get a distro from a brick? */
767 if (shape(tux_x, tux_y, scroll_x) == 'x' ||
768 shape(tux_x, tux_y, scroll_x) == 'y')
770 add_bouncy_distro(((tux_x + scroll_x + 1)
774 if (counting_distros == NO)
776 counting_distros = YES;
777 distro_counter = 100;
780 if (distro_counter <= 0)
781 change(tux_x, tux_y, scroll_x, 'a');
783 play_sound(sounds[SND_DISTRO]);
784 score = score + SCORE_DISTRO;
787 else if (shape(tux_x + 31, tux_y, scroll_x) == 'x' ||
788 shape(tux_x + 31, tux_y, scroll_x) == 'y')
790 add_bouncy_distro(((tux_x + scroll_x + 1 + 31)
794 if (counting_distros == NO)
796 counting_distros = YES;
797 distro_counter = 100;
800 if (distro_counter <= 0)
801 change(tux_x + 31, tux_y, scroll_x, 'a');
803 play_sound(sounds[SND_DISTRO]);
804 score = score + SCORE_DISTRO;
812 tux_y = (tux_y / 32) * 32 + 30;
818 tux_y = (tux_y / 32) * 32 - 32;
823 jump_counter = MAX_JUMP_COUNT;
833 trygrabdistro(tux_x, tux_y, scroll_x, NO_BOUNCE);
834 trygrabdistro(tux_x + 31, tux_y, scroll_x, NO_BOUNCE);
836 if (tux_size == BIG && !tux_duck)
838 trygrabdistro(tux_x, tux_y - 32, scroll_x, NO_BOUNCE);
839 trygrabdistro(tux_x + 31, tux_y - 32, scroll_x, NO_BOUNCE);
844 /* Enough distros for a One-up? */
846 if (distros >= DISTROS_LIFEUP)
848 distros = distros - DISTROS_LIFEUP;
849 if(lives < MAX_LIVES)
851 play_sound(sounds[SND_LIFEUP]); /*We want to hear the sound even, if MAX_LIVES is reached*/
855 /* Keep in-bounds, vertically: */
859 else if (tux_y > 480)
865 /* Slow down horizontally: */
869 if (right == UP && left == UP)
871 if (isice(tux_x, tux_y + 32, scroll_x) ||
872 !issolid(tux_x, tux_y + 32, scroll_x))
874 /* Slowly on ice or in air: */
883 /* Quickly, otherwise: */
890 /* Drop vertically: */
892 if (!issolid(tux_x, tux_y + 32, scroll_x))
894 tux_ym = tux_ym + GRAVITY;
906 /* ---- DONE HANDLING TUX! --- */
909 /* Handle bouncy distros: */
911 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
913 if (bouncy_distros[i].alive)
915 bouncy_distros[i].y = bouncy_distros[i].y + bouncy_distros[i].ym;
917 bouncy_distros[i].ym++;
919 if (bouncy_distros[i].ym >= 0)
920 bouncy_distros[i].alive = NO;
925 /* Handle broken bricks: */
927 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
929 if (broken_bricks[i].alive)
931 broken_bricks[i].x = broken_bricks[i].x + broken_bricks[i].xm;
932 broken_bricks[i].y = broken_bricks[i].y + broken_bricks[i].ym;
934 broken_bricks[i].ym++;
936 if (broken_bricks[i].ym >= 0)
937 broken_bricks[i].alive = NO;
942 /* Handle distro counting: */
944 if (counting_distros == YES)
948 if (distro_counter <= 0)
949 counting_distros = -1;
953 /* Handle bouncy bricks: */
955 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
957 if (bouncy_bricks[i].alive)
959 bouncy_bricks[i].offset = (bouncy_bricks[i].offset +
960 bouncy_bricks[i].offset_m);
964 if (bouncy_bricks[i].offset < -BOUNCY_BRICK_MAX_OFFSET)
965 bouncy_bricks[i].offset_m = BOUNCY_BRICK_SPEED;
970 if (bouncy_bricks[i].offset == 0)
971 bouncy_bricks[i].alive = NO;
976 /* Handle floating scores: */
978 for (i = 0; i < NUM_FLOATING_SCORES; i++)
980 if (floating_scores[i].alive)
982 floating_scores[i].y = floating_scores[i].y - 2;
983 floating_scores[i].timer--;
985 if (floating_scores[i].timer <= 0)
986 floating_scores[i].alive = NO;
991 /* Handle bullets: */
993 for (i = 0; i < NUM_BULLETS; i++)
995 if (bullets[i].alive)
997 bullets[i].x = bullets[i].x + bullets[i].xm;
998 bullets[i].y = bullets[i].y + bullets[i].ym;
1000 if (issolid(bullets[i].x, bullets[i].y, 0))
1002 if (issolid(bullets[i].x, bullets[i].y - bullets[i].ym, 0))
1003 bullets[i].alive = NO;
1006 if (bullets[i].ym >= 0)
1008 bullets[i].y = (bullets[i].y / 32) * 32 - 8;
1010 bullets[i].ym = -bullets[i].ym;
1014 bullets[i].ym = bullets[i].ym + GRAVITY;
1016 if (bullets[i].x < scroll_x ||
1017 bullets[i].x > scroll_x + 640)
1019 bullets[i].alive = NO;
1024 if (bullets[i].alive)
1026 for (j = 0; j < NUM_BAD_GUYS; j++)
1028 if (bad_guys[j].alive && !bad_guys[j].dying)
1030 if (bullets[i].x >= bad_guys[j].x - 4 &&
1031 bullets[i].x <= bad_guys[j].x + 32 + 4 &&
1032 bullets[i].y >= bad_guys[j].y - 4 &&
1033 bullets[i].y <= bad_guys[j].y + 32 + 4)
1035 /* Kill the bad guy! */
1037 bullets[i].alive = 0;
1038 bad_guys[j].dying = FALLING;
1039 bad_guys[j].ym = -8;
1042 /* Gain some points: */
1044 if (bad_guys[j].kind == BAD_BSOD)
1046 add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
1047 50 * score_multiplier);
1049 else if (bad_guys[j].kind == BAD_LAPTOP)
1051 add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
1052 25 * score_multiplier);
1056 /* Play death sound: */
1057 play_sound(sounds[SND_FALL]);
1065 /* Handle background timer: */
1067 if (super_bkgd_time)
1071 /* Handle invincibility timer: */
1074 if (tux_invincible_time > 50)
1076 tux_invincible_time--;
1079 if (!playing_music())
1080 play_music( herring_song, 1 );
1084 if (current_music == HERRING_MUSIC)
1086 /* stop the herring_song, now play the level_song ! */
1087 current_music = LEVEL_MUSIC;
1091 if (!playing_music())
1093 if (time_left <= TIME_WARNING)
1094 play_music( level_song_fast, 1 );
1096 play_music( level_song, 1 );
1099 if (tux_invincible_time > 0)
1100 tux_invincible_time--;
1104 /* Handle upgrades: */
1106 for (i = 0; i < NUM_UPGRADES; i++)
1108 if (upgrades[i].alive)
1110 if (upgrades[i].height < 32)
1114 upgrades[i].height++;
1120 if (upgrades[i].kind == UPGRADE_MINTS ||
1121 upgrades[i].kind == UPGRADE_HERRING)
1123 upgrades[i].x = upgrades[i].x + upgrades[i].xm;
1124 upgrades[i].y = upgrades[i].y + upgrades[i].ym;
1126 if (issolid(upgrades[i].x, upgrades[i].y + 31, 0) ||
1127 issolid(upgrades[i].x + 31, upgrades[i].y + 31, 0))
1129 if (upgrades[i].ym > 0)
1131 if (upgrades[i].kind == UPGRADE_MINTS)
1135 else if (upgrades[i].kind == UPGRADE_HERRING)
1137 upgrades[i].ym = -24;
1140 upgrades[i].y = (upgrades[i].y / 32) * 32;
1144 upgrades[i].ym = upgrades[i].ym + GRAVITY;
1146 if (issolid(upgrades[i].x, upgrades[i].y, 0))
1148 upgrades[i].xm = -upgrades[i].xm;
1153 /* Off the screen? Kill it! */
1155 if (upgrades[i].x < scroll_x)
1156 upgrades[i].alive = NO;
1159 /* Did the player grab it? */
1161 if (tux_x + scroll_x >= upgrades[i].x - 32 &&
1162 tux_x + scroll_x <= upgrades[i].x + 32 &&
1163 tux_y >= upgrades[i].y - 32 &&
1164 tux_y <= upgrades[i].y + 32)
1166 /* Remove the upgrade: */
1168 upgrades[i].alive = NO;
1171 /* Affect the player: */
1173 if (upgrades[i].kind == UPGRADE_MINTS)
1175 play_sound(sounds[SND_EXCELLENT]);
1177 super_bkgd_time = 8;
1179 else if (upgrades[i].kind == UPGRADE_COFFEE)
1181 play_sound(sounds[SND_COFFEE]);
1182 tux_got_coffee = YES;
1183 super_bkgd_time = 4;
1185 else if (upgrades[i].kind == UPGRADE_HERRING)
1187 play_sound(sounds[SND_HERRING]);
1188 tux_invincible_time = TUX_INVINCIBLE_TIME;
1189 super_bkgd_time = 4;
1190 /* play the herring song ^^ */
1191 current_music = HERRING_MUSIC;
1192 if (playing_music())
1194 play_music( herring_song, 1 );
1202 /* Handle bad guys: */
1204 for (i = 0; i < NUM_BAD_GUYS; i++)
1206 if (bad_guys[i].alive)
1208 if (bad_guys[i].seen)
1210 if (bad_guys[i].kind == BAD_BSOD)
1212 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
1214 /* Move left/right: */
1216 if (bad_guys[i].dying == NO ||
1217 bad_guys[i].dying == FALLING)
1219 if (bad_guys[i].dir == RIGHT)
1220 bad_guys[i].x = bad_guys[i].x + 4;
1221 else if (bad_guys[i].dir == LEFT)
1222 bad_guys[i].x = bad_guys[i].x - 4;
1226 /* Move vertically: */
1228 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1231 /* Bump into things horizontally: */
1233 if (!bad_guys[i].dying)
1235 if (issolid(bad_guys[i].x, bad_guys[i].y, 0))
1236 bad_guys[i].dir = !bad_guys[i].dir;
1240 /* Bump into other bad guys: */
1242 for (j = 0; j < NUM_BAD_GUYS; j++)
1244 if (j != i && bad_guys[j].alive &&
1245 !bad_guys[j].dying && !bad_guys[i].dying &&
1246 bad_guys[i].x >= bad_guys[j].x - 32 &&
1247 bad_guys[i].x <= bad_guys[j].x + 32 &&
1248 bad_guys[i].y >= bad_guys[j].y - 32 &&
1249 bad_guys[i].y <= bad_guys[j].y + 32)
1251 bad_guys[i].dir = !bad_guys[i].dir;
1256 /* Fall if we get off the ground: */
1258 if (bad_guys[i].dying != FALLING)
1260 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0) &&
1261 bad_guys[i].ym < MAX_YM)
1263 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1269 if (bad_guys[i].ym > 0)
1271 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1277 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1279 if (bad_guys[i].y > 480)
1280 bad_guys[i].alive = NO;
1282 else if (bad_guys[i].kind == BAD_LAPTOP)
1284 /* --- LAPTOP MONSTER: --- */
1286 /* Move left/right: */
1288 if (bad_guys[i].mode != FLAT && bad_guys[i].mode != KICK)
1290 if (bad_guys[i].dying == NO ||
1291 bad_guys[i].dying == FALLING)
1293 if (bad_guys[i].dir == RIGHT)
1294 bad_guys[i].x = bad_guys[i].x + 4;
1295 else if (bad_guys[i].dir == LEFT)
1296 bad_guys[i].x = bad_guys[i].x - 4;
1299 else if (bad_guys[i].mode == KICK)
1301 if (bad_guys[i].dir == RIGHT)
1302 bad_guys[i].x = bad_guys[i].x + 16;
1303 else if (bad_guys[i].dir == LEFT)
1304 bad_guys[i].x = bad_guys[i].x - 16;
1308 /* Move vertically: */
1310 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1313 /* Bump into things horizontally: */
1315 if (!bad_guys[i].dying)
1317 if (issolid(bad_guys[i].x, bad_guys[i].y, 0))
1319 bad_guys[i].dir = !bad_guys[i].dir;
1321 if (bad_guys[i].mode == KICK)
1322 play_sound(sounds[SND_RICOCHET]);
1327 /* Bump into other bad guys: */
1329 for (j = 0; j < NUM_BAD_GUYS; j++)
1331 if (j != i && bad_guys[j].alive &&
1332 !bad_guys[j].dying && !bad_guys[i].dying &&
1333 bad_guys[i].x >= bad_guys[j].x - 32 &&
1334 bad_guys[i].x <= bad_guys[j].x + 32 &&
1335 bad_guys[i].y >= bad_guys[j].y - 32 &&
1336 bad_guys[i].y <= bad_guys[j].y + 32)
1338 if (bad_guys[i].mode != KICK)
1339 bad_guys[i].dir = !bad_guys[i].dir;
1342 /* We're in kick mode, kill the other guy: */
1344 bad_guys[j].dying = FALLING;
1345 bad_guys[j].ym = -8;
1346 play_sound(sounds[SND_FALL]);
1348 add_score(bad_guys[i].x - scroll_x,
1349 bad_guys[i].y, 100);
1355 /* Fall if we get off the ground: */
1357 if (bad_guys[i].dying != FALLING)
1359 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0) &&
1360 bad_guys[i].ym < MAX_YM)
1362 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1368 if (bad_guys[i].ym > 0)
1370 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1376 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1378 if (bad_guys[i].y > 480)
1379 bad_guys[i].alive = NO;
1381 else if (bad_guys[i].kind == BAD_MONEY)
1383 /* --- MONEY BAGS: --- */
1386 /* Move vertically: */
1388 bad_guys[i].y = bad_guys[i].y + bad_guys[i].ym;
1391 /* Fall if we get off the ground: */
1393 if (bad_guys[i].dying != FALLING)
1395 if (!issolid(bad_guys[i].x, bad_guys[i].y + 32, 0))
1397 if (bad_guys[i].ym < MAX_YM)
1399 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1406 if (bad_guys[i].ym > 0)
1408 bad_guys[i].y = (bad_guys[i].y / 32) * 32;
1409 bad_guys[i].ym = -MAX_YM;
1414 bad_guys[i].ym = bad_guys[i].ym + GRAVITY;
1416 if (bad_guys[i].y > 480)
1417 bad_guys[i].alive = NO;
1419 else if (bad_guys[i].kind == -1)
1423 /* Kill it if the player jumped on it: */
1425 if (!bad_guys[i].dying && !tux_dying && !tux_safe &&
1426 tux_x + scroll_x >= bad_guys[i].x - 32 &&
1427 tux_x + scroll_x <= bad_guys[i].x + 32 &&
1428 tux_y >= bad_guys[i].y - 32 &&
1429 tux_y <= bad_guys[i].y - 8
1433 if (bad_guys[i].kind == BAD_BSOD)
1435 bad_guys[i].dying = SQUISHED;
1436 bad_guys[i].timer = 16;
1437 tux_ym = -KILL_BOUNCE_YM;
1439 add_score(bad_guys[i].x - scroll_x, bad_guys[i].y,
1440 50 * score_multiplier);
1442 play_sound(sounds[SND_SQUISH]);
1444 else if (bad_guys[i].kind == BAD_LAPTOP)
1446 if (bad_guys[i].mode != FLAT)
1450 play_sound(sounds[SND_STOMP]);
1451 bad_guys[i].mode = FLAT;
1453 bad_guys[i].timer = 64;
1461 bad_guys[i].mode = KICK;
1462 play_sound(sounds[SND_KICK]);
1464 if (tux_x + scroll_x <= bad_guys[i].x)
1465 bad_guys[i].dir = RIGHT;
1467 bad_guys[i].dir = LEFT;
1469 bad_guys[i].timer = 8;
1472 tux_ym = -KILL_BOUNCE_YM;
1474 add_score(bad_guys[i].x - scroll_x,
1476 25 * score_multiplier);
1478 /* play_sound(sounds[SND_SQUISH]); */
1480 else if (bad_guys[i].kind == -1)
1487 /* Hurt the player if he just touched it: */
1489 if (!bad_guys[i].dying && !tux_dying &&
1491 tux_x + scroll_x >= bad_guys[i].x - 32 &&
1492 tux_x + scroll_x <= bad_guys[i].x + 32 &&
1493 tux_y >= bad_guys[i].y - 32 &&
1494 tux_y <= bad_guys[i].y + 32)
1496 if (bad_guys[i].mode == FLAT)
1500 bad_guys[i].mode = KICK;
1502 if (tux_x + scroll_x <= bad_guys[i].x)
1504 bad_guys[i].dir = RIGHT;
1505 bad_guys[i].x = bad_guys[i].x + 16;
1509 bad_guys[i].dir = LEFT;
1510 bad_guys[i].x = bad_guys[i].x - 16;
1513 bad_guys[i].timer = 8;
1515 else if (bad_guys[i].mode == KICK)
1517 if (tux_y < bad_guys[i].y - 16 &&
1518 bad_guys[i].timer == 0)
1520 /* Step on (stop being kicked) */
1522 bad_guys[i].mode = FLAT;
1523 play_sound(sounds[SND_STOMP]);
1524 bad_guys[i].timer = 64;
1528 /* Hurt if you get hit by kicked laptop: */
1530 if (bad_guys[i].timer == 0)
1532 if (tux_invincible_time == 0)
1538 bad_guys[i].dying = FALLING;
1539 bad_guys[i].ym = -8;
1540 play_sound(sounds[SND_FALL]);
1547 if (tux_invincible_time == 0)
1553 bad_guys[i].dying = FALLING;
1554 bad_guys[i].ym = -8;
1555 play_sound(sounds[SND_FALL]);
1561 /* Handle mode timer: */
1563 if (bad_guys[i].mode == FLAT)
1565 bad_guys[i].timer--;
1567 if (bad_guys[i].timer <= 0)
1568 bad_guys[i].mode = NORMAL;
1570 else if (bad_guys[i].mode == KICK)
1572 if (bad_guys[i].timer > 0)
1573 bad_guys[i].timer--;
1577 /* Handle dying timer: */
1579 if (bad_guys[i].dying == SQUISHED)
1581 bad_guys[i].timer--;
1584 /* Remove it if time's up: */
1586 if (bad_guys[i].timer <= 0)
1587 bad_guys[i].alive = NO;
1591 /* Remove if it's far off the screen: */
1593 if (bad_guys[i].x < scroll_x - OFFSCREEN_DISTANCE)
1594 bad_guys[i].alive = NO;
1598 /* Once it's on screen, it's activated! */
1600 if (bad_guys[i].x <= scroll_x + 640 + OFFSCREEN_DISTANCE)
1601 bad_guys[i].seen = YES;
1607 /* Handle skidding: */
1609 if (tux_skidding > 0)
1617 /* --- GAME DRAW! --- */
1625 if (tux_dying && (frame % 4) == 0)
1626 clearscreen(255, 255, 255);
1629 if (super_bkgd_time == 0)
1630 clearscreen(bkgd_red, bkgd_green, bkgd_blue);
1632 drawimage(img_super_bkgd, 0, 0, NO_UPDATE);
1636 /* Draw background: */
1638 for (y = 0; y < 15; y++)
1640 for (x = 0; x < 21; x++)
1642 drawshape(x * 32 - (scroll_x % 32), y * 32,
1643 tiles[y][x + (scroll_x / 32)]);
1648 /* (Bouncy bricks): */
1650 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
1652 if (bouncy_bricks[i].alive)
1654 if (bouncy_bricks[i].x >= scroll_x - 32 &&
1655 bouncy_bricks[i].x <= scroll_x + 640)
1657 dest.x = bouncy_bricks[i].x - scroll_x;
1658 dest.y = bouncy_bricks[i].y;
1662 SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format,
1667 drawshape(bouncy_bricks[i].x - scroll_x,
1668 bouncy_bricks[i].y + bouncy_bricks[i].offset,
1669 bouncy_bricks[i].shape);
1677 for (i = 0; i < NUM_BAD_GUYS; i++)
1679 if (bad_guys[i].alive &&
1680 bad_guys[i].x > scroll_x - 32 &&
1681 bad_guys[i].x < scroll_x + 640)
1683 if (bad_guys[i].kind == BAD_BSOD)
1685 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
1687 if (bad_guys[i].dying == NO)
1691 if (bad_guys[i].dir == LEFT)
1693 drawimage(img_bsod_left[(frame / 5) % 4],
1694 bad_guys[i].x - scroll_x,
1700 drawimage(img_bsod_right[(frame / 5) % 4],
1701 bad_guys[i].x - scroll_x,
1706 else if (bad_guys[i].dying == FALLING)
1710 if (bad_guys[i].dir == LEFT)
1712 drawimage(img_bsod_falling_left,
1713 bad_guys[i].x - scroll_x,
1719 drawimage(img_bsod_falling_right,
1720 bad_guys[i].x - scroll_x,
1725 else if (bad_guys[i].dying == SQUISHED)
1727 /* Dying - Squished: */
1729 if (bad_guys[i].dir == LEFT)
1731 drawimage(img_bsod_squished_left,
1732 bad_guys[i].x - scroll_x,
1738 drawimage(img_bsod_squished_right,
1739 bad_guys[i].x - scroll_x,
1745 else if (bad_guys[i].kind == BAD_LAPTOP)
1747 /* --- LAPTOP MONSTER: --- */
1749 if (bad_guys[i].dying == NO)
1753 if (bad_guys[i].mode == NORMAL)
1757 if (bad_guys[i].dir == LEFT)
1759 drawimage(img_laptop_left[(frame / 5) % 3],
1760 bad_guys[i].x - scroll_x,
1766 drawimage(img_laptop_right[(frame / 5) % 3],
1767 bad_guys[i].x - scroll_x,
1776 if (bad_guys[i].dir == LEFT)
1778 drawimage(img_laptop_flat_left,
1779 bad_guys[i].x - scroll_x,
1785 drawimage(img_laptop_flat_right,
1786 bad_guys[i].x - scroll_x,
1792 else if (bad_guys[i].dying == FALLING)
1796 if (bad_guys[i].dir == LEFT)
1798 drawimage(img_laptop_falling_left,
1799 bad_guys[i].x - scroll_x,
1805 drawimage(img_laptop_falling_right,
1806 bad_guys[i].x - scroll_x,
1812 else if (bad_guys[i].kind == BAD_MONEY)
1814 if (bad_guys[i].ym > -16)
1816 if (bad_guys[i].dir == LEFT)
1818 drawimage(img_money_left[0],
1819 bad_guys[i].x - scroll_x,
1825 drawimage(img_money_right[0],
1826 bad_guys[i].x - scroll_x,
1833 if (bad_guys[i].dir == LEFT)
1835 drawimage(img_money_left[1],
1836 bad_guys[i].x - scroll_x,
1842 drawimage(img_money_right[1],
1843 bad_guys[i].x - scroll_x,
1849 else if (bad_guys[i].kind == -1)
1857 if (right == UP && left == UP)
1864 if ((fire == DOWN && (frame % 2) == 0) ||
1866 tux_frame_main = (tux_frame_main + 1) % 4;
1868 tux_frame = tux_frame_main;
1875 if (tux_safe == 0 || (frame % 2) == 0)
1877 if (tux_size == SMALL)
1879 if (tux_invincible_time)
1883 if (tux_dir == RIGHT)
1885 drawimage(cape_right[frame % 2],
1891 drawimage(cape_left[frame % 2],
1898 if (!tux_got_coffee)
1900 if (tux_dir == RIGHT)
1902 drawimage(tux_right[tux_frame], tux_x, tux_y, NO_UPDATE);
1906 drawimage(tux_left[tux_frame], tux_x, tux_y, NO_UPDATE);
1911 /* Tux got coffee! */
1913 if (tux_dir == RIGHT)
1915 drawimage(firetux_right[tux_frame], tux_x, tux_y, NO_UPDATE);
1919 drawimage(firetux_left[tux_frame], tux_x, tux_y, NO_UPDATE);
1925 if (tux_invincible_time)
1929 if (tux_dir == RIGHT)
1931 drawimage(bigcape_right[frame % 2],
1932 tux_x - 8 - 16, tux_y - 32,
1937 drawimage(bigcape_left[frame % 2],
1938 tux_x - 8, tux_y - 32,
1943 if (!tux_got_coffee)
1949 if (!jumping || tux_ym > 0)
1951 if (tux_dir == RIGHT)
1953 drawimage(bigtux_right[tux_frame],
1954 tux_x - 8, tux_y - 32,
1959 drawimage(bigtux_left[tux_frame],
1960 tux_x - 8, tux_y - 32,
1966 if (tux_dir == RIGHT)
1968 drawimage(bigtux_right_jump,
1969 tux_x - 8, tux_y - 32,
1974 drawimage(bigtux_left_jump,
1975 tux_x - 8, tux_y - 32,
1982 if (tux_dir == RIGHT)
1984 drawimage(skidtux_right,
1985 tux_x - 8, tux_y - 32,
1990 drawimage(skidtux_left,
1991 tux_x - 8, tux_y - 32,
1998 if (tux_dir == RIGHT)
2000 drawimage(ducktux_right, tux_x - 8, tux_y - 16,
2005 drawimage(ducktux_left, tux_x - 8, tux_y - 16,
2012 /* Tux has coffee! */
2018 if (!jumping || tux_ym > 0)
2020 if (tux_dir == RIGHT)
2022 drawimage(bigfiretux_right[tux_frame],
2023 tux_x - 8, tux_y - 32,
2028 drawimage(bigfiretux_left[tux_frame],
2029 tux_x - 8, tux_y - 32,
2035 if (tux_dir == RIGHT)
2037 drawimage(bigfiretux_right_jump,
2038 tux_x - 8, tux_y - 32,
2043 drawimage(bigfiretux_left_jump,
2044 tux_x - 8, tux_y - 32,
2051 if (tux_dir == RIGHT)
2053 drawimage(skidfiretux_right,
2054 tux_x - 8, tux_y - 32,
2059 drawimage(skidfiretux_left,
2060 tux_x - 8, tux_y - 32,
2067 if (tux_dir == RIGHT)
2069 drawimage(duckfiretux_right, tux_x - 8, tux_y - 16,
2074 drawimage(duckfiretux_left, tux_x - 8, tux_y - 16,
2085 for (i = 0; i < NUM_BULLETS; i++)
2087 if (bullets[i].alive &&
2088 bullets[i].x >= scroll_x - 4 &&
2089 bullets[i].x <= scroll_x + 640)
2091 drawimage(img_bullet, bullets[i].x - scroll_x, bullets[i].y,
2097 /* (Floating scores): */
2099 for (i = 0; i < NUM_FLOATING_SCORES; i++)
2101 if (floating_scores[i].alive)
2103 sprintf(str, "%d", floating_scores[i].value);
2105 floating_scores[i].x + 16 - strlen(str) * 8,
2106 floating_scores[i].y,
2107 letters_gold, NO_UPDATE);
2114 for (i = 0; i < NUM_UPGRADES; i++)
2116 if (upgrades[i].alive)
2118 if (upgrades[i].height < 32)
2122 dest.x = upgrades[i].x - scroll_x;
2123 dest.y = upgrades[i].y + 32 - upgrades[i].height;
2125 dest.h = upgrades[i].height;
2130 src.h = upgrades[i].height;
2132 if (upgrades[i].kind == UPGRADE_MINTS)
2133 SDL_BlitSurface(img_mints, &src, screen, &dest);
2134 else if (upgrades[i].kind == UPGRADE_COFFEE)
2135 SDL_BlitSurface(img_coffee, &src, screen, &dest);
2136 else if (upgrades[i].kind == UPGRADE_HERRING)
2137 SDL_BlitSurface(img_golden_herring, &src, screen, &dest);
2141 if (upgrades[i].kind == UPGRADE_MINTS)
2143 drawimage(img_mints,
2144 upgrades[i].x - scroll_x, upgrades[i].y,
2147 else if (upgrades[i].kind == UPGRADE_COFFEE)
2149 drawimage(img_coffee,
2150 upgrades[i].x - scroll_x, upgrades[i].y,
2153 else if (upgrades[i].kind == UPGRADE_HERRING)
2155 drawimage(img_golden_herring,
2156 upgrades[i].x - scroll_x, upgrades[i].y,
2164 /* (Bouncy distros): */
2166 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
2168 if (bouncy_distros[i].alive)
2170 drawimage(img_distro[0],
2171 bouncy_distros[i].x - scroll_x,
2172 bouncy_distros[i].y,
2178 /* (Broken bricks): */
2180 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
2182 if (broken_bricks[i].alive)
2184 src.x = rand() % 16;
2185 src.y = rand() % 16;
2189 dest.x = broken_bricks[i].x - scroll_x;
2190 dest.y = broken_bricks[i].y;
2194 SDL_BlitSurface(img_brick[0], &src, screen, &dest);
2201 sprintf(str, "%d", score);
2202 drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE);
2203 drawtext(str, 96, 0, letters_gold, NO_UPDATE);
2205 sprintf(str, "%d", highscore);
2206 drawtext("HIGH", 0, 20, letters_blue, NO_UPDATE);
2207 drawtext(str, 96, 20, letters_gold, NO_UPDATE);
2209 if (time_left >= TIME_WARNING || (frame % 10) < 5)
2211 sprintf(str, "%d", time_left);
2212 drawtext("TIME", 224, 0, letters_blue, NO_UPDATE);
2213 drawtext(str, 304, 0, letters_gold, NO_UPDATE);
2216 sprintf(str, "%d", distros);
2217 drawtext("DISTROS", 480, 0, letters_blue, NO_UPDATE);
2218 drawtext(str, 608, 0, letters_gold, NO_UPDATE);
2220 drawtext("LIVES", 480, 20, letters_blue, NO_UPDATE);
2222 for(i=0; i < lives; ++i)
2224 drawimage(tux_life,565+(18*i),20,NO_UPDATE);
2228 drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE);
2233 /* (Update it all!) */
2240 /* --- GAME LOOP! --- */
2245 Uint32 last_time, now_time;
2249 clearscreen(0, 0, 0);
2253 /* Init the game: */
2261 highscore = load_hs();
2264 /* --- MAIN GAME LOOP!!! --- */
2276 last_time = SDL_GetTicks();
2280 /* Handle events: */
2286 /* Handle actions: */
2288 if(!game_pause && !show_menu)
2290 if (game_action() == 0)
2292 /* == 0: no more lives */
2293 /* == -1: continues */
2300 /*Draw the current scene to the screen */
2303 /* Keep playing music: */
2306 if (!playing_music())
2308 switch (current_music)
2311 if (time_left <= TIME_WARNING)
2312 play_music(level_song_fast, 1);
2314 play_music(level_song, 1);
2317 play_music(herring_song, 1);
2319 case HURRYUP_MUSIC: // keep the compiler happy
2320 case NO_MUSIC: // keep the compiler happy for the moment :-)
2326 /* Time stops in pause mode */
2327 if(game_pause || show_menu )
2332 /* Pause til next frame: */
2334 now_time = SDL_GetTicks();
2335 if (now_time < last_time + FPS)
2336 SDL_Delay(last_time + FPS - now_time);
2341 if ((frame % 10) == 0 && time_left > 0)
2345 /* Stop the music; it will start again, faster! */
2346 if (time_left == TIME_WARNING)
2353 while (!done && !quit);
2355 if (playing_music())
2366 /* Initialize the game stuff: */
2378 /* Load data for this level: */
2380 void loadlevel(void)
2391 for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
2392 bouncy_distros[i].alive = NO;
2394 for (i = 0; i < NUM_BROKEN_BRICKS; i++)
2395 broken_bricks[i].alive = NO;
2397 for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
2398 bouncy_bricks[i].alive = NO;
2400 for (i = 0; i < NUM_BAD_GUYS; i++)
2401 bad_guys[i].alive = NO;
2403 for (i = 0; i < NUM_FLOATING_SCORES; i++)
2404 floating_scores[i].alive = NO;
2406 for (i = 0; i < NUM_UPGRADES; i++)
2407 upgrades[i].alive = NO;
2409 for (i = 0; i < NUM_BULLETS; i++)
2410 bullets[i].alive = NO;
2413 /* Load data file: */
2415 filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20));
2416 sprintf(filename, "%s/levels/level%d.dat", DATA_PREFIX, level);
2417 fi = fopen(filename, "r");
2428 /* Load header info: */
2433 strcpy(levelname, str);
2434 levelname[strlen(levelname)-1] = '\0';
2438 strcpy(leveltheme, str);
2439 leveltheme[strlen(leveltheme)-1] = '\0';
2443 /* (Time to beat level) */
2445 time_left = atoi(str);
2447 /* (Song file for this level) */
2448 fgets(str, sizeof(song_title), fi);
2449 strcpy(song_title, str);
2450 song_title[strlen(song_title)-1] = '\0';
2454 /* (Level background color) */
2456 bkgd_red = atoi(str);
2458 bkgd_green= atoi(str);
2460 bkgd_blue = atoi(str);
2464 level_width = atoi(str);
2467 /* Allocate some space for the line-reading! */
2469 line = (char *) malloc(sizeof(char) * (level_width + 5));
2472 fprintf(stderr, "Couldn't allocate space to load level data!");
2477 /* Load the level lines: */
2479 for (y = 0; y < 15; y++)
2481 if(fgets(line, level_width + 5, fi) == NULL)
2483 fprintf(stderr, "Level %s isn't complete!\n",levelname);
2486 line[strlen(line) - 1] = '\0';
2487 tiles[y] = strdup(line);
2493 /* Activate bad guys: */
2495 for (y = 0; y < 15; y++)
2497 for (x = 0; x < level_width; x++)
2499 if (tiles[y][x] >= '0' && tiles[y][x] <= '9')
2501 add_bad_guy(x * 32, y * 32, tiles[y][x] - '0');
2516 tux_got_coffee = NO;
2517 tux_invincible_time = 0;
2521 tux_safe = TUX_SAFE_TIME;
2537 score_multiplier = 1;
2538 super_bkgd_time = 0;
2540 counting_distros = NO;
2545 /* set current song/music */
2546 current_music = LEVEL_MUSIC;
2550 clearscreen(0, 0, 0);
2552 sprintf(str, "LEVEL %d", level);
2553 drawcenteredtext(str, 200, letters_red, NO_UPDATE);
2555 sprintf(str, "%s", levelname);
2556 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
2558 sprintf(str, "TUX x %d", lives);
2559 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
2569 /* Load a level-specific graphic... */
2571 SDL_Surface * load_level_image(char * file, int use_alpha)
2575 snprintf(fname, 1024, "%s/images/%s/%s", DATA_PREFIX, leveltheme, file);
2577 return(load_image(fname, use_alpha));
2581 /* Load graphics: */
2583 void loadlevelgfx(void)
2585 img_brick[0] = load_level_image("brick0.png", IGNORE_ALPHA);
2586 img_brick[1] = load_level_image("brick1.png", IGNORE_ALPHA);
2588 img_solid[0] = load_level_image("solid0.png", USE_ALPHA);
2589 img_solid[1] = load_level_image("solid1.png", USE_ALPHA);
2590 img_solid[2] = load_level_image("solid2.png", USE_ALPHA);
2591 img_solid[3] = load_level_image("solid3.png", USE_ALPHA);
2593 img_bkgd[0][0] = load_level_image("bkgd-00.png", USE_ALPHA);
2594 img_bkgd[0][1] = load_level_image("bkgd-01.png", USE_ALPHA);
2595 img_bkgd[0][2] = load_level_image("bkgd-02.png", USE_ALPHA);
2596 img_bkgd[0][3] = load_level_image("bkgd-03.png", USE_ALPHA);
2598 img_bkgd[1][0] = load_level_image("bkgd-10.png", USE_ALPHA);
2599 img_bkgd[1][1] = load_level_image("bkgd-11.png", USE_ALPHA);
2600 img_bkgd[1][2] = load_level_image("bkgd-12.png", USE_ALPHA);
2601 img_bkgd[1][3] = load_level_image("bkgd-13.png", USE_ALPHA);
2607 void loadlevelsong(void)
2611 char * song_subtitle;
2613 song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
2614 strlen(song_title) + 8));
2615 sprintf(song_path, "%s/music/%s", DATA_PREFIX, song_title);
2616 level_song = load_song(song_path);
2620 song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
2621 strlen(song_title) + 8 + 5));
2622 song_subtitle = strdup(song_title);
2623 strcpy(strstr(song_subtitle, "."), "\0");
2624 sprintf(song_path, "%s/music/%s-fast%s", DATA_PREFIX, song_subtitle, strstr(song_title, "."));
2625 level_song_fast = load_song(song_path);
2626 free(song_subtitle);
2631 /* Free graphics data for this level: */
2633 void unloadlevelgfx(void)
2637 for (i = 0; i < 2; i++)
2639 SDL_FreeSurface(img_brick[i]);
2641 for (i = 0; i < 4; i++)
2643 SDL_FreeSurface(img_solid[i]);
2644 SDL_FreeSurface(img_bkgd[0][i]);
2645 SDL_FreeSurface(img_bkgd[1][i]);
2650 /* Free music data for this level: */
2652 void unloadlevelsong(void)
2654 free_music(level_song);
2658 /* Load graphics/sounds shared between all levels: */
2660 void loadshared(void)
2663 char * herring_song_path; /* for loading herring song*/
2667 tux_right[0] = load_image(DATA_PREFIX "/images/shared/tux-right-0.png",
2670 tux_right[1] = load_image(DATA_PREFIX "/images/shared/tux-right-1.png",
2673 tux_right[2] = load_image(DATA_PREFIX "/images/shared/tux-right-2.png",
2676 tux_left[0] = load_image(DATA_PREFIX "/images/shared/tux-left-0.png",
2679 tux_left[1] = load_image(DATA_PREFIX "/images/shared/tux-left-1.png",
2682 tux_left[2] = load_image(DATA_PREFIX "/images/shared/tux-left-2.png",
2685 firetux_right[0] = load_image(DATA_PREFIX "/images/shared/firetux-right-0.png",
2688 firetux_right[1] = load_image(DATA_PREFIX "/images/shared/firetux-right-1.png",
2691 firetux_right[2] = load_image(DATA_PREFIX "/images/shared/firetux-right-2.png",
2694 firetux_left[0] = load_image(DATA_PREFIX "/images/shared/firetux-left-0.png",
2697 firetux_left[1] = load_image(DATA_PREFIX "/images/shared/firetux-left-1.png",
2700 firetux_left[2] = load_image(DATA_PREFIX "/images/shared/firetux-left-2.png",
2703 cape_right[0] = load_image(DATA_PREFIX "/images/shared/cape-right-0.png",
2706 cape_right[1] = load_image(DATA_PREFIX "/images/shared/cape-right-1.png",
2709 cape_left[0] = load_image(DATA_PREFIX "/images/shared/cape-left-0.png",
2712 cape_left[1] = load_image(DATA_PREFIX "/images/shared/cape-left-1.png",
2715 bigtux_right[0] = load_image(DATA_PREFIX "/images/shared/bigtux-right-0.png",
2718 bigtux_right[1] = load_image(DATA_PREFIX "/images/shared/bigtux-right-1.png",
2721 bigtux_right[2] = load_image(DATA_PREFIX "/images/shared/bigtux-right-2.png",
2725 load_image(DATA_PREFIX "/images/shared/bigtux-right-jump.png", USE_ALPHA);
2727 bigtux_left[0] = load_image(DATA_PREFIX "/images/shared/bigtux-left-0.png",
2730 bigtux_left[1] = load_image(DATA_PREFIX "/images/shared/bigtux-left-1.png",
2733 bigtux_left[2] = load_image(DATA_PREFIX "/images/shared/bigtux-left-2.png",
2737 load_image(DATA_PREFIX "/images/shared/bigtux-left-jump.png", USE_ALPHA);
2740 load_image(DATA_PREFIX "/images/shared/bigcape-right-0.png",
2744 load_image(DATA_PREFIX "/images/shared/bigcape-right-1.png",
2748 load_image(DATA_PREFIX "/images/shared/bigcape-left-0.png",
2752 load_image(DATA_PREFIX "/images/shared/bigcape-left-1.png",
2755 bigfiretux_right[0] = load_image(DATA_PREFIX "/images/shared/bigfiretux-right-0.png",
2758 bigfiretux_right[1] = load_image(DATA_PREFIX "/images/shared/bigfiretux-right-1.png",
2761 bigfiretux_right[2] = load_image(DATA_PREFIX "/images/shared/bigfiretux-right-2.png",
2764 bigfiretux_right_jump =
2765 load_image(DATA_PREFIX "/images/shared/bigfiretux-right-jump.png", USE_ALPHA);
2767 bigfiretux_left[0] = load_image(DATA_PREFIX "/images/shared/bigfiretux-left-0.png",
2770 bigfiretux_left[1] = load_image(DATA_PREFIX "/images/shared/bigfiretux-left-1.png",
2773 bigfiretux_left[2] = load_image(DATA_PREFIX "/images/shared/bigfiretux-left-2.png",
2776 bigfiretux_left_jump =
2777 load_image(DATA_PREFIX "/images/shared/bigfiretux-left-jump.png", USE_ALPHA);
2780 load_image(DATA_PREFIX "/images/shared/bigcape-right-0.png",
2784 load_image(DATA_PREFIX "/images/shared/bigcape-right-1.png",
2788 load_image(DATA_PREFIX "/images/shared/bigcape-left-0.png",
2792 load_image(DATA_PREFIX "/images/shared/bigcape-left-1.png",
2796 ducktux_right = load_image(DATA_PREFIX
2797 "/images/shared/ducktux-right.png",
2800 ducktux_left = load_image(DATA_PREFIX
2801 "/images/shared/ducktux-left.png",
2804 skidtux_right = load_image(DATA_PREFIX
2805 "/images/shared/skidtux-right.png",
2808 skidtux_left = load_image(DATA_PREFIX
2809 "/images/shared/skidtux-left.png",
2812 duckfiretux_right = load_image(DATA_PREFIX
2813 "/images/shared/duckfiretux-right.png",
2816 duckfiretux_left = load_image(DATA_PREFIX
2817 "/images/shared/duckfiretux-left.png",
2820 skidfiretux_right = load_image(DATA_PREFIX
2821 "/images/shared/skidfiretux-right.png",
2824 skidfiretux_left = load_image(DATA_PREFIX
2825 "/images/shared/skidfiretux-left.png",
2831 img_box_full = load_image(DATA_PREFIX "/images/shared/box-full.png",
2833 img_box_empty = load_image(DATA_PREFIX "/images/shared/box-empty.png",
2840 img_water = load_image(DATA_PREFIX "/images/shared/water.png", IGNORE_ALPHA);
2842 img_waves[0] = load_image(DATA_PREFIX "/images/shared/waves-0.png",
2845 img_waves[1] = load_image(DATA_PREFIX "/images/shared/waves-1.png",
2848 img_waves[2] = load_image(DATA_PREFIX "/images/shared/waves-2.png",
2854 img_pole = load_image(DATA_PREFIX "/images/shared/pole.png", USE_ALPHA);
2855 img_poletop = load_image(DATA_PREFIX "/images/shared/poletop.png",
2861 img_flag[0] = load_image(DATA_PREFIX "/images/shared/flag-0.png",
2863 img_flag[1] = load_image(DATA_PREFIX "/images/shared/flag-1.png",
2869 img_cloud[0][0] = load_image(DATA_PREFIX "/images/shared/cloud-00.png",
2872 img_cloud[0][1] = load_image(DATA_PREFIX "/images/shared/cloud-01.png",
2875 img_cloud[0][2] = load_image(DATA_PREFIX "/images/shared/cloud-02.png",
2878 img_cloud[0][3] = load_image(DATA_PREFIX "/images/shared/cloud-03.png",
2882 img_cloud[1][0] = load_image(DATA_PREFIX "/images/shared/cloud-10.png",
2885 img_cloud[1][1] = load_image(DATA_PREFIX "/images/shared/cloud-11.png",
2888 img_cloud[1][2] = load_image(DATA_PREFIX "/images/shared/cloud-12.png",
2891 img_cloud[1][3] = load_image(DATA_PREFIX "/images/shared/cloud-13.png",
2899 img_bsod_left[0] = load_image(DATA_PREFIX
2900 "/images/shared/bsod-left-0.png",
2903 img_bsod_left[1] = load_image(DATA_PREFIX
2904 "/images/shared/bsod-left-1.png",
2907 img_bsod_left[2] = load_image(DATA_PREFIX
2908 "/images/shared/bsod-left-2.png",
2911 img_bsod_left[3] = load_image(DATA_PREFIX
2912 "/images/shared/bsod-left-3.png",
2915 img_bsod_right[0] = load_image(DATA_PREFIX
2916 "/images/shared/bsod-right-0.png",
2919 img_bsod_right[1] = load_image(DATA_PREFIX
2920 "/images/shared/bsod-right-1.png",
2923 img_bsod_right[2] = load_image(DATA_PREFIX
2924 "/images/shared/bsod-right-2.png",
2927 img_bsod_right[3] = load_image(DATA_PREFIX
2928 "/images/shared/bsod-right-3.png",
2931 img_bsod_squished_left = load_image(DATA_PREFIX
2932 "/images/shared/bsod-squished-left.png",
2935 img_bsod_squished_right = load_image(DATA_PREFIX
2936 "/images/shared/bsod-squished-right.png",
2939 img_bsod_falling_left = load_image(DATA_PREFIX
2940 "/images/shared/bsod-falling-left.png",
2943 img_bsod_falling_right = load_image(DATA_PREFIX
2944 "/images/shared/bsod-falling-right.png",
2950 img_laptop_left[0] = load_image(DATA_PREFIX
2951 "/images/shared/laptop-left-0.png",
2954 img_laptop_left[1] = load_image(DATA_PREFIX
2955 "/images/shared/laptop-left-1.png",
2958 img_laptop_left[2] = load_image(DATA_PREFIX
2959 "/images/shared/laptop-left-2.png",
2962 img_laptop_right[0] = load_image(DATA_PREFIX
2963 "/images/shared/laptop-right-0.png",
2966 img_laptop_right[1] = load_image(DATA_PREFIX
2967 "/images/shared/laptop-right-1.png",
2970 img_laptop_right[2] = load_image(DATA_PREFIX
2971 "/images/shared/laptop-right-2.png",
2974 img_laptop_flat_left = load_image(DATA_PREFIX
2975 "/images/shared/laptop-flat-left.png",
2978 img_laptop_flat_right = load_image(DATA_PREFIX
2979 "/images/shared/laptop-flat-right.png",
2982 img_laptop_falling_left =
2983 load_image(DATA_PREFIX
2984 "/images/shared/laptop-falling-left.png",
2987 img_laptop_falling_right =
2988 load_image(DATA_PREFIX
2989 "/images/shared/laptop-falling-right.png",
2995 img_money_left[0] = load_image(DATA_PREFIX
2996 "/images/shared/bag-left-0.png",
2999 img_money_left[1] = load_image(DATA_PREFIX
3000 "/images/shared/bag-left-1.png",
3003 img_money_right[0] = load_image(DATA_PREFIX
3004 "/images/shared/bag-right-0.png",
3007 img_money_right[1] = load_image(DATA_PREFIX
3008 "/images/shared/bag-right-1.png",
3015 img_mints = load_image(DATA_PREFIX "/images/shared/mints.png", USE_ALPHA);
3016 img_coffee = load_image(DATA_PREFIX "/images/shared/coffee.png", USE_ALPHA);
3021 img_bullet = load_image(DATA_PREFIX "/images/shared/bullet.png", USE_ALPHA);
3023 img_red_glow = load_image(DATA_PREFIX "/images/shared/red-glow.png",
3030 img_distro[0] = load_image(DATA_PREFIX "/images/shared/distro-0.png",
3033 img_distro[1] = load_image(DATA_PREFIX "/images/shared/distro-1.png",
3036 img_distro[2] = load_image(DATA_PREFIX "/images/shared/distro-2.png",
3039 img_distro[3] = load_image(DATA_PREFIX "/images/shared/distro-3.png",
3045 tux_life = load_image(DATA_PREFIX "/images/shared/tux-life.png",
3050 img_golden_herring =
3051 load_image(DATA_PREFIX "/images/shared/golden-herring.png",
3055 /* Super background: */
3057 img_super_bkgd = load_image(DATA_PREFIX "/images/shared/super-bkgd.png",
3061 /* Sound effects: */
3063 /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
3064 // initialize sounds[i] with the correct pointer's value:
3065 // NULL or something else. And it will be dangerous to
3066 // play with not-initialized pointers.
3067 // This is also true with if (use_music)
3068 Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
3070 for (i = 0; i < NUM_SOUNDS; i++)
3071 sounds[i] = load_sound(soundfilenames[i]);
3074 herring_song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
3075 strlen("SALCON.MOD") + 8)); /* FIXME: We need a real herring_song! Thats a fake.:) */
3077 sprintf(herring_song_path, "%s/music/%s", DATA_PREFIX, "SALCON.MOD");
3079 herring_song = load_song(herring_song_path);
3081 free(herring_song_path);
3086 /* Free shared data: */
3088 void unloadshared(void)
3092 for (i = 0; i < 3; i++)
3094 SDL_FreeSurface(tux_right[i]);
3095 SDL_FreeSurface(tux_left[i]);
3096 SDL_FreeSurface(bigtux_right[i]);
3097 SDL_FreeSurface(bigtux_left[i]);
3100 SDL_FreeSurface(bigtux_right_jump);
3101 SDL_FreeSurface(bigtux_left_jump);
3103 for (i = 0; i < 2; i++)
3105 SDL_FreeSurface(cape_right[i]);
3106 SDL_FreeSurface(cape_left[i]);
3107 SDL_FreeSurface(bigcape_right[i]);
3108 SDL_FreeSurface(bigcape_left[i]);
3111 SDL_FreeSurface(ducktux_left);
3112 SDL_FreeSurface(ducktux_right);
3114 SDL_FreeSurface(skidtux_left);
3115 SDL_FreeSurface(skidtux_right);
3117 for (i = 0; i < 4; i++)
3119 SDL_FreeSurface(img_bsod_left[i]);
3120 SDL_FreeSurface(img_bsod_right[i]);
3123 SDL_FreeSurface(img_bsod_squished_left);
3124 SDL_FreeSurface(img_bsod_squished_right);
3126 SDL_FreeSurface(img_bsod_falling_left);
3127 SDL_FreeSurface(img_bsod_falling_right);
3129 for (i = 0; i < 3; i++)
3131 SDL_FreeSurface(img_laptop_left[i]);
3132 SDL_FreeSurface(img_laptop_right[i]);
3135 SDL_FreeSurface(img_laptop_flat_left);
3136 SDL_FreeSurface(img_laptop_flat_right);
3138 SDL_FreeSurface(img_laptop_falling_left);
3139 SDL_FreeSurface(img_laptop_falling_right);
3141 for (i = 0; i < 2; i++)
3143 SDL_FreeSurface(img_money_left[i]);
3144 SDL_FreeSurface(img_money_right[i]);
3147 SDL_FreeSurface(img_box_full);
3148 SDL_FreeSurface(img_box_empty);
3150 SDL_FreeSurface(img_water);
3151 for (i = 0; i < 3; i++)
3152 SDL_FreeSurface(img_waves[i]);
3154 SDL_FreeSurface(img_pole);
3155 SDL_FreeSurface(img_poletop);
3157 for (i = 0; i < 2; i++)
3158 SDL_FreeSurface(img_flag[i]);
3160 SDL_FreeSurface(img_mints);
3161 SDL_FreeSurface(img_coffee);
3163 for (i = 0; i < 4; i++)
3165 SDL_FreeSurface(img_distro[i]);
3166 SDL_FreeSurface(img_cloud[0][i]);
3167 SDL_FreeSurface(img_cloud[1][i]);
3170 SDL_FreeSurface(img_golden_herring);
3172 for (i = 0; i < NUM_SOUNDS; i++)
3173 free_chunk(sounds[i]);
3175 /* free the herring song */
3176 free_music( herring_song );
3180 /* Draw a tile on the screen: */
3182 void drawshape(int x, int y, unsigned char c)
3186 if (c == 'X' || c == 'x')
3187 drawimage(img_brick[0], x, y, NO_UPDATE);
3188 else if (c == 'Y' || c == 'y')
3189 drawimage(img_brick[1], x, y, NO_UPDATE);
3190 else if (c == 'A' || c =='B' || c == '!')
3191 drawimage(img_box_full, x, y, NO_UPDATE);
3193 drawimage(img_box_empty, x, y, NO_UPDATE);
3194 else if (c >= 'C' && c <= 'F')
3195 drawimage(img_cloud[0][c - 'C'], x, y, NO_UPDATE);
3196 else if (c >= 'c' && c <= 'f')
3197 drawimage(img_cloud[1][c - 'c'], x, y, NO_UPDATE);
3198 else if (c >= 'G' && c <= 'J')
3199 drawimage(img_bkgd[0][c - 'G'], x, y, NO_UPDATE);
3200 else if (c >= 'g' && c <= 'j')
3201 drawimage(img_bkgd[1][c - 'g'], x, y, NO_UPDATE);
3203 drawimage(img_solid[0], x, y, NO_UPDATE);
3205 drawimage(img_solid[1], x, y, NO_UPDATE);
3207 drawimage(img_solid[2], x, y, NO_UPDATE);
3209 drawimage(img_solid[3], x, y, NO_UPDATE);
3212 z = (frame / 2) % 6;
3215 drawimage(img_distro[z], x, y, NO_UPDATE);
3217 drawimage(img_distro[2], x, y, NO_UPDATE);
3219 drawimage(img_distro[1], x, y, NO_UPDATE);
3223 z = (frame / 3) % 3;
3225 drawimage(img_waves[z], x, y, NO_UPDATE);
3228 drawimage(img_poletop, x, y, NO_UPDATE);
3231 drawimage(img_pole, x, y, NO_UPDATE);
3233 /* Mark this as the end position of the level! */
3239 z = (frame / 3) % 2;
3241 drawimage(img_flag[z], x + 16, y, NO_UPDATE);
3244 drawimage(img_water, x, y, NO_UPDATE);
3248 /* What shape is at some position? */
3250 unsigned char shape(int x, int y, int sx)
3256 xx = ((x + sx) / 32);
3258 if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
3269 int issolid(int x, int y, int sx)
3275 if (isbrick(x, y, sx) ||
3276 isbrick(x + 31, y, sx) ||
3278 isice(x + 31, y, sx) ||
3279 (shape(x, y, sx) == '[' ||
3280 shape(x + 31, y, sx) == '[') ||
3281 (shape(x, y, sx) == '=' ||
3282 shape(x + 31, y, sx) == '=') ||
3283 (shape(x, y, sx) == ']' ||
3284 shape(x + 31, y, sx) == ']') ||
3285 (shape(x, y, sx) == 'A' ||
3286 shape(x + 31, y, sx) == 'A') ||
3287 (shape(x, y, sx) == 'B' ||
3288 shape(x + 31, y, sx) == 'B') ||
3289 (shape(x, y, sx) == '!' ||
3290 shape(x + 31, y, sx) == '!') ||
3291 (shape(x, y, sx) == 'a' ||
3292 shape(x + 31, y, sx) == 'a'))
3301 /* Is it a brick? */
3303 int isbrick(int x, int y, int sx)
3309 if (shape(x, y, sx) == 'X' ||
3310 shape(x, y, sx) == 'x' ||
3311 shape(x, y, sx) == 'Y' ||
3312 shape(x, y, sx) == 'y')
3323 int isice(int x, int y, int sx)
3329 if (shape(x, y, sx) == '#')
3338 /* Is it a full box? */
3340 int isfullbox(int x, int y, int sx)
3346 if (shape(x, y, sx) == 'A' ||
3347 shape(x, y, sx) == 'B' ||
3348 shape(x, y, sx) == '!')
3357 /* Edit a piece of the map! */
3359 void change(int x, int y, int sx, unsigned char c)
3364 xx = ((x + sx) / 32);
3366 if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
3371 /* Break a brick: */
3373 void trybreakbrick(int x, int y, int sx)
3375 if (isbrick(x, y, sx))
3377 if (shape(x, y, sx) == 'x' || shape(x, y, sx) == 'y')
3379 /* Get a distro from it: */
3381 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3384 if (counting_distros == NO)
3386 counting_distros = YES;
3387 distro_counter = 50;
3390 if (distro_counter <= 0)
3391 change(x, y, sx, 'a');
3393 play_sound(sounds[SND_DISTRO]);
3394 score = score + SCORE_DISTRO;
3399 /* Get rid of it: */
3401 change(x, y, sx, '.');
3405 /* Replace it with broken bits: */
3407 add_broken_brick(((x + sx + 1) / 32) * 32,
3411 /* Get some score: */
3413 play_sound(sounds[SND_BRICK]);
3414 score = score + SCORE_BRICK;
3419 /* Bounce a brick: */
3421 void bumpbrick(int x, int y, int sx)
3423 add_bouncy_brick(((x + sx + 1) / 32) * 32,
3426 play_sound(sounds[SND_BRICK]);
3432 void tryemptybox(int x, int y, int sx)
3434 if (isfullbox(x, y, sx))
3436 if (shape(x, y, sx) == 'A')
3438 /* Box with a distro! */
3440 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3441 (y / 32) * 32 - 32);
3443 play_sound(sounds[SND_DISTRO]);
3444 score = score + SCORE_DISTRO;
3447 else if (shape(x, y, sx) == 'B')
3449 /* Add an upgrade! */
3451 if (tux_size == SMALL)
3453 /* Tux is small, add mints! */
3455 add_upgrade(((x + sx + 1) / 32) * 32,
3461 /* Tux is big, add coffee: */
3463 add_upgrade(((x + sx + 1) / 32) * 32,
3468 play_sound(sounds[SND_UPGRADE]);
3470 else if (shape(x, y, sx) == '!')
3472 /* Add a golden herring */
3474 add_upgrade(((x + sx + 1) / 32) * 32,
3479 /* Empty the box: */
3481 change(x, y, sx, 'a');
3486 /* Try to grab a distro: */
3488 void trygrabdistro(int x, int y, int sx, int bounciness)
3490 if (shape(x, y, sx) == '$')
3492 change(x, y, sx, '.');
3493 play_sound(sounds[SND_DISTRO]);
3495 if (bounciness == BOUNCE)
3497 add_bouncy_distro(((x + sx + 1) / 32) * 32,
3501 score = score + SCORE_DISTRO;
3507 /* Add a bouncy distro: */
3509 void add_bouncy_distro(int x, int y)
3515 for (i = 0; i < NUM_BOUNCY_DISTROS && found == -1; i++)
3517 if (!bouncy_distros[i].alive)
3523 bouncy_distros[found].alive = YES;
3524 bouncy_distros[found].x = x;
3525 bouncy_distros[found].y = y;
3526 bouncy_distros[found].ym = -6;
3531 /* Add broken brick pieces: */
3533 void add_broken_brick(int x, int y)
3535 add_broken_brick_piece(x, y, -4, -16);
3536 add_broken_brick_piece(x, y + 16, -6, -12);
3538 add_broken_brick_piece(x + 16, y, 4, -16);
3539 add_broken_brick_piece(x + 16, y + 16, 6, -12);
3543 /* Add a broken brick piece: */
3545 void add_broken_brick_piece(int x, int y, int xm, int ym)
3551 for (i = 0; i < NUM_BROKEN_BRICKS && found == -1; i++)
3553 if (!broken_bricks[i].alive)
3559 broken_bricks[found].alive = YES;
3560 broken_bricks[found].x = x;
3561 broken_bricks[found].y = y;
3562 broken_bricks[found].xm = xm;
3563 broken_bricks[found].ym = ym;
3568 /* Add a bouncy brick piece: */
3570 void add_bouncy_brick(int x, int y)
3576 for (i = 0; i < NUM_BOUNCY_BRICKS && found == -1; i++)
3578 if (!bouncy_bricks[i].alive)
3584 bouncy_bricks[found].alive = YES;
3585 bouncy_bricks[found].x = x;
3586 bouncy_bricks[found].y = y;
3587 bouncy_bricks[found].offset = 0;
3588 bouncy_bricks[found].offset_m = -BOUNCY_BRICK_SPEED;
3589 bouncy_bricks[found].shape = shape(x, y, 0);
3594 /* Add a bad guy: */
3596 void add_bad_guy(int x, int y, int kind)
3602 for (i = 0; i < NUM_BAD_GUYS && found == -1; i++)
3604 if (!bad_guys[i].alive)
3610 bad_guys[found].alive = YES;
3611 bad_guys[found].mode = NORMAL;
3612 bad_guys[found].dying = NO;
3613 bad_guys[found].timer = 0;
3614 bad_guys[found].kind = kind;
3615 bad_guys[found].x = x;
3616 bad_guys[found].y = y;
3617 bad_guys[found].xm = 0;
3618 bad_guys[found].ym = 0;
3619 bad_guys[found].dir = LEFT;
3620 bad_guys[found].seen = NO;
3627 void add_score(int x, int y, int s)
3632 /* Add the score: */
3637 /* Add a floating score thing to the game: */
3641 for (i = 0; i < NUM_FLOATING_SCORES && found == -1; i++)
3643 if (!floating_scores[i].alive)
3650 floating_scores[found].alive = YES;
3651 floating_scores[found].x = x;
3652 floating_scores[found].y = y - 16;
3653 floating_scores[found].timer = 8;
3654 floating_scores[found].value = s;
3659 /* Try to bump a bad guy from below: */
3661 void trybumpbadguy(int x, int y, int sx)
3668 for (i = 0; i < NUM_BAD_GUYS; i++)
3670 if (bad_guys[i].alive &&
3671 bad_guys[i].x >= x + sx - 32 && bad_guys[i].x <= x + sx + 32 &&
3672 bad_guys[i].y >= y - 16 && bad_guys[i].y <= y + 16)
3674 if (bad_guys[i].kind == BAD_BSOD ||
3675 bad_guys[i].kind == BAD_LAPTOP)
3677 bad_guys[i].dying = FALLING;
3678 bad_guys[i].ym = -8;
3679 play_sound(sounds[SND_FALL]);
3687 for (i = 0; i < NUM_UPGRADES; i++)
3689 if (upgrades[i].alive && upgrades[i].height == 32 &&
3690 upgrades[i].x >= x + sx - 32 && upgrades[i].x <= x + sx + 32 &&
3691 upgrades[i].y >= y - 16 && upgrades[i].y <= y + 16)
3693 upgrades[i].xm = -upgrades[i].xm;
3694 upgrades[i].ym = -8;
3695 play_sound(sounds[SND_BUMP_UPGRADE]);
3701 /* Add an upgrade: */
3703 void add_upgrade(int x, int y, int kind)
3709 for (i = 0; i < NUM_UPGRADES && found == -1; i++)
3711 if (!upgrades[i].alive)
3717 upgrades[found].alive = YES;
3718 upgrades[found].kind = kind;
3719 upgrades[found].x = x;
3720 upgrades[found].y = y;
3721 upgrades[found].xm = 4;
3722 upgrades[found].ym = -4;
3723 upgrades[found].height = 0;
3730 void killtux(int mode)
3734 play_sound(sounds[SND_HURT]);
3736 if (tux_dir == RIGHT)
3738 else if (tux_dir == LEFT)
3741 if (mode == SHRINK && tux_size == BIG)
3744 tux_got_coffee = NO;
3748 tux_safe = TUX_SAFE_TIME;
3759 void add_bullet(int x, int y, int dir, int xm)
3765 for (i = 0; i < NUM_BULLETS && found == -1; i++)
3767 if (!bullets[i].alive)
3773 bullets[found].alive = YES;
3777 bullets[found].x = x + 32;
3778 bullets[found].xm = BULLET_XM + xm;
3782 bullets[found].x = x;
3783 bullets[found].xm = -BULLET_XM + xm;
3786 bullets[found].y = y;
3787 bullets[found].ym = BULLET_STARTING_YM;
3789 play_sound(sounds[SND_SHOOT]);
3794 void drawendscreen(void)
3798 clearscreen(0, 0, 0);
3800 drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE);
3802 sprintf(str, "SCORE: %d", score);
3803 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
3805 sprintf(str, "DISTROS: %d", distros);
3806 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
3812 void drawresultscreen(void)
3816 clearscreen(0, 0, 0);
3818 drawcenteredtext("Result:", 200, letters_red, NO_UPDATE);
3820 sprintf(str, "SCORE: %d", score);
3821 drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
3823 sprintf(str, "DISTROS: %d", distros);
3824 drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
3827 /*SDL_Delay(2000);*/