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 extern boolean checkIfAllPlayersFitToScreen();
15 static void check_player(struct PLAYER *);
16 static void kill_player(struct PLAYER *);
17 static boolean player_digfield(struct PLAYER *, int, int);
18 static boolean player_killed(struct PLAYER *);
25 game_em.any_player_moving = FALSE;
27 /* must test for death and actually kill separately */
28 for (i = 0; i < MAX_PLAYERS; i++)
30 boolean ply_kill = player_killed(&ply[i]);
32 if (ply[i].alive && ply_kill)
36 for (i = 0; i < MAX_PLAYERS; i++)
38 ply[i].oldx = ply[i].x;
39 ply[i].oldy = ply[i].y;
40 ply[i].anim = SPR_still;
43 start_check_nr = (RandomEM & 128 ? 0 : 1) * 2 + (RandomEM & 256 ? 0 : 1);
45 for (i = 0; i < MAX_PLAYERS; i++)
47 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
49 if (ply[check_nr].alive)
50 check_player(&ply[check_nr]);
53 for (i = 0; i < MAX_PLAYERS; i++)
58 if (Cave[ply[i].oldy][ply[i].oldx] == Zplayer)
60 Cave[ply[i].oldy][ply[i].oldx] = Xblank;
61 Next[ply[i].oldy][ply[i].oldx] = Xblank;
64 if (Cave[ply[i].y][ply[i].x] == Xblank)
66 Cave[ply[i].y][ply[i].x] = Zplayer;
67 Next[ply[i].y][ply[i].x] = Zplayer;
72 static boolean player_killed(struct PLAYER *ply)
80 if (lev.killed_out_of_time && setup.time_limit)
170 case Yacid_splash_eB:
171 case Yacid_splash_wB:
193 static void kill_player(struct PLAYER *ply)
210 Cave[y-1][x] = Xboom_bug;
221 Cave[y-1][x] = Xboom_bomb;
235 Cave[y][x+1] = Xboom_bug;
246 Cave[y][x+1] = Xboom_bomb;
260 Cave[y+1][x] = Xboom_bug;
271 Cave[y+1][x] = Xboom_bomb;
285 Cave[y][x-1] = Xboom_bug;
296 Cave[y][x-1] = Xboom_bomb;
307 play_element_sound(x, y, SAMPLE_exit_leave, Xexit_1);
311 play_element_sound(x, y, SAMPLE_die, Zplayer);
317 #if USE_CHANGED_ACID_STUFF
330 Cave[y][x] = Xboom_1;
336 static void check_player(struct PLAYER *ply)
344 game_em.last_player_direction[ply->num] = MV_NONE;
346 if (ply->joy_w) /* west */
351 else if (ply->joy_e) /* east */
357 if (ply->joy_n) /* north */
362 else if (ply->joy_s) /* south */
374 boolean players_visible_before_move;
375 boolean players_visible_after_move;
378 players_visible_before_move = checkIfAllPlayersFitToScreen();
383 players_visible_after_move = checkIfAllPlayersFitToScreen();
386 player is allowed to move only in the following cases:
387 - it is not needed to display all players (not focussed to all players)
388 - all players are (still or again) visible after the move
389 - some players were already outside visible screen area before the move
391 can_move = (game.centered_player_nr != -1 ||
392 players_visible_after_move ||
393 !players_visible_before_move);
400 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
406 if (dx == 0 && dy == 0)
412 if (++ply->dynamite_cnt == 5 && ply->dynamite)
414 Cave[y][x] = Xdynamite_1;
415 play_element_sound(x, y, SAMPLE_dynamite, Xdynamite_1);
421 ply->dynamite_cnt = 0;
424 RandomEM += 7; /* be a bit more random if the player doesn't move */
430 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
431 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
432 ply->joy_spin = !ply->joy_spin;
434 if (ply->joy_snap == 0) /* player wants to move */
436 boolean moved = FALSE;
438 if (ply->last_move_dir & MV_HORIZONTAL)
440 if (!(moved = player_digfield(ply, 0, dy)))
441 moved = player_digfield(ply, dx, 0);
445 if (!(moved = player_digfield(ply, dx, 0)))
446 moved = player_digfield(ply, 0, dy);
452 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
453 else if (oldy != ply->y)
454 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
456 game_em.any_player_moving = TRUE;
457 game_em.last_moving_player = ply->num;
458 game_em.last_player_direction[ply->num] = ply->last_move_dir;
461 else /* player wants to snap */
463 player_digfield(ply, dx, dy);
467 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
469 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
474 boolean result = TRUE;
476 if (!dx && !dy) /* no direction specified */
479 if (dx && dy && ply->joy_snap) /* more than one direction specified */
482 if (ply->joy_snap == 0) /* player wants to move */
484 int element = Cave[y][x];
488 /* fire is released */
490 case Yacid_splash_eB:
491 case Yacid_splash_wB:
492 Cave[y][x] = Zplayer;
493 Next[y][x] = Zplayer;
504 play_element_sound(x, y, SAMPLE_blank, Xblank);
505 ply->anim = SPR_walk + anim;
510 #if USE_CHANGED_ACID_STUFF
519 if (Cave[y-1][x+1] == Xblank)
520 Cave[y-1][x+1] = Yacid_splash_eB;
521 if (Cave[y-1][x-1] == Xblank)
522 Cave[y-1][x-1] = Yacid_splash_wB;
523 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
545 #if !USE_CHANGED_ACID_STUFF
555 ply->anim = SPR_walk + anim;
561 Cave[y][x] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
562 (dx > 0 ? Ygrass_eB : Ygrass_wB));
563 Next[y][x] = Zplayer;
564 play_element_sound(x, y, SAMPLE_dirt, Xgrass);
565 ply->anim = SPR_walk + anim;
571 Cave[y][x] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
572 (dx > 0 ? Ydirt_eB : Ydirt_wB));
573 Next[y][x] = Zplayer;
574 play_element_sound(x, y, SAMPLE_dirt, Xdirt);
575 ply->anim = SPR_walk + anim;
582 Cave[y][x] = Ydiamond_eat;
583 Next[y][x] = Zplayer;
584 play_element_sound(x, y, SAMPLE_collect, element);
585 lev.score += lev.diamond_score;
586 lev.required = lev.required < 3 ? 0 : lev.required - 3;
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 ply->anim = SPR_walk + anim;
605 Cave[y][x] = Ydynamite_eat;
606 Next[y][x] = Zplayer;
607 play_element_sound(x, y, SAMPLE_collect, element);
608 lev.score += lev.dynamite_score;
609 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
610 ply->anim = SPR_walk + anim;
617 Cave[y][x] = Ykey_1_eat;
622 Cave[y][x] = Ykey_2_eat;
627 Cave[y][x] = Ykey_3_eat;
632 Cave[y][x] = Ykey_4_eat;
637 Cave[y][x] = Ykey_5_eat;
642 Cave[y][x] = Ykey_6_eat;
647 Cave[y][x] = Ykey_7_eat;
652 Cave[y][x] = Ykey_8_eat;
657 Next[y][x] = Zplayer;
658 play_element_sound(x, y, SAMPLE_collect, element);
659 lev.score += lev.key_score;
660 ply->anim = SPR_walk + anim;
666 Cave[y][x] = Ylenses_eat;
667 Next[y][x] = Zplayer;
668 play_element_sound(x, y, SAMPLE_collect, element);
669 lev.score += lev.lenses_score;
670 lev.lenses_cnt = lev.lenses_time;
671 ply->anim = SPR_walk + anim;
677 Cave[y][x] = Ymagnify_eat;
678 Next[y][x] = Zplayer;
679 play_element_sound(x, y, SAMPLE_collect, element);
680 lev.score += lev.magnify_score;
681 lev.magnify_cnt = lev.magnify_time;
682 ply->anim = SPR_walk + anim;
691 switch(Cave[y][x+dx])
701 if (Cave[y-1][x+dx+1] == Xblank)
702 Cave[y-1][x+dx+1] = Yacid_splash_eB;
703 if (Cave[y-1][x+dx-1] == Xblank)
704 Cave[y-1][x+dx-1] = Yacid_splash_wB;
705 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
709 case Yacid_splash_eB:
710 case Yacid_splash_wB:
711 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
712 Next[y][x+dx] = Xstone_pause;
716 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
717 Next[y][x] = Zplayer;
718 play_element_sound(x, y, SAMPLE_roll, Xstone);
722 ply->anim = SPR_push + anim;
729 switch(Cave[y][x+dx])
739 if (Cave[y-1][x+dx+1] == Xblank)
740 Cave[y-1][x+dx+1] = Yacid_splash_eB;
741 if (Cave[y-1][x+dx-1] == Xblank)
742 Cave[y-1][x+dx-1] = Yacid_splash_wB;
743 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
747 case Yacid_splash_eB:
748 case Yacid_splash_wB:
749 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
750 Next[y][x+dx] = Xbomb_pause;
754 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
755 Next[y][x] = Zplayer;
756 play_element_sound(x, y, SAMPLE_roll, Xbomb);
760 ply->anim = SPR_push + anim;
767 switch(Cave[y][x+dx])
777 if (Cave[y-1][x+dx+1] == Xblank)
778 Cave[y-1][x+dx+1] = Yacid_splash_eB;
779 if (Cave[y-1][x+dx-1] == Xblank)
780 Cave[y-1][x+dx-1] = Yacid_splash_wB;
781 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
785 case Yacid_splash_eB:
786 case Yacid_splash_wB:
787 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
788 Next[y][x+dx] = Xnut_pause;
792 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
793 Next[y][x] = Zplayer;
794 play_element_sound(x, y, SAMPLE_roll, Xnut);
798 ply->anim = SPR_push + anim;
805 switch(Cave[y][x+dx])
809 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
810 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
811 Next[y][x] = Zplayer;
812 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
813 play_element_sound(x, y, SAMPLE_slurp, Xalien);
814 lev.score += lev.slurp_score;
826 if (Cave[y-1][x+dx+1] == Xblank)
827 Cave[y-1][x+dx+1] = Yacid_splash_eB;
828 if (Cave[y-1][x+dx-1] == Xblank)
829 Cave[y-1][x+dx-1] = Yacid_splash_wB;
830 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
834 case Yacid_splash_eB:
835 case Yacid_splash_wB:
836 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
837 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
840 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
841 Next[y][x] = Zplayer;
842 play_element_sound(x, y, SAMPLE_roll, Xspring);
846 ply->anim = SPR_push + anim;
853 case Xsand_stonein_1:
854 case Xsand_stonein_2:
855 case Xsand_stonein_3:
856 case Xsand_stonein_4:
860 ply->anim = SPR_push + anim;
864 switch(Cave[y+dy][x+dx])
874 if (Cave[y+dy-1][x+dx+1] == Xblank)
875 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
876 if (Cave[y+dy-1][x+dx-1] == Xblank)
877 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
878 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
882 case Yacid_splash_eB:
883 case Yacid_splash_wB:
884 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
885 (dx > 0 ? Yballoon_e : Yballoon_w));
886 Next[y+dy][x+dx] = Xballoon;
889 Cave[y][x] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
890 (dx > 0 ? Yballoon_eB : Yballoon_wB));
891 Next[y][x] = Zplayer;
892 play_element_sound(x, y, SAMPLE_push, Xballoon);
897 ply->anim = SPR_push + anim;
909 switch(Cave[y+dy][x+dx])
919 if (Cave[y+dy-1][x+dx+1] == Xblank)
920 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
921 if (Cave[y+dy-1][x+dx-1] == Xblank)
922 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
923 play_element_sound(x, y, SAMPLE_acid, Xacid_1);
927 case Yacid_splash_eB:
928 case Yacid_splash_wB:
929 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
930 (dx > 0 ? Yandroid_e : Yandroid_w));
931 Next[y+dy][x+dx] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
932 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
935 Cave[y][x] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
936 (dx > 0 ? Yandroid_eB : Yandroid_wB));
937 Next[y][x] = Zplayer;
938 play_element_sound(x, y, SAMPLE_push, Xandroid);
943 ply->anim = SPR_push + anim;
948 if (ply->keys & 0x01)
955 if (ply->keys & 0x02)
962 if (ply->keys & 0x04)
969 if (ply->keys & 0x08)
976 if (ply->keys & 0x10)
983 if (ply->keys & 0x20)
990 if (ply->keys & 0x40)
997 if (ply->keys & 0x80)
1003 if (!tab_blank[Cave[y+dy][x+dx]])
1006 Cave[y+dy][x+dx] = Zplayer;
1007 Next[y+dy][x+dx] = Zplayer;
1008 play_element_sound(x, y, SAMPLE_door, element);
1009 ply->anim = SPR_walk + anim;
1015 play_element_sound(x, y, SAMPLE_press, element);
1016 lev.wheel_cnt = lev.wheel_time;
1022 lev.wind_direction = 0;
1026 lev.wind_direction = 1;
1030 lev.wind_direction = 2;
1034 lev.wind_direction = 3;
1038 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1042 play_element_sound(x, y, SAMPLE_press, element);
1043 lev.wind_cnt = lev.wind_time;
1047 play_element_sound(x, y, SAMPLE_press, element);
1052 play_element_sound(x, y, SAMPLE_press, element);
1053 lev.ball_cnt = lev.ball_time;
1054 lev.ball_state = !lev.ball_state;
1058 Cave[y][x] = Yplant;
1059 Next[y][x] = Xplant;
1060 play_element_sound(x, y, SAMPLE_blank, Xplant);
1061 ply->anim = SPR_walk + anim;
1071 ply->anim = SPR_walk + anim;
1078 if (ply->x == oldx && ply->y == oldy) /* no movement */
1081 else /* player wants to snap */
1083 int element = Cave[y][x];
1087 /* fire is pressed */
1090 Cave[y][x] = Ygrass_eat;
1091 Next[y][x] = Xblank;
1092 play_element_sound(x, y, SAMPLE_dirt, element);
1093 ply->anim = SPR_spray + anim;
1097 Cave[y][x] = Ydirt_eat;
1098 Next[y][x] = Xblank;
1099 play_element_sound(x, y, SAMPLE_dirt, element);
1100 ply->anim = SPR_spray + anim;
1104 case Xdiamond_pause:
1105 Cave[y][x] = Ydiamond_eat;
1106 Next[y][x] = Xblank;
1107 play_element_sound(x, y, SAMPLE_collect, element);
1108 lev.score += lev.diamond_score;
1109 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1110 ply->anim = SPR_walk + anim;
1114 case Xemerald_pause:
1115 Cave[y][x] = Yemerald_eat;
1116 Next[y][x] = Xblank;
1117 play_element_sound(x, y, SAMPLE_collect, element);
1118 lev.score += lev.emerald_score;
1119 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1120 ply->anim = SPR_walk + anim;
1124 Cave[y][x] = Ydynamite_eat;
1125 Next[y][x] = Xblank;
1126 play_element_sound(x, y, SAMPLE_collect, element);
1127 lev.score += lev.dynamite_score;
1128 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1129 ply->anim = SPR_walk + anim;
1134 Cave[y][x] = Ykey_1_eat;
1139 Cave[y][x] = Ykey_2_eat;
1144 Cave[y][x] = Ykey_3_eat;
1149 Cave[y][x] = Ykey_4_eat;
1154 Cave[y][x] = Ykey_5_eat;
1159 Cave[y][x] = Ykey_6_eat;
1164 Cave[y][x] = Ykey_7_eat;
1169 Cave[y][x] = Ykey_8_eat;
1173 Next[y][x] = Xblank;
1174 play_element_sound(x, y, SAMPLE_collect, element);
1175 lev.score += lev.key_score;
1176 ply->anim = SPR_walk + anim;
1180 Cave[y][x] = Ylenses_eat;
1181 Next[y][x] = Xblank;
1182 play_element_sound(x, y, SAMPLE_collect, element);
1183 lev.score += lev.lenses_score;
1184 lev.lenses_cnt = lev.lenses_time;
1185 ply->anim = SPR_walk + anim;
1189 Cave[y][x] = Ymagnify_eat;
1190 Next[y][x] = Xblank;
1191 play_element_sound(x, y, SAMPLE_collect, element);
1192 lev.score += lev.magnify_score;
1193 lev.magnify_cnt = lev.magnify_time;
1194 ply->anim = SPR_walk + anim;