1 /* 2000-08-13T15:29:40Z
3 * handle input from x11 and keyboard and joystick
13 struct PLAYER ply[MAX_PLAYERS];
18 struct EngineSnapshotInfo_EM engine_snapshot_em;
20 void game_init_random(void)
22 RandomEM = 1684108901;
25 void game_init_cave_buffers(void)
29 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
30 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
31 lev.cavebuf[x][y] = Zborder;
32 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
33 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
34 lev.nextbuf[x][y] = Zborder;
35 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
36 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
37 lev.drawbuf[x][y] = Zborder;
38 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
39 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
40 lev.boombuf[x][y] = Xblank;
42 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
43 lev.cavecol[x] = lev.cavebuf[x];
44 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
45 lev.nextcol[x] = lev.nextbuf[x];
46 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
47 lev.drawcol[x] = lev.drawbuf[x];
48 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
49 lev.boomcol[x] = lev.boombuf[x];
51 lev.cave = lev.cavecol;
52 lev.next = lev.nextcol;
53 lev.draw = lev.drawcol;
54 lev.boom = lev.boomcol;
57 void InitGameEngine_EM(void)
63 RedrawPlayfield_EM(FALSE);
66 static void UpdateGameDoorValues_EM(void)
70 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
73 boolean any_player_dropping = FALSE;
75 RandomEM = RandomEM * 129 + 1;
77 frame = (frame - 1) & 7;
79 for (i = 0; i < MAX_PLAYERS; i++)
80 readjoy(action[i], &ply[i]);
82 UpdateEngineValues(screen_x / TILEX, screen_y / TILEY, ply[0].x, ply[0].y);
94 UpdateGameDoorValues_EM();
97 for (i = 0; i < MAX_PLAYERS; i++)
98 if (ply[i].joy_drop &&
100 ply[i].dynamite_cnt > 0 &&
101 ply[i].dynamite_cnt < 5)
102 any_player_dropping = TRUE;
104 CheckSingleStepMode_EM(action, frame, game_em.any_player_moving,
105 game_em.any_player_snapping, any_player_dropping);
107 RedrawPlayfield_EM(FALSE);
110 /* read input device for players */
112 void readjoy(byte action, struct PLAYER *ply)
114 int north = 0, east = 0, south = 0, west = 0;
115 int snap = 0, drop = 0;
117 if (game_em.use_single_button && action & (JOY_BUTTON_1 | JOY_BUTTON_2))
118 action |= JOY_BUTTON_1 | JOY_BUTTON_2;
120 if (action & JOY_LEFT)
123 if (action & JOY_RIGHT)
129 if (action & JOY_DOWN)
132 if (action & JOY_BUTTON_1)
135 if (action & JOY_BUTTON_2)
138 /* always update drop action */
139 ply->joy_drop = drop;
141 if (ply->joy_stick || (north | east | south | west)) /* (no "| snap"!) */
148 /* when storing last action, only update snap action with direction */
149 /* (prevents clearing direction if snapping stopped before frame 7) */
150 ply->joy_snap = snap;
153 /* if no direction was stored before, allow setting snap to current state */
158 ply->joy_snap = snap;
160 /* use bug with snap key (mainly TAS keys) sometimes moving the player */
161 if (game_em.use_snap_key_bug)
162 ply->joy_snap = snap;
165 void SaveEngineSnapshotValues_EM(void)
169 engine_snapshot_em.game_em = game_em;
170 engine_snapshot_em.lev = lev;
172 engine_snapshot_em.RandomEM = RandomEM;
173 engine_snapshot_em.frame = frame;
175 engine_snapshot_em.screen_x = screen_x;
176 engine_snapshot_em.screen_y = screen_y;
178 for (i = 0; i < 4; i++)
179 engine_snapshot_em.ply[i] = ply[i];
182 void LoadEngineSnapshotValues_EM(void)
186 game_em = engine_snapshot_em.game_em;
187 lev = engine_snapshot_em.lev;
189 RandomEM = engine_snapshot_em.RandomEM;
190 frame = engine_snapshot_em.frame;
192 screen_x = engine_snapshot_em.screen_x;
193 screen_y = engine_snapshot_em.screen_y;
195 for (i = 0; i < 4; i++)
196 ply[i] = engine_snapshot_em.ply[i];