X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=86d83660ce7baec0059ee2edc0219758492807b2;hb=cfe0b06c84dc509e45c616c21ca1d5ef71f2304f;hp=a261b15f428dd2c7ee665fbbdbaf5ff3fd842104;hpb=1478ab1f979ae33fd900e5148c5d00dcba5ad402;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index a261b15f..86d83660 100644 --- a/src/game.c +++ b/src/game.c @@ -114,7 +114,11 @@ void InitGame() /* TEST TEST TEST */ + + /* stored_player[i].active = TRUE; + */ + /* TEST TEST TEST */ player->LevelSolved = FALSE; @@ -130,7 +134,10 @@ void InitGame() FrameCounter = 0; TimeFrames = 0; TimeLeft = level.time; + + ScreenMovDir = MV_NO_MOVING; ScreenMovPos = 0; + ScreenGfxPos = 0; AllPlayersGone = SiebAktiv = FALSE; @@ -168,6 +175,8 @@ void InitGame() if (StorePlayer[jx][jy] == Feld[x][y]) StorePlayer[jx][jy] = 0; + player->active = TRUE; + StorePlayer[x][y] = Feld[x][y]; Feld[x][y] = EL_LEERRAUM; player->jx = player->last_jx = x; @@ -2701,6 +2710,8 @@ void CheckForDragon(int x, int y) void PlayerActions(struct PlayerInfo *player, int player_action) { + static int stored_player_action[MAX_PLAYERS]; + static int num_stored_actions = 0; BOOL moved = FALSE, snapped = FALSE, bombed = FALSE; int jx = player->jx, jy = player->jy; int left = player_action & JOY_LEFT; @@ -2712,6 +2723,9 @@ void PlayerActions(struct PlayerInfo *player, int player_action) int dx = (left ? -1 : right ? 1 : 0); int dy = (up ? -1 : down ? 1 : 0); + stored_player_action[player->nr] = 0; + num_stored_actions++; + if (!player->active || player->gone) return; @@ -2732,7 +2746,15 @@ void PlayerActions(struct PlayerInfo *player, int player_action) { if (bombed && !moved) player_action &= JOY_BUTTON; - TapeRecordAction(player_action); + + stored_player_action[player->nr] = player_action; + + /* this allows cycled sequences of PlayerActions() */ + if (num_stored_actions >= MAX_PLAYERS) + { + TapeRecordAction(stored_player_action); + num_stored_actions = 0; + } } else if (tape.playing && snapped) SnapField(player, 0,0); /* stop snapping */ @@ -2748,7 +2770,8 @@ void PlayerActions(struct PlayerInfo *player, int player_action) if (tape.playing && !tape.pausing && !player_action && tape.counter < tape.length) { - int next_joy = tape.pos[tape.counter].joystickdata & (JOY_LEFT|JOY_RIGHT); + int next_joy = + tape.pos[tape.counter].joystickdata[player->nr] & (JOY_LEFT|JOY_RIGHT); if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT) { @@ -2776,6 +2799,7 @@ void GameActions(int player_action) long action_delay_value; int sieb_x = 0, sieb_y = 0; int i, x,y, element; + int *recorded_player_action; if (game_status != PLAYING) return; @@ -2791,12 +2815,30 @@ void GameActions(int player_action) /* main game synchronization point */ WaitUntilDelayReached(&action_delay, action_delay_value); + if (tape.playing) + recorded_player_action = TapePlayAction(); + else + recorded_player_action = NULL; + for(i=0; iGfxPos; + /* + ScreenGfxPos = local_player->GfxPos; + */ XCopyArea(display,drawto_field,drawto_field,gc, FX + TILEX*(dx==-1) - softscroll_offset, @@ -2997,6 +3081,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 +3116,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 +3147,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 +3271,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 +3292,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 +3328,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;