rnd-20050314-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 #if 1
74   unsigned long game_frame_delay_value = getGameFrameDelay_EM(20);
75 #else
76   unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
77 #endif
78
79 #if 0
80   /* this is done in screens.c/HandleGameActions() by calling BackToFront() */
81   XSync(display, False);        /* block until all graphics are drawn */
82 #endif
83
84   WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
85
86   game_animscreen();
87
88   Random = Random * 129 + 1;
89
90   frame = (frame - 1) & 7;
91
92   readjoy(action);
93
94   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
95
96   if (frame == 7)
97   {
98     synchro_1();
99     synchro_2();
100   }
101
102   if (frame == 6)
103   {
104     synchro_3();
105     sound_play();
106
107     if (game_frame_delay_value > 0)     /* do not redraw values in warp mode */
108       DrawGameDoorValues_EM();
109   }
110
111 #if 0
112   if (lev.time_initial == 0)
113     lev.time++;
114   else if (lev.time > 0)
115     lev.time--;
116 #endif
117
118 #if 0
119   if (lev.time_initial > 0 &&
120       lev.time > 0 && lev.time <= 50 && lev.time % 5 == 0 && setup.time_limit)
121     play_sound(-1, -1, SAMPLE_time);
122 #endif
123 }
124
125
126 /* read input device for players */
127
128 void readjoy(byte action)
129 {
130   unsigned int north = 0, east = 0, south = 0, west = 0;
131   unsigned int snap = 0, drop = 0;
132
133   if (action & JOY_LEFT)
134     west = 1;
135
136   if (action & JOY_RIGHT)
137     east = 1;
138
139   if (action & JOY_UP)
140     north = 1;
141
142   if (action & JOY_DOWN)
143     south = 1;
144
145   if (action & JOY_BUTTON_1)
146     snap = 1;
147
148   if (action & JOY_BUTTON_2)
149     drop = 1;
150
151 #if 1
152   ply1.joy_snap = snap;
153   ply1.joy_drop = drop;
154   if (ply1.joy_stick || (north | east | south | west))
155   {
156     ply1.joy_n = north;
157     ply1.joy_e = east;
158     ply1.joy_s = south;
159     ply1.joy_w = west;
160   }
161
162 #else
163
164   ply2.joy_snap = snap;
165   ply2.joy_drop = drop;
166   if (ply2.joy_stick || (north | east | south | west))
167   {
168     ply2.joy_n = north;
169     ply2.joy_e = east;
170     ply2.joy_s = south;
171     ply2.joy_w = west;
172   }
173 #endif
174 }