1 /* first part of synchro.
3 * game logic for players.
5 * large switch statement for tiles the player interacts with.
11 #define USE_CHANGED_ACID_STUFF 1
13 static void check_player(struct PLAYER *);
14 static void kill_player(struct PLAYER *);
15 static boolean player_digfield(struct PLAYER *, int, int);
16 static boolean player_killed(struct PLAYER *);
23 game_em.any_player_moving = FALSE;
24 game_em.any_player_snapping = FALSE;
26 /* must test for death and actually kill separately */
27 for (i = 0; i < MAX_PLAYERS; i++)
29 boolean ply_kill = player_killed(&ply[i]);
31 if (ply[i].alive && ply_kill)
35 for (i = 0; i < MAX_PLAYERS; i++)
37 ply[i].oldx = ply[i].x;
38 ply[i].oldy = ply[i].y;
39 ply[i].anim = SPR_still;
42 start_check_nr = (RandomEM & 128 ? 0 : 1) * 2 + (RandomEM & 256 ? 0 : 1);
44 for (i = 0; i < MAX_PLAYERS; i++)
46 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
48 if (ply[check_nr].alive)
49 check_player(&ply[check_nr]);
52 for (i = 0; i < MAX_PLAYERS; i++)
57 if (Cave[ply[i].oldy][ply[i].oldx] == Zplayer)
59 Cave[ply[i].oldy][ply[i].oldx] = Xblank;
60 Next[ply[i].oldy][ply[i].oldx] = Xblank;
63 if (Cave[ply[i].y][ply[i].x] == Xblank)
65 Cave[ply[i].y][ply[i].x] = Zplayer;
66 Next[ply[i].y][ply[i].x] = Zplayer;
71 static boolean player_killed(struct PLAYER *ply)
79 if (lev.killed_out_of_time && setup.time_limit)
169 case Yacid_splash_eB:
170 case Yacid_splash_wB:
192 static void kill_player(struct PLAYER *ply)
209 Cave[y-1][x] = Xboom_bug;
220 Cave[y-1][x] = Xboom_bomb;
234 Cave[y][x+1] = Xboom_bug;
245 Cave[y][x+1] = Xboom_bomb;
259 Cave[y+1][x] = Xboom_bug;
270 Cave[y+1][x] = Xboom_bomb;
284 Cave[y][x-1] = Xboom_bug;
295 Cave[y][x-1] = Xboom_bomb;
306 play_element_sound(x, y, SAMPLE_exit_leave, Xexit_1);
310 play_element_sound(x, y, SAMPLE_die, Zplayer);
316 #if USE_CHANGED_ACID_STUFF
329 Cave[y][x] = Xboom_1;
335 static void check_player(struct PLAYER *ply)
343 game_em.last_player_direction[ply->num] = MV_NONE;
345 if (ply->joy_w) /* west */
350 else if (ply->joy_e) /* east */
356 if (ply->joy_n) /* north */
361 else if (ply->joy_s) /* south */
373 boolean players_visible_before_move;
374 boolean players_visible_after_move;
377 players_visible_before_move = checkIfAllPlayersFitToScreen();
382 players_visible_after_move = checkIfAllPlayersFitToScreen();
385 player is allowed to move only in the following cases:
386 - it is not needed to display all players (not focussed to all players)
387 - all players are (still or again) visible after the move
388 - some players were already outside visible screen area before the move
390 can_move = (game.centered_player_nr != -1 ||
391 players_visible_after_move ||
392 !players_visible_before_move);
399 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
405 if (dx == 0 && dy == 0)
411 if (++ply->dynamite_cnt == 5 && ply->dynamite)
413 Cave[y][x] = Xdynamite_1;
414 play_element_sound(x, y, SAMPLE_dynamite, Xdynamite_1);
420 ply->dynamite_cnt = 0;
423 RandomEM += 7; /* be a bit more random if the player doesn't move */
429 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
430 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
431 ply->joy_spin = !ply->joy_spin;
433 if (ply->joy_snap == 0) /* player wants to move */
435 boolean moved = FALSE;
437 if (ply->last_move_dir & MV_HORIZONTAL)
439 if (!(moved = player_digfield(ply, 0, dy)))
440 moved = player_digfield(ply, dx, 0);
444 if (!(moved = player_digfield(ply, dx, 0)))
445 moved = player_digfield(ply, 0, dy);
451 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
452 else if (oldy != ply->y)
453 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
455 game_em.any_player_moving = TRUE;
456 game_em.last_moving_player = ply->num;
457 game_em.last_player_direction[ply->num] = ply->last_move_dir;
460 else /* player wants to snap */
462 game_em.any_player_snapping = player_digfield(ply, dx, dy);
466 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
468 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
473 boolean result = TRUE;
475 if (!dx && !dy) /* no direction specified */
478 if (dx && dy && ply->joy_snap) /* more than one direction specified */
481 if (ply->joy_snap == 0) /* player wants to move */
483 int element = Cave[y][x];
487 /* fire is released */
489 case Yacid_splash_eB:
490 case Yacid_splash_wB:
491 Cave[y][x] = Zplayer;
492 Next[y][x] = Zplayer;
503 play_element_sound(x, y, SAMPLE_blank, Xblank);
504 ply->anim = SPR_walk + anim;
509 #if USE_CHANGED_ACID_STUFF
518 if (Cave[y-1][x+1] == Xblank)
519 Cave[y-1][x+1] = Yacid_splash_eB;
520 if (Cave[y-1][x-1] == Xblank)
521 Cave[y-1][x-1] = Yacid_splash_wB;
522 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
544 #if !USE_CHANGED_ACID_STUFF
554 ply->anim = SPR_walk + anim;
560 Cave[y][x] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
561 (dx > 0 ? Ygrass_eB : Ygrass_wB));
562 Next[y][x] = Zplayer;
563 play_element_sound(x, y, SAMPLE_dirt, Xgrass);
564 ply->anim = SPR_walk + anim;
570 Cave[y][x] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
571 (dx > 0 ? Ydirt_eB : Ydirt_wB));
572 Next[y][x] = Zplayer;
573 play_element_sound(x, y, SAMPLE_dirt, Xdirt);
574 ply->anim = SPR_walk + anim;
581 Cave[y][x] = Ydiamond_eat;
582 Next[y][x] = Zplayer;
583 play_element_sound(x, y, SAMPLE_collect, element);
584 lev.score += lev.diamond_score;
585 lev.required = lev.required < 3 ? 0 : lev.required - 3;
586 game.snapshot.collected_item = TRUE;
587 ply->anim = SPR_walk + anim;
594 Cave[y][x] = Yemerald_eat;
595 Next[y][x] = Zplayer;
596 play_element_sound(x, y, SAMPLE_collect, element);
597 lev.score += lev.emerald_score;
598 lev.required = lev.required < 1 ? 0 : lev.required - 1;
599 game.snapshot.collected_item = TRUE;
600 ply->anim = SPR_walk + anim;
606 Cave[y][x] = Ydynamite_eat;
607 Next[y][x] = Zplayer;
608 play_element_sound(x, y, SAMPLE_collect, element);
609 lev.score += lev.dynamite_score;
610 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
611 ply->anim = SPR_walk + anim;
618 Cave[y][x] = Ykey_1_eat;
623 Cave[y][x] = Ykey_2_eat;
628 Cave[y][x] = Ykey_3_eat;
633 Cave[y][x] = Ykey_4_eat;
638 Cave[y][x] = Ykey_5_eat;
643 Cave[y][x] = Ykey_6_eat;
648 Cave[y][x] = Ykey_7_eat;
653 Cave[y][x] = Ykey_8_eat;
658 Next[y][x] = Zplayer;
659 play_element_sound(x, y, SAMPLE_collect, element);
660 lev.score += lev.key_score;
661 ply->anim = SPR_walk + anim;
667 Cave[y][x] = Ylenses_eat;
668 Next[y][x] = Zplayer;
669 play_element_sound(x, y, SAMPLE_collect, element);
670 lev.score += lev.lenses_score;
671 lev.lenses_cnt = lev.lenses_time;
672 ply->anim = SPR_walk + anim;
678 Cave[y][x] = Ymagnify_eat;
679 Next[y][x] = Zplayer;
680 play_element_sound(x, y, SAMPLE_collect, element);
681 lev.score += lev.magnify_score;
682 lev.magnify_cnt = lev.magnify_time;
683 ply->anim = SPR_walk + anim;
692 switch(Cave[y][x+dx])
702 if (Cave[y-1][x+dx+1] == Xblank)
703 Cave[y-1][x+dx+1] = Yacid_splash_eB;
704 if (Cave[y-1][x+dx-1] == Xblank)
705 Cave[y-1][x+dx-1] = Yacid_splash_wB;
706 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
710 case Yacid_splash_eB:
711 case Yacid_splash_wB:
712 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
713 Next[y][x+dx] = Xstone_pause;
717 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
718 Next[y][x] = Zplayer;
719 play_element_sound(x, y, SAMPLE_roll, Xstone);
723 ply->anim = SPR_push + anim;
730 switch(Cave[y][x+dx])
740 if (Cave[y-1][x+dx+1] == Xblank)
741 Cave[y-1][x+dx+1] = Yacid_splash_eB;
742 if (Cave[y-1][x+dx-1] == Xblank)
743 Cave[y-1][x+dx-1] = Yacid_splash_wB;
744 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
748 case Yacid_splash_eB:
749 case Yacid_splash_wB:
750 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
751 Next[y][x+dx] = Xbomb_pause;
755 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
756 Next[y][x] = Zplayer;
757 play_element_sound(x, y, SAMPLE_roll, Xbomb);
761 ply->anim = SPR_push + anim;
768 switch(Cave[y][x+dx])
778 if (Cave[y-1][x+dx+1] == Xblank)
779 Cave[y-1][x+dx+1] = Yacid_splash_eB;
780 if (Cave[y-1][x+dx-1] == Xblank)
781 Cave[y-1][x+dx-1] = Yacid_splash_wB;
782 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
786 case Yacid_splash_eB:
787 case Yacid_splash_wB:
788 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
789 Next[y][x+dx] = Xnut_pause;
793 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
794 Next[y][x] = Zplayer;
795 play_element_sound(x, y, SAMPLE_roll, Xnut);
799 ply->anim = SPR_push + anim;
806 switch(Cave[y][x+dx])
810 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
811 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
812 Next[y][x] = Zplayer;
813 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
814 play_element_sound(x, y, SAMPLE_slurp, Xalien);
815 lev.score += lev.slurp_score;
827 if (Cave[y-1][x+dx+1] == Xblank)
828 Cave[y-1][x+dx+1] = Yacid_splash_eB;
829 if (Cave[y-1][x+dx-1] == Xblank)
830 Cave[y-1][x+dx-1] = Yacid_splash_wB;
831 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
835 case Yacid_splash_eB:
836 case Yacid_splash_wB:
837 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
838 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
841 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
842 Next[y][x] = Zplayer;
843 play_element_sound(x, y, SAMPLE_roll, Xspring);
847 ply->anim = SPR_push + anim;
854 case Xsand_stonein_1:
855 case Xsand_stonein_2:
856 case Xsand_stonein_3:
857 case Xsand_stonein_4:
861 ply->anim = SPR_push + anim;
865 switch(Cave[y+dy][x+dx])
875 if (Cave[y+dy-1][x+dx+1] == Xblank)
876 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
877 if (Cave[y+dy-1][x+dx-1] == Xblank)
878 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
879 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
883 case Yacid_splash_eB:
884 case Yacid_splash_wB:
885 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
886 (dx > 0 ? Yballoon_e : Yballoon_w));
887 Next[y+dy][x+dx] = Xballoon;
890 Cave[y][x] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
891 (dx > 0 ? Yballoon_eB : Yballoon_wB));
892 Next[y][x] = Zplayer;
893 play_element_sound(x, y, SAMPLE_push, Xballoon);
898 ply->anim = SPR_push + anim;
910 switch(Cave[y+dy][x+dx])
920 if (Cave[y+dy-1][x+dx+1] == Xblank)
921 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
922 if (Cave[y+dy-1][x+dx-1] == Xblank)
923 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
924 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
928 case Yacid_splash_eB:
929 case Yacid_splash_wB:
930 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
931 (dx > 0 ? Yandroid_e : Yandroid_w));
932 Next[y+dy][x+dx] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
933 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
936 Cave[y][x] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
937 (dx > 0 ? Yandroid_eB : Yandroid_wB));
938 Next[y][x] = Zplayer;
939 play_element_sound(x, y, SAMPLE_push, Xandroid);
944 ply->anim = SPR_push + anim;
949 if (ply->keys & 0x01)
956 if (ply->keys & 0x02)
963 if (ply->keys & 0x04)
970 if (ply->keys & 0x08)
977 if (ply->keys & 0x10)
984 if (ply->keys & 0x20)
991 if (ply->keys & 0x40)
998 if (ply->keys & 0x80)
1004 if (!tab_blank[Cave[y+dy][x+dx]])
1007 Cave[y+dy][x+dx] = Zplayer;
1008 Next[y+dy][x+dx] = Zplayer;
1009 play_element_sound(x, y, SAMPLE_door, element);
1010 ply->anim = SPR_walk + anim;
1016 play_element_sound(x, y, SAMPLE_press, element);
1017 lev.wheel_cnt = lev.wheel_time;
1023 lev.wind_direction = 0;
1027 lev.wind_direction = 1;
1031 lev.wind_direction = 2;
1035 lev.wind_direction = 3;
1039 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1043 play_element_sound(x, y, SAMPLE_press, element);
1044 lev.wind_cnt = lev.wind_time;
1048 play_element_sound(x, y, SAMPLE_press, element);
1053 play_element_sound(x, y, SAMPLE_press, element);
1054 lev.ball_cnt = lev.ball_time;
1055 lev.ball_state = !lev.ball_state;
1059 Cave[y][x] = Yplant;
1060 Next[y][x] = Xplant;
1061 play_element_sound(x, y, SAMPLE_blank, Xplant);
1062 ply->anim = SPR_walk + anim;
1073 game_em.level_solved = TRUE;
1075 ply->anim = SPR_walk + anim;
1082 if (ply->x == oldx && ply->y == oldy) /* no movement */
1085 else /* player wants to snap */
1087 int element = Cave[y][x];
1091 /* fire is pressed */
1094 Cave[y][x] = Ygrass_eat;
1095 Next[y][x] = Xblank;
1096 play_element_sound(x, y, SAMPLE_dirt, element);
1097 ply->anim = SPR_spray + anim;
1101 Cave[y][x] = Ydirt_eat;
1102 Next[y][x] = Xblank;
1103 play_element_sound(x, y, SAMPLE_dirt, element);
1104 ply->anim = SPR_spray + anim;
1108 case Xdiamond_pause:
1109 Cave[y][x] = Ydiamond_eat;
1110 Next[y][x] = Xblank;
1111 play_element_sound(x, y, SAMPLE_collect, element);
1112 lev.score += lev.diamond_score;
1113 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1114 game.snapshot.collected_item = TRUE;
1115 ply->anim = SPR_walk + anim;
1119 case Xemerald_pause:
1120 Cave[y][x] = Yemerald_eat;
1121 Next[y][x] = Xblank;
1122 play_element_sound(x, y, SAMPLE_collect, element);
1123 lev.score += lev.emerald_score;
1124 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1125 game.snapshot.collected_item = TRUE;
1126 ply->anim = SPR_walk + anim;
1130 Cave[y][x] = Ydynamite_eat;
1131 Next[y][x] = Xblank;
1132 play_element_sound(x, y, SAMPLE_collect, element);
1133 lev.score += lev.dynamite_score;
1134 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1135 ply->anim = SPR_walk + anim;
1140 Cave[y][x] = Ykey_1_eat;
1145 Cave[y][x] = Ykey_2_eat;
1150 Cave[y][x] = Ykey_3_eat;
1155 Cave[y][x] = Ykey_4_eat;
1160 Cave[y][x] = Ykey_5_eat;
1165 Cave[y][x] = Ykey_6_eat;
1170 Cave[y][x] = Ykey_7_eat;
1175 Cave[y][x] = Ykey_8_eat;
1179 Next[y][x] = Xblank;
1180 play_element_sound(x, y, SAMPLE_collect, element);
1181 lev.score += lev.key_score;
1182 ply->anim = SPR_walk + anim;
1186 Cave[y][x] = Ylenses_eat;
1187 Next[y][x] = Xblank;
1188 play_element_sound(x, y, SAMPLE_collect, element);
1189 lev.score += lev.lenses_score;
1190 lev.lenses_cnt = lev.lenses_time;
1191 ply->anim = SPR_walk + anim;
1195 Cave[y][x] = Ymagnify_eat;
1196 Next[y][x] = Xblank;
1197 play_element_sound(x, y, SAMPLE_collect, element);
1198 lev.score += lev.magnify_score;
1199 lev.magnify_cnt = lev.magnify_time;
1200 ply->anim = SPR_walk + anim;