1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * ©1995 Artsoft Development *
6 * 33659 Bielefeld-Senne *
7 * Telefon: (0521) 493245 *
8 * eMail: aeglos@valinor.owl.de *
9 * aeglos@uni-paderborn.de *
10 * q99492@pbhrzx.uni-paderborn.de *
11 *----------------------------------------------------------*
13 ***********************************************************/
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);
61 else /* got no event, but don't be lazy... */
64 Delay(10000); /* don't use all CPU time when idle */
69 if (game_status==EXITGAME)
74 void ClearEventQueue()
76 while(XPending(display))
80 XNextEvent(display, &event);
85 HandleExposeEvent((XExposeEvent *) &event);
91 button_status = MB_RELEASED;
94 key_joystick_mapping = 0;
98 HandleFocusEvent((XFocusChangeEvent *) &event);
106 void SleepWhileUnmapped()
108 BOOL window_unmapped = TRUE;
110 XAutoRepeatOn(display);
112 while(window_unmapped)
116 XNextEvent(display, &event);
121 HandleExposeEvent((XExposeEvent *) &event);
124 button_status = MB_RELEASED;
127 key_joystick_mapping = 0;
130 window_unmapped = FALSE;
137 if (game_status==PLAYING)
138 XAutoRepeatOff(display);
141 void HandleExposeEvent(XExposeEvent *event)
143 int x = event->x, y = event->y;
144 int width = event->width, height = event->height;
146 if (direct_draw_on && game_status==PLAYING)
149 int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY;
150 int x2 = (x-SX+width)/TILEX, y2 = (y-SY+height)/TILEY;
152 drawto_field = backbuffer;
154 for(xx=0;xx<SCR_FIELDX;xx++)
155 for(yy=0;yy<SCR_FIELDY;yy++)
156 if (xx>=x1 && xx<=x2 && yy>=y1 && yy<=y2)
157 DrawScreenField(xx,yy);
160 drawto_field = window;
163 XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
168 void HandleButtonEvent(XButtonEvent *event)
170 motion_status = FALSE;
172 if (event->type==ButtonPress)
173 button_status = event->button;
175 button_status = MB_RELEASED;
177 HandleButton(event->x, event->y, button_status);
180 void HandleMotionEvent(XMotionEvent *event)
182 motion_status = TRUE;
184 HandleButton(event->x, event->y, button_status);
187 void HandleKeyEvent(XKeyEvent *event)
189 int key_status = (event->type == KeyPress ? KEY_PRESSED : KEY_RELEASED);
190 unsigned int event_state = (game_status != PLAYING ? event->state : 0);
191 KeySym key = XLookupKeysym(event, event_state);
193 HandleKey(key, key_status);
196 void HandleFocusEvent(XFocusChangeEvent *event)
198 static int old_joystick_status = -1;
200 if (event->type == FocusOut)
202 XAutoRepeatOn(display);
203 old_joystick_status = joystick_status;
204 joystick_status = JOYSTICK_OFF;
206 else if (event->type == FocusIn)
208 if (game_status == PLAYING)
209 XAutoRepeatOff(display);
210 if (old_joystick_status != -1)
211 joystick_status = old_joystick_status;
215 void HandleButton(int mx, int my, int button)
217 static int old_mx = 0, old_my = 0;
229 HandleVideoButtons(mx,my,button);
230 HandleSoundButtons(mx,my,button);
231 HandleGameButtons(mx,my,button);
237 HandleMainMenu(mx,my,0,0,button);
240 HandleTypeName(0,XK_Return);
243 HandleChooseLevel(mx,my,0,0,button);
246 HandleHallOfFame(button);
249 LevelEd(mx,my,button);
252 HandleHelpScreen(button);
255 HandleSetupScreen(mx,my,0,0,button);
267 int Movespeed[2] = { 10, 3 };
268 char *Movespeed_text[2] = { "asynchron", "syncron" };
270 void HandleKey(KeySym key, int key_status)
274 /* Map cursor keys to joystick directions */
278 case XK_Left: /* normale Richtungen */
315 case XK_KP_Home: /* Diagonalrichtungen */
318 joy |= JOY_UP | JOY_LEFT;
324 joy = JOY_UP | JOY_RIGHT;
330 joy |= JOY_DOWN | JOY_LEFT;
332 #ifdef XK_KP_Page_Down
333 case XK_KP_Page_Down:
336 joy |= JOY_DOWN | JOY_RIGHT;
338 case XK_S: /* Feld entfernen */
340 joy |= JOY_BUTTON_1 | JOY_LEFT;
344 joy |= JOY_BUTTON_1 | JOY_RIGHT;
348 joy |= JOY_BUTTON_1 | JOY_UP;
352 joy |= JOY_BUTTON_1 | JOY_DOWN;
354 case XK_Shift_L: /* Linker Feuerknopf */
360 case XK_Shift_R: /* Rechter Feuerknopf */
364 case XK_B: /* (Bombe legen) */
374 if (key_status == KEY_PRESSED)
375 key_joystick_mapping |= joy;
377 key_joystick_mapping &= ~joy;
381 if (game_status != PLAYING)
382 key_joystick_mapping = 0;
385 if (key_status == KEY_RELEASED)
388 if (key==XK_Return && game_status==PLAYING && GameOver)
390 CloseDoor(DOOR_CLOSE_1);
391 game_status = MAINMENU;
396 if (key==XK_Escape && game_status!=MAINMENU) /* quick quit to MAINMENU */
398 CloseDoor(DOOR_CLOSE_1 | DOOR_NO_DELAY);
399 game_status = MAINMENU;
404 if (game_status==PLAYING && (tape.playing || tape.pausing))
410 HandleTypeName(0,key);
419 if (game_status==MAINMENU)
420 HandleMainMenu(0,0,0,0,MB_MENU_CHOICE);
421 else if (game_status==CHOOSELEVEL)
422 HandleChooseLevel(0,0,0,0,MB_MENU_CHOICE);
423 else if (game_status==SETUP)
424 HandleSetupScreen(0,0,0,0,MB_MENU_CHOICE);
432 HandleHelpScreen(MB_RELEASED);
438 game_status = MAINMENU;
447 LevelNameTyping(key);
465 Movespeed[Movemethod] = (Movemethod == 0 ? 4 : 0) + (key - XK_0);
466 printf("method == %d, speed == %d (%s)\n",
467 Movemethod, Movespeed[Movemethod],
468 Movespeed_text[Movemethod]);
472 Movemethod = !Movemethod;
473 printf("method == %d, speed == %d (%s)\n",
474 Movemethod, Movespeed[Movemethod],
475 Movespeed_text[Movemethod]);
480 printf("gamespeed == %d\n", Gamespeed);
484 printf("gamespeed == %d\n", Gamespeed);
488 printf("gamespeed == %d\n", Gamespeed);
492 printf("gamespeed == %d\n", Gamespeed);
504 int i,j,k, num_steps = 16, step_size = TILEX / num_steps;
505 static long scroll_delay=0;
506 long scroll_delay_value = 4*4 / num_steps;
508 printf("Scroll test\n");
512 for(j=0;j<SCR_FIELDX;j++)
514 for(k=0;k<num_steps;k++)
516 int xxx = j*TILEX+k*step_size;
521 if (DelayReached(&scroll_delay, scroll_delay_value))
523 XCopyArea(display,backbuffer,window,gc,
527 XCopyArea(display,backbuffer,window,gc,
533 XSync(display,FALSE);
544 Delay(160000 / num_steps);
547 Delay(120000 / num_steps);
566 void HandleNoXEvent()
568 if (button_status && game_status!=PLAYING)
570 HandleButton(-1,-1,button_status);
592 void HandleJoystick()
594 int joystick = Joystick();
595 int keyboard = key_joystick_mapping;
596 int joy = (tape.playing ? TapePlayAction() : (joystick | keyboard));
597 int left = joy & JOY_LEFT;
598 int right = joy & JOY_RIGHT;
599 int up = joy & JOY_UP;
600 int down = joy & JOY_DOWN;
601 int button = joy & JOY_BUTTON;
602 int button1 = joy & JOY_BUTTON_1;
603 int button2 = joy & JOY_BUTTON_2;
604 int newbutton = (JoystickButton() == JOY_BUTTON_NEW_PRESSED);
605 int dx = (left ? -1 : right ? 1 : 0);
606 int dy = (up ? -1 : down ? 1 : 0);
608 if (game_status==PLAYING && (tape.playing || keyboard))
609 newbutton = ((joy & JOY_BUTTON) != 0);
617 static long joystickmove_delay = 0;
619 if (joystick && !button && !DelayReached(&joystickmove_delay,15))
620 newbutton = dx = dy = 0;
622 if (game_status==MAINMENU)
623 HandleMainMenu(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
624 else if (game_status==CHOOSELEVEL)
625 HandleChooseLevel(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
626 else if (game_status==SETUP)
627 HandleSetupScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
631 HandleHallOfFame(!newbutton);
634 HandleHelpScreen(!newbutton);
638 BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
640 if (GameOver && newbutton)
642 CloseDoor(DOOR_CLOSE_1);
643 game_status = MAINMENU;
655 if (tape.pausing || PlayerGone)
661 snapped = SnapField(dx,dy);
665 bombed = PlaceBomb();
666 moved = MoveFigure(dx,dy);
669 if (tape.recording && (moved || snapped || bombed))
671 if (bombed && !moved)
673 TapeRecordAction(joy);
675 else if (tape.playing && snapped)
676 SnapField(0,0); /* stop snapping */
680 DigField(0,0,0,0,DF_NO_PUSH);
685 if (tape.playing && !tape.pausing && !joy && tape.counter<tape.length)
688 tape.pos[tape.counter].joystickdata & (JOY_LEFT|JOY_RIGHT);
690 if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT)
692 int dx = (next_joy == JOY_LEFT ? -1 : +1);
694 if (IN_LEV_FIELD(JX+dx,JY) && IS_PUSHABLE(Feld[JX+dx][JY]))
696 int el = Feld[JX+dx][JY];
697 int push_delay = (IS_SB_ELEMENT(el) || el==EL_SONDE ? 2 : 10);
699 if (tape.delay_played + push_delay >= tape.pos[tape.counter].delay)
701 PlayerMovDir = next_joy;
702 PlayerFrame = FrameCounter % 4;
703 PlayerPushing = TRUE;