rnd-20060216-1-src
[rocksndiamonds.git] / src / game_em / input.c
1 /* 2000-08-13T15:29:40Z
2  *
3  * handle input from x11 and keyboard and joystick
4  */
5
6 #include "global.h"
7 #include "display.h"
8 #include "level.h"
9
10
11 unsigned long RandomEM;
12
13 struct LEVEL lev;
14 struct PLAYER ply[MAX_PLAYERS];
15
16 short **Boom;
17 short **Cave;
18 short **Next;
19 short **Draw;
20
21 static short *Index[4][HEIGHT];
22 static short Array[4][HEIGHT][WIDTH];
23
24 extern int screen_x;
25 extern int screen_y;
26
27 void game_init_vars(void)
28 {
29   int x, y;
30
31   RandomEM = 1684108901;
32
33   for (y = 0; y < HEIGHT; y++)
34     for (x = 0; x < WIDTH; x++)
35       Array[0][y][x] = ZBORDER;
36   for (y = 0; y < HEIGHT; y++)
37     for (x = 0; x < WIDTH; x++)
38       Array[1][y][x] = ZBORDER;
39   for (y = 0; y < HEIGHT; y++)
40     for (x = 0; x < WIDTH; x++)
41       Array[2][y][x] = ZBORDER;
42   for (y = 0; y < HEIGHT; y++)
43     for (x = 0; x < WIDTH; x++)
44       Array[3][y][x] = Xblank;
45
46   for (y = 0; y < HEIGHT; y++)
47     Index[0][y] = Array[0][y];
48   for (y = 0; y < HEIGHT; y++)
49     Index[1][y] = Array[1][y];
50   for (y = 0; y < HEIGHT; y++)
51     Index[2][y] = Array[2][y];
52   for (y = 0; y < HEIGHT; y++)
53     Index[3][y] = Array[3][y];
54
55   Cave = Index[0];
56   Next = Index[1];
57   Draw = Index[2];
58   Boom = Index[3];
59 }
60
61 void InitGameEngine_EM()
62 {
63   prepare_em_level();
64
65   game_initscreen();
66   game_animscreen();
67 }
68
69 #if 1
70
71 void GameActions_EM(byte action[MAX_PLAYERS])
72 {
73   static unsigned long game_frame_delay = 0;
74 #if 1
75   unsigned long game_frame_delay_value = getGameFrameDelay_EM(20);
76 #else
77   unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
78 #endif
79   int i;
80
81 #if 0
82   /* this is done in screens.c/HandleGameActions() by calling BackToFront() */
83   XSync(display, False);        /* block until all graphics are drawn */
84 #endif
85
86   WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
87
88   game_animscreen();
89
90   RandomEM = RandomEM * 129 + 1;
91
92   frame = (frame - 1) & 7;
93
94   for (i = 0; i < MAX_PLAYERS; i++)
95     readjoy(action[i], &ply[i]);
96
97   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
98
99   if (frame == 7)
100   {
101     synchro_1();
102     synchro_2();
103   }
104
105   if (frame == 6)
106   {
107     synchro_3();
108     sound_play();
109
110     if (game_frame_delay_value > 0)     /* do not redraw values in warp mode */
111       DrawGameDoorValues_EM();
112   }
113
114 #if 0
115   if (lev.time_initial == 0)
116     lev.time++;
117   else if (lev.time > 0)
118     lev.time--;
119 #endif
120
121 #if 0
122   if (lev.time_initial > 0 &&
123       lev.time > 0 && lev.time <= 50 && lev.time % 5 == 0 && setup.time_limit)
124     play_sound(-1, -1, SAMPLE_time);
125 #endif
126 }
127
128 #else
129
130 void GameActions_EM(byte action)
131 {
132   static unsigned long game_frame_delay = 0;
133 #if 1
134   unsigned long game_frame_delay_value = getGameFrameDelay_EM(20);
135 #else
136   unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
137 #endif
138
139 #if 0
140   /* this is done in screens.c/HandleGameActions() by calling BackToFront() */
141   XSync(display, False);        /* block until all graphics are drawn */
142 #endif
143
144   WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
145
146   game_animscreen();
147
148   RandomEM = RandomEM * 129 + 1;
149
150   frame = (frame - 1) & 7;
151
152   readjoy(action);
153
154   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
155
156   if (frame == 7)
157   {
158     synchro_1();
159     synchro_2();
160   }
161
162   if (frame == 6)
163   {
164     synchro_3();
165     sound_play();
166
167     if (game_frame_delay_value > 0)     /* do not redraw values in warp mode */
168       DrawGameDoorValues_EM();
169   }
170
171 #if 0
172   if (lev.time_initial == 0)
173     lev.time++;
174   else if (lev.time > 0)
175     lev.time--;
176 #endif
177
178 #if 0
179   if (lev.time_initial > 0 &&
180       lev.time > 0 && lev.time <= 50 && lev.time % 5 == 0 && setup.time_limit)
181     play_sound(-1, -1, SAMPLE_time);
182 #endif
183 }
184
185 #endif
186
187
188 /* read input device for players */
189
190 #if 1
191
192 void readjoy(byte action, struct PLAYER *ply)
193 {
194   int north = 0, east = 0, south = 0, west = 0;
195   int snap = 0, drop = 0;
196
197   if (action & JOY_LEFT)
198     west = 1;
199
200   if (action & JOY_RIGHT)
201     east = 1;
202
203   if (action & JOY_UP)
204     north = 1;
205
206   if (action & JOY_DOWN)
207     south = 1;
208
209   if (action & JOY_BUTTON_1)
210     snap = 1;
211
212   if (action & JOY_BUTTON_2)
213     drop = 1;
214
215   ply->joy_snap = snap;
216   ply->joy_drop = drop;
217
218   if (ply->joy_stick || (north | east | south | west))
219   {
220     ply->joy_n = north;
221     ply->joy_e = east;
222     ply->joy_s = south;
223     ply->joy_w = west;
224   }
225 }
226
227 #else
228
229 void readjoy(byte action)
230 {
231   int north = 0, east = 0, south = 0, west = 0;
232   int snap = 0, drop = 0;
233
234   if (action & JOY_LEFT)
235     west = 1;
236
237   if (action & JOY_RIGHT)
238     east = 1;
239
240   if (action & JOY_UP)
241     north = 1;
242
243   if (action & JOY_DOWN)
244     south = 1;
245
246   if (action & JOY_BUTTON_1)
247     snap = 1;
248
249   if (action & JOY_BUTTON_2)
250     drop = 1;
251
252 #if 1
253   ply1.joy_snap = snap;
254   ply1.joy_drop = drop;
255   if (ply1.joy_stick || (north | east | south | west))
256   {
257     ply1.joy_n = north;
258     ply1.joy_e = east;
259     ply1.joy_s = south;
260     ply1.joy_w = west;
261   }
262
263 #else
264
265   ply2.joy_snap = snap;
266   ply2.joy_drop = drop;
267   if (ply2.joy_stick || (north | east | south | west))
268   {
269     ply2.joy_n = north;
270     ply2.joy_e = east;
271     ply2.joy_s = south;
272     ply2.joy_w = west;
273   }
274 #endif
275 }
276
277 #endif