rnd-20060818-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 "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 #if 0
75   static int foo = -1;
76
77   if (action[0] == 0 && foo != 0)
78     printf("KEY RELEASED @ %05d\n", FrameCounter);
79
80   foo = action[0];
81 #endif
82
83 #if 0
84 #if 1
85   if (FrameCounter % 10 == 0)
86 #endif
87     printf("::: %05d: %lu, %d\n", FrameCounter, RandomEM, frame);
88 #endif
89
90   game_animscreen();
91
92 #if 1
93   SyncDisplay();
94
95   blitscreen();
96
97   FlushDisplay();
98 #endif
99
100   RandomEM = RandomEM * 129 + 1;
101
102   frame = (frame - 1) & 7;
103
104   for (i = 0; i < MAX_PLAYERS; i++)
105     readjoy(action[i], &ply[i]);
106
107   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
108
109   if (frame == 7)
110   {
111     synchro_1();
112     synchro_2();
113   }
114
115   if (frame == 6)
116   {
117     synchro_3();
118     sound_play();
119
120     if (!warp_mode)             /* do not redraw values in warp mode */
121       DrawGameDoorValues_EM();
122   }
123 }
124
125 /* read input device for players */
126
127 void readjoy(byte action, struct PLAYER *ply)
128 {
129   int north = 0, east = 0, south = 0, west = 0;
130   int snap = 0, drop = 0;
131
132   if (action & JOY_LEFT)
133     west = 1;
134
135   if (action & JOY_RIGHT)
136     east = 1;
137
138   if (action & JOY_UP)
139     north = 1;
140
141   if (action & JOY_DOWN)
142     south = 1;
143
144   if (action & JOY_BUTTON_1)
145     snap = 1;
146
147   if (action & JOY_BUTTON_2)
148     drop = 1;
149
150   ply->joy_snap = snap;
151   ply->joy_drop = drop;
152
153   if (ply->joy_stick || (north | east | south | west))
154   {
155     ply->joy_n = north;
156     ply->joy_e = east;
157     ply->joy_s = south;
158     ply->joy_w = west;
159   }
160 }