0dd2bb3b95f99f1621b0d1c426a09a28c690fcb5
[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 void game_init_vars(void)
26 {
27   int x, y;
28
29   RandomEM = 1684108901;
30
31   for (y = 0; y < HEIGHT; y++)
32     for (x = 0; x < WIDTH; x++)
33       Array[0][y][x] = ZBORDER;
34   for (y = 0; y < HEIGHT; y++)
35     for (x = 0; x < WIDTH; x++)
36       Array[1][y][x] = ZBORDER;
37   for (y = 0; y < HEIGHT; y++)
38     for (x = 0; x < WIDTH; x++)
39       Array[2][y][x] = ZBORDER;
40   for (y = 0; y < HEIGHT; y++)
41     for (x = 0; x < WIDTH; x++)
42       Array[3][y][x] = Xblank;
43
44   for (y = 0; y < HEIGHT; y++)
45     Index[0][y] = Array[0][y];
46   for (y = 0; y < HEIGHT; y++)
47     Index[1][y] = Array[1][y];
48   for (y = 0; y < HEIGHT; y++)
49     Index[2][y] = Array[2][y];
50   for (y = 0; y < HEIGHT; y++)
51     Index[3][y] = Array[3][y];
52
53   Cave = Index[0];
54   Next = Index[1];
55   Draw = Index[2];
56   Boom = Index[3];
57 }
58
59 void InitGameEngine_EM()
60 {
61   prepare_em_level();
62
63   game_initscreen();
64   game_animscreen();
65
66 #if 0
67   /* blit playfield from scroll buffer to normal back buffer for fading in */
68   BlitScreenToBitmap_EM(backbuffer);
69 #endif
70 }
71
72 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
73 {
74   int i;
75
76 #if 0
77   static int foo = -1;
78
79   if (action[0] == 0 && foo != 0)
80     printf("KEY RELEASED @ %05d\n", FrameCounter);
81
82   foo = action[0];
83 #endif
84
85 #if 0
86 #if 1
87   if (FrameCounter % 10 == 0)
88 #endif
89     printf("::: %05d: %lu, %d\n", FrameCounter, RandomEM, frame);
90 #endif
91
92   game_animscreen();
93
94 #if 1
95 #if 0
96   SyncDisplay();
97 #endif
98
99   blitscreen();
100 #endif
101
102   RandomEM = RandomEM * 129 + 1;
103
104   frame = (frame - 1) & 7;
105
106   for (i = 0; i < MAX_PLAYERS; i++)
107     readjoy(action[i], &ply[i]);
108
109   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
110
111   if (frame == 7)
112   {
113     synchro_1();
114     synchro_2();
115   }
116
117   if (frame == 6)
118   {
119     synchro_3();
120     sound_play();
121
122     if (!warp_mode)             /* do not redraw values in warp mode */
123       DrawGameDoorValues_EM();
124   }
125 }
126
127 /* read input device for players */
128
129 void readjoy(byte action, struct PLAYER *ply)
130 {
131   int north = 0, east = 0, south = 0, west = 0;
132   int snap = 0, drop = 0;
133
134   if (action & JOY_LEFT)
135     west = 1;
136
137   if (action & JOY_RIGHT)
138     east = 1;
139
140   if (action & JOY_UP)
141     north = 1;
142
143   if (action & JOY_DOWN)
144     south = 1;
145
146   if (action & JOY_BUTTON_1)
147     snap = 1;
148
149   if (action & JOY_BUTTON_2)
150     drop = 1;
151
152   ply->joy_snap = snap;
153   ply->joy_drop = drop;
154
155   if (ply->joy_stick || (north | east | south | west))
156   {
157     ply->joy_n = north;
158     ply->joy_e = east;
159     ply->joy_s = south;
160     ply->joy_w = west;
161   }
162 }