1 /* 2000-08-13T15:29:40Z
3 * handle input from x11 and keyboard and joystick
9 #include <X11/keysym.h>
11 #include <sys/types.h>
23 #if defined(TARGET_X11)
31 struct LevelInfo_EM native_em_level;
33 unsigned short **Boom;
34 unsigned short **Cave;
35 unsigned short **Next;
36 unsigned short **Draw;
38 static unsigned short *Index[4][HEIGHT];
39 static unsigned short Array[4][HEIGHT][WIDTH];
41 void game_init_vars(void)
47 for (y = 0; y < HEIGHT; y++)
48 for (x = 0; x < WIDTH; x++)
49 Array[0][y][x] = ZBORDER;
50 for (y = 0; y < HEIGHT; y++)
51 for (x = 0; x < WIDTH; x++)
52 Array[1][y][x] = ZBORDER;
53 for (y = 0; y < HEIGHT; y++)
54 for (x = 0; x < WIDTH; x++)
55 Array[2][y][x] = ZBORDER;
56 for (y = 0; y < HEIGHT; y++)
57 for (x = 0; x < WIDTH; x++)
58 Array[3][y][x] = Xblank;
60 for (y = 0; y < HEIGHT; y++)
61 Index[0][y] = Array[0][y];
62 for (y = 0; y < HEIGHT; y++)
63 Index[1][y] = Array[1][y];
64 for (y = 0; y < HEIGHT; y++)
65 Index[2][y] = Array[2][y];
66 for (y = 0; y < HEIGHT; y++)
67 Index[3][y] = Array[3][y];
75 void InitGameEngine_EM()
83 void GameActions_EM(byte action)
89 Random = Random * 129 + 1;
91 frame = (frame - 1) & 7;
106 DrawGameDoorValues_EM(lev.required, ply1.dynamite, lev.score,
112 /* read input device for players */
114 void readjoy(byte action)
116 unsigned int north = 0, east = 0, south = 0, west = 0, fire = 0;
118 if (action & JOY_LEFT)
121 if (action & JOY_RIGHT)
127 if (action & JOY_DOWN)
130 if (action & JOY_BUTTON_1)
133 ply1.joy_fire = fire;
134 if (ply1.joy_stick || (north | east | south | west))
144 /* handle events from x windows and block until the next frame */
146 void input_eventloop(void)
148 static struct timeval tv1 = { 0, 0 };
149 static struct timeval tv2 = { 0, 0 };
152 XSync(display, False); /* block until all graphics are drawn */
154 if (gettimeofday(&tv2, 0) == -1)
157 count = tv2.tv_usec + 1000000 - tv1.tv_usec;
158 if (count >= 1000000)
161 tv1.tv_usec = tv2.tv_usec;
165 tv2.tv_usec = 25000 - count;
167 select(0, 0, 0, 0, &tv2); /* sleep a bit */