X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=9a2cdd41b6f6cce864ff645838e8572564bd3d9d;hb=1478ab1f979ae33fd900e5148c5d00dcba5ad402;hp=edce9a9c4ac35ae3a8026938199847e2e3f24c10;hpb=4b0f1eb4220d2dbe4cffb288f745661b32c96a5b;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index edce9a9c..9a2cdd41 100644 --- a/src/events.c +++ b/src/events.c @@ -65,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==EXITGAME) + if (game_status != PLAYING) + { + XSync(display, FALSE); + Delay(10); + } + } + + if (game_status == EXITGAME) return; } } @@ -161,19 +167,26 @@ void HandleExposeEvent(XExposeEvent *event) SetDrawtoField(DRAW_BACKBUFFER); - for(xx=0;xx=x1 && xx<=x2 && yy>=y1 && yy<=y2) DrawScreenField(xx,yy); - DrawPlayerField(); + DrawAllPlayers(); SetDrawtoField(DRAW_DIRECT); } - if (soft_scrolling_on && game_status==PLAYING) + if (soft_scrolling_on && game_status == PLAYING) + { + int fx = FX, fy = FY; + + fx += (local_player->MovDir & (MV_LEFT|MV_RIGHT) ? ScreenMovPos : 0); + fy += (local_player->MovDir & (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); @@ -254,6 +267,29 @@ void HandleButton(int mx, int my, int button) HandleGameButtons(mx,my,button); } +#ifdef DEBUG + if (game_status == PLAYING && !button) + { + int sx = (mx - SX) / TILEX; + int sy = (my - SY) / TILEY; + + if (IN_SCR_FIELD(sx,sy)) + { + int x = LEVELX(sx); + int y = LEVELY(sy); + + printf("INFO: Feld[%d][%d] == %d\n", x,y, Feld[x][y]); + printf(" Store[%d][%d] == %d\n", x,y, Store[x][y]); + printf(" Store2[%d][%d] == %d\n", x,y, Store2[x][y]); + printf(" StorePlayer[%d][%d] == %d\n", x,y, StorePlayer[x][y]); + printf(" MovPos[%d][%d] == %d\n", x,y, MovPos[x][y]); + printf(" MovDir[%d][%d] == %d\n", x,y, MovDir[x][y]); + printf(" MovDelay[%d][%d] == %d\n", x,y, MovDelay[x][y]); + printf("\n"); + } + } +#endif + switch(game_status) { case MAINMENU: @@ -278,16 +314,13 @@ void HandleButton(int mx, int my, int button) HandleSetupScreen(mx,my,0,0,button); break; case PLAYING: - HandleGameActions(); + HandleGameActions(0); break; default: break; } } -int GameSpeed = 2; -int MoveSpeed = 8; - void HandleKey(KeySym key, int key_status) { int joy = 0; @@ -428,7 +461,7 @@ void HandleKey(KeySym key, int key_status) if (key_status == KEY_RELEASED) return; - if (key==XK_Return && game_status==PLAYING && GameOver) + if (key==XK_Return && game_status==PLAYING && AllPlayersGone) { CloseDoor(DOOR_CLOSE_1); game_status = MAINMENU; @@ -506,10 +539,11 @@ void HandleKey(KeySym key, int key_status) case XK_8: case XK_9: 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: @@ -541,7 +575,7 @@ void HandleKey(KeySym key, int key_status) case XK_Q: #endif case XK_q: - Dynamite = 1000; + local_player->dynamite = 1000; break; case XK_x: @@ -582,15 +616,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); */ } } @@ -600,6 +634,7 @@ void HandleKey(KeySym key, int key_status) break; case XK_y: + /* { printf("FX = %d, FY = %d\n", FX,FY); @@ -609,30 +644,27 @@ void HandleKey(KeySym key, int key_status) 0,0); XFlush(display); XSync(display,FALSE); - Delay(1000000); + Delay(1000); } + */ + + printf("direct_draw_on == %d\n", direct_draw_on); break; case XK_z: { - static int test_picture_pos = 0; + int i; - printf("test picture %d\n", test_picture_pos); - - XCopyArea(display,test_pix[test_picture_pos],window,gc, - 0,0, 100,100, - 0,0); - /* - XCopyArea(display,test_clipmask[test_picture_pos],window,gc, - 0,0, 100,100, - 100,0); - */ - XFlush(display); - XSync(display,FALSE); - Delay(1000000); - - test_picture_pos = (test_picture_pos + 1) % test_picture_count; + for(i=0; i= tape.pos[tape.counter].delay) - { - PlayerMovDir = next_joy; - PlayerFrame = FrameCounter % 4; - PlayerPushing = TRUE; - } - } - } - } + HandleGameActions(joy); break; - } + default: break; }