X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=b563a8605e0c54fd28fea397576e9a119613eadf;hb=19e3dfa321d39a822bda8fa489fb76f25f9f9165;hp=9eb8d62312979a1b418dd4d95edfbd563130bb63;hpb=c3d03cdffce070695ba0520d00667b42b8460087;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index 9eb8d623..b563a860 100644 --- a/src/events.c +++ b/src/events.c @@ -18,6 +18,8 @@ #include "game.h" #include "editor.h" #include "misc.h" +#include "tape.h" +#include "joystick.h" void EventLoop(void) { @@ -38,8 +40,6 @@ void EventLoop(void) SleepWhileUnmapped(); break; case ButtonPress: - HandleButtonEvent((XButtonEvent *) &event); - break; case ButtonRelease: HandleButtonEvent((XButtonEvent *) &event); break; @@ -47,16 +47,12 @@ void EventLoop(void) HandleMotionEvent((XMotionEvent *) &event); break; case KeyPress: - HandleKeyEvent((XKeyEvent *) &event); - break; case KeyRelease: HandleKeyEvent((XKeyEvent *) &event); break; case FocusIn: - HandleFocusEvent(FOCUS_IN); - break; case FocusOut: - HandleFocusEvent(FOCUS_OUT); + HandleFocusEvent((XFocusChangeEvent *) &event); break; default: break; @@ -65,13 +61,11 @@ void EventLoop(void) else /* got no event, but don't be lazy... */ { HandleNoXEvent(); - - XSync(display,FALSE); - - if (game_status!=PLAYING) - Delay(10000); /* don't use all CPU time when idle */ + Delay(1000); /* don't use all CPU time when idle */ } + XSync(display,FALSE); + if (game_status==EXITGAME) return; } @@ -97,13 +91,11 @@ void ClearEventQueue() button_status = MB_RELEASED; break; case KeyRelease: - key_status = KEY_RELEASED; + key_joystick_mapping = 0; break; case FocusIn: - HandleFocusEvent(FOCUS_IN); - break; case FocusOut: - HandleFocusEvent(FOCUS_OUT); + HandleFocusEvent((XFocusChangeEvent *) &event); break; default: break; @@ -132,7 +124,7 @@ void SleepWhileUnmapped() button_status = MB_RELEASED; break; case KeyRelease: - key_status = KEY_RELEASED; + key_joystick_mapping = 0; break; case MapNotify: window_unmapped = FALSE; @@ -151,21 +143,30 @@ void HandleExposeEvent(XExposeEvent *event) int x = event->x, y = event->y; int width = event->width, height = event->height; - XCopyArea(display,drawto,window,gc, x,y, width,height, x,y); - if (direct_draw_on && game_status==PLAYING) { int xx,yy; int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY; int x2 = (x-SX+width)/TILEX, y2 = (y-SY+height)/TILEY; + SetDrawtoField(DRAW_BACKBUFFER); + for(xx=0;xx=x1 && xx<=x2 && yy>=y1 && yy<=y2) DrawScreenField(xx,yy); - DrawLevelElement(JX,JY,EL_SPIELFIGUR); + DrawPlayerField(); + + SetDrawtoField(DRAW_DIRECT); } + if (soft_scrolling_on && game_status==PLAYING) + XCopyArea(display,fieldbuffer,backbuffer,gc, + FX,FY, SXSIZE,SYSIZE, + SX,SY); + + XCopyArea(display,drawto,window,gc, x,y, width,height, x,y); + XFlush(display); } @@ -190,34 +191,31 @@ void HandleMotionEvent(XMotionEvent *event) void HandleKeyEvent(XKeyEvent *event) { - static KeySym old_keycode = 0; - int new_keycode = event->keycode; - KeySym new_key = XLookupKeysym(event,event->state); - int new_key_status = (event->type==KeyPress ? KEY_PRESSED : KEY_RELEASED); + int key_status = (event->type == KeyPress ? KEY_PRESSED : KEY_RELEASED); + unsigned int event_state = (game_status != PLAYING ? event->state : 0); + KeySym key = XLookupKeysym(event, event_state); - if (game_status==PLAYING && - (old_keycode!=new_keycode || key_status!=new_key_status)) - { - DigField(0,0,DF_NO_PUSH); - SnapField(0,0); - } - - if (event->type==KeyPress) - { - key_status = KEY_PRESSED; - HandleKey(new_key); - old_keycode = new_keycode; - } - else if (key_status==KEY_PRESSED && old_keycode==new_keycode) - key_status = KEY_RELEASED; + HandleKey(key, key_status); } -void HandleFocusEvent(int focus_status) +void HandleFocusEvent(XFocusChangeEvent *event) { - if (focus_status==FOCUS_OUT) + static int old_joystick_status = -1; + + if (event->type == FocusOut) + { XAutoRepeatOn(display); - else if (game_status==PLAYING) - XAutoRepeatOff(display); + old_joystick_status = joystick_status; + joystick_status = JOYSTICK_OFF; + key_joystick_mapping = 0; + } + else if (event->type == FocusIn) + { + if (game_status == PLAYING) + XAutoRepeatOff(display); + if (old_joystick_status != -1) + joystick_status = old_joystick_status; + } } void HandleButton(int mx, int my, int button) @@ -263,41 +261,143 @@ void HandleButton(int mx, int my, int button) HandleSetupScreen(mx,my,0,0,button); break; case PLAYING: - if (!LevelSolved) - { - switch(GameActions(mx,my,button)) - { - case ACT_GAME_OVER: - game_status = MAINMENU; - DrawMainMenu(); - BackToFront(); - break; - case ACT_NEW_GAME: - game_status = PLAYING; - InitGame(); - break; - case ACT_GO_ON: - break; - default: - break; - } - } - BackToFront(); - Delay(10000); + HandleGameActions(); break; default: break; } } -void HandleKey(KeySym key) +int GameSpeed = 2; +int MoveSpeed = 8; + +void HandleKey(KeySym key, int key_status) { - static KeySym old_key = 0; + int joy = 0; - if (!key) - key = old_key; - else - old_key = key; + /* Map cursor keys to joystick directions */ + + switch(key) + { + case XK_Left: /* normale Richtungen */ +#ifdef XK_KP_Left + case XK_KP_Left: +#endif + case XK_KP_4: + case XK_J: + case XK_j: + joy |= JOY_LEFT; + break; + case XK_Right: +#ifdef XK_KP_Right + case XK_KP_Right: +#endif + case XK_KP_6: + case XK_K: + case XK_k: + joy |= JOY_RIGHT; + break; + case XK_Up: +#ifdef XK_KP_Up + case XK_KP_Up: +#endif + case XK_KP_8: + case XK_I: + case XK_i: + joy |= JOY_UP; + break; + case XK_Down: +#ifdef XK_KP_Down + case XK_KP_Down: +#endif + case XK_KP_2: + case XK_M: + case XK_m: + joy |= JOY_DOWN; + break; +#ifdef XK_KP_Home + case XK_KP_Home: /* Diagonalrichtungen */ +#endif + case XK_KP_7: + joy |= JOY_UP | JOY_LEFT; + break; +#ifdef XK_KP_Page_Up + case XK_KP_Page_Up: +#endif + case XK_KP_9: + joy = JOY_UP | JOY_RIGHT; + break; +#ifdef XK_KP_End + case XK_KP_End: +#endif + case XK_KP_1: + joy |= JOY_DOWN | JOY_LEFT; + break; +#ifdef XK_KP_Page_Down + case XK_KP_Page_Down: +#endif + case XK_KP_3: + joy |= JOY_DOWN | JOY_RIGHT; + break; + case XK_S: /* Feld entfernen */ + case XK_s: + joy |= JOY_BUTTON_1 | JOY_LEFT; + break; + case XK_D: + case XK_d: + joy |= JOY_BUTTON_1 | JOY_RIGHT; + break; + case XK_E: + case XK_e: + joy |= JOY_BUTTON_1 | JOY_UP; + break; + case XK_X: + case XK_x: + joy |= JOY_BUTTON_1 | JOY_DOWN; + break; + case XK_Shift_L: /* Linker Feuerknopf */ + case XK_Control_L: + case XK_Alt_L: + case XK_Meta_L: + joy |= JOY_BUTTON_1; + break; + case XK_Shift_R: /* Rechter Feuerknopf */ + case XK_Control_R: + case XK_Alt_R: + case XK_Meta_R: + case XK_Mode_switch: + case XK_Multi_key: + case XK_B: /* (Bombe legen) */ + case XK_b: + joy |= JOY_BUTTON_2; + break; + default: + break; + } + + if (joy) + { + if (key_status == KEY_PRESSED) + key_joystick_mapping |= joy; + else + key_joystick_mapping &= ~joy; + + HandleJoystick(); + } + + if (game_status != PLAYING) + key_joystick_mapping = 0; + + if (key_status == KEY_RELEASED) + return; + + if (key==XK_Return && game_status==PLAYING && GameOver) + { + CloseDoor(DOOR_CLOSE_1); + game_status = MAINMENU; + DrawMainMenu(); + return; + } if (key==XK_Escape && game_status!=MAINMENU) /* quick quit to MAINMENU */ { @@ -319,8 +419,6 @@ void HandleKey(KeySym key) case CHOOSELEVEL: case SETUP: { - int dx = 0, dy = 0; - switch(key) { case XK_Return: @@ -331,55 +429,9 @@ void HandleKey(KeySym key) else if (game_status==SETUP) HandleSetupScreen(0,0,0,0,MB_MENU_CHOICE); break; - case XK_Left: -#ifdef XK_KP_Left - case XK_KP_Left: -#endif - case XK_KP_4: - case XK_J: - case XK_j: - dx = -1; - break; - case XK_Right: -#ifdef XK_KP_Right - case XK_KP_Right: -#endif - case XK_KP_6: - case XK_K: - case XK_k: - dx = 1; - break; - case XK_Up: -#ifdef XK_KP_Up - case XK_KP_Up: -#endif - case XK_KP_8: - case XK_I: - case XK_i: - dy = -1; - break; - case XK_Down: -#ifdef XK_KP_Down - case XK_KP_Down: -#endif - case XK_KP_2: - case XK_M: - case XK_m: - dy = 1; - break; default: break; } - - if (dx || dy) - { - if (game_status==MAINMENU) - HandleMainMenu(0,0,dx,dy,MB_MENU_MARK); - else if (game_status==CHOOSELEVEL) - HandleChooseLevel(0,0,dx,dy,MB_MENU_MARK); - else if (game_status==SETUP) - HandleSetupScreen(0,0,dx,dy,MB_MENU_MARK); - } break; } case HELPSCREEN: @@ -402,128 +454,136 @@ void HandleKey(KeySym key) break; case PLAYING: { - int mvx = 0, mvy = 0; - int sbx = 0, sby = 0; - int joy = 0; - BOOL bomb = FALSE; - BOOL moved = FALSE, snapped = FALSE, bombed = FALSE; - switch(key) { - case XK_Left: /* normale Richtungen */ -#ifdef XK_KP_Left - case XK_KP_Left: -#endif - case XK_KP_4: - case XK_J: - case XK_j: - mvx = -1; - joy = JOY_LEFT; - break; - case XK_Right: -#ifdef XK_KP_Right - case XK_KP_Right: -#endif - case XK_KP_6: - case XK_K: - case XK_k: - mvx = 1; - joy = JOY_RIGHT; - break; - case XK_Up: -#ifdef XK_KP_Up - case XK_KP_Up: -#endif - case XK_KP_8: - case XK_I: - case XK_i: - mvy = -1; - joy = JOY_UP; - break; - case XK_Down: -#ifdef XK_KP_Down - case XK_KP_Down: -#endif - case XK_KP_2: - case XK_M: - case XK_m: - mvy = 1; - joy = JOY_DOWN; - break; -#ifdef XK_KP_Home - case XK_KP_Home: /* Diagonalrichtungen */ -#endif - case XK_KP_7: - mvx = -1; - mvy = -1; - joy = JOY_UP | JOY_LEFT; - break; -#ifdef XK_KP_Page_Up - case XK_KP_Page_Up: -#endif - case XK_KP_9: - mvx = 1; - mvy = -1; - joy = JOY_UP | JOY_RIGHT; - break; -#ifdef XK_KP_End - case XK_KP_End: -#endif - case XK_KP_1: - mvx = -1; - mvy = 1; - joy = JOY_DOWN | JOY_LEFT; + +#ifdef DEBUG + case XK_0: + case XK_1: + case XK_2: + case XK_3: + case XK_4: + case XK_5: + case XK_6: + case XK_7: + case XK_8: + case XK_9: + /* + MoveSpeed = key - XK_0; + printf("speed == %d\n", MoveSpeed); break; -#ifdef XK_KP_Page_Down - case XK_KP_Page_Down: -#endif - case XK_KP_3: - mvx = 1; - mvy = 1; - joy = JOY_DOWN | JOY_RIGHT; + */ + + if (key == XK_0) + GameSpeed = 50; + else + GameSpeed = key - XK_0; + printf("GameSpeed == %d\n", GameSpeed); break; - case XK_S: /* Feld entfernen */ - case XK_s: - sbx = -1; - joy = JOY_BUTTON_1 | JOY_LEFT; + + case XK_a: + if (ScrollSteps == TILEX/4) + ScrollSteps = TILEX/8; + else + ScrollSteps = TILEX/4; break; - case XK_D: - case XK_d: - sbx = 1; - joy = JOY_BUTTON_1 | JOY_RIGHT; + + case XK_f: + GameSpeed = 2; + printf("GameSpeed == %d\n", GameSpeed); break; - case XK_E: - case XK_e: - sby = -1; - joy = JOY_BUTTON_1 | JOY_UP; + case XK_g: + GameSpeed = 3; + printf("GameSpeed == %d\n", GameSpeed); break; - case XK_X: - case XK_x: - sby = 1; - joy = JOY_BUTTON_1 | JOY_DOWN; + case XK_h: + GameSpeed = 4; + printf("GameSpeed == %d\n", GameSpeed); break; - case XK_B: /* Bombe legen */ - case XK_b: - bomb = TRUE; - joy = JOY_BUTTON_2; + case XK_l: + GameSpeed = 50; + printf("GameSpeed == %d\n", GameSpeed); break; + case XK_Q: + case XK_q: Dynamite = 1000; break; - default: - break; - } - if (mvx || mvy) - moved = MoveFigure(mvx,mvy); - else if (sbx || sby) - snapped = SnapField(sbx,sby); - else if (bomb) - bombed = PlaceBomb(); + case XK_x: + + { + int i,j,k, num_steps = 8, step_size = TILEX / num_steps; + static long scroll_delay=0; + long scroll_delay_value = 4*4 / num_steps; + + printf("Scroll test\n"); + + for(i=0;i<3;i++) + { + for(j=0;j= tape.pos[tape.counter].delay) + { + PlayerMovDir = next_joy; + PlayerFrame = FrameCounter % 4; + PlayerPushing = TRUE; + } + } + } + } break; } default: