1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
28 if (XPending(display)) /* got an event */
32 XNextEvent(display, &event);
37 HandleExposeEvent((XExposeEvent *) &event);
44 HandleButtonEvent((XButtonEvent *) &event);
47 HandleMotionEvent((XMotionEvent *) &event);
51 HandleKeyEvent((XKeyEvent *) &event);
55 HandleFocusEvent((XFocusChangeEvent *) &event);
58 HandleClientMessageEvent((XClientMessageEvent *) &event);
64 else /* got no event, but don't be lazy... */
68 /* don't use all CPU time when idle; the main loop while playing
69 has its own synchronization and is CPU friendly, too */
71 if (game_status != PLAYING)
73 XSync(display, FALSE);
78 if (game_status == EXITGAME)
83 void ClearEventQueue()
85 while(XPending(display))
89 XNextEvent(display, &event);
94 HandleExposeEvent((XExposeEvent *) &event);
100 button_status = MB_RELEASED;
103 key_joystick_mapping = 0;
107 HandleFocusEvent((XFocusChangeEvent *) &event);
110 HandleClientMessageEvent((XClientMessageEvent *) &event);
118 void SleepWhileUnmapped()
120 BOOL window_unmapped = TRUE;
122 XAutoRepeatOn(display);
124 while(window_unmapped)
128 XNextEvent(display, &event);
133 HandleExposeEvent((XExposeEvent *) &event);
136 button_status = MB_RELEASED;
139 key_joystick_mapping = 0;
142 window_unmapped = FALSE;
145 HandleClientMessageEvent((XClientMessageEvent *) &event);
152 if (game_status==PLAYING)
153 XAutoRepeatOff(display);
156 void HandleExposeEvent(XExposeEvent *event)
158 int x = event->x, y = event->y;
159 int width = event->width, height = event->height;
161 if (direct_draw_on && game_status==PLAYING)
164 int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY;
165 int x2 = (x-SX+width)/TILEX, y2 = (y-SY+height)/TILEY;
167 SetDrawtoField(DRAW_BACKBUFFER);
169 for(xx=0; xx<SCR_FIELDX; xx++)
170 for(yy=0; yy<SCR_FIELDY; yy++)
171 if (xx>=x1 && xx<=x2 && yy>=y1 && yy<=y2)
172 DrawScreenField(xx,yy);
175 SetDrawtoField(DRAW_DIRECT);
178 if (soft_scrolling_on && game_status == PLAYING)
180 int fx = FX, fy = FY;
182 fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0);
183 fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0);
185 XCopyArea(display,fieldbuffer,backbuffer,gc,
186 fx,fy, SXSIZE,SYSIZE,
190 XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
195 void HandleButtonEvent(XButtonEvent *event)
197 motion_status = FALSE;
199 if (event->type==ButtonPress)
200 button_status = event->button;
202 button_status = MB_RELEASED;
204 HandleButton(event->x, event->y, button_status);
207 void HandleMotionEvent(XMotionEvent *event)
209 motion_status = TRUE;
211 HandleButton(event->x, event->y, button_status);
214 void HandleKeyEvent(XKeyEvent *event)
216 int key_status = (event->type == KeyPress ? KEY_PRESSED : KEY_RELEASED);
217 unsigned int event_state = (game_status != PLAYING ? event->state : 0);
218 KeySym key = XLookupKeysym(event, event_state);
220 HandleKey(key, key_status);
223 void HandleFocusEvent(XFocusChangeEvent *event)
225 static int old_joystick_status = -1;
227 if (event->type == FocusOut)
229 XAutoRepeatOn(display);
230 old_joystick_status = joystick_status;
231 joystick_status = JOYSTICK_OFF;
232 key_joystick_mapping = 0;
234 else if (event->type == FocusIn)
236 if (game_status == PLAYING)
237 XAutoRepeatOff(display);
238 if (old_joystick_status != -1)
239 joystick_status = old_joystick_status;
243 void HandleClientMessageEvent(XClientMessageEvent *event)
245 if ((event->window == window) &&
246 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
250 void HandleButton(int mx, int my, int button)
252 static int old_mx = 0, old_my = 0;
264 HandleVideoButtons(mx,my,button);
265 HandleSoundButtons(mx,my,button);
266 HandleGameButtons(mx,my,button);
270 if (game_status == PLAYING && !button)
272 int sx = (mx - SX) / TILEX;
273 int sy = (my - SY) / TILEY;
275 if (IN_VIS_FIELD(sx,sy))
280 printf("INFO: Feld[%d][%d] == %d\n", x,y, Feld[x][y]);
281 printf(" Store[%d][%d] == %d\n", x,y, Store[x][y]);
282 printf(" Store2[%d][%d] == %d\n", x,y, Store2[x][y]);
283 printf(" StorePlayer[%d][%d] == %d\n", x,y, StorePlayer[x][y]);
284 printf(" MovPos[%d][%d] == %d\n", x,y, MovPos[x][y]);
285 printf(" MovDir[%d][%d] == %d\n", x,y, MovDir[x][y]);
286 printf(" MovDelay[%d][%d] == %d\n", x,y, MovDelay[x][y]);
295 HandleMainMenu(mx,my,0,0,button);
298 HandleTypeName(0,XK_Return);
301 HandleChooseLevel(mx,my,0,0,button);
304 HandleHallOfFame(button);
307 LevelEd(mx,my,button);
310 HandleHelpScreen(button);
313 HandleSetupScreen(mx,my,0,0,button);
316 HandleGameActions(0);
323 void HandleKey(KeySym key, int key_status)
327 /* Map cursor keys to joystick directions */
331 case XK_Left: /* normale Richtungen */
376 case XK_KP_Home: /* Diagonalrichtungen */
379 joy |= JOY_UP | JOY_LEFT;
385 joy = JOY_UP | JOY_RIGHT;
391 joy |= JOY_DOWN | JOY_LEFT;
393 #ifdef XK_KP_Page_Down
394 case XK_KP_Page_Down:
397 joy |= JOY_DOWN | JOY_RIGHT;
400 case XK_S: /* Feld entfernen */
403 joy |= JOY_BUTTON_1 | JOY_LEFT;
409 joy |= JOY_BUTTON_1 | JOY_RIGHT;
415 joy |= JOY_BUTTON_1 | JOY_UP;
421 joy |= JOY_BUTTON_1 | JOY_DOWN;
423 case XK_Shift_L: /* Linker Feuerknopf */
431 case XK_Shift_R: /* Rechter Feuerknopf */
438 case XK_B: /* (Bombe legen) */
449 if (key_status == KEY_PRESSED)
450 key_joystick_mapping |= joy;
452 key_joystick_mapping &= ~joy;
457 if (game_status != PLAYING)
458 key_joystick_mapping = 0;
460 if (key_status == KEY_RELEASED)
463 if (key==XK_Return && game_status==PLAYING && AllPlayersGone)
465 CloseDoor(DOOR_CLOSE_1);
466 game_status = MAINMENU;
471 if (key==XK_Escape && game_status!=MAINMENU) /* quick quit to MAINMENU */
473 CloseDoor(DOOR_CLOSE_1 | DOOR_NO_DELAY);
474 game_status = MAINMENU;
479 if (game_status==PLAYING && (tape.playing || tape.pausing))
485 HandleTypeName(0,key);
494 if (game_status==MAINMENU)
495 HandleMainMenu(0,0,0,0,MB_MENU_CHOICE);
496 else if (game_status==CHOOSELEVEL)
497 HandleChooseLevel(0,0,0,0,MB_MENU_CHOICE);
498 else if (game_status==SETUP)
499 HandleSetupScreen(0,0,0,0,MB_MENU_CHOICE);
507 HandleHelpScreen(MB_RELEASED);
513 game_status = MAINMENU;
522 LevelNameTyping(key);
541 GameFrameDelay = 500;
543 GameFrameDelay = (key - XK_0) * 10;
544 printf("Game speed == %d%% (%d ms delay between two frames)\n",
545 GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay);
549 if (ScrollStepSize == TILEX/8)
550 ScrollStepSize = TILEX/4;
552 ScrollStepSize = TILEX/8;
553 printf("ScrollStepSize == %d\n", ScrollStepSize);
557 ScrollStepSize = TILEX/8;
558 printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize);
561 ScrollStepSize = TILEX/4;
562 printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize);
565 ScrollStepSize = TILEX/2;
566 printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize);
569 ScrollStepSize = TILEX;
570 printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize);
577 local_player->dynamite = 1000;
583 int i,j,k, num_steps = 8, step_size = TILEX / num_steps;
584 static long scroll_delay=0;
585 long scroll_delay_value = 4*4 / num_steps;
587 printf("Scroll test\n");
591 for(j=0;j<SCR_FIELDX;j++)
593 for(k=0;k<num_steps;k++)
595 int xxx = j*TILEX+k*step_size;
600 if (DelayReached(&scroll_delay, scroll_delay_value))
602 XCopyArea(display,fieldbuffer,window,gc,
606 XCopyArea(display,fieldbuffer,window,gc,
612 XSync(display,FALSE);
623 Delay(160 / num_steps);
626 Delay(120 / num_steps);
638 printf("FX = %d, FY = %d\n", FX,FY);
640 XCopyArea(display,fieldbuffer,window,gc,
642 MIN(WIN_XSIZE,FXSIZE),MIN(WIN_YSIZE,FYSIZE),
645 XSync(display,FALSE);
650 printf("direct_draw_on == %d\n", direct_draw_on);
658 for(i=0; i<MAX_PLAYERS; i++)
660 printf("Player %d:\n", i);
661 printf(" jx == %d, jy == %d\n",
662 stored_player[i].jx, stored_player[i].jy);
663 printf(" last_jx == %d, last_jy == %d\n",
664 stored_player[i].last_jx, stored_player[i].last_jy);
673 char *color[] = { "yellow", "red", "green", "blue" };
676 TestPlayer = (TestPlayer + 1) % MAX_PLAYERS;
677 while(!stored_player[TestPlayer].active);
679 printf("TestPlayer = %d (%s player)\n",
680 TestPlayer, color[TestPlayer]);
696 void HandleNoXEvent()
698 if (button_status && game_status != PLAYING)
700 HandleButton(-1,-1,button_status);
717 HandleGameActions(0);
726 void HandleJoystick()
728 int joystick = Joystick();
729 int keyboard = key_joystick_mapping;
732 int joy = (tape.playing ? TapePlayAction() : (joystick | keyboard));
735 int joy = (joystick | keyboard);
736 int left = joy & JOY_LEFT;
737 int right = joy & JOY_RIGHT;
738 int up = joy & JOY_UP;
739 int down = joy & JOY_DOWN;
740 int button = joy & JOY_BUTTON;
741 int newbutton = (JoystickButton() == JOY_BUTTON_NEW_PRESSED);
742 int dx = (left ? -1 : right ? 1 : 0);
743 int dy = (up ? -1 : down ? 1 : 0);
751 static long joystickmove_delay = 0;
753 if (joystick && !button && !DelayReached(&joystickmove_delay,15))
754 newbutton = dx = dy = 0;
756 if (game_status==MAINMENU)
757 HandleMainMenu(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
758 else if (game_status==CHOOSELEVEL)
759 HandleChooseLevel(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
760 else if (game_status==SETUP)
761 HandleSetupScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
766 HandleHallOfFame(!newbutton);
770 HandleHelpScreen(!newbutton);
774 if (tape.playing || keyboard)
775 newbutton = ((joy & JOY_BUTTON) != 0);
777 if (AllPlayersGone && newbutton)
779 CloseDoor(DOOR_CLOSE_1);
780 game_status = MAINMENU;
785 if (tape.pausing || AllPlayersGone)
788 HandleGameActions(joy);