a6ddcfab8bd49694846bc46ec6e9bf3703dce69f
[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 "global.h"
7 #include "display.h"
8 #include "level.h"
9
10
11 unsigned long Random;
12
13 struct PLAYER ply1;
14 struct PLAYER ply2;
15 struct LEVEL lev;
16
17 struct LevelInfo_EM native_em_level;
18
19 unsigned short **Boom;
20 unsigned short **Cave;
21 unsigned short **Next;
22 unsigned short **Draw;
23
24 static unsigned short *Index[4][HEIGHT];
25 static unsigned short Array[4][HEIGHT][WIDTH];
26
27 void game_init_vars(void)
28 {
29   int x, y;
30
31   Random = 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
69 void GameActions_EM(byte action)
70 {
71   static unsigned long game_frame_delay = 0;
72   unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
73
74 #if 0
75   /* this is done in screens.c/HandleGameActions() by calling BackToFront() */
76   XSync(display, False);        /* block until all graphics are drawn */
77 #endif
78
79   WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
80
81   game_animscreen();
82
83   Random = Random * 129 + 1;
84
85   frame = (frame - 1) & 7;
86
87   readjoy(action);
88
89   if (frame == 7)
90   {
91     synchro_1();
92     synchro_2();
93   }
94
95   if (frame == 6)
96   {
97     synchro_3();
98     sound_play();
99
100     DrawGameDoorValues_EM(lev.required, ply1.dynamite, lev.score,
101                           (lev.time + 4) / 5);
102   }
103 }
104
105
106 /* read input device for players */
107
108 void readjoy(byte action)
109 {
110   unsigned int north = 0, east = 0, south = 0, west = 0, fire = 0;
111
112   if (action & JOY_LEFT)
113     west = 1;
114
115   if (action & JOY_RIGHT)
116     east = 1;
117
118   if (action & JOY_UP)
119     north = 1;
120
121   if (action & JOY_DOWN)
122     south = 1;
123
124   if (action & JOY_BUTTON_1)
125     fire = 1;
126
127   ply1.joy_fire = fire;
128   if (ply1.joy_stick || (north | east | south | west))
129   {
130     ply1.joy_n = north;
131     ply1.joy_e = east;
132     ply1.joy_s = south;
133     ply1.joy_w = west;
134   }
135 }