1 /*                             */
2 /* xemeraldia    ------ move.c */
3 /*                             */
4 
5 #ifdef HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8 
9 #include "games.h"
10 
11 static void rotation(int rot);
12 
Rotation()13 void  Rotation ()
14 {
15   if ((! gameover_flag) && (!paused)) rotation (CLOCKWIZE);
16 }
17 
18 
CCRotation()19 void  CCRotation ()
20 {
21   if ((! gameover_flag) && (!paused))  rotation (COUNTER_CLOCKWIZE);
22 }
23 
24 
MoveLeft()25 void  MoveLeft ()
26 {
27   if ((! gameover_flag) && (!paused))  moveItem (MOVE_LEFT, 0);
28 }
29 
30 
MoveRight()31 void  MoveRight ()
32 {
33   if ((! gameover_flag) && (!paused))  moveItem (MOVE_RIGHT, 0);
34 }
35 
36 
MoveDown()37 void  MoveDown ()
38 {
39   if ((! gameover_flag) && (!paused))
40     {
41       if (timer)  stopTimer ();
42       if (star_comes)
43 	while (CanStarMove (0, MOVE_DOWN))
44 	  {
45 	    moveItem (0, MOVE_DOWN);
46 	    sc += 1;
47 	  }
48       else
49 	while (CanItemMove (0, MOVE_DOWN, drop_i.rot))
50 	  {
51 	    moveItem (0, MOVE_DOWN);
52 	    sc += 1;
53 	  }
54       printScore ();
55       if (++movedown_counter < BOARD_HEIGHT)
56 	startTimer ();
57       else
58 	DropItem ();
59     }
60 }
61 
62 
rotation(int rot)63 static void rotation (int rot)
64 {
65   int  vrot, i;
66 
67   if (! gameover_flag)
68     {
69       vrot = drop_i.rot + rot;
70       if (vrot == 4)
71 	vrot = 0;
72       else  if (vrot == -1)
73 	vrot = 3;
74       if (CanItemMove (0, 0, vrot))
75 	{
76 	  for (i = 0; i < 3; i++)
77 	  {
78 	    board[drop_i.x + iRot_vx[drop_i.rot][i]]
79 	                     [drop_i.y + iRot_vy[drop_i.rot][i]].blk = EMPTY;
80 	    board[drop_i.x + iRot_vx[drop_i.rot][i]]
81                      [drop_i.y + iRot_vy[drop_i.rot][i]].sub = EMPTY_SUB;
82 	  }
83 	  drop_i.rot += rot;
84 	  if (drop_i.rot == 4)
85 	    drop_i.rot = 0;
86 	  else  if (drop_i.rot == -1)
87 	    drop_i.rot = 3;
88 	  printItem ();
89 	}
90     }
91 }
92 
93 
moveItem(int vx,int vy)94 void  moveItem (int vx, int vy)
95 {
96   int  i;
97 
98   if (star_comes)
99     {
100       if (! CanStarMove (vx, vy))
101 	{
102 	  vx = 0;  vy = 0;
103 	}
104       if ((vx != 0) || (vy != 0))
105 	{
106 	  board[drop_i.x][drop_i.y].sub = EMPTY_SUB;
107 	  board[drop_i.x][drop_i.y].blk = EMPTY;
108 	  drop_i.x += vx;
109 	  drop_i.y += vy;
110 	  printItem ();
111 	}
112     }
113   else
114     {
115       if (! CanItemMove (vx, vy, drop_i.rot))
116 	{
117 	  vx = 0;  vy = 0;
118 	}
119       if ((vx != 0) || (vy != 0))
120 	{
121 	  for (i = 0; i < 3; i++)
122 	  {
123 	    board[drop_i.x + iRot_vx[drop_i.rot][i]]
124 	      [drop_i.y + iRot_vy[drop_i.rot][i]].blk = EMPTY;
125 	    board[drop_i.x + iRot_vx[drop_i.rot][i]]
126 	      [drop_i.y + iRot_vy[drop_i.rot][i]].sub = EMPTY_SUB;
127 	  }
128 	  drop_i.x += vx;
129 	  drop_i.y += vy;
130 	  printItem ();
131 	}
132     }
133 	if(vy != 0)
134 		offset_down = 0;
135 }
136 
137 
CanItemMove(int vx,int vy,int vrot)138 gboolean CanItemMove(int vx, int vy, int vrot)
139 {
140   int  flag, i;
141 
142   /* If we are moving sideways, we need to check the next row, since the block
143    * might have already have been shown next to another block
144    * (since adding "soft fall").
145    */
146   if(vx != 0)
147 	  vy++;
148 
149   for (i = 0; i < 3; i++)
150     board[drop_i.x + iRot_vx[drop_i.rot][i]]
151          [drop_i.y + iRot_vy[drop_i.rot][i]].blk = EMPTY;
152   if ((board[drop_i.x + iRot_vx[vrot][0] + vx]
153             [drop_i.y + iRot_vy[vrot][0] + vy].blk == EMPTY) &&
154       (board[drop_i.x + iRot_vx[vrot][1] + vx]
155             [drop_i.y + iRot_vy[vrot][1] + vy].blk == EMPTY) &&
156       (board[drop_i.x + iRot_vx[vrot][2] + vx]
157             [drop_i.y + iRot_vy[vrot][2] + vy].blk == EMPTY))
158     flag = TRUE;
159   else
160     flag = FALSE;
161   /*
162    * This shouldn't be here!
163    */
164   for (i = 0; i < 3; i++)
165     board[drop_i.x + iRot_vx[drop_i.rot][i]]
166          [drop_i.y + iRot_vy[drop_i.rot][i]].blk = drop_i.col[i];
167   return flag;
168 }
169 
170 
CanStarMove(int vx,int vy)171 gboolean CanStarMove(int vx, int vy)
172 {
173 	  /* If we are moving sideways, we need to check the next row, since the block
174 	   * might have already have been shown next to another block
175 	   * (since adding "soft fall").
176 	   */
177 	  if(vx != 0)
178 		  vy++;
179 
180 	if(board[drop_i.x + vx][drop_i.y + vy].blk == EMPTY)
181 		return TRUE;
182 	else
183 		return FALSE;
184 }
185