From: Holger Schemel Date: Mon, 28 Sep 1998 14:30:20 +0000 (+0200) Subject: rnd-19980928-2 X-Git-Tag: 1.2.0^2~75 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=7b31a77eec53ed2b96d5924a743b0706c9e4b11c;p=rocksndiamonds.git rnd-19980928-2 --- diff --git a/src/cartoons.c b/src/cartoons.c index 4857e06f..8aee8a26 100644 --- a/src/cartoons.c +++ b/src/cartoons.c @@ -143,8 +143,8 @@ void HandleAnimation(int mode) { 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); + fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0); + fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0); XCopyArea(display,fieldbuffer,backbuffer,gc, fx,fy, SXSIZE,SYSIZE, diff --git a/src/events.c b/src/events.c index 9a2cdd41..48638bde 100644 --- a/src/events.c +++ b/src/events.c @@ -180,8 +180,8 @@ void HandleExposeEvent(XExposeEvent *event) { 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); + fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0); + fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0); XCopyArea(display,fieldbuffer,backbuffer,gc, fx,fy, SXSIZE,SYSIZE, @@ -667,6 +667,18 @@ void HandleKey(KeySym key, int key_status) printf("\n"); } + break; + + case XK_t: + { + char *color[] = { "yellow", "red", "green", "blue" }; + + TestPlayer = (TestPlayer + 1) % MAX_PLAYERS; + + printf("TestPlayer = %d (%s player)\n", + TestPlayer, color[TestPlayer]); + } + break; #endif 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; diff --git a/src/game.h b/src/game.h index b0aa6e9f..9cf6a297 100644 --- a/src/game.h +++ b/src/game.h @@ -25,8 +25,8 @@ #define MF_MOVING 1 #define MF_ACTION 2 -#define SCROLL_FIGURE_INIT 0 -#define SCROLL_FIGURE_GO_ON 1 +#define SCROLL_INIT 0 +#define SCROLL_GO_ON 1 /* explosion position marks */ #define EX_NORMAL 0 @@ -81,6 +81,7 @@ void ScrollLevel(int, int); BOOL MoveFigureOneStep(struct PlayerInfo *, int, int, int, int); BOOL MoveFigure(struct PlayerInfo *, int, int); void ScrollFigure(struct PlayerInfo *, int); +void ScrollScreen(struct PlayerInfo *, int); void TestIfGoodThingHitsBadThing(int, int); void TestIfBadThingHitsGoodThing(int, int); diff --git a/src/main.c b/src/main.c index d5c50148..93cff5b0 100644 --- a/src/main.c +++ b/src/main.c @@ -64,6 +64,7 @@ int fading_on = FALSE; int autorecord_on = FALSE; int joystick_nr = 0; int quick_doors = FALSE; +int networking = FALSE; BOOL redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; int redraw_x1 = 0, redraw_y1 = 0; @@ -88,7 +89,9 @@ long Elementeigenschaften[MAX_ELEMENTS]; int level_nr, leveldir_nr, num_leveldirs; int lev_fieldx,lev_fieldy, scroll_x,scroll_y; -int FX = SX, FY = SY, ScreenMovPos = 0, ScrollStepSize = TILEX/8; +int FX = SX, FY = SY, ScrollStepSize = TILEX/8; +int ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0; +int ScreenGfxPos = 0; int GameFrameDelay = GAME_FRAME_DELAY, MoveSpeed = 8; int BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1; int ZX,ZY, ExitX,ExitY; @@ -96,6 +99,8 @@ int AllPlayersGone; int FrameCounter, TimeFrames, TimeLeft; int MampferNr, SiebAktiv; +int TestPlayer = 0; + struct LevelDirInfo leveldir[MAX_LEVDIR_ENTRIES]; struct LevelInfo level; struct PlayerInfo stored_player[MAX_PLAYERS+1]; diff --git a/src/main.h b/src/main.h index bff64380..a9fba370 100644 --- a/src/main.h +++ b/src/main.h @@ -86,6 +86,7 @@ typedef int BOOL; #define SCREENY(a) ((a) - scroll_y) #define LEVELX(a) ((a) + scroll_x) #define LEVELY(a) ((a) + scroll_y) +#define IN_VIS_FIELD(x,y) ((x)>=0 && (x)=0 &&(y)=BX1 && (x)<=BX2 && (y)>=BY1 &&(y)<=BY2) #define IN_LEV_FIELD(x,y) ((x)>=0 && (x)=0 &&(y) REDRAWTILES_THRESHOLD) redraw_mask |= REDRAW_FIELD; - if (redraw_mask & REDRAW_FIELD || ScreenMovPos) + if (redraw_mask & REDRAW_FIELD || ScreenGfxPos) redraw_mask &= ~REDRAW_TILES; if (!redraw_mask) @@ -109,8 +109,8 @@ void BackToFront() if (soft_scrolling_on) { - fx += (local_player->MovDir & (MV_LEFT|MV_RIGHT) ? ScreenMovPos : 0); - fy += (local_player->MovDir & (MV_UP|MV_DOWN) ? ScreenMovPos : 0); + fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0); + fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0); } XCopyArea(display,buffer,window,gc, @@ -486,18 +486,10 @@ void DrawPlayer(struct PlayerInfo *player) if (direct_draw_on) { - int dest_x = SX + sx*TILEX; - int dest_y = SY + sy*TILEY; - int x_size = TILEX; - int y_size = TILEY; - - if (!ScreenMovPos) - { - dest_x = SX + SCREENX(MIN(jx,last_jx))*TILEX; - dest_y = SY + SCREENY(MIN(jy,last_jy))*TILEY; - x_size = TILEX * (1 + ABS(jx - last_jx)); - y_size = TILEY * (1 + ABS(jy - last_jy)); - } + int dest_x = SX + SCREENX(MIN(jx,last_jx))*TILEX; + int dest_y = SY + SCREENY(MIN(jy,last_jy))*TILEY; + int x_size = TILEX * (1 + ABS(jx - last_jx)); + int y_size = TILEY * (1 + ABS(jy - last_jy)); XCopyArea(display,drawto_field,window,gc, dest_x,dest_y, x_size,y_size, dest_x,dest_y);