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