rnd-20060824-1-src
[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 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
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   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
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   game_animscreen();
95
96 #if 1
97 #if 0
98   SyncDisplay();
99 #endif
100
101   blitscreen();
102 #endif
103
104   RandomEM = RandomEM * 129 + 1;
105
106   frame = (frame - 1) & 7;
107
108   for (i = 0; i < MAX_PLAYERS; i++)
109     readjoy(action[i], &ply[i]);
110
111   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
112
113   if (frame == 7)
114   {
115     synchro_1();
116     synchro_2();
117   }
118
119   if (frame == 6)
120   {
121     synchro_3();
122     sound_play();
123
124     if (!warp_mode)             /* do not redraw values in warp mode */
125       DrawGameDoorValues_EM();
126   }
127 }
128
129 /* read input device for players */
130
131 void readjoy(byte action, struct PLAYER *ply)
132 {
133   int north = 0, east = 0, south = 0, west = 0;
134   int snap = 0, drop = 0;
135
136   if (action & JOY_LEFT)
137     west = 1;
138
139   if (action & JOY_RIGHT)
140     east = 1;
141
142   if (action & JOY_UP)
143     north = 1;
144
145   if (action & JOY_DOWN)
146     south = 1;
147
148   if (action & JOY_BUTTON_1)
149     snap = 1;
150
151   if (action & JOY_BUTTON_2)
152     drop = 1;
153
154   ply->joy_snap = snap;
155   ply->joy_drop = drop;
156
157   if (ply->joy_stick || (north | east | south | west))
158   {
159     ply->joy_n = north;
160     ply->joy_e = east;
161     ply->joy_s = south;
162     ply->joy_w = west;
163   }
164 }
165
166 void SaveEngineSnapshotValues_EM()
167 {
168   int i, j, k;
169
170   engine_snapshot_em.RandomEM = RandomEM;
171   engine_snapshot_em.game_em = game_em;
172   engine_snapshot_em.lev = lev;
173   engine_snapshot_em.screen_x = screen_x;
174   engine_snapshot_em.screen_y = screen_y;
175   engine_snapshot_em.frame = frame;
176
177   for (i = 0; i < 4; i++)
178     engine_snapshot_em.ply[i] = ply[i];
179
180   for (i = 0; i < 4; i++)
181     for (j = 0; j < HEIGHT; j++)
182       for (k = 0; k < WIDTH; k++)
183         engine_snapshot_em.Array[i][j][k] = Array[i][j][k];
184
185 }
186
187 void LoadEngineSnapshotValues_EM()
188 {
189   int i, j, k;
190
191   RandomEM = engine_snapshot_em.RandomEM;
192   game_em = engine_snapshot_em.game_em;
193   screen_x = engine_snapshot_em.screen_x;
194   screen_y = engine_snapshot_em.screen_y;
195   frame = engine_snapshot_em.frame;
196
197   for (i = 0; i < 4; i++)
198     ply[i] = engine_snapshot_em.ply[i];
199
200   for (i = 0; i < 4; i++)
201     for (j = 0; j < HEIGHT; j++)
202       for (k = 0; k < WIDTH; k++)
203         Array[i][j][k] = engine_snapshot_em.Array[i][j][k];
204 }