rnd-20060816-2-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 "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   /* blit playfield from scroll buffer to back buffer for fading in */
67   BlitScreenToBitmap_EM(backbuffer);
68 }
69
70 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
71 {
72   int i;
73
74   game_animscreen();
75
76 #if 1
77   SyncDisplay();
78
79   blitscreen();
80
81   FlushDisplay();
82 #endif
83
84   RandomEM = RandomEM * 129 + 1;
85
86   frame = (frame - 1) & 7;
87
88   for (i = 0; i < MAX_PLAYERS; i++)
89     readjoy(action[i], &ply[i]);
90
91   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
92
93   if (frame == 7)
94   {
95     synchro_1();
96     synchro_2();
97   }
98
99   if (frame == 6)
100   {
101     synchro_3();
102     sound_play();
103
104     if (!warp_mode)             /* do not redraw values in warp mode */
105       DrawGameDoorValues_EM();
106   }
107 }
108
109 /* read input device for players */
110
111 void readjoy(byte action, struct PLAYER *ply)
112 {
113   int north = 0, east = 0, south = 0, west = 0;
114   int snap = 0, drop = 0;
115
116   if (action & JOY_LEFT)
117     west = 1;
118
119   if (action & JOY_RIGHT)
120     east = 1;
121
122   if (action & JOY_UP)
123     north = 1;
124
125   if (action & JOY_DOWN)
126     south = 1;
127
128   if (action & JOY_BUTTON_1)
129     snap = 1;
130
131   if (action & JOY_BUTTON_2)
132     drop = 1;
133
134   ply->joy_snap = snap;
135   ply->joy_drop = drop;
136
137   if (ply->joy_stick || (north | east | south | west))
138   {
139     ply->joy_n = north;
140     ply->joy_e = east;
141     ply->joy_s = south;
142     ply->joy_w = west;
143   }
144 }