2 /* first part of synchro.
4 * game logic for players.
6 * large switch statement for tiles the player interacts with.
13 static void player(struct PLAYER *);
14 static int test(struct PLAYER *);
15 static void die(struct PLAYER *);
19 char ply1_kill = test(&ply1); /* must test for death and actually kill separately */
20 char ply2_kill = test(&ply2);
21 if(ply1.alive && ply1_kill) die(&ply1);
22 if(ply2.alive && ply2_kill) die(&ply2);
25 ply1.alive = 1; /* debugging */
30 ply1.anim = SPR_still;
33 ply2.anim = SPR_still;
36 if(ply1.alive) player(&ply1);
37 if(ply2.alive) player(&ply2);
39 if(ply2.alive) player(&ply2);
40 if(ply1.alive) player(&ply1);
43 if(Cave[ply1.oldy][ply1.oldx] == Zplayer) {
44 Cave[ply1.oldy][ply1.oldx] = Xblank;
45 Next[ply1.oldy][ply1.oldx] = Xblank;
47 if(Cave[ply1.y][ply1.x] == Xblank) {
48 Cave[ply1.y][ply1.x] = Zplayer;
49 Next[ply1.y][ply1.x] = Zplayer;
53 if(Cave[ply2.oldy][ply2.oldx] == Zplayer) {
54 Cave[ply2.oldy][ply2.oldx] = Xblank;
55 Next[ply2.oldy][ply2.oldx] = Xblank;
57 if(Cave[ply2.y][ply2.x] == Xblank) {
58 Cave[ply2.y][ply2.x] = Zplayer;
59 Next[ply2.y][ply2.x] = Zplayer;
64 static int test(struct PLAYER *ply)
66 register unsigned int x = ply->x;
67 register unsigned int y = ply->y;
69 if(lev.time == 0) return(1);
71 switch(Cave[y-1][x]) {
90 switch(Cave[y][x+1]) {
109 switch(Cave[y+1][x]) {
128 switch(Cave[y][x-1]) {
149 case Yacid_splash_eB:
150 case Yacid_splash_wB:
161 static void die(struct PLAYER *ply)
163 register unsigned int x = ply->x;
164 register unsigned int y = ply->y;
168 switch(Cave[y-1][x]) {
177 Cave[y-1][x] = Xboom_bug; break;
186 Cave[y-1][x] = Xboom_bomb; break;
188 switch(Cave[y][x+1]) {
197 Cave[y][x+1] = Xboom_bug; break;
206 Cave[y][x+1] = Xboom_bomb; break;
208 switch(Cave[y+1][x]) {
217 Cave[y+1][x] = Xboom_bug; break;
226 Cave[y+1][x] = Xboom_bomb; break;
228 switch(Cave[y][x-1]) {
237 Cave[y][x-1] = Xboom_bug; break;
246 Cave[y][x-1] = Xboom_bomb; break;
252 play[SAMPLE_exit] = 1; break;
254 play[SAMPLE_die] = 1; break;
256 Cave[y][x] = Xboom_1;
260 static void player(struct PLAYER *ply)
262 register unsigned int x = ply->x;
263 register unsigned int y = ply->y;
264 unsigned int anim = 0; /* initialized to make compilers happy */
267 if((ply->joy_spin = !ply->joy_spin)) {
269 y--; dy = -1; anim = 0; /* north */
270 } else if(ply->joy_e) {
271 x++; dx = 1; anim = 1; /* east */
272 } else if(ply->joy_s) {
273 y++; dy = 1; anim = 2; /* south */
274 } else if(ply->joy_w) {
275 x--; dx = -1; anim = 3; /* west */
279 x--; dx = -1; anim = 3; /* west */
280 } else if(ply->joy_s) {
281 y++; dy = 1; anim = 2; /* south */
282 } else if(ply->joy_e) {
283 x++; dx = 1; anim = 1; /* east */
284 } else if(ply->joy_n) {
285 y--; dy = -1; anim = 0; /* north */
288 if(dx == 0 && dy == 0) {
291 if(++ply->dynamite_cnt == 5 && ply->dynamite) {
292 Cave[y][x] = Xdynamite_1;
293 play[SAMPLE_dynamite] = 1;
297 ply->dynamite_cnt = 0;
299 Random += 7; /* bit more random if we dont move */
303 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
304 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
306 if(ply->joy_fire == 0) {
307 switch(Cave[y][x]) { /* fire is released */
309 case Yacid_splash_eB:
310 case Yacid_splash_wB:
311 Cave[y][x] = Zplayer;
312 Next[y][x] = Zplayer;
313 play[SAMPLE_blank] = 1;
314 ply->anim = SPR_walk + anim;
344 ply->anim = SPR_walk + anim;
349 Cave[y][x] = dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) : (dx > 0 ? Ygrass_eB : Ygrass_wB);
350 Next[y][x] = Zplayer;
351 play[SAMPLE_dirt] = 1;
352 ply->anim = SPR_walk + anim;
357 Cave[y][x] = dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) : (dx > 0 ? Ydirt_eB : Ydirt_wB);
358 Next[y][x] = Zplayer;
359 play[SAMPLE_dirt] = 1;
360 ply->anim = SPR_walk + anim;
366 Cave[y][x] = Ydiamond_eat;
367 Next[y][x] = Zplayer;
368 play[SAMPLE_collect] = 1;
369 lev.score += lev.diamond_score;
370 lev.required = lev.required < 3 ? 0 : lev.required - 3;
371 ply->anim = SPR_walk + anim;
377 Cave[y][x] = Yemerald_eat;
378 Next[y][x] = Zplayer;
379 play[SAMPLE_collect] = 1;
380 lev.score += lev.emerald_score;
381 lev.required = lev.required < 1 ? 0 : lev.required - 1;
382 ply->anim = SPR_walk + anim;
387 Cave[y][x] = Ydynamite_eat;
388 Next[y][x] = Zplayer;
389 play[SAMPLE_collect] = 1;
390 lev.score += lev.dynamite_score;
391 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
392 ply->anim = SPR_walk + anim;
397 ply->keys |= 0x01; goto key_walk;
399 ply->keys |= 0x02; goto key_walk;
401 ply->keys |= 0x04; goto key_walk;
403 ply->keys |= 0x08; goto key_walk;
405 ply->keys |= 0x10; goto key_walk;
407 ply->keys |= 0x20; goto key_walk;
409 ply->keys |= 0x40; goto key_walk;
411 ply->keys |= 0x80; goto key_walk;
413 Cave[y][x] = Yball_eat;
414 Next[y][x] = Zplayer;
415 play[SAMPLE_collect] = 1;
416 lev.score += lev.key_score;
417 ply->anim = SPR_walk + anim;
422 Cave[y][x] = Yball_eat;
423 Next[y][x] = Zplayer;
424 play[SAMPLE_collect] = 1;
425 lev.score += lev.lenses_score;
426 lev.lenses_cnt = lev.lenses_time;
427 ply->anim = SPR_walk + anim;
432 Cave[y][x] = Yball_eat;
433 Next[y][x] = Zplayer;
434 play[SAMPLE_collect] = 1;
435 lev.score += lev.magnify_score;
436 lev.magnify_cnt = lev.magnify_time;
437 ply->anim = SPR_walk + anim;
443 switch(Cave[y][x+dx]) {
452 if(Cave[y-1][x+dx+1] == Xblank) Cave[y-1][x+dx+1] = Yacid_splash_eB;
453 if(Cave[y-1][x+dx-1] == Xblank) Cave[y-1][x+dx-1] = Yacid_splash_wB;
454 play[SAMPLE_acid] = 1;
457 case Yacid_splash_eB:
458 case Yacid_splash_wB:
459 Cave[y][x+dx] = dx > 0 ? Ystone_e : Ystone_w;
460 Next[y][x+dx] = Xstone_pause;
462 Cave[y][x] = dx > 0 ? Ystone_eB : Ystone_wB;
463 Next[y][x] = Zplayer;
464 play[SAMPLE_roll] = 1;
467 ply->anim = SPR_push + anim;
471 switch(Cave[y][x+dx]) {
480 if(Cave[y-1][x+dx+1] == Xblank) Cave[y-1][x+dx+1] = Yacid_splash_eB;
481 if(Cave[y-1][x+dx-1] == Xblank) Cave[y-1][x+dx-1] = Yacid_splash_wB;
482 play[SAMPLE_acid] = 1;
485 case Yacid_splash_eB:
486 case Yacid_splash_wB:
487 Cave[y][x+dx] = dx > 0 ? Ybomb_e : Ybomb_w;
488 Next[y][x+dx] = Xbomb_pause;
490 Cave[y][x] = dx > 0 ? Ybomb_eB : Ybomb_wB;
491 Next[y][x] = Zplayer;
492 play[SAMPLE_roll] = 1;
495 ply->anim = SPR_push + anim;
499 switch(Cave[y][x+dx]) {
508 if(Cave[y-1][x+dx+1] == Xblank) Cave[y-1][x+dx+1] = Yacid_splash_eB;
509 if(Cave[y-1][x+dx-1] == Xblank) Cave[y-1][x+dx-1] = Yacid_splash_wB;
510 play[SAMPLE_acid] = 1;
513 case Yacid_splash_eB:
514 case Yacid_splash_wB:
515 Cave[y][x+dx] = dx > 0 ? Ynut_e : Ynut_w;
516 Next[y][x+dx] = Xnut_pause;
518 Cave[y][x] = dx > 0 ? Ynut_eB : Ynut_wB;
519 Next[y][x] = Zplayer;
520 play[SAMPLE_roll] = 1;
523 ply->anim = SPR_push + anim;
527 switch(Cave[y][x+dx]) {
530 Cave[y][x] = dx > 0 ? Yspring_kill_eB : Yspring_kill_wB;
531 Cave[y][x+dx] = dx > 0 ? Yspring_kill_e : Yspring_kill_w;
532 Next[y][x] = Zplayer;
533 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
534 play[SAMPLE_slurp] = 1;
535 lev.score += lev.slurp_score;
546 if(Cave[y-1][x+dx+1] == Xblank) Cave[y-1][x+dx+1] = Yacid_splash_eB;
547 if(Cave[y-1][x+dx-1] == Xblank) Cave[y-1][x+dx-1] = Yacid_splash_wB;
548 play[SAMPLE_acid] = 1;
551 case Yacid_splash_eB:
552 case Yacid_splash_wB:
553 Cave[y][x+dx] = dx > 0 ? Yspring_e : Yspring_w;
554 Next[y][x+dx] = dx > 0 ? Xspring_e : Xspring_w;
556 Cave[y][x] = dx > 0 ? Yspring_eB : Yspring_wB;
557 Next[y][x] = Zplayer;
558 play[SAMPLE_roll] = 1;
561 ply->anim = SPR_push + anim;
567 case Xsand_stonein_1:
568 case Xsand_stonein_2:
569 case Xsand_stonein_3:
570 case Xsand_stonein_4:
572 ply->anim = SPR_push + anim;
575 switch(Cave[y+dy][x+dx]) {
584 if(Cave[y+dy-1][x+dx+1] == Xblank) Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
585 if(Cave[y+dy-1][x+dx-1] == Xblank) Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
586 play[SAMPLE_acid] = 1;
589 case Yacid_splash_eB:
590 case Yacid_splash_wB:
591 Cave[y+dy][x+dx] = dy ? (dy < 0 ? Yballoon_n : Yballoon_s) : (dx > 0 ? Yballoon_e : Yballoon_w);
592 Next[y+dy][x+dx] = Xballoon;
594 Cave[y][x] = dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) : (dx > 0 ? Yballoon_eB : Yballoon_wB);
595 Next[y][x] = Zplayer;
596 play[SAMPLE_push] = 1;
600 ply->anim = SPR_push + anim;
611 switch(Cave[y+dy][x+dx]) {
620 if(Cave[y+dy-1][x+dx+1] == Xblank) Cave[y+dy-1][x+dx+1] = Yacid_splash_eB;
621 if(Cave[y+dy-1][x+dx-1] == Xblank) Cave[y+dy-1][x+dx-1] = Yacid_splash_wB;
622 play[SAMPLE_acid] = 1;
625 case Yacid_splash_eB:
626 case Yacid_splash_wB:
627 Cave[y+dy][x+dx] = dy ? (dy < 0 ? Yandroid_n : Yandroid_s) : (dx > 0 ? Yandroid_e : Yandroid_w);
628 Next[y+dy][x+dx] = dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) : (dx > 0 ? Xandroid_2_e : Xandroid_2_w);
630 Cave[y][x] = dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) : (dx > 0 ? Yandroid_eB : Yandroid_wB);
631 Next[y][x] = Zplayer;
632 play[SAMPLE_push] = 1;
636 ply->anim = SPR_push + anim;
640 if(ply->keys & 0x01) goto door_walk; else break;
643 if(ply->keys & 0x02) goto door_walk; else break;
646 if(ply->keys & 0x04) goto door_walk; else break;
649 if(ply->keys & 0x08) goto door_walk; else break;
652 if(ply->keys & 0x10) goto door_walk; else break;
655 if(ply->keys & 0x20) goto door_walk; else break;
658 if(ply->keys & 0x40) goto door_walk; else break;
661 if(ply->keys & 0x80) goto door_walk; else break;
663 if(!tab_blank[Cave[y+dy][x+dx]]) break;
664 Cave[y+dy][x+dx] = Zplayer;
665 Next[y+dy][x+dx] = Zplayer;
666 play[SAMPLE_door] = 1;
667 ply->anim = SPR_walk + anim;
672 play[SAMPLE_press] = 1;
673 lev.wheel_cnt = lev.wheel_time;
678 lev.wind_direction = 0; goto wind_walk;
680 lev.wind_direction = 1; goto wind_walk;
682 lev.wind_direction = 2; goto wind_walk;
684 lev.wind_direction = 3; goto wind_walk;
686 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3); goto wind_walk;
688 play[SAMPLE_press] = 1;
689 lev.wind_cnt = lev.wind_time;
692 play[SAMPLE_press] = 1;
696 play[SAMPLE_press] = 1;
697 lev.ball_cnt = lev.ball_time;
698 lev.ball_state = !lev.ball_state;
703 play[SAMPLE_blank] = 1;
704 ply->anim = SPR_walk + anim;
711 play[SAMPLE_exit] = 1;
712 if(--lev.home == 0) lev.score += lev.time * lev.exit_score / 100;
713 ply->anim = SPR_walk + anim;
719 switch(Cave[y][x]) { /* fire is pressed */
722 Cave[y][x] = Yball_eat;
724 play[SAMPLE_dirt] = 1;
725 ply->anim = SPR_spray + anim;
729 Cave[y][x] = Ydiamond_eat;
731 play[SAMPLE_collect] = 1;
732 lev.score += lev.diamond_score;
733 lev.required = lev.required < 3 ? 0 : lev.required - 3;
734 ply->anim = SPR_walk + anim;
738 Cave[y][x] = Yemerald_eat;
740 play[SAMPLE_collect] = 1;
741 lev.score += lev.emerald_score;
742 lev.required = lev.required < 1 ? 0 : lev.required - 1;
743 ply->anim = SPR_walk + anim;
746 Cave[y][x] = Ydynamite_eat;
748 play[SAMPLE_collect] = 1;
749 lev.score += lev.dynamite_score;
750 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
751 ply->anim = SPR_walk + anim;
754 ply->keys |= 0x01; goto key_shoot;
756 ply->keys |= 0x02; goto key_shoot;
758 ply->keys |= 0x04; goto key_shoot;
760 ply->keys |= 0x08; goto key_shoot;
762 ply->keys |= 0x10; goto key_shoot;
764 ply->keys |= 0x20; goto key_shoot;
766 ply->keys |= 0x40; goto key_shoot;
768 ply->keys |= 0x80; goto key_shoot;
770 Cave[y][x] = Yball_eat;
772 play[SAMPLE_collect] = 1;
773 lev.score += lev.key_score;
774 ply->anim = SPR_walk + anim;
777 Cave[y][x] = Yball_eat;
779 play[SAMPLE_collect] = 1;
780 lev.score += lev.lenses_score;
781 lev.lenses_cnt = lev.lenses_time;
782 ply->anim = SPR_walk + anim;
785 Cave[y][x] = Yball_eat;
787 play[SAMPLE_collect] = 1;
788 lev.score += lev.magnify_score;
789 lev.magnify_cnt = lev.magnify_time;
790 ply->anim = SPR_walk + anim;