1 /* first part of synchro.
3 * game logic for players.
5 * large switch statement for tiles the player interacts with.
14 static void player(struct PLAYER *);
15 static int test(struct PLAYER *);
16 static void die(struct PLAYER *);
20 /* must test for death and actually kill separately */
21 char ply1_kill = test(&ply1);
22 char ply2_kill = test(&ply2);
24 if (ply1.alive && ply1_kill)
26 if (ply2.alive && ply2_kill)
30 ply1.alive = 1; /* debugging */
35 ply1.anim = SPR_still;
38 ply2.anim = SPR_still;
42 if (ply1.alive) player(&ply1);
43 if (ply2.alive) player(&ply2);
47 if (ply2.alive) player(&ply2);
48 if (ply1.alive) player(&ply1);
53 if (Cave[ply1.oldy][ply1.oldx] == Zplayer)
55 Cave[ply1.oldy][ply1.oldx] = Xblank;
56 Next[ply1.oldy][ply1.oldx] = Xblank;
59 if (Cave[ply1.y][ply1.x] == Xblank)
61 Cave[ply1.y][ply1.x] = Zplayer;
62 Next[ply1.y][ply1.x] = Zplayer;
68 if (Cave[ply2.oldy][ply2.oldx] == Zplayer)
70 Cave[ply2.oldy][ply2.oldx] = Xblank;
71 Next[ply2.oldy][ply2.oldx] = Xblank;
74 if (Cave[ply2.y][ply2.x] == Xblank)
76 Cave[ply2.y][ply2.x] = Zplayer;
77 Next[ply2.y][ply2.x] = Zplayer;
82 static int test(struct PLAYER *ply)
84 register unsigned int x = ply->x;
85 register unsigned int y = ply->y;
180 case Yacid_splash_eB:
181 case Yacid_splash_wB:
193 static void die(struct PLAYER *ply)
195 register unsigned int x = ply->x;
196 register unsigned int y = ply->y;
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;
305 play_sound(x, y, SAMPLE_exit);
309 play_sound(x, y, SAMPLE_die);
313 Cave[y][x] = Xboom_1;
317 static void player(struct PLAYER *ply)
319 register unsigned int x = ply->x;
320 register unsigned int y = ply->y;
321 unsigned int anim = 0; /* initialized to make compilers happy */
324 if ((ply->joy_spin = !ply->joy_spin))
387 if (dx == 0 && dy == 0)
393 if (++ply->dynamite_cnt == 5 && ply->dynamite)
395 Cave[y][x] = Xdynamite_1;
396 play_sound(x, y, SAMPLE_dynamite);
402 ply->dynamite_cnt = 0;
405 Random += 7; /* bit more random if we dont move */
411 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
412 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
414 if (ply->joy_fire == 0)
416 int element = Cave[y][x];
420 /* fire is released */
422 case Yacid_splash_eB:
423 case Yacid_splash_wB:
424 Cave[y][x] = Zplayer;
425 Next[y][x] = Zplayer;
426 play_sound(x, y, SAMPLE_blank);
427 ply->anim = SPR_walk + anim;
458 ply->anim = SPR_walk + anim;
464 Cave[y][x] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
465 (dx > 0 ? Ygrass_eB : Ygrass_wB));
466 Next[y][x] = Zplayer;
467 play_element_sound(x, y, SAMPLE_dirt, Xgrass);
468 ply->anim = SPR_walk + anim;
474 Cave[y][x] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
475 (dx > 0 ? Ydirt_eB : Ydirt_wB));
476 Next[y][x] = Zplayer;
477 play_element_sound(x, y, SAMPLE_dirt, Xdirt);
478 ply->anim = SPR_walk + anim;
485 Cave[y][x] = Ydiamond_eat;
486 Next[y][x] = Zplayer;
487 play_element_sound(x, y, SAMPLE_collect, element);
488 lev.score += lev.diamond_score;
489 lev.required = lev.required < 3 ? 0 : lev.required - 3;
490 ply->anim = SPR_walk + anim;
497 Cave[y][x] = Yemerald_eat;
498 Next[y][x] = Zplayer;
499 play_element_sound(x, y, SAMPLE_collect, element);
500 lev.score += lev.emerald_score;
501 lev.required = lev.required < 1 ? 0 : lev.required - 1;
502 ply->anim = SPR_walk + anim;
508 Cave[y][x] = Ydynamite_eat;
509 Next[y][x] = Zplayer;
510 play_element_sound(x, y, SAMPLE_collect, element);
511 lev.score += lev.dynamite_score;
512 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
513 ply->anim = SPR_walk + anim;
552 Cave[y][x] = Yball_eat;
553 Next[y][x] = Zplayer;
554 play_element_sound(x, y, SAMPLE_collect, element);
555 lev.score += lev.key_score;
556 ply->anim = SPR_walk + anim;
562 Cave[y][x] = Yball_eat;
563 Next[y][x] = Zplayer;
564 play_element_sound(x, y, SAMPLE_collect, element);
565 lev.score += lev.lenses_score;
566 lev.lenses_cnt = lev.lenses_time;
567 ply->anim = SPR_walk + anim;
573 Cave[y][x] = Yball_eat;
574 Next[y][x] = Zplayer;
575 play_element_sound(x, y, SAMPLE_collect, element);
576 lev.score += lev.magnify_score;
577 lev.magnify_cnt = lev.magnify_time;
578 ply->anim = SPR_walk + anim;
587 switch(Cave[y][x+dx])
597 if (Cave[y-1][x+dx+1] == Xblank)
598 Cave[y-1][x+dx+1] = Yacid_splash_eB;
599 if (Cave[y-1][x+dx-1] == Xblank)
600 Cave[y-1][x+dx-1] = Yacid_splash_wB;
601 play_sound(x, y, SAMPLE_acid);
605 case Yacid_splash_eB:
606 case Yacid_splash_wB:
607 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
608 Next[y][x+dx] = Xstone_pause;
612 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
613 Next[y][x] = Zplayer;
614 play_element_sound(x, y, SAMPLE_roll, Xstone);
618 ply->anim = SPR_push + anim;
625 switch(Cave[y][x+dx])
635 if (Cave[y-1][x+dx+1] == Xblank)
636 Cave[y-1][x+dx+1] = Yacid_splash_eB;
637 if (Cave[y-1][x+dx-1] == Xblank)
638 Cave[y-1][x+dx-1] = Yacid_splash_wB;
639 play_sound(x, y, SAMPLE_acid);
643 case Yacid_splash_eB:
644 case Yacid_splash_wB:
645 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
646 Next[y][x+dx] = Xbomb_pause;
650 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
651 Next[y][x] = Zplayer;
652 play_element_sound(x, y, SAMPLE_roll, Xbomb);
656 ply->anim = SPR_push + anim;
663 switch(Cave[y][x+dx])
673 if (Cave[y-1][x+dx+1] == Xblank)
674 Cave[y-1][x+dx+1] = Yacid_splash_eB;
675 if (Cave[y-1][x+dx-1] == Xblank)
676 Cave[y-1][x+dx-1] = Yacid_splash_wB;
677 play_sound(x, y, SAMPLE_acid);
681 case Yacid_splash_eB:
682 case Yacid_splash_wB:
683 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
684 Next[y][x+dx] = Xnut_pause;
688 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
689 Next[y][x] = Zplayer;
690 play_element_sound(x, y, SAMPLE_roll, Xnut);
694 ply->anim = SPR_push + anim;
701 switch(Cave[y][x+dx])
705 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
706 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
707 Next[y][x] = Zplayer;
708 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
709 play_sound(x, y, SAMPLE_slurp);
710 lev.score += lev.slurp_score;
722 if (Cave[y-1][x+dx+1] == Xblank)
723 Cave[y-1][x+dx+1] = Yacid_splash_eB;
724 if (Cave[y-1][x+dx-1] == Xblank)
725 Cave[y-1][x+dx-1] = Yacid_splash_wB;
726 play_sound(x, y, SAMPLE_acid);
730 case Yacid_splash_eB:
731 case Yacid_splash_wB:
732 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
733 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
736 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
737 Next[y][x] = Zplayer;
738 play_element_sound(x, y, SAMPLE_roll, Xspring);
742 ply->anim = SPR_push + anim;
749 case Xsand_stonein_1:
750 case Xsand_stonein_2:
751 case Xsand_stonein_3:
752 case Xsand_stonein_4:
756 ply->anim = SPR_push + anim;
760 switch(Cave[y+dy][x+dx])
770 if (Cave[y+dy-1][x+dx+1] == Xblank)
771 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
772 if (Cave[y+dy-1][x+dx-1] == Xblank)
773 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
774 play_sound(x, y, SAMPLE_acid);
778 case Yacid_splash_eB:
779 case Yacid_splash_wB:
780 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
781 (dx > 0 ? Yballoon_e : Yballoon_w));
782 Next[y+dy][x+dx] = Xballoon;
785 Cave[y][x] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
786 (dx > 0 ? Yballoon_eB : Yballoon_wB));
787 Next[y][x] = Zplayer;
788 play_element_sound(x, y, SAMPLE_push, Xballoon);
793 ply->anim = SPR_push + anim;
805 switch(Cave[y+dy][x+dx])
815 if (Cave[y+dy-1][x+dx+1] == Xblank)
816 Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
817 if (Cave[y+dy-1][x+dx-1] == Xblank)
818 Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
819 play_sound(x, y, SAMPLE_acid);
823 case Yacid_splash_eB:
824 case Yacid_splash_wB:
825 Cave[y+dy][x+dx] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
826 (dx > 0 ? Yandroid_e : Yandroid_w));
827 Next[y+dy][x+dx] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
828 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
831 Cave[y][x] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
832 (dx > 0 ? Yandroid_eB : Yandroid_wB));
833 Next[y][x] = Zplayer;
834 play_element_sound(x, y, SAMPLE_push, Xandroid);
839 ply->anim = SPR_push + anim;
844 if (ply->keys & 0x01)
851 if (ply->keys & 0x02)
858 if (ply->keys & 0x04)
865 if (ply->keys & 0x08)
872 if (ply->keys & 0x10)
879 if (ply->keys & 0x20)
886 if (ply->keys & 0x40)
893 if (ply->keys & 0x80)
899 if (!tab_blank[Cave[y+dy][x+dx]])
902 Cave[y+dy][x+dx] = Zplayer;
903 Next[y+dy][x+dx] = Zplayer;
904 play_element_sound(x, y, SAMPLE_door, element);
905 ply->anim = SPR_walk + anim;
911 play_element_sound(x, y, SAMPLE_press, element);
912 lev.wheel_cnt = lev.wheel_time;
918 lev.wind_direction = 0;
922 lev.wind_direction = 1;
926 lev.wind_direction = 2;
930 lev.wind_direction = 3;
934 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
938 play_element_sound(x, y, SAMPLE_press, element);
939 lev.wind_cnt = lev.wind_time;
943 play_element_sound(x, y, SAMPLE_press, element);
948 play_element_sound(x, y, SAMPLE_press, element);
949 lev.ball_cnt = lev.ball_time;
950 lev.ball_state = !lev.ball_state;
956 play_element_sound(x, y, SAMPLE_blank, Xplant);
957 ply->anim = SPR_walk + anim;
965 play_sound(x, y, SAMPLE_exit);
967 lev.score += lev.time * lev.exit_score / 100;
968 ply->anim = SPR_walk + anim;
976 int element = Cave[y][x];
980 /* fire is pressed */
984 Cave[y][x] = Yball_eat;
986 play_element_sound(x, y, SAMPLE_dirt, element);
987 ply->anim = SPR_spray + anim;
992 Cave[y][x] = Ydiamond_eat;
994 play_element_sound(x, y, SAMPLE_collect, element);
995 lev.score += lev.diamond_score;
996 lev.required = lev.required < 3 ? 0 : lev.required - 3;
997 ply->anim = SPR_walk + anim;
1001 case Xemerald_pause:
1002 Cave[y][x] = Yemerald_eat;
1003 Next[y][x] = Xblank;
1004 play_element_sound(x, y, SAMPLE_collect, element);
1005 lev.score += lev.emerald_score;
1006 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1007 ply->anim = SPR_walk + anim;
1011 Cave[y][x] = Ydynamite_eat;
1012 Next[y][x] = Xblank;
1013 play_element_sound(x, y, SAMPLE_collect, element);
1014 lev.score += lev.dynamite_score;
1015 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1016 ply->anim = SPR_walk + anim;
1052 Cave[y][x] = Yball_eat;
1053 Next[y][x] = Xblank;
1054 play_element_sound(x, y, SAMPLE_collect, element);
1055 lev.score += lev.key_score;
1056 ply->anim = SPR_walk + anim;
1060 Cave[y][x] = Yball_eat;
1061 Next[y][x] = Xblank;
1062 play_element_sound(x, y, SAMPLE_collect, element);
1063 lev.score += lev.lenses_score;
1064 lev.lenses_cnt = lev.lenses_time;
1065 ply->anim = SPR_walk + anim;
1069 Cave[y][x] = Yball_eat;
1070 Next[y][x] = Xblank;
1071 play_element_sound(x, y, SAMPLE_collect, element);
1072 lev.score += lev.magnify_score;
1073 lev.magnify_cnt = lev.magnify_time;
1074 ply->anim = SPR_walk + anim;