rnd-20050103-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
112
113 /* read input device for players */
114
115 void readjoy(byte action)
116 {
117   unsigned int north = 0, east = 0, south = 0, west = 0, fire = 0;
118
119   if (action & JOY_LEFT)
120     west = 1;
121
122   if (action & JOY_RIGHT)
123     east = 1;
124
125   if (action & JOY_UP)
126     north = 1;
127
128   if (action & JOY_DOWN)
129     south = 1;
130
131   if (action & JOY_BUTTON_1)
132     fire = 1;
133
134 #if 1
135   ply1.joy_fire = fire;
136   if (ply1.joy_stick || (north | east | south | west))
137   {
138     ply1.joy_n = north;
139     ply1.joy_e = east;
140     ply1.joy_s = south;
141     ply1.joy_w = west;
142   }
143 #else
144   ply2.joy_fire = fire;
145   if (ply2.joy_stick || (north | east | south | west))
146   {
147     ply2.joy_n = north;
148     ply2.joy_e = east;
149     ply2.joy_s = south;
150     ply2.joy_w = west;
151   }
152 #endif
153 }