rnd-20060319-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 RandomEM;
12
13 struct LEVEL lev;
14 struct PLAYER ply[MAX_PLAYERS];
15
16 short **Boom;
17 short **Cave;
18 short **Next;
19 short **Draw;
20
21 static short *Index[4][HEIGHT];
22 static short Array[4][HEIGHT][WIDTH];
23
24 extern int screen_x;
25 extern int screen_y;
26
27 void game_init_vars(void)
28 {
29   int x, y;
30
31   RandomEM = 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[MAX_PLAYERS], boolean warp_mode)
70 {
71   int i;
72
73   game_animscreen();
74
75   RandomEM = RandomEM * 129 + 1;
76
77   frame = (frame - 1) & 7;
78
79   for (i = 0; i < MAX_PLAYERS; i++)
80     readjoy(action[i], &ply[i]);
81
82   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
83
84   if (frame == 7)
85   {
86     synchro_1();
87     synchro_2();
88   }
89
90   if (frame == 6)
91   {
92     synchro_3();
93     sound_play();
94
95     if (!warp_mode)             /* do not redraw values in warp mode */
96       DrawGameDoorValues_EM();
97   }
98 }
99
100 /* read input device for players */
101
102 void readjoy(byte action, struct PLAYER *ply)
103 {
104   int north = 0, east = 0, south = 0, west = 0;
105   int snap = 0, drop = 0;
106
107   if (action & JOY_LEFT)
108     west = 1;
109
110   if (action & JOY_RIGHT)
111     east = 1;
112
113   if (action & JOY_UP)
114     north = 1;
115
116   if (action & JOY_DOWN)
117     south = 1;
118
119   if (action & JOY_BUTTON_1)
120     snap = 1;
121
122   if (action & JOY_BUTTON_2)
123     drop = 1;
124
125   ply->joy_snap = snap;
126   ply->joy_drop = drop;
127
128   if (ply->joy_stick || (north | east | south | west))
129   {
130     ply->joy_n = north;
131     ply->joy_e = east;
132     ply->joy_s = south;
133     ply->joy_w = west;
134   }
135 }