353b36eec71687f862d7a44fd7b2f7a0061c9b16
[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 "main_em.h"
7
8
9 unsigned long RandomEM;
10
11 struct LEVEL lev;
12 struct PLAYER ply[MAX_PLAYERS];
13
14 short **Boom;
15 short **Cave;
16 short **Next;
17 short **Draw;
18
19 static short *Index[4][HEIGHT];
20 static short Array[4][HEIGHT][WIDTH];
21
22 extern int screen_x;
23 extern int screen_y;
24
25 void game_init_vars(void)
26 {
27   int x, y;
28
29   RandomEM = 1684108901;
30
31   for (y = 0; y < HEIGHT; y++)
32     for (x = 0; x < WIDTH; x++)
33       Array[0][y][x] = ZBORDER;
34   for (y = 0; y < HEIGHT; y++)
35     for (x = 0; x < WIDTH; x++)
36       Array[1][y][x] = ZBORDER;
37   for (y = 0; y < HEIGHT; y++)
38     for (x = 0; x < WIDTH; x++)
39       Array[2][y][x] = ZBORDER;
40   for (y = 0; y < HEIGHT; y++)
41     for (x = 0; x < WIDTH; x++)
42       Array[3][y][x] = Xblank;
43
44   for (y = 0; y < HEIGHT; y++)
45     Index[0][y] = Array[0][y];
46   for (y = 0; y < HEIGHT; y++)
47     Index[1][y] = Array[1][y];
48   for (y = 0; y < HEIGHT; y++)
49     Index[2][y] = Array[2][y];
50   for (y = 0; y < HEIGHT; y++)
51     Index[3][y] = Array[3][y];
52
53   Cave = Index[0];
54   Next = Index[1];
55   Draw = Index[2];
56   Boom = Index[3];
57 }
58
59 void InitGameEngine_EM()
60 {
61   prepare_em_level();
62
63   game_initscreen();
64   game_animscreen();
65 }
66
67 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
68 {
69   int i;
70
71   game_animscreen();
72
73   RandomEM = RandomEM * 129 + 1;
74
75   frame = (frame - 1) & 7;
76
77   for (i = 0; i < MAX_PLAYERS; i++)
78     readjoy(action[i], &ply[i]);
79
80   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
81
82   if (frame == 7)
83   {
84     synchro_1();
85     synchro_2();
86   }
87
88   if (frame == 6)
89   {
90     synchro_3();
91     sound_play();
92
93     if (!warp_mode)             /* do not redraw values in warp mode */
94       DrawGameDoorValues_EM();
95   }
96 }
97
98 /* read input device for players */
99
100 void readjoy(byte action, struct PLAYER *ply)
101 {
102   int north = 0, east = 0, south = 0, west = 0;
103   int snap = 0, drop = 0;
104
105   if (action & JOY_LEFT)
106     west = 1;
107
108   if (action & JOY_RIGHT)
109     east = 1;
110
111   if (action & JOY_UP)
112     north = 1;
113
114   if (action & JOY_DOWN)
115     south = 1;
116
117   if (action & JOY_BUTTON_1)
118     snap = 1;
119
120   if (action & JOY_BUTTON_2)
121     drop = 1;
122
123   ply->joy_snap = snap;
124   ply->joy_drop = drop;
125
126   if (ply->joy_stick || (north | east | south | west))
127   {
128     ply->joy_n = north;
129     ply->joy_e = east;
130     ply->joy_s = south;
131     ply->joy_w = west;
132   }
133 }