1 /* 2000-08-13T15:29:40Z
3 * handle input from x11 and keyboard and joystick
11 struct PLAYER ply[MAX_PLAYERS];
13 struct EngineSnapshotInfo_EM engine_snapshot_em;
15 void game_init_random(void)
17 game_em.random = 1684108901;
20 void game_init_cave_buffers(void)
24 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
25 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
26 lev.cavebuf[x][y] = Zborder;
27 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
28 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
29 lev.nextbuf[x][y] = Zborder;
30 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
31 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
32 lev.drawbuf[x][y] = Zborder;
33 for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
34 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
35 lev.boombuf[x][y] = Xblank;
37 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
38 lev.cavecol[x] = lev.cavebuf[x];
39 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
40 lev.nextcol[x] = lev.nextbuf[x];
41 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
42 lev.drawcol[x] = lev.drawbuf[x];
43 for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
44 lev.boomcol[x] = lev.boombuf[x];
46 lev.cave = lev.cavecol;
47 lev.next = lev.nextcol;
48 lev.draw = lev.drawcol;
49 lev.boom = lev.boomcol;
52 void InitGameEngine_EM(void)
58 RedrawPlayfield_EM(FALSE);
61 static void UpdateGameDoorValues_EM(void)
65 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
68 boolean any_player_dropping = FALSE;
70 game_em.random = game_em.random * 129 + 1;
72 frame = (frame - 1) & 7;
74 for (i = 0; i < MAX_PLAYERS; i++)
75 readjoy(action[i], &ply[i]);
77 UpdateEngineValues(screen_x / TILEX, screen_y / TILEY, ply[0].x, ply[0].y);
89 UpdateGameDoorValues_EM();
92 for (i = 0; i < MAX_PLAYERS; i++)
93 if (ply[i].joy_drop &&
95 ply[i].dynamite_cnt > 0 &&
96 ply[i].dynamite_cnt < 5)
97 any_player_dropping = TRUE;
99 CheckSingleStepMode_EM(action, frame, game_em.any_player_moving,
100 game_em.any_player_snapping, any_player_dropping);
102 RedrawPlayfield_EM(FALSE);
105 /* read input device for players */
107 void readjoy(byte action, struct PLAYER *ply)
109 int north = 0, east = 0, south = 0, west = 0;
110 int snap = 0, drop = 0;
112 if (game_em.use_single_button && action & (JOY_BUTTON_1 | JOY_BUTTON_2))
113 action |= JOY_BUTTON_1 | JOY_BUTTON_2;
115 if (action & JOY_LEFT)
118 if (action & JOY_RIGHT)
124 if (action & JOY_DOWN)
127 if (action & JOY_BUTTON_1)
130 if (action & JOY_BUTTON_2)
133 /* always update drop action */
134 ply->joy_drop = drop;
136 if (ply->joy_stick || (north | east | south | west)) /* (no "| snap"!) */
143 /* when storing last action, only update snap action with direction */
144 /* (prevents clearing direction if snapping stopped before frame 7) */
145 ply->joy_snap = snap;
148 /* if no direction was stored before, allow setting snap to current state */
153 ply->joy_snap = snap;
155 /* use bug with snap key (mainly TAS keys) sometimes moving the player */
156 if (game_em.use_snap_key_bug)
157 ply->joy_snap = snap;
160 void SaveEngineSnapshotValues_EM(void)
164 engine_snapshot_em.game_em = game_em;
165 engine_snapshot_em.lev = lev;
167 engine_snapshot_em.frame = frame;
168 engine_snapshot_em.screen_x = screen_x;
169 engine_snapshot_em.screen_y = screen_y;
171 for (i = 0; i < 4; i++)
172 engine_snapshot_em.ply[i] = ply[i];
175 void LoadEngineSnapshotValues_EM(void)
179 game_em = engine_snapshot_em.game_em;
180 lev = engine_snapshot_em.lev;
182 frame = engine_snapshot_em.frame;
183 screen_x = engine_snapshot_em.screen_x;
184 screen_y = engine_snapshot_em.screen_y;
186 for (i = 0; i < 4; i++)
187 ply[i] = engine_snapshot_em.ply[i];