1 /* 2000-08-13T15:29:40Z
2  *
3  * handle input from x11 and keyboard and joystick
4  */
5 
6 #include "main_em.h"
7 
8 
9 unsigned int RandomEM;
10 
11 struct LEVEL lev;
12 struct PLAYER ply[MAX_PLAYERS];
13 
14 short **Boom;
15 short **Cave;
16 short **Next;
17 short **Draw;
18 
19 static short *Index[4][HEIGHT];
20 static short Array[4][HEIGHT][WIDTH];
21 
22 extern int screen_x;
23 extern int screen_y;
24 
25 struct EngineSnapshotInfo_EM engine_snapshot_em;
26 
game_init_vars(void)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 
InitGameEngine_EM()61 void InitGameEngine_EM()
62 {
63   prepare_em_level();
64 
65   game_initscreen();
66   game_animscreen();
67 
68 #if 0
69   /* blit playfield from scroll buffer to normal back buffer for fading in */
70   BlitScreenToBitmap_EM(backbuffer);
71 #endif
72 }
73 
GameActions_EM(byte action[MAX_PLAYERS],boolean warp_mode)74 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
75 {
76   int i;
77   boolean player_is_dropping = FALSE;
78 
79 #if 0
80   static int foo = -1;
81 
82   if (action[0] == 0 && foo != 0)
83     printf("KEY RELEASED @ %05d\n", FrameCounter);
84 
85   foo = action[0];
86 #endif
87 
88 #if 0
89 #if 1
90   if (FrameCounter % 10 == 0)
91 #endif
92     printf("::: %05d: %lu, %d\n", FrameCounter, RandomEM, frame);
93 #endif
94 
95 #if 0
96   game_animscreen();
97 
98 #if 1
99 #if 0
100   SyncDisplay();
101 #endif
102 
103   blitscreen();
104 #endif
105 #endif
106 
107   RandomEM = RandomEM * 129 + 1;
108 
109   frame = (frame - 1) & 7;
110 
111   for (i = 0; i < MAX_PLAYERS; i++)
112     readjoy(action[i], &ply[i]);
113 
114   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
115 
116   if (frame == 7)
117   {
118     synchro_1();
119     synchro_2();
120   }
121 
122   if (frame == 6)
123   {
124     synchro_3();
125     sound_play();
126 
127     if (!warp_mode)		/* do not redraw values in warp mode */
128       DrawGameDoorValues_EM();
129   }
130 
131   for (i = 0; i < MAX_PLAYERS; i++)
132     if (ply[i].joy_drop &&
133 	ply[i].dynamite &&
134 	ply[i].dynamite_cnt > 0 &&
135 	ply[i].dynamite_cnt < 5)
136       player_is_dropping = TRUE;
137 
138   CheckSingleStepMode_EM(action, frame, game_em.any_player_moving,
139 			 player_is_dropping);
140 
141 #if 1
142   game_animscreen();
143 
144 #if 1
145 #if 0
146   SyncDisplay();
147 #endif
148 
149   blitscreen();
150 #endif
151 #endif
152 }
153 
154 /* read input device for players */
155 
readjoy(byte action,struct PLAYER * ply)156 void readjoy(byte action, struct PLAYER *ply)
157 {
158   int north = 0, east = 0, south = 0, west = 0;
159   int snap = 0, drop = 0;
160 
161   if (action & JOY_LEFT)
162     west = 1;
163 
164   if (action & JOY_RIGHT)
165     east = 1;
166 
167   if (action & JOY_UP)
168     north = 1;
169 
170   if (action & JOY_DOWN)
171     south = 1;
172 
173   if (action & JOY_BUTTON_1)
174     snap = 1;
175 
176   if (action & JOY_BUTTON_2)
177     drop = 1;
178 
179   ply->joy_snap = snap;
180   ply->joy_drop = drop;
181 
182   if (ply->joy_stick || (north | east | south | west))
183   {
184     ply->joy_n = north;
185     ply->joy_e = east;
186     ply->joy_s = south;
187     ply->joy_w = west;
188   }
189 }
190 
SaveEngineSnapshotValues_EM()191 void SaveEngineSnapshotValues_EM()
192 {
193   int i, j, k;
194 
195   engine_snapshot_em.game_em = game_em;
196   engine_snapshot_em.lev = lev;
197 
198   engine_snapshot_em.RandomEM = RandomEM;
199   engine_snapshot_em.frame = frame;
200 
201   engine_snapshot_em.screen_x = screen_x;
202   engine_snapshot_em.screen_y = screen_y;
203 
204   engine_snapshot_em.Boom = Boom;
205   engine_snapshot_em.Cave = Cave;
206   engine_snapshot_em.Next = Next;
207   engine_snapshot_em.Draw = Draw;
208 
209   for (i = 0; i < 4; i++)
210     engine_snapshot_em.ply[i] = ply[i];
211 
212   for (i = 0; i < 4; i++)
213     for (j = 0; j < HEIGHT; j++)
214       for (k = 0; k < WIDTH; k++)
215 	engine_snapshot_em.Array[i][j][k] = Array[i][j][k];
216 }
217 
LoadEngineSnapshotValues_EM()218 void LoadEngineSnapshotValues_EM()
219 {
220   int i, j, k;
221 
222   game_em = engine_snapshot_em.game_em;
223   lev = engine_snapshot_em.lev;
224 
225   RandomEM = engine_snapshot_em.RandomEM;
226   frame = engine_snapshot_em.frame;
227 
228   screen_x = engine_snapshot_em.screen_x;
229   screen_y = engine_snapshot_em.screen_y;
230 
231   Boom = engine_snapshot_em.Boom;
232   Cave = engine_snapshot_em.Cave;
233   Next = engine_snapshot_em.Next;
234   Draw = engine_snapshot_em.Draw;
235 
236   for (i = 0; i < 4; i++)
237     ply[i] = engine_snapshot_em.ply[i];
238 
239   for (i = 0; i < 4; i++)
240     for (j = 0; j < HEIGHT; j++)
241       for (k = 0; k < WIDTH; k++)
242 	Array[i][j][k] = engine_snapshot_em.Array[i][j][k];
243 }
244