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 long 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
78 #if 0
79 static int foo = -1;
80
81 if (action[0] == 0 && foo != 0)
82 printf("KEY RELEASED @ %05d\n", FrameCounter);
83
84 foo = action[0];
85 #endif
86
87 #if 0
88 #if 1
89 if (FrameCounter % 10 == 0)
90 #endif
91 printf("::: %05d: %lu, %d\n", FrameCounter, RandomEM, frame);
92 #endif
93
94 #if 0
95 game_animscreen();
96
97 #if 1
98 #if 0
99 SyncDisplay();
100 #endif
101
102 blitscreen();
103 #endif
104 #endif
105
106 RandomEM = RandomEM * 129 + 1;
107
108 frame = (frame - 1) & 7;
109
110 for (i = 0; i < MAX_PLAYERS; i++)
111 readjoy(action[i], &ply[i]);
112
113 UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
114
115 if (frame == 7)
116 {
117 synchro_1();
118 synchro_2();
119 }
120
121 if (frame == 6)
122 {
123 synchro_3();
124 sound_play();
125
126 if (!warp_mode) /* do not redraw values in warp mode */
127 DrawGameDoorValues_EM();
128 }
129
130 CheckSingleStepMode_EM(action, frame, game_em.any_player_moving);
131
132 #if 1
133 game_animscreen();
134
135 #if 1
136 #if 0
137 SyncDisplay();
138 #endif
139
140 blitscreen();
141 #endif
142 #endif
143 }
144
145 /* read input device for players */
146
readjoy(byte action,struct PLAYER * ply)147 void readjoy(byte action, struct PLAYER *ply)
148 {
149 int north = 0, east = 0, south = 0, west = 0;
150 int snap = 0, drop = 0;
151
152 if (action & JOY_LEFT)
153 west = 1;
154
155 if (action & JOY_RIGHT)
156 east = 1;
157
158 if (action & JOY_UP)
159 north = 1;
160
161 if (action & JOY_DOWN)
162 south = 1;
163
164 if (action & JOY_BUTTON_1)
165 snap = 1;
166
167 if (action & JOY_BUTTON_2)
168 drop = 1;
169
170 ply->joy_snap = snap;
171 ply->joy_drop = drop;
172
173 if (ply->joy_stick || (north | east | south | west))
174 {
175 ply->joy_n = north;
176 ply->joy_e = east;
177 ply->joy_s = south;
178 ply->joy_w = west;
179 }
180 }
181
SaveEngineSnapshotValues_EM()182 void SaveEngineSnapshotValues_EM()
183 {
184 int i, j, k;
185
186 engine_snapshot_em.game_em = game_em;
187 engine_snapshot_em.lev = lev;
188
189 engine_snapshot_em.RandomEM = RandomEM;
190 engine_snapshot_em.frame = frame;
191
192 engine_snapshot_em.screen_x = screen_x;
193 engine_snapshot_em.screen_y = screen_y;
194
195 engine_snapshot_em.Boom = Boom;
196 engine_snapshot_em.Cave = Cave;
197 engine_snapshot_em.Next = Next;
198 engine_snapshot_em.Draw = Draw;
199
200 for (i = 0; i < 4; i++)
201 engine_snapshot_em.ply[i] = ply[i];
202
203 for (i = 0; i < 4; i++)
204 for (j = 0; j < HEIGHT; j++)
205 for (k = 0; k < WIDTH; k++)
206 engine_snapshot_em.Array[i][j][k] = Array[i][j][k];
207 }
208
LoadEngineSnapshotValues_EM()209 void LoadEngineSnapshotValues_EM()
210 {
211 int i, j, k;
212
213 game_em = engine_snapshot_em.game_em;
214 lev = engine_snapshot_em.lev;
215
216 RandomEM = engine_snapshot_em.RandomEM;
217 frame = engine_snapshot_em.frame;
218
219 screen_x = engine_snapshot_em.screen_x;
220 screen_y = engine_snapshot_em.screen_y;
221
222 Boom = engine_snapshot_em.Boom;
223 Cave = engine_snapshot_em.Cave;
224 Next = engine_snapshot_em.Next;
225 Draw = engine_snapshot_em.Draw;
226
227 for (i = 0; i < 4; i++)
228 ply[i] = engine_snapshot_em.ply[i];
229
230 for (i = 0; i < 4; i++)
231 for (j = 0; j < HEIGHT; j++)
232 for (k = 0; k < WIDTH; k++)
233 Array[i][j][k] = engine_snapshot_em.Array[i][j][k];
234 }
235