1 /* 2000-08-13T15:29:40Z
3 * handle input from x11 and keyboard and joystick
12 struct PLAYER ply[MAX_PLAYERS];
17 struct EngineSnapshotInfo_EM engine_snapshot_em;
19 void game_init_random(void)
21 RandomEM = 1684108901;
24 void game_init_cave_buffers(void)
28 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
29 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
30 lev.cavebuf[x][y] = Zborder;
31 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
32 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
33 lev.nextbuf[x][y] = Zborder;
34 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
35 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
36 lev.drawbuf[x][y] = Zborder;
37 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
38 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
39 lev.boombuf[x][y] = Xblank;
41 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
42 lev.cavecol[x] = lev.cavebuf[x];
43 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
44 lev.nextcol[x] = lev.nextbuf[x];
45 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
46 lev.drawcol[x] = lev.drawbuf[x];
47 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
48 lev.boomcol[x] = lev.boombuf[x];
50 lev.cave = lev.cavecol;
51 lev.next = lev.nextcol;
52 lev.draw = lev.drawcol;
53 lev.boom = lev.boomcol;
56 void InitGameEngine_EM(void)
62 RedrawPlayfield_EM(FALSE);
65 static void UpdateGameDoorValues_EM(void)
69 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
72 boolean any_player_dropping = FALSE;
74 RandomEM = RandomEM * 129 + 1;
76 frame = (frame - 1) & 7;
78 for (i = 0; i < MAX_PLAYERS; i++)
79 readjoy(action[i], &ply[i]);
81 UpdateEngineValues(screen_x / TILEX, screen_y / TILEY, ply[0].x, ply[0].y);
93 UpdateGameDoorValues_EM();
96 for (i = 0; i < MAX_PLAYERS; i++)
97 if (ply[i].joy_drop &&
99 ply[i].dynamite_cnt > 0 &&
100 ply[i].dynamite_cnt < 5)
101 any_player_dropping = TRUE;
103 CheckSingleStepMode_EM(action, frame, game_em.any_player_moving,
104 game_em.any_player_snapping, any_player_dropping);
106 RedrawPlayfield_EM(FALSE);
109 /* read input device for players */
111 void readjoy(byte action, struct PLAYER *ply)
113 int north = 0, east = 0, south = 0, west = 0;
114 int snap = 0, drop = 0;
116 if (game_em.use_single_button && action & (JOY_BUTTON_1 | JOY_BUTTON_2))
117 action |= JOY_BUTTON_1 | JOY_BUTTON_2;
119 if (action & JOY_LEFT)
122 if (action & JOY_RIGHT)
128 if (action & JOY_DOWN)
131 if (action & JOY_BUTTON_1)
134 if (action & JOY_BUTTON_2)
137 /* always update drop action */
138 ply->joy_drop = drop;
140 if (ply->joy_stick || (north | east | south | west)) /* (no "| snap"!) */
147 /* when storing last action, only update snap action with direction */
148 /* (prevents clearing direction if snapping stopped before frame 7) */
149 ply->joy_snap = snap;
152 /* if no direction was stored before, allow setting snap to current state */
157 ply->joy_snap = snap;
159 /* use bug with snap key (mainly TAS keys) sometimes moving the player */
160 if (game_em.use_snap_key_bug)
161 ply->joy_snap = snap;
164 void SaveEngineSnapshotValues_EM(void)
168 engine_snapshot_em.game_em = game_em;
169 engine_snapshot_em.lev = lev;
171 engine_snapshot_em.RandomEM = RandomEM;
172 engine_snapshot_em.frame = frame;
174 engine_snapshot_em.screen_x = screen_x;
175 engine_snapshot_em.screen_y = screen_y;
177 for (i = 0; i < 4; i++)
178 engine_snapshot_em.ply[i] = ply[i];
181 void LoadEngineSnapshotValues_EM(void)
185 game_em = engine_snapshot_em.game_em;
186 lev = engine_snapshot_em.lev;
188 RandomEM = engine_snapshot_em.RandomEM;
189 frame = engine_snapshot_em.frame;
191 screen_x = engine_snapshot_em.screen_x;
192 screen_y = engine_snapshot_em.screen_y;
194 for (i = 0; i < 4; i++)
195 ply[i] = engine_snapshot_em.ply[i];