ply1.anim = 0;
ply1.oldx = ply1.x = ply1.x_initial;
ply1.oldy = ply1.y = ply1.y_initial;
- ply1.joy_n = ply1.joy_e = ply1.joy_s = ply1.joy_w = ply1.joy_fire = 0;
+ ply1.last_move_dir = MV_NO_MOVING;
+ ply1.joy_n = ply1.joy_e = ply1.joy_s = ply1.joy_w = 0;
+ ply1.joy_snap = ply1.joy_drop = 0;
ply1.joy_stick = ply1.joy_spin = 0;
ply2.num = 1;
ply2.anim = 0;
ply2.oldx = ply2.x = ply2.x_initial;
ply2.oldy = ply2.y = ply2.y_initial;
- ply2.joy_n = ply2.joy_e = ply2.joy_s = ply2.joy_w = ply2.joy_fire = 0;
+ ply2.last_move_dir = MV_NO_MOVING;
+ ply2.joy_n = ply2.joy_e = ply2.joy_s = ply2.joy_w = 0;
+ ply2.joy_snap = ply1.joy_drop = 0;
ply2.joy_stick = ply2.joy_spin = 0;
}
static void player(struct PLAYER *);
+static boolean player_digfield(struct PLAYER *, int, int);
static int test(struct PLAYER *);
static void die(struct PLAYER *);
static void player(struct PLAYER *ply)
{
- register unsigned int x = ply->x;
- register unsigned int y = ply->y;
- unsigned int anim = 0; /* initialized to make compilers happy */
+ unsigned int oldx = ply->x;
+ unsigned int oldy = ply->y;
+ register unsigned int x = oldx;
+ register unsigned int y = oldy;
+ unsigned int anim = 0;
int dx = 0, dy = 0;
+#if 0
+ printf("::: up == %d, down == %d, left == %d, right == %d, fire == %d [spin == %d, stick == %d]\n",
+ ply->joy_n, ply->joy_s, ply->joy_w, ply->joy_e, ply->joy_fire,
+ ply->joy_spin, ply->joy_stick);
+#endif
+
+#if 1
+ if (ply->joy_w) /* west */
+ {
+ x--;
+ dx = -1;
+ anim = 3;
+ }
+ else if (ply->joy_e) /* east */
+ {
+ x++;
+ dx = 1;
+ anim = 1;
+ }
+
+ if (ply->joy_n) /* north */
+ {
+ y--;
+ dy = -1;
+ anim = 0;
+ }
+ else if (ply->joy_s) /* south */
+ {
+ y++;
+ dy = 1;
+ anim = 2;
+ }
+
+#else
+
if ((ply->joy_spin = !ply->joy_spin))
{
- if (ply->joy_n)
+ if (ply->joy_n) /* north */
{
y--;
dy = -1;
anim = 0;
- /* north */
}
- else if (ply->joy_e)
+ else if (ply->joy_e) /* east */
{
x++;
dx = 1;
anim = 1;
- /* east */
}
- else if (ply->joy_s)
+ else if (ply->joy_s) /* south */
{
y++;
dy = 1;
anim = 2;
- /* south */
}
- else if (ply->joy_w)
+ else if (ply->joy_w) /* west */
{
x--;
dx = -1;
anim = 3;
- /* west */
}
}
else
{
- if (ply->joy_w)
+ if (ply->joy_w) /* west */
{
x--;
dx = -1;
anim = 3;
- /* west */
}
- else if (ply->joy_s)
+ else if (ply->joy_s) /* south */
{
y++;
dy = 1;
anim = 2;
- /* south */
}
- else if (ply->joy_e)
+ else if (ply->joy_e) /* east */
{
x++;
dx = 1;
anim = 1;
- /* east */
}
- else if (ply->joy_n)
+ else if (ply->joy_n) /* north */
{
y--;
dy = -1;
anim = 0;
- /* north */
}
}
+#endif
if (dx == 0 && dy == 0)
{
ply->joy_stick = 0;
- if (ply->joy_fire)
+ if (ply->joy_drop)
{
if (++ply->dynamite_cnt == 5 && ply->dynamite)
{
ply->dynamite_cnt = 0;
}
- Random += 7; /* bit more random if we dont move */
+ Random += 7; /* be a bit more random if the player doesn't move */
return;
}
ply->joy_stick = 1;
ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
+ ply->joy_spin = !ply->joy_spin;
+
+ if (ply->joy_snap == 0) /* player wants to move */
+ {
+ boolean moved = FALSE;
+
+ if (ply->last_move_dir & MV_HORIZONTAL)
+ {
+ if (!(moved = player_digfield(ply, 0, dy)))
+ moved = player_digfield(ply, dx, 0);
+ }
+ else
+ {
+ if (!(moved = player_digfield(ply, dx, 0)))
+ moved = player_digfield(ply, 0, dy);
+ }
+
+ if (moved)
+ {
+ if (oldx != ply->x)
+ ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
+ else if (oldy != ply->y)
+ ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
+ }
+ }
+ else /* player wants to snap */
+ {
+ player_digfield(ply, dx, dy);
+ }
+}
+
+static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
+{
+ int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
+ unsigned int oldx = ply->x;
+ unsigned int oldy = ply->y;
+ register unsigned int x = oldx + dx;
+ register unsigned int y = oldy + dy;
+ boolean result = TRUE;
+
+ if (!dx && !dy) /* no direction specified */
+ return FALSE;
- if (ply->joy_fire == 0)
+ if (dx && dy && ply->joy_snap) /* more than one direction specified */
+ return FALSE;
+
+ if (ply->joy_snap == 0) /* player wants to move */
{
int element = Cave[y][x];
break;
}
+
+ if (ply->x == oldx && ply->y == oldy) /* no movement */
+ result = FALSE;
}
- else
+ else /* player wants to snap */
{
int element = Cave[y][x];
lev.magnify_cnt = lev.magnify_time;
ply->anim = SPR_walk + anim;
break;
+
+ default:
+ result = FALSE;
}
}
+
+ return result;
}