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(1000); /* 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 SetDrawtoField(DRAW_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 SetDrawtoField(DRAW_DIRECT);
163 if (soft_scrolling_on && game_status==PLAYING)
164 XCopyArea(display,fieldbuffer,backbuffer,gc,
165 FX,FY, SXSIZE,SYSIZE,
168 XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
173 void HandleButtonEvent(XButtonEvent *event)
175 motion_status = FALSE;
177 if (event->type==ButtonPress)
178 button_status = event->button;
180 button_status = MB_RELEASED;
182 HandleButton(event->x, event->y, button_status);
185 void HandleMotionEvent(XMotionEvent *event)
187 motion_status = TRUE;
189 HandleButton(event->x, event->y, button_status);
192 void HandleKeyEvent(XKeyEvent *event)
194 int key_status = (event->type == KeyPress ? KEY_PRESSED : KEY_RELEASED);
195 unsigned int event_state = (game_status != PLAYING ? event->state : 0);
196 KeySym key = XLookupKeysym(event, event_state);
198 HandleKey(key, key_status);
201 void HandleFocusEvent(XFocusChangeEvent *event)
203 static int old_joystick_status = -1;
205 if (event->type == FocusOut)
207 XAutoRepeatOn(display);
208 old_joystick_status = joystick_status;
209 joystick_status = JOYSTICK_OFF;
210 key_joystick_mapping = 0;
212 else if (event->type == FocusIn)
214 if (game_status == PLAYING)
215 XAutoRepeatOff(display);
216 if (old_joystick_status != -1)
217 joystick_status = old_joystick_status;
221 void HandleButton(int mx, int my, int button)
223 static int old_mx = 0, old_my = 0;
235 HandleVideoButtons(mx,my,button);
236 HandleSoundButtons(mx,my,button);
237 HandleGameButtons(mx,my,button);
243 HandleMainMenu(mx,my,0,0,button);
246 HandleTypeName(0,XK_Return);
249 HandleChooseLevel(mx,my,0,0,button);
252 HandleHallOfFame(button);
255 LevelEd(mx,my,button);
258 HandleHelpScreen(button);
261 HandleSetupScreen(mx,my,0,0,button);
274 void HandleKey(KeySym key, int key_status)
278 /* Map cursor keys to joystick directions */
282 case XK_Left: /* normale Richtungen */
319 case XK_KP_Home: /* Diagonalrichtungen */
322 joy |= JOY_UP | JOY_LEFT;
328 joy = JOY_UP | JOY_RIGHT;
334 joy |= JOY_DOWN | JOY_LEFT;
336 #ifdef XK_KP_Page_Down
337 case XK_KP_Page_Down:
340 joy |= JOY_DOWN | JOY_RIGHT;
342 case XK_S: /* Feld entfernen */
344 joy |= JOY_BUTTON_1 | JOY_LEFT;
348 joy |= JOY_BUTTON_1 | JOY_RIGHT;
352 joy |= JOY_BUTTON_1 | JOY_UP;
356 joy |= JOY_BUTTON_1 | JOY_DOWN;
358 case XK_Shift_L: /* Linker Feuerknopf */
364 case XK_Shift_R: /* Rechter Feuerknopf */
370 case XK_B: /* (Bombe legen) */
380 if (key_status == KEY_PRESSED)
381 key_joystick_mapping |= joy;
383 key_joystick_mapping &= ~joy;
388 if (game_status != PLAYING)
389 key_joystick_mapping = 0;
391 if (key_status == KEY_RELEASED)
394 if (key==XK_Return && game_status==PLAYING && GameOver)
396 CloseDoor(DOOR_CLOSE_1);
397 game_status = MAINMENU;
402 if (key==XK_Escape && game_status!=MAINMENU) /* quick quit to MAINMENU */
404 CloseDoor(DOOR_CLOSE_1 | DOOR_NO_DELAY);
405 game_status = MAINMENU;
410 if (game_status==PLAYING && (tape.playing || tape.pausing))
416 HandleTypeName(0,key);
425 if (game_status==MAINMENU)
426 HandleMainMenu(0,0,0,0,MB_MENU_CHOICE);
427 else if (game_status==CHOOSELEVEL)
428 HandleChooseLevel(0,0,0,0,MB_MENU_CHOICE);
429 else if (game_status==SETUP)
430 HandleSetupScreen(0,0,0,0,MB_MENU_CHOICE);
438 HandleHelpScreen(MB_RELEASED);
444 game_status = MAINMENU;
453 LevelNameTyping(key);
474 GameSpeed = key - XK_0;
475 printf("GameSpeed == %d\n", GameSpeed);
479 if (ScrollStepSize == TILEX/8)
480 ScrollStepSize = TILEX/4;
482 ScrollStepSize = TILEX/8;
483 printf("ScrollStepSize == %d\n", ScrollStepSize);
487 ScrollStepSize = TILEX/8;
488 printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize);
491 ScrollStepSize = TILEX/4;
492 printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize);
495 ScrollStepSize = TILEX/2;
496 printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize);
499 ScrollStepSize = TILEX;
500 printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize);
511 int i,j,k, num_steps = 8, step_size = TILEX / num_steps;
512 static long scroll_delay=0;
513 long scroll_delay_value = 4*4 / num_steps;
515 printf("Scroll test\n");
519 for(j=0;j<SCR_FIELDX;j++)
521 for(k=0;k<num_steps;k++)
523 int xxx = j*TILEX+k*step_size;
528 if (DelayReached(&scroll_delay, scroll_delay_value))
530 XCopyArea(display,fieldbuffer,window,gc,
534 XCopyArea(display,fieldbuffer,window,gc,
540 XSync(display,FALSE);
551 Delay(160000 / num_steps);
554 Delay(120000 / num_steps);
565 printf("FX = %d, FY = %d\n", FX,FY);
567 XCopyArea(display,fieldbuffer,window,gc,
569 MIN(WIN_XSIZE,FXSIZE),MIN(WIN_YSIZE,FYSIZE),
572 XSync(display,FALSE);
589 void HandleNoXEvent()
591 if (button_status && game_status != PLAYING)
593 HandleButton(-1,-1,button_status);
615 void HandleJoystick()
617 int joystick = Joystick();
618 int keyboard = key_joystick_mapping;
619 int joy = (tape.playing ? TapePlayAction() : (joystick | keyboard));
620 int left = joy & JOY_LEFT;
621 int right = joy & JOY_RIGHT;
622 int up = joy & JOY_UP;
623 int down = joy & JOY_DOWN;
624 int button = joy & JOY_BUTTON;
625 int button1 = joy & JOY_BUTTON_1;
626 int button2 = joy & JOY_BUTTON_2;
627 int newbutton = (JoystickButton() == JOY_BUTTON_NEW_PRESSED);
628 int dx = (left ? -1 : right ? 1 : 0);
629 int dy = (up ? -1 : down ? 1 : 0);
631 if (game_status==PLAYING && (tape.playing || keyboard))
632 newbutton = ((joy & JOY_BUTTON) != 0);
640 static long joystickmove_delay = 0;
642 if (joystick && !button && !DelayReached(&joystickmove_delay,15))
643 newbutton = dx = dy = 0;
645 if (game_status==MAINMENU)
646 HandleMainMenu(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
647 else if (game_status==CHOOSELEVEL)
648 HandleChooseLevel(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
649 else if (game_status==SETUP)
650 HandleSetupScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
654 HandleHallOfFame(!newbutton);
657 HandleHelpScreen(!newbutton);
661 BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
663 if (GameOver && newbutton)
665 CloseDoor(DOOR_CLOSE_1);
666 game_status = MAINMENU;
671 if (tape.pausing || PlayerGone)
677 snapped = SnapField(dx,dy);
681 bombed = PlaceBomb();
682 moved = MoveFigure(dx,dy);
685 if (tape.recording && (moved || snapped || bombed))
687 if (bombed && !moved)
689 TapeRecordAction(joy);
691 else if (tape.playing && snapped)
692 SnapField(0,0); /* stop snapping */
696 DigField(0,0,0,0,DF_NO_PUSH);
701 if (tape.playing && !tape.pausing && !joy && tape.counter<tape.length)
704 tape.pos[tape.counter].joystickdata & (JOY_LEFT|JOY_RIGHT);
706 if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT)
708 int dx = (next_joy == JOY_LEFT ? -1 : +1);
710 if (IN_LEV_FIELD(JX+dx,JY) && IS_PUSHABLE(Feld[JX+dx][JY]))
712 int el = Feld[JX+dx][JY];
713 int push_delay = (IS_SB_ELEMENT(el) || el==EL_SONDE ? 2 : 10);
715 if (tape.delay_played + push_delay >= tape.pos[tape.counter].delay)
717 PlayerMovDir = next_joy;
718 PlayerFrame = FrameCounter % 4;
719 PlayerPushing = TRUE;