X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=d2b364886627bc5412235e3f85cd260f1b63bd58;hb=34b9fd6b89ffe8fa0637840118b43e4d36bb1798;hp=b563a8605e0c54fd28fea397576e9a119613eadf;hpb=19e3dfa321d39a822bda8fa489fb76f25f9f9165;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index b563a860..d2b36488 100644 --- a/src/events.c +++ b/src/events.c @@ -13,6 +13,7 @@ ***********************************************************/ #include "events.h" +#include "init.h" #include "screens.h" #include "tools.h" #include "game.h" @@ -54,6 +55,9 @@ void EventLoop(void) case FocusOut: HandleFocusEvent((XFocusChangeEvent *) &event); break; + case ClientMessage: + HandleClientMessageEvent((XClientMessageEvent *) &event); + break; default: break; } @@ -61,12 +65,18 @@ void EventLoop(void) else /* got no event, but don't be lazy... */ { HandleNoXEvent(); - Delay(1000); /* don't use all CPU time when idle */ - } - XSync(display,FALSE); + /* don't use all CPU time when idle; the main loop while playing + has its own synchronization and is CPU friendly, too */ + + if (game_status != PLAYING) + { + XSync(display, FALSE); + Delay(10); + } + } - if (game_status==EXITGAME) + if (game_status == EXITGAME) return; } } @@ -97,6 +107,9 @@ void ClearEventQueue() case FocusOut: HandleFocusEvent((XFocusChangeEvent *) &event); break; + case ClientMessage: + HandleClientMessageEvent((XClientMessageEvent *) &event); + break; default: break; } @@ -129,6 +142,9 @@ void SleepWhileUnmapped() case MapNotify: window_unmapped = FALSE; break; + case ClientMessage: + HandleClientMessageEvent((XClientMessageEvent *) &event); + break; default: break; } @@ -160,10 +176,17 @@ void HandleExposeEvent(XExposeEvent *event) SetDrawtoField(DRAW_DIRECT); } - if (soft_scrolling_on && game_status==PLAYING) + if (soft_scrolling_on && game_status == PLAYING) + { + int fx = FX, fy = FY; + + fx += (PlayerMovDir & (MV_LEFT|MV_RIGHT) ? ScreenMovPos : 0); + fy += (PlayerMovDir & (MV_UP|MV_DOWN) ? ScreenMovPos : 0); + XCopyArea(display,fieldbuffer,backbuffer,gc, - FX,FY, SXSIZE,SYSIZE, + fx,fy, SXSIZE,SYSIZE, SX,SY); + } XCopyArea(display,drawto,window,gc, x,y, width,height, x,y); @@ -218,6 +241,13 @@ void HandleFocusEvent(XFocusChangeEvent *event) } } +void HandleClientMessageEvent(XClientMessageEvent *event) +{ + if ((event->window == window) && + (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE))) + CloseAll(); +} + void HandleButton(int mx, int my, int button) { static int old_mx = 0, old_my = 0; @@ -268,9 +298,6 @@ void HandleButton(int mx, int my, int button) } } -int GameSpeed = 2; -int MoveSpeed = 8; - void HandleKey(KeySym key, int key_status) { int joy = 0; @@ -284,7 +311,9 @@ void HandleKey(KeySym key, int key_status) case XK_KP_Left: #endif case XK_KP_4: +#ifndef MSDOS case XK_J: +#endif case XK_j: joy |= JOY_LEFT; break; @@ -293,7 +322,9 @@ void HandleKey(KeySym key, int key_status) case XK_KP_Right: #endif case XK_KP_6: +#ifndef MSDOS case XK_K: +#endif case XK_k: joy |= JOY_RIGHT; break; @@ -302,7 +333,9 @@ void HandleKey(KeySym key, int key_status) case XK_KP_Up: #endif case XK_KP_8: +#ifndef MSDOS case XK_I: +#endif case XK_i: joy |= JOY_UP; break; @@ -311,7 +344,9 @@ void HandleKey(KeySym key, int key_status) case XK_KP_Down: #endif case XK_KP_2: +#ifndef MSDOS case XK_M: +#endif case XK_m: joy |= JOY_DOWN; break; @@ -339,35 +374,47 @@ void HandleKey(KeySym key, int key_status) case XK_KP_3: joy |= JOY_DOWN | JOY_RIGHT; break; +#ifndef MSDOS case XK_S: /* Feld entfernen */ +#endif case XK_s: joy |= JOY_BUTTON_1 | JOY_LEFT; break; +#ifndef MSDOS case XK_D: +#endif case XK_d: joy |= JOY_BUTTON_1 | JOY_RIGHT; break; +#ifndef MSDOS case XK_E: +#endif case XK_e: joy |= JOY_BUTTON_1 | JOY_UP; break; +#ifndef MSDOS case XK_X: +#endif case XK_x: joy |= JOY_BUTTON_1 | JOY_DOWN; break; case XK_Shift_L: /* Linker Feuerknopf */ +#ifndef MSDOS case XK_Control_L: case XK_Alt_L: case XK_Meta_L: +#endif joy |= JOY_BUTTON_1; break; case XK_Shift_R: /* Rechter Feuerknopf */ +#ifndef MSDOS 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) */ +#endif case XK_b: joy |= JOY_BUTTON_2; break; @@ -468,46 +515,44 @@ void HandleKey(KeySym key, int key_status) case XK_7: case XK_8: case XK_9: - /* - MoveSpeed = key - XK_0; - printf("speed == %d\n", MoveSpeed); - break; - */ - if (key == XK_0) - GameSpeed = 50; + GameFrameDelay = 500; else - GameSpeed = key - XK_0; - printf("GameSpeed == %d\n", GameSpeed); + GameFrameDelay = (key - XK_0) * 10; + printf("Game speed == %d%% (%d ms delay between two frames)\n", + GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay); break; case XK_a: - if (ScrollSteps == TILEX/4) - ScrollSteps = TILEX/8; + if (ScrollStepSize == TILEX/8) + ScrollStepSize = TILEX/4; else - ScrollSteps = TILEX/4; + ScrollStepSize = TILEX/8; + printf("ScrollStepSize == %d\n", ScrollStepSize); break; case XK_f: - GameSpeed = 2; - printf("GameSpeed == %d\n", GameSpeed); + ScrollStepSize = TILEX/8; + printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize); break; case XK_g: - GameSpeed = 3; - printf("GameSpeed == %d\n", GameSpeed); + ScrollStepSize = TILEX/4; + printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize); break; case XK_h: - GameSpeed = 4; - printf("GameSpeed == %d\n", GameSpeed); + ScrollStepSize = TILEX/2; + printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize); break; case XK_l: - GameSpeed = 50; - printf("GameSpeed == %d\n", GameSpeed); + ScrollStepSize = TILEX; + printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize); break; +#ifndef MSDOS case XK_Q: +#endif case XK_q: - Dynamite = 1000; + local_player->dynamite = 1000; break; case XK_x: @@ -548,15 +593,15 @@ void HandleKey(KeySym key, int key_status) } else { - Delay(1000); + Delay(1); } } /* - Delay(160000 / num_steps); + Delay(160 / num_steps); */ /* - Delay(120000 / num_steps); + Delay(120 / num_steps); */ } } @@ -575,7 +620,7 @@ void HandleKey(KeySym key, int key_status) 0,0); XFlush(display); XSync(display,FALSE); - Delay(1000000); + Delay(1000); } break; @@ -663,6 +708,7 @@ void HandleJoystick() break; case PLAYING: { + static int player_frame_reset_delay = 0; BOOL moved = FALSE, snapped = FALSE, bombed = FALSE; if (GameOver && newbutton) @@ -678,6 +724,8 @@ void HandleJoystick() if (joy) { + player_frame_reset_delay = 0; + if (button1) snapped = SnapField(dx,dy); else @@ -700,7 +748,8 @@ void HandleJoystick() { DigField(0,0,0,0,DF_NO_PUSH); SnapField(0,0); - PlayerFrame = 0; + if (++player_frame_reset_delay > MoveSpeed) + PlayerFrame = 0; } if (tape.playing && !tape.pausing && !joy && tape.counter