rnd-20041017-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 "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 unsigned short **Boom;
18 unsigned short **Cave;
19 unsigned short **Next;
20 unsigned short **Draw;
21
22 static unsigned short *Index[4][HEIGHT];
23 static unsigned short Array[4][HEIGHT][WIDTH];
24
25 extern unsigned int screen_x;
26 extern unsigned int screen_y;
27
28 void game_init_vars(void)
29 {
30   int x, y;
31
32   Random = 1684108901;
33
34   for (y = 0; y < HEIGHT; y++)
35     for (x = 0; x < WIDTH; x++)
36       Array[0][y][x] = ZBORDER;
37   for (y = 0; y < HEIGHT; y++)
38     for (x = 0; x < WIDTH; x++)
39       Array[1][y][x] = ZBORDER;
40   for (y = 0; y < HEIGHT; y++)
41     for (x = 0; x < WIDTH; x++)
42       Array[2][y][x] = ZBORDER;
43   for (y = 0; y < HEIGHT; y++)
44     for (x = 0; x < WIDTH; x++)
45       Array[3][y][x] = Xblank;
46
47   for (y = 0; y < HEIGHT; y++)
48     Index[0][y] = Array[0][y];
49   for (y = 0; y < HEIGHT; y++)
50     Index[1][y] = Array[1][y];
51   for (y = 0; y < HEIGHT; y++)
52     Index[2][y] = Array[2][y];
53   for (y = 0; y < HEIGHT; y++)
54     Index[3][y] = Array[3][y];
55
56   Cave = Index[0];
57   Next = Index[1];
58   Draw = Index[2];
59   Boom = Index[3];
60 }
61
62 void InitGameEngine_EM()
63 {
64   prepare_em_level();
65
66   game_initscreen();
67   game_animscreen();
68 }
69
70 void GameActions_EM(byte action)
71 {
72   static unsigned long game_frame_delay = 0;
73   unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
74
75 #if 0
76   /* this is done in screens.c/HandleGameActions() by calling BackToFront() */
77   XSync(display, False);        /* block until all graphics are drawn */
78 #endif
79
80   WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
81
82   game_animscreen();
83
84   Random = Random * 129 + 1;
85
86   frame = (frame - 1) & 7;
87
88   readjoy(action);
89
90   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
91
92   if (frame == 7)
93   {
94     synchro_1();
95     synchro_2();
96   }
97
98   if (frame == 6)
99   {
100     synchro_3();
101     sound_play();
102
103     DrawGameDoorValues_EM(lev.required, ply1.dynamite, lev.score,
104                           (lev.time + 4) / 5);
105   }
106 }
107
108
109 /* read input device for players */
110
111 void readjoy(byte action)
112 {
113   unsigned int north = 0, east = 0, south = 0, west = 0, fire = 0;
114
115   if (action & JOY_LEFT)
116     west = 1;
117
118   if (action & JOY_RIGHT)
119     east = 1;
120
121   if (action & JOY_UP)
122     north = 1;
123
124   if (action & JOY_DOWN)
125     south = 1;
126
127   if (action & JOY_BUTTON_1)
128     fire = 1;
129
130 #if 1
131   ply1.joy_fire = fire;
132   if (ply1.joy_stick || (north | east | south | west))
133   {
134     ply1.joy_n = north;
135     ply1.joy_e = east;
136     ply1.joy_s = south;
137     ply1.joy_w = west;
138   }
139 #else
140   ply2.joy_fire = fire;
141   if (ply2.joy_stick || (north | east | south | west))
142   {
143     ply2.joy_n = north;
144     ply2.joy_e = east;
145     ply2.joy_s = south;
146     ply2.joy_w = west;
147   }
148 #endif
149 }