1 /* first part of synchro.
3 * game logic for players.
5 * large switch statement for tiles the player interacts with.
12 extern int centered_player_nr;
15 #define USE_CHANGED_ACID_STUFF 1
17 extern boolean checkIfAllPlayersFitToScreen();
19 static void check_player(struct PLAYER *);
20 static void kill_player(struct PLAYER *);
21 static boolean player_digfield(struct PLAYER *, int, int);
22 static boolean player_killed(struct PLAYER *);
31 game_em.any_player_moving = FALSE;
33 /* must test for death and actually kill separately */
35 for (i = 0; i < MAX_PLAYERS; i++)
37 boolean ply_kill = player_killed(&ply[i]);
39 if (ply[i].alive && ply_kill)
45 /* must test for death and actually kill separately */
46 boolean ply1_kill = player_killed(&ply1);
47 boolean ply2_kill = player_killed(&ply2);
49 if (ply1.alive && ply1_kill)
51 if (ply2.alive && ply2_kill)
57 ply1.alive = 1; /* debugging */
62 for (i = 0; i < MAX_PLAYERS; i++)
64 ply[i].oldx = ply[i].x;
65 ply[i].oldy = ply[i].y;
66 ply[i].anim = SPR_still;
69 start_check_nr = (RandomEM & 128 ? 0 : 1) * 2 + (RandomEM & 256 ? 0 : 1);
71 for (i = 0; i < MAX_PLAYERS; i++)
73 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
75 if (ply[check_nr].alive)
76 check_player(&ply[check_nr]);
79 for (i = 0; i < MAX_PLAYERS; i++)
84 if (Cave[ply[i].oldy][ply[i].oldx] == Zplayer)
86 Cave[ply[i].oldy][ply[i].oldx] = Xblank;
87 Next[ply[i].oldy][ply[i].oldx] = Xblank;
90 if (Cave[ply[i].y][ply[i].x] == Xblank)
92 Cave[ply[i].y][ply[i].x] = Zplayer;
93 Next[ply[i].y][ply[i].x] = Zplayer;
101 ply1.anim = SPR_still;
104 ply2.anim = SPR_still;
108 if (ply1.alive) check_player(&ply1);
109 if (ply2.alive) check_player(&ply2);
113 if (ply2.alive) check_player(&ply2);
114 if (ply1.alive) check_player(&ply1);
119 if (Cave[ply1.oldy][ply1.oldx] == Zplayer)
121 Cave[ply1.oldy][ply1.oldx] = Xblank;
122 Next[ply1.oldy][ply1.oldx] = Xblank;
125 if (Cave[ply1.y][ply1.x] == Xblank)
127 Cave[ply1.y][ply1.x] = Zplayer;
128 Next[ply1.y][ply1.x] = Zplayer;
134 if (Cave[ply2.oldy][ply2.oldx] == Zplayer)
136 Cave[ply2.oldy][ply2.oldx] = Xblank;
137 Next[ply2.oldy][ply2.oldx] = Xblank;
140 if (Cave[ply2.y][ply2.x] == Xblank)
142 Cave[ply2.y][ply2.x] = Zplayer;
143 Next[ply2.y][ply2.x] = Zplayer;
150 static boolean player_killed(struct PLAYER *ply)
156 printf("::: %d: %d, %d\n", ply->num, x, y);
163 if (lev.killed_out_of_time && setup.time_limit)
166 if (lev.time_initial > 0 && lev.time == 0 && setup.time_limit)
257 case Yacid_splash_eB:
258 case Yacid_splash_wB:
280 static void kill_player(struct PLAYER *ply)
297 Cave[y-1][x] = Xboom_bug;
299 play_element_sound(x, y, SAMPLE_boom, Zplayer);
311 Cave[y-1][x] = Xboom_bomb;
313 play_element_sound(x, y, SAMPLE_boom, Zplayer);
328 Cave[y][x+1] = Xboom_bug;
330 play_element_sound(x, y, SAMPLE_boom, Zplayer);
342 Cave[y][x+1] = Xboom_bomb;
344 play_element_sound(x, y, SAMPLE_boom, Zplayer);
359 Cave[y+1][x] = Xboom_bug;
361 play_element_sound(x, y, SAMPLE_boom, Zplayer);
373 Cave[y+1][x] = Xboom_bomb;
375 play_element_sound(x, y, SAMPLE_boom, Zplayer);
390 Cave[y][x-1] = Xboom_bug;
392 play_element_sound(x, y, SAMPLE_boom, Zplayer);
404 Cave[y][x-1] = Xboom_bomb;
406 play_element_sound(x, y, SAMPLE_boom, Zplayer);
416 play_element_sound(x, y, SAMPLE_exit_leave, Xexit_1);
420 play_element_sound(x, y, SAMPLE_die, Zplayer);
426 #if USE_CHANGED_ACID_STUFF
439 Cave[y][x] = Xboom_1;
445 static void check_player(struct PLAYER *ply)
454 game_em.last_player_direction[ply->num] = MV_NONE;
457 printf("::: up == %d, down == %d, left == %d, right == %d, fire == %d [spin == %d, stick == %d]\n",
458 ply->joy_n, ply->joy_s, ply->joy_w, ply->joy_e, ply->joy_fire,
459 ply->joy_spin, ply->joy_stick);
463 if (ply->joy_w) /* west */
469 else if (ply->joy_e) /* east */
476 if (ply->joy_n) /* north */
482 else if (ply->joy_s) /* south */
491 if ((ply->joy_spin = !ply->joy_spin))
493 if (ply->joy_n) /* north */
499 else if (ply->joy_e) /* east */
505 else if (ply->joy_s) /* south */
511 else if (ply->joy_w) /* west */
520 if (ply->joy_w) /* west */
526 else if (ply->joy_s) /* south */
532 else if (ply->joy_e) /* east */
538 else if (ply->joy_n) /* north */
553 boolean players_visible_before_move;
554 boolean players_visible_after_move;
557 players_visible_before_move = checkIfAllPlayersFitToScreen();
562 players_visible_after_move = checkIfAllPlayersFitToScreen();
565 player is allowed to move only in the following cases:
566 - it is not needed to display all players (not focussed to all players)
567 - all players are (still or again) visible after the move
568 - some players were already outside visible screen area before the move
570 can_move = (game.centered_player_nr != -1 ||
571 players_visible_after_move ||
572 !players_visible_before_move);
579 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
585 if (dx == 0 && dy == 0)
591 if (++ply->dynamite_cnt == 5 && ply->dynamite)
593 Cave[y][x] = Xdynamite_1;
594 play_element_sound(x, y, SAMPLE_dynamite, Xdynamite_1);
600 ply->dynamite_cnt = 0;
603 RandomEM += 7; /* be a bit more random if the player doesn't move */
609 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
610 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
611 ply->joy_spin = !ply->joy_spin;
613 if (ply->joy_snap == 0) /* player wants to move */
615 boolean moved = FALSE;
617 if (ply->last_move_dir & MV_HORIZONTAL)
619 if (!(moved = player_digfield(ply, 0, dy)))
620 moved = player_digfield(ply, dx, 0);
624 if (!(moved = player_digfield(ply, dx, 0)))
625 moved = player_digfield(ply, 0, dy);
631 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
632 else if (oldy != ply->y)
633 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
635 game_em.any_player_moving = TRUE;
636 game_em.last_moving_player = ply->num;
637 game_em.last_player_direction[ply->num] = ply->last_move_dir;
640 else /* player wants to snap */
642 player_digfield(ply, dx, dy);
646 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
648 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
653 boolean result = TRUE;
655 if (!dx && !dy) /* no direction specified */
658 if (dx && dy && ply->joy_snap) /* more than one direction specified */
661 if (ply->joy_snap == 0) /* player wants to move */
663 int element = Cave[y][x];
667 /* fire is released */
669 case Yacid_splash_eB:
670 case Yacid_splash_wB:
671 Cave[y][x] = Zplayer;
672 Next[y][x] = Zplayer;
683 play_element_sound(x, y, SAMPLE_blank, Xblank);
684 ply->anim = SPR_walk + anim;
689 #if USE_CHANGED_ACID_STUFF
698 if (Cave[y-1][x+1] == Xblank)
699 Cave[y-1][x+1] = Yacid_splash_eB;
700 if (Cave[y-1][x-1] == Xblank)
701 Cave[y-1][x-1] = Yacid_splash_wB;
702 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
724 #if !USE_CHANGED_ACID_STUFF
734 ply->anim = SPR_walk + anim;
740 Cave[y][x] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
741 (dx > 0 ? Ygrass_eB : Ygrass_wB));
742 Next[y][x] = Zplayer;
743 play_element_sound(x, y, SAMPLE_dirt, Xgrass);
744 ply->anim = SPR_walk + anim;
750 Cave[y][x] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
751 (dx > 0 ? Ydirt_eB : Ydirt_wB));
752 Next[y][x] = Zplayer;
753 play_element_sound(x, y, SAMPLE_dirt, Xdirt);
754 ply->anim = SPR_walk + anim;
761 Cave[y][x] = Ydiamond_eat;
762 Next[y][x] = Zplayer;
763 play_element_sound(x, y, SAMPLE_collect, element);
764 lev.score += lev.diamond_score;
765 lev.required = lev.required < 3 ? 0 : lev.required - 3;
766 ply->anim = SPR_walk + anim;
773 Cave[y][x] = Yemerald_eat;
774 Next[y][x] = Zplayer;
775 play_element_sound(x, y, SAMPLE_collect, element);
776 lev.score += lev.emerald_score;
777 lev.required = lev.required < 1 ? 0 : lev.required - 1;
778 ply->anim = SPR_walk + anim;
784 Cave[y][x] = Ydynamite_eat;
785 Next[y][x] = Zplayer;
786 play_element_sound(x, y, SAMPLE_collect, element);
787 lev.score += lev.dynamite_score;
788 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
789 ply->anim = SPR_walk + anim;
796 Cave[y][x] = Ykey_1_eat;
801 Cave[y][x] = Ykey_2_eat;
806 Cave[y][x] = Ykey_3_eat;
811 Cave[y][x] = Ykey_4_eat;
816 Cave[y][x] = Ykey_5_eat;
821 Cave[y][x] = Ykey_6_eat;
826 Cave[y][x] = Ykey_7_eat;
831 Cave[y][x] = Ykey_8_eat;
836 Next[y][x] = Zplayer;
837 play_element_sound(x, y, SAMPLE_collect, element);
838 lev.score += lev.key_score;
839 ply->anim = SPR_walk + anim;
845 Cave[y][x] = Ylenses_eat;
846 Next[y][x] = Zplayer;
847 play_element_sound(x, y, SAMPLE_collect, element);
848 lev.score += lev.lenses_score;
849 lev.lenses_cnt = lev.lenses_time;
850 ply->anim = SPR_walk + anim;
856 Cave[y][x] = Ymagnify_eat;
857 Next[y][x] = Zplayer;
858 play_element_sound(x, y, SAMPLE_collect, element);
859 lev.score += lev.magnify_score;
860 lev.magnify_cnt = lev.magnify_time;
861 ply->anim = SPR_walk + anim;
870 switch(Cave[y][x+dx])
880 if (Cave[y-1][x+dx+1] == Xblank)
881 Cave[y-1][x+dx+1] = Yacid_splash_eB;
882 if (Cave[y-1][x+dx-1] == Xblank)
883 Cave[y-1][x+dx-1] = Yacid_splash_wB;
884 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
888 case Yacid_splash_eB:
889 case Yacid_splash_wB:
890 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
891 Next[y][x+dx] = Xstone_pause;
895 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
896 Next[y][x] = Zplayer;
897 play_element_sound(x, y, SAMPLE_roll, Xstone);
901 ply->anim = SPR_push + anim;
908 switch(Cave[y][x+dx])
918 if (Cave[y-1][x+dx+1] == Xblank)
919 Cave[y-1][x+dx+1] = Yacid_splash_eB;
920 if (Cave[y-1][x+dx-1] == Xblank)
921 Cave[y-1][x+dx-1] = Yacid_splash_wB;
922 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
926 case Yacid_splash_eB:
927 case Yacid_splash_wB:
928 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
929 Next[y][x+dx] = Xbomb_pause;
933 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
934 Next[y][x] = Zplayer;
935 play_element_sound(x, y, SAMPLE_roll, Xbomb);
939 ply->anim = SPR_push + anim;
946 switch(Cave[y][x+dx])
956 if (Cave[y-1][x+dx+1] == Xblank)
957 Cave[y-1][x+dx+1] = Yacid_splash_eB;
958 if (Cave[y-1][x+dx-1] == Xblank)
959 Cave[y-1][x+dx-1] = Yacid_splash_wB;
960 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
964 case Yacid_splash_eB:
965 case Yacid_splash_wB:
966 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
967 Next[y][x+dx] = Xnut_pause;
971 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
972 Next[y][x] = Zplayer;
973 play_element_sound(x, y, SAMPLE_roll, Xnut);
977 ply->anim = SPR_push + anim;
984 switch(Cave[y][x+dx])
988 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
989 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
990 Next[y][x] = Zplayer;
991 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
992 play_element_sound(x, y, SAMPLE_slurp, Xalien);
993 lev.score += lev.slurp_score;
1005 if (Cave[y-1][x+dx+1] == Xblank)
1006 Cave[y-1][x+dx+1] = Yacid_splash_eB;
1007 if (Cave[y-1][x+dx-1] == Xblank)
1008 Cave[y-1][x+dx-1] = Yacid_splash_wB;
1009 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
1013 case Yacid_splash_eB:
1014 case Yacid_splash_wB:
1015 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
1016 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
1019 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
1020 Next[y][x] = Zplayer;
1021 play_element_sound(x, y, SAMPLE_roll, Xspring);
1025 ply->anim = SPR_push + anim;
1032 case Xsand_stonein_1:
1033 case Xsand_stonein_2:
1034 case Xsand_stonein_3:
1035 case Xsand_stonein_4:
1039 ply->anim = SPR_push + anim;
1043 switch(Cave[y+dy][x+dx])
1053 if (Cave[y+dy-1][x+dx+1] == Xblank)
1054 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
1055 if (Cave[y+dy-1][x+dx-1] == Xblank)
1056 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
1057 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
1061 case Yacid_splash_eB:
1062 case Yacid_splash_wB:
1063 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
1064 (dx > 0 ? Yballoon_e : Yballoon_w));
1065 Next[y+dy][x+dx] = Xballoon;
1068 Cave[y][x] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
1069 (dx > 0 ? Yballoon_eB : Yballoon_wB));
1070 Next[y][x] = Zplayer;
1071 play_element_sound(x, y, SAMPLE_push, Xballoon);
1076 ply->anim = SPR_push + anim;
1088 switch(Cave[y+dy][x+dx])
1098 if (Cave[y+dy-1][x+dx+1] == Xblank)
1099 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
1100 if (Cave[y+dy-1][x+dx-1] == Xblank)
1101 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
1102 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
1106 case Yacid_splash_eB:
1107 case Yacid_splash_wB:
1108 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
1109 (dx > 0 ? Yandroid_e : Yandroid_w));
1110 Next[y+dy][x+dx] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
1111 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
1114 Cave[y][x] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
1115 (dx > 0 ? Yandroid_eB : Yandroid_wB));
1116 Next[y][x] = Zplayer;
1117 play_element_sound(x, y, SAMPLE_push, Xandroid);
1122 ply->anim = SPR_push + anim;
1127 if (ply->keys & 0x01)
1134 if (ply->keys & 0x02)
1141 if (ply->keys & 0x04)
1148 if (ply->keys & 0x08)
1155 if (ply->keys & 0x10)
1162 if (ply->keys & 0x20)
1169 if (ply->keys & 0x40)
1176 if (ply->keys & 0x80)
1182 if (!tab_blank[Cave[y+dy][x+dx]])
1185 Cave[y+dy][x+dx] = Zplayer;
1186 Next[y+dy][x+dx] = Zplayer;
1187 play_element_sound(x, y, SAMPLE_door, element);
1188 ply->anim = SPR_walk + anim;
1194 play_element_sound(x, y, SAMPLE_press, element);
1195 lev.wheel_cnt = lev.wheel_time;
1201 lev.wind_direction = 0;
1205 lev.wind_direction = 1;
1209 lev.wind_direction = 2;
1213 lev.wind_direction = 3;
1217 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1221 play_element_sound(x, y, SAMPLE_press, element);
1222 lev.wind_cnt = lev.wind_time;
1226 play_element_sound(x, y, SAMPLE_press, element);
1231 play_element_sound(x, y, SAMPLE_press, element);
1232 lev.ball_cnt = lev.ball_time;
1233 lev.ball_state = !lev.ball_state;
1237 Cave[y][x] = Yplant;
1238 Next[y][x] = Xplant;
1239 play_element_sound(x, y, SAMPLE_blank, Xplant);
1240 ply->anim = SPR_walk + anim;
1248 play_element_sound(x, y, SAMPLE_exit_leave, Xexit_1);
1253 /* !!! CHECK SCORE CALCULATION !!! */
1254 if (lev.home == 0 && lev.time_initial > 0) /* game won */
1255 lev.score += lev.time * lev.exit_score / 100;
1258 ply->anim = SPR_walk + anim;
1265 if (ply->x == oldx && ply->y == oldy) /* no movement */
1268 else /* player wants to snap */
1270 int element = Cave[y][x];
1274 /* fire is pressed */
1277 Cave[y][x] = Ygrass_eat;
1278 Next[y][x] = Xblank;
1279 play_element_sound(x, y, SAMPLE_dirt, element);
1280 ply->anim = SPR_spray + anim;
1284 Cave[y][x] = Ydirt_eat;
1285 Next[y][x] = Xblank;
1286 play_element_sound(x, y, SAMPLE_dirt, element);
1287 ply->anim = SPR_spray + anim;
1291 case Xdiamond_pause:
1292 Cave[y][x] = Ydiamond_eat;
1293 Next[y][x] = Xblank;
1294 play_element_sound(x, y, SAMPLE_collect, element);
1295 lev.score += lev.diamond_score;
1296 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1297 ply->anim = SPR_walk + anim;
1301 case Xemerald_pause:
1302 Cave[y][x] = Yemerald_eat;
1303 Next[y][x] = Xblank;
1304 play_element_sound(x, y, SAMPLE_collect, element);
1305 lev.score += lev.emerald_score;
1306 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1307 ply->anim = SPR_walk + anim;
1311 Cave[y][x] = Ydynamite_eat;
1312 Next[y][x] = Xblank;
1313 play_element_sound(x, y, SAMPLE_collect, element);
1314 lev.score += lev.dynamite_score;
1315 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1316 ply->anim = SPR_walk + anim;
1321 Cave[y][x] = Ykey_1_eat;
1326 Cave[y][x] = Ykey_2_eat;
1331 Cave[y][x] = Ykey_3_eat;
1336 Cave[y][x] = Ykey_4_eat;
1341 Cave[y][x] = Ykey_5_eat;
1346 Cave[y][x] = Ykey_6_eat;
1351 Cave[y][x] = Ykey_7_eat;
1356 Cave[y][x] = Ykey_8_eat;
1360 Next[y][x] = Xblank;
1361 play_element_sound(x, y, SAMPLE_collect, element);
1362 lev.score += lev.key_score;
1363 ply->anim = SPR_walk + anim;
1367 Cave[y][x] = Ylenses_eat;
1368 Next[y][x] = Xblank;
1369 play_element_sound(x, y, SAMPLE_collect, element);
1370 lev.score += lev.lenses_score;
1371 lev.lenses_cnt = lev.lenses_time;
1372 ply->anim = SPR_walk + anim;
1376 Cave[y][x] = Ymagnify_eat;
1377 Next[y][x] = Xblank;
1378 play_element_sound(x, y, SAMPLE_collect, element);
1379 lev.score += lev.magnify_score;
1380 lev.magnify_cnt = lev.magnify_time;
1381 ply->anim = SPR_walk + anim;