X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fgame.c;h=b785616403af98b17add1109e1b1cf49ac448726;hp=a261b15f428dd2c7ee665fbbdbaf5ff3fd842104;hb=7b31a77eec53ed2b96d5924a743b0706c9e4b11c;hpb=1478ab1f979ae33fd900e5148c5d00dcba5ad402 diff --git a/src/game.c b/src/game.c index a261b15f..b7856164 100644 --- a/src/game.c +++ b/src/game.c @@ -130,7 +130,10 @@ void InitGame() FrameCounter = 0; TimeFrames = 0; TimeLeft = level.time; + + ScreenMovDir = MV_NO_MOVING; ScreenMovPos = 0; + ScreenGfxPos = 0; AllPlayersGone = SiebAktiv = FALSE; @@ -2793,10 +2796,19 @@ void GameActions(int player_action) for(i=0; iGfxPos; + /* + ScreenGfxPos = local_player->GfxPos; + */ XCopyArea(display,drawto_field,drawto_field,gc, FX + TILEX*(dx==-1) - softscroll_offset, @@ -2997,6 +3051,9 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player, if (!IN_LEV_FIELD(new_jx,new_jy)) return(MF_NO_ACTION); + if (!networking && !AllPlayersInSight(player, new_jx,new_jy)) + return(MF_NO_ACTION); + element = MovingOrBlocked2Element(new_jx,new_jy); if (DONT_GO_TO(element)) @@ -3029,7 +3086,7 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player, player->MovPos = (dx > 0 || dy > 0 ? -1 : 1) * 7*TILEX/8; - ScrollFigure(player, SCROLL_FIGURE_INIT); + ScrollFigure(player, SCROLL_INIT); return(MF_MOVING); } @@ -3060,20 +3117,93 @@ BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy) jx = player->jx; jy = player->jy; + + + /* if (moved & MF_MOVING && player == local_player) + */ + + if (moved & MF_MOVING && !ScreenMovPos) { int old_scroll_x = scroll_x, old_scroll_y = scroll_y; int offset = (scroll_delay_on ? 3 : 0); - if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) && - jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset)) - scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset); - if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) && - jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset)) - scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset); + if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy))) + { + /* actual player has left the screen -- scroll in that direction */ + if (jx != old_jx) /* player has moved horizontally */ + scroll_x += (jx - old_jx); + else /* player has moved vertically */ + scroll_y += (jy - old_jy); + } + else + { + if (jx != old_jx) /* player has moved horizontally */ + { + if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) && + jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset)) + scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset); + + /* don't scroll more than one field at a time */ + scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x); + + /* don't scroll against the player's moving direction */ + if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) || + (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x)) + scroll_x = old_scroll_x; + } + else /* player has moved vertically */ + { + if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) && + jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset)) + scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset); + + /* don't scroll more than one field at a time */ + scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y); + + /* don't scroll against the player's moving direction */ + if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) || + (player->MovDir == MV_DOWN && scroll_y < old_scroll_y)) + scroll_y = old_scroll_y; + } + } + +#if 0 + if (player == local_player) + { + if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) && + jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset)) + scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset); + if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) && + jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset)) + scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset); + + /* don't scroll more than one field at a time */ + scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x); + scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y); + } +#endif if (scroll_x != old_scroll_x || scroll_y != old_scroll_y) - ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y); + { + if (networking || AllPlayersInVisibleScreen()) + { + ScrollScreen(player, SCROLL_INIT); + + /* + ScreenMovDir = player->MovDir; + ScreenMovPos = player->MovPos; + ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize); + */ + + ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y); + } + else + { + scroll_x = old_scroll_x; + scroll_y = old_scroll_y; + } + } } if (!(moved & MF_MOVING) && !player->Pushing) @@ -3111,11 +3241,15 @@ void ScrollFigure(struct PlayerInfo *player, int mode) if (!player->active || player->gone || !player->MovPos) return; - if (mode == SCROLL_FIGURE_INIT) + if (mode == SCROLL_INIT) { player->actual_frame_counter = FrameCounter; player->GfxPos = ScrollStepSize * (player->MovPos / ScrollStepSize); + /* + ScreenGfxPos = local_player->GfxPos; + */ + if (Feld[last_jx][last_jy] == EL_LEERRAUM) Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING; @@ -3128,11 +3262,21 @@ void ScrollFigure(struct PlayerInfo *player, int mode) player->MovPos += (player->MovPos > 0 ? -1 : 1) * TILEX/8; player->GfxPos = ScrollStepSize * (player->MovPos / ScrollStepSize); - if (ScreenMovPos && ScreenMovPos != local_player->GfxPos) + /* + if (ScreenMovPos) { - ScreenMovPos = local_player->GfxPos; + ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * TILEX/8; + ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize); + } + */ + + /* + if (ScreenGfxPos && ScreenGfxPos != local_player->GfxPos) + { + ScreenGfxPos = local_player->GfxPos; redraw_mask |= REDRAW_FIELD; } + */ if (Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING) Feld[last_jx][last_jy] = EL_LEERRAUM; @@ -3154,6 +3298,37 @@ void ScrollFigure(struct PlayerInfo *player, int mode) } } +void ScrollScreen(struct PlayerInfo *player, int mode) +{ + static long screen_frame_counter = 0; + + if (mode == SCROLL_INIT) + { + screen_frame_counter = FrameCounter; + ScreenMovDir = player->MovDir; + ScreenMovPos = player->MovPos; + ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize); + return; + } + else if (!FrameReached(&screen_frame_counter,1)) + return; + + if (ScreenMovPos) + { + /* + printf("ScreenMovDir = %d, ", ScreenMovDir); + printf("ScreenMovPos = %d, ", ScreenMovPos); + printf("ScreenGfxPos = %d\n", ScreenGfxPos); + */ + + ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * TILEX/8; + ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize); + redraw_mask |= REDRAW_FIELD; + } + else + ScreenMovDir = MV_NO_MOVING; +} + void TestIfGoodThingHitsBadThing(int goodx, int goody) { int i, killx = goodx, killy = goody;