small code cleanup of screen redraw functions (EM)
[rocksndiamonds.git] / src / game_em / input.c
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
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
61 void InitGameEngine_EM()
62 {
63   prepare_em_level();
64
65   game_initscreen();
66
67   RedrawPlayfield_EM(FALSE);
68 }
69
70 void UpdateGameDoorValues_EM()
71 {
72 }
73
74 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
75 {
76   int i;
77   boolean any_player_dropping = FALSE;
78
79   RandomEM = RandomEM * 129 + 1;
80
81   frame = (frame - 1) & 7;
82
83   for (i = 0; i < MAX_PLAYERS; i++)
84     readjoy(action[i], &ply[i]);
85
86   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
87
88   if (frame == 7)
89   {
90     synchro_1();
91     synchro_2();
92   }
93
94   if (frame == 6)
95   {
96     synchro_3();
97     sound_play();
98
99     UpdateGameDoorValues_EM();
100   }
101
102   for (i = 0; i < MAX_PLAYERS; i++)
103     if (ply[i].joy_drop &&
104         ply[i].dynamite &&
105         ply[i].dynamite_cnt > 0 &&
106         ply[i].dynamite_cnt < 5)
107       any_player_dropping = TRUE;
108
109   CheckSingleStepMode_EM(action, frame, game_em.any_player_moving,
110                          game_em.any_player_snapping, any_player_dropping);
111
112   RedrawPlayfield_EM(FALSE);
113
114   BlitScreenToBitmap_EM(backbuffer);
115   BackToFront_EM();
116 }
117
118 /* read input device for players */
119
120 void readjoy(byte action, struct PLAYER *ply)
121 {
122   int north = 0, east = 0, south = 0, west = 0;
123   int snap = 0, drop = 0;
124
125   if (action & JOY_LEFT)
126     west = 1;
127
128   if (action & JOY_RIGHT)
129     east = 1;
130
131   if (action & JOY_UP)
132     north = 1;
133
134   if (action & JOY_DOWN)
135     south = 1;
136
137   if (action & JOY_BUTTON_1)
138     snap = 1;
139
140   if (action & JOY_BUTTON_2)
141     drop = 1;
142
143   ply->joy_snap = snap;
144   ply->joy_drop = drop;
145
146   if (ply->joy_stick || (north | east | south | west))
147   {
148     ply->joy_n = north;
149     ply->joy_e = east;
150     ply->joy_s = south;
151     ply->joy_w = west;
152   }
153 }
154
155 void SaveEngineSnapshotValues_EM()
156 {
157   int i, j, k;
158
159   engine_snapshot_em.game_em = game_em;
160   engine_snapshot_em.lev = lev;
161
162   engine_snapshot_em.RandomEM = RandomEM;
163   engine_snapshot_em.frame = frame;
164
165   engine_snapshot_em.screen_x = screen_x;
166   engine_snapshot_em.screen_y = screen_y;
167
168   engine_snapshot_em.Boom = Boom;
169   engine_snapshot_em.Cave = Cave;
170   engine_snapshot_em.Next = Next;
171   engine_snapshot_em.Draw = Draw;
172
173   for (i = 0; i < 4; i++)
174     engine_snapshot_em.ply[i] = ply[i];
175
176   for (i = 0; i < 4; i++)
177     for (j = 0; j < HEIGHT; j++)
178       for (k = 0; k < WIDTH; k++)
179         engine_snapshot_em.Array[i][j][k] = Array[i][j][k];
180 }
181
182 void LoadEngineSnapshotValues_EM()
183 {
184   int i, j, k;
185
186   game_em = engine_snapshot_em.game_em;
187   lev = engine_snapshot_em.lev;
188
189   RandomEM = engine_snapshot_em.RandomEM;
190   frame = engine_snapshot_em.frame;
191
192   screen_x = engine_snapshot_em.screen_x;
193   screen_y = engine_snapshot_em.screen_y;
194
195   Boom = engine_snapshot_em.Boom;
196   Cave = engine_snapshot_em.Cave;
197   Next = engine_snapshot_em.Next;
198   Draw = engine_snapshot_em.Draw;
199
200   for (i = 0; i < 4; i++)
201     ply[i] = engine_snapshot_em.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         Array[i][j][k] = engine_snapshot_em.Array[i][j][k];
207 }