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);
472 MoveSpeed = key - XK_0;
473 printf("speed == %d\n", MoveSpeed);
480 GameSpeed = key - XK_0;
481 printf("GameSpeed == %d\n", GameSpeed);
485 if (ScrollSteps == TILEX/4)
486 ScrollSteps = TILEX/8;
488 ScrollSteps = TILEX/4;
493 printf("GameSpeed == %d\n", GameSpeed);
497 printf("GameSpeed == %d\n", GameSpeed);
501 printf("GameSpeed == %d\n", GameSpeed);
505 printf("GameSpeed == %d\n", GameSpeed);
516 int i,j,k, num_steps = 8, step_size = TILEX / num_steps;
517 static long scroll_delay=0;
518 long scroll_delay_value = 4*4 / num_steps;
520 printf("Scroll test\n");
524 for(j=0;j<SCR_FIELDX;j++)
526 for(k=0;k<num_steps;k++)
528 int xxx = j*TILEX+k*step_size;
533 if (DelayReached(&scroll_delay, scroll_delay_value))
535 XCopyArea(display,fieldbuffer,window,gc,
539 XCopyArea(display,fieldbuffer,window,gc,
545 XSync(display,FALSE);
556 Delay(160000 / num_steps);
559 Delay(120000 / num_steps);
570 printf("FX = %d, FY = %d\n", FX,FY);
572 XCopyArea(display,fieldbuffer,window,gc,
574 MIN(WIN_XSIZE,FXSIZE),MIN(WIN_YSIZE,FYSIZE),
577 XSync(display,FALSE);
594 void HandleNoXEvent()
596 if (button_status && game_status != PLAYING)
598 HandleButton(-1,-1,button_status);
620 void HandleJoystick()
622 int joystick = Joystick();
623 int keyboard = key_joystick_mapping;
624 int joy = (tape.playing ? TapePlayAction() : (joystick | keyboard));
625 int left = joy & JOY_LEFT;
626 int right = joy & JOY_RIGHT;
627 int up = joy & JOY_UP;
628 int down = joy & JOY_DOWN;
629 int button = joy & JOY_BUTTON;
630 int button1 = joy & JOY_BUTTON_1;
631 int button2 = joy & JOY_BUTTON_2;
632 int newbutton = (JoystickButton() == JOY_BUTTON_NEW_PRESSED);
633 int dx = (left ? -1 : right ? 1 : 0);
634 int dy = (up ? -1 : down ? 1 : 0);
636 if (game_status==PLAYING && (tape.playing || keyboard))
637 newbutton = ((joy & JOY_BUTTON) != 0);
645 static long joystickmove_delay = 0;
647 if (joystick && !button && !DelayReached(&joystickmove_delay,15))
648 newbutton = dx = dy = 0;
650 if (game_status==MAINMENU)
651 HandleMainMenu(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
652 else if (game_status==CHOOSELEVEL)
653 HandleChooseLevel(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
654 else if (game_status==SETUP)
655 HandleSetupScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
659 HandleHallOfFame(!newbutton);
662 HandleHelpScreen(!newbutton);
666 BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
668 if (GameOver && newbutton)
670 CloseDoor(DOOR_CLOSE_1);
671 game_status = MAINMENU;
676 if (tape.pausing || PlayerGone)
682 snapped = SnapField(dx,dy);
686 bombed = PlaceBomb();
687 moved = MoveFigure(dx,dy);
690 if (tape.recording && (moved || snapped || bombed))
692 if (bombed && !moved)
694 TapeRecordAction(joy);
696 else if (tape.playing && snapped)
697 SnapField(0,0); /* stop snapping */
701 DigField(0,0,0,0,DF_NO_PUSH);
706 if (tape.playing && !tape.pausing && !joy && tape.counter<tape.length)
709 tape.pos[tape.counter].joystickdata & (JOY_LEFT|JOY_RIGHT);
711 if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT)
713 int dx = (next_joy == JOY_LEFT ? -1 : +1);
715 if (IN_LEV_FIELD(JX+dx,JY) && IS_PUSHABLE(Feld[JX+dx][JY]))
717 int el = Feld[JX+dx][JY];
718 int push_delay = (IS_SB_ELEMENT(el) || el==EL_SONDE ? 2 : 10);
720 if (tape.delay_played + push_delay >= tape.pos[tape.counter].delay)
722 PlayerMovDir = next_joy;
723 PlayerFrame = FrameCounter % 4;
724 PlayerPushing = TRUE;