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 #if PLAY_ELEMENT_SOUND
300 play_element_sound(x, y, SAMPLE_boom, Zplayer);
313 Cave[y-1][x] = Xboom_bomb;
315 #if PLAY_ELEMENT_SOUND
316 play_element_sound(x, y, SAMPLE_boom, Zplayer);
332 Cave[y][x+1] = Xboom_bug;
334 #if PLAY_ELEMENT_SOUND
335 play_element_sound(x, y, SAMPLE_boom, Zplayer);
348 Cave[y][x+1] = Xboom_bomb;
350 #if PLAY_ELEMENT_SOUND
351 play_element_sound(x, y, SAMPLE_boom, Zplayer);
367 Cave[y+1][x] = Xboom_bug;
369 #if PLAY_ELEMENT_SOUND
370 play_element_sound(x, y, SAMPLE_boom, Zplayer);
383 Cave[y+1][x] = Xboom_bomb;
385 #if PLAY_ELEMENT_SOUND
386 play_element_sound(x, y, SAMPLE_boom, Zplayer);
402 Cave[y][x-1] = Xboom_bug;
404 #if PLAY_ELEMENT_SOUND
405 play_element_sound(x, y, SAMPLE_boom, Zplayer);
418 Cave[y][x-1] = Xboom_bomb;
420 #if PLAY_ELEMENT_SOUND
421 play_element_sound(x, y, SAMPLE_boom, Zplayer);
434 play_element_sound(x, y, SAMPLE_exit_leave, Xexit_1);
438 #if PLAY_ELEMENT_SOUND
439 play_element_sound(x, y, SAMPLE_boom, Zplayer);
441 play_element_sound(x, y, SAMPLE_die, Zplayer);
447 #if USE_CHANGED_ACID_STUFF
460 Cave[y][x] = Xboom_1;
466 static void check_player(struct PLAYER *ply)
475 game_em.last_player_direction[ply->num] = MV_NONE;
478 printf("::: up == %d, down == %d, left == %d, right == %d, fire == %d [spin == %d, stick == %d]\n",
479 ply->joy_n, ply->joy_s, ply->joy_w, ply->joy_e, ply->joy_fire,
480 ply->joy_spin, ply->joy_stick);
484 if (ply->joy_w) /* west */
490 else if (ply->joy_e) /* east */
497 if (ply->joy_n) /* north */
503 else if (ply->joy_s) /* south */
512 if ((ply->joy_spin = !ply->joy_spin))
514 if (ply->joy_n) /* north */
520 else if (ply->joy_e) /* east */
526 else if (ply->joy_s) /* south */
532 else if (ply->joy_w) /* west */
541 if (ply->joy_w) /* west */
547 else if (ply->joy_s) /* south */
553 else if (ply->joy_e) /* east */
559 else if (ply->joy_n) /* north */
574 boolean players_visible_before_move;
575 boolean players_visible_after_move;
578 players_visible_before_move = checkIfAllPlayersFitToScreen();
583 players_visible_after_move = checkIfAllPlayersFitToScreen();
586 player is allowed to move only in the following cases:
587 - it is not needed to display all players (not focussed to all players)
588 - all players are (still or again) visible after the move
589 - some players were already outside visible screen area before the move
591 can_move = (game.centered_player_nr != -1 ||
592 players_visible_after_move ||
593 !players_visible_before_move);
600 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
606 if (dx == 0 && dy == 0)
612 if (++ply->dynamite_cnt == 5 && ply->dynamite)
614 Cave[y][x] = Xdynamite_1;
615 play_element_sound(x, y, SAMPLE_dynamite, Xdynamite_1);
621 ply->dynamite_cnt = 0;
624 RandomEM += 7; /* be a bit more random if the player doesn't move */
630 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
631 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
632 ply->joy_spin = !ply->joy_spin;
634 if (ply->joy_snap == 0) /* player wants to move */
636 boolean moved = FALSE;
638 if (ply->last_move_dir & MV_HORIZONTAL)
640 if (!(moved = player_digfield(ply, 0, dy)))
641 moved = player_digfield(ply, dx, 0);
645 if (!(moved = player_digfield(ply, dx, 0)))
646 moved = player_digfield(ply, 0, dy);
652 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
653 else if (oldy != ply->y)
654 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
656 game_em.any_player_moving = TRUE;
657 game_em.last_moving_player = ply->num;
658 game_em.last_player_direction[ply->num] = ply->last_move_dir;
661 else /* player wants to snap */
663 player_digfield(ply, dx, dy);
667 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
669 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
674 boolean result = TRUE;
676 if (!dx && !dy) /* no direction specified */
679 if (dx && dy && ply->joy_snap) /* more than one direction specified */
682 if (ply->joy_snap == 0) /* player wants to move */
684 int element = Cave[y][x];
688 /* fire is released */
690 case Yacid_splash_eB:
691 case Yacid_splash_wB:
692 Cave[y][x] = Zplayer;
693 Next[y][x] = Zplayer;
704 play_element_sound(x, y, SAMPLE_blank, Xblank);
705 ply->anim = SPR_walk + anim;
710 #if USE_CHANGED_ACID_STUFF
719 if (Cave[y-1][x+1] == Xblank)
720 Cave[y-1][x+1] = Yacid_splash_eB;
721 if (Cave[y-1][x-1] == Xblank)
722 Cave[y-1][x-1] = Yacid_splash_wB;
723 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
745 #if !USE_CHANGED_ACID_STUFF
755 ply->anim = SPR_walk + anim;
761 Cave[y][x] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
762 (dx > 0 ? Ygrass_eB : Ygrass_wB));
763 Next[y][x] = Zplayer;
764 play_element_sound(x, y, SAMPLE_dirt, Xgrass);
765 ply->anim = SPR_walk + anim;
771 Cave[y][x] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
772 (dx > 0 ? Ydirt_eB : Ydirt_wB));
773 Next[y][x] = Zplayer;
774 play_element_sound(x, y, SAMPLE_dirt, Xdirt);
775 ply->anim = SPR_walk + anim;
782 Cave[y][x] = Ydiamond_eat;
783 Next[y][x] = Zplayer;
784 play_element_sound(x, y, SAMPLE_collect, element);
785 lev.score += lev.diamond_score;
786 lev.required = lev.required < 3 ? 0 : lev.required - 3;
787 ply->anim = SPR_walk + anim;
794 Cave[y][x] = Yemerald_eat;
795 Next[y][x] = Zplayer;
796 play_element_sound(x, y, SAMPLE_collect, element);
797 lev.score += lev.emerald_score;
798 lev.required = lev.required < 1 ? 0 : lev.required - 1;
799 ply->anim = SPR_walk + anim;
805 Cave[y][x] = Ydynamite_eat;
806 Next[y][x] = Zplayer;
807 play_element_sound(x, y, SAMPLE_collect, element);
808 lev.score += lev.dynamite_score;
809 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
810 ply->anim = SPR_walk + anim;
817 Cave[y][x] = Ykey_1_eat;
822 Cave[y][x] = Ykey_2_eat;
827 Cave[y][x] = Ykey_3_eat;
832 Cave[y][x] = Ykey_4_eat;
837 Cave[y][x] = Ykey_5_eat;
842 Cave[y][x] = Ykey_6_eat;
847 Cave[y][x] = Ykey_7_eat;
852 Cave[y][x] = Ykey_8_eat;
857 Next[y][x] = Zplayer;
858 play_element_sound(x, y, SAMPLE_collect, element);
859 lev.score += lev.key_score;
860 ply->anim = SPR_walk + anim;
866 Cave[y][x] = Ylenses_eat;
867 Next[y][x] = Zplayer;
868 play_element_sound(x, y, SAMPLE_collect, element);
869 lev.score += lev.lenses_score;
870 lev.lenses_cnt = lev.lenses_time;
871 ply->anim = SPR_walk + anim;
877 Cave[y][x] = Ymagnify_eat;
878 Next[y][x] = Zplayer;
879 play_element_sound(x, y, SAMPLE_collect, element);
880 lev.score += lev.magnify_score;
881 lev.magnify_cnt = lev.magnify_time;
882 ply->anim = SPR_walk + anim;
891 switch(Cave[y][x+dx])
901 if (Cave[y-1][x+dx+1] == Xblank)
902 Cave[y-1][x+dx+1] = Yacid_splash_eB;
903 if (Cave[y-1][x+dx-1] == Xblank)
904 Cave[y-1][x+dx-1] = Yacid_splash_wB;
905 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
909 case Yacid_splash_eB:
910 case Yacid_splash_wB:
911 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
912 Next[y][x+dx] = Xstone_pause;
916 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
917 Next[y][x] = Zplayer;
918 play_element_sound(x, y, SAMPLE_roll, Xstone);
922 ply->anim = SPR_push + anim;
929 switch(Cave[y][x+dx])
939 if (Cave[y-1][x+dx+1] == Xblank)
940 Cave[y-1][x+dx+1] = Yacid_splash_eB;
941 if (Cave[y-1][x+dx-1] == Xblank)
942 Cave[y-1][x+dx-1] = Yacid_splash_wB;
943 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
947 case Yacid_splash_eB:
948 case Yacid_splash_wB:
949 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
950 Next[y][x+dx] = Xbomb_pause;
954 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
955 Next[y][x] = Zplayer;
956 play_element_sound(x, y, SAMPLE_roll, Xbomb);
960 ply->anim = SPR_push + anim;
967 switch(Cave[y][x+dx])
977 if (Cave[y-1][x+dx+1] == Xblank)
978 Cave[y-1][x+dx+1] = Yacid_splash_eB;
979 if (Cave[y-1][x+dx-1] == Xblank)
980 Cave[y-1][x+dx-1] = Yacid_splash_wB;
981 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
985 case Yacid_splash_eB:
986 case Yacid_splash_wB:
987 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
988 Next[y][x+dx] = Xnut_pause;
992 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
993 Next[y][x] = Zplayer;
994 play_element_sound(x, y, SAMPLE_roll, Xnut);
998 ply->anim = SPR_push + anim;
1005 switch(Cave[y][x+dx])
1009 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
1010 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
1011 Next[y][x] = Zplayer;
1012 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
1013 play_element_sound(x, y, SAMPLE_slurp, Xalien);
1014 lev.score += lev.slurp_score;
1026 if (Cave[y-1][x+dx+1] == Xblank)
1027 Cave[y-1][x+dx+1] = Yacid_splash_eB;
1028 if (Cave[y-1][x+dx-1] == Xblank)
1029 Cave[y-1][x+dx-1] = Yacid_splash_wB;
1030 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
1034 case Yacid_splash_eB:
1035 case Yacid_splash_wB:
1036 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
1037 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
1040 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
1041 Next[y][x] = Zplayer;
1042 play_element_sound(x, y, SAMPLE_roll, Xspring);
1046 ply->anim = SPR_push + anim;
1053 case Xsand_stonein_1:
1054 case Xsand_stonein_2:
1055 case Xsand_stonein_3:
1056 case Xsand_stonein_4:
1060 ply->anim = SPR_push + anim;
1064 switch(Cave[y+dy][x+dx])
1074 if (Cave[y+dy-1][x+dx+1] == Xblank)
1075 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
1076 if (Cave[y+dy-1][x+dx-1] == Xblank)
1077 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
1078 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
1082 case Yacid_splash_eB:
1083 case Yacid_splash_wB:
1084 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
1085 (dx > 0 ? Yballoon_e : Yballoon_w));
1086 Next[y+dy][x+dx] = Xballoon;
1089 Cave[y][x] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
1090 (dx > 0 ? Yballoon_eB : Yballoon_wB));
1091 Next[y][x] = Zplayer;
1092 play_element_sound(x, y, SAMPLE_push, Xballoon);
1097 ply->anim = SPR_push + anim;
1109 switch(Cave[y+dy][x+dx])
1119 if (Cave[y+dy-1][x+dx+1] == Xblank)
1120 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
1121 if (Cave[y+dy-1][x+dx-1] == Xblank)
1122 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
1123 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
1127 case Yacid_splash_eB:
1128 case Yacid_splash_wB:
1129 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
1130 (dx > 0 ? Yandroid_e : Yandroid_w));
1131 Next[y+dy][x+dx] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
1132 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
1135 Cave[y][x] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
1136 (dx > 0 ? Yandroid_eB : Yandroid_wB));
1137 Next[y][x] = Zplayer;
1138 play_element_sound(x, y, SAMPLE_push, Xandroid);
1143 ply->anim = SPR_push + anim;
1148 if (ply->keys & 0x01)
1155 if (ply->keys & 0x02)
1162 if (ply->keys & 0x04)
1169 if (ply->keys & 0x08)
1176 if (ply->keys & 0x10)
1183 if (ply->keys & 0x20)
1190 if (ply->keys & 0x40)
1197 if (ply->keys & 0x80)
1203 if (!tab_blank[Cave[y+dy][x+dx]])
1206 Cave[y+dy][x+dx] = Zplayer;
1207 Next[y+dy][x+dx] = Zplayer;
1208 play_element_sound(x, y, SAMPLE_door, element);
1209 ply->anim = SPR_walk + anim;
1215 play_element_sound(x, y, SAMPLE_press, element);
1216 lev.wheel_cnt = lev.wheel_time;
1222 lev.wind_direction = 0;
1226 lev.wind_direction = 1;
1230 lev.wind_direction = 2;
1234 lev.wind_direction = 3;
1238 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1242 play_element_sound(x, y, SAMPLE_press, element);
1243 lev.wind_cnt = lev.wind_time;
1247 play_element_sound(x, y, SAMPLE_press, element);
1252 play_element_sound(x, y, SAMPLE_press, element);
1253 lev.ball_cnt = lev.ball_time;
1254 lev.ball_state = !lev.ball_state;
1258 Cave[y][x] = Yplant;
1259 Next[y][x] = Xplant;
1260 play_element_sound(x, y, SAMPLE_blank, Xplant);
1261 ply->anim = SPR_walk + anim;
1270 /* !!! already played in kill_player !!! */
1271 play_element_sound(x, y, SAMPLE_exit_leave, Xexit_1);
1277 /* !!! CHECK SCORE CALCULATION !!! */
1278 if (lev.home == 0 && lev.time_initial > 0) /* game won */
1279 lev.score += lev.time * lev.exit_score / 100;
1282 ply->anim = SPR_walk + anim;
1289 if (ply->x == oldx && ply->y == oldy) /* no movement */
1292 else /* player wants to snap */
1294 int element = Cave[y][x];
1298 /* fire is pressed */
1301 Cave[y][x] = Ygrass_eat;
1302 Next[y][x] = Xblank;
1303 play_element_sound(x, y, SAMPLE_dirt, element);
1304 ply->anim = SPR_spray + anim;
1308 Cave[y][x] = Ydirt_eat;
1309 Next[y][x] = Xblank;
1310 play_element_sound(x, y, SAMPLE_dirt, element);
1311 ply->anim = SPR_spray + anim;
1315 case Xdiamond_pause:
1316 Cave[y][x] = Ydiamond_eat;
1317 Next[y][x] = Xblank;
1318 play_element_sound(x, y, SAMPLE_collect, element);
1319 lev.score += lev.diamond_score;
1320 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1321 ply->anim = SPR_walk + anim;
1325 case Xemerald_pause:
1326 Cave[y][x] = Yemerald_eat;
1327 Next[y][x] = Xblank;
1328 play_element_sound(x, y, SAMPLE_collect, element);
1329 lev.score += lev.emerald_score;
1330 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1331 ply->anim = SPR_walk + anim;
1335 Cave[y][x] = Ydynamite_eat;
1336 Next[y][x] = Xblank;
1337 play_element_sound(x, y, SAMPLE_collect, element);
1338 lev.score += lev.dynamite_score;
1339 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1340 ply->anim = SPR_walk + anim;
1345 Cave[y][x] = Ykey_1_eat;
1350 Cave[y][x] = Ykey_2_eat;
1355 Cave[y][x] = Ykey_3_eat;
1360 Cave[y][x] = Ykey_4_eat;
1365 Cave[y][x] = Ykey_5_eat;
1370 Cave[y][x] = Ykey_6_eat;
1375 Cave[y][x] = Ykey_7_eat;
1380 Cave[y][x] = Ykey_8_eat;
1384 Next[y][x] = Xblank;
1385 play_element_sound(x, y, SAMPLE_collect, element);
1386 lev.score += lev.key_score;
1387 ply->anim = SPR_walk + anim;
1391 Cave[y][x] = Ylenses_eat;
1392 Next[y][x] = Xblank;
1393 play_element_sound(x, y, SAMPLE_collect, element);
1394 lev.score += lev.lenses_score;
1395 lev.lenses_cnt = lev.lenses_time;
1396 ply->anim = SPR_walk + anim;
1400 Cave[y][x] = Ymagnify_eat;
1401 Next[y][x] = Xblank;
1402 play_element_sound(x, y, SAMPLE_collect, element);
1403 lev.score += lev.magnify_score;
1404 lev.magnify_cnt = lev.magnify_time;
1405 ply->anim = SPR_walk + anim;