From 567cfcb396e3fc031a25362b747dd0a5a096b4ec Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 7 Nov 2016 22:02:06 +0100 Subject: [PATCH] added functions to get current player position for all game engines --- src/engines.h | 2 +- src/game.c | 13 ++++++++++++- src/game.h | 2 +- src/game_em/input.c | 2 +- src/game_sp/main.c | 3 ++- src/tools.c | 23 +++++++++++++++++++---- src/tools.h | 3 +++ 7 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/engines.h b/src/engines.h index 0fc44577..ab6c38fd 100644 --- a/src/engines.h +++ b/src/engines.h @@ -25,7 +25,7 @@ /* ========================================================================= */ extern void SetBitmaps_EM(Bitmap **); -extern void UpdateEngineValues(int, int); +extern void UpdateEngineValues(int, int, int, int); extern boolean getTeamMode_EM(); extern int getGameFrameDelay_EM(int); diff --git a/src/game.c b/src/game.c index 09dc63fd..3d2f055f 100644 --- a/src/game.c +++ b/src/game.c @@ -4037,13 +4037,24 @@ void InitGame() SaveEngineSnapshotToListInitial(); } -void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y) +void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y, + int actual_player_x, int actual_player_y) { /* this is used for non-R'n'D game engines to update certain engine values */ + if (level.game_engine_type == GAME_ENGINE_TYPE_EM) + { + actual_player_x = correctLevelPosX_EM(actual_player_x); + actual_player_y = correctLevelPosY_EM(actual_player_y); + } + /* needed to determine if sounds are played within the visible screen area */ scroll_x = actual_scroll_x; scroll_y = actual_scroll_y; + + /* needed to get player position for "follow finger" playing input method */ + local_player->jx = actual_player_x; + local_player->jy = actual_player_y; } void InitMovDir(int x, int y) diff --git a/src/game.h b/src/game.h index 2f21455f..22e59af6 100644 --- a/src/game.h +++ b/src/game.h @@ -352,7 +352,7 @@ void UpdateAndDisplayGameControlValues(); void InitGameSound(); void InitGame(); -void UpdateEngineValues(int, int); +void UpdateEngineValues(int, int, int, int); void GameWon(void); void GameEnd(void); diff --git a/src/game_em/input.c b/src/game_em/input.c index f7542440..4028f19a 100644 --- a/src/game_em/input.c +++ b/src/game_em/input.c @@ -83,7 +83,7 @@ void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode) for (i = 0; i < MAX_PLAYERS; i++) readjoy(action[i], &ply[i]); - UpdateEngineValues(screen_x / TILEX, screen_y / TILEY); + UpdateEngineValues(screen_x / TILEX, screen_y / TILEY, ply[0].x, ply[0].y); if (frame == 7) { diff --git a/src/game_sp/main.c b/src/game_sp/main.c index f9dcecc5..92fc9120 100644 --- a/src/game_sp/main.c +++ b/src/game_sp/main.c @@ -73,7 +73,8 @@ void GameActions_SP(byte action[MAX_PLAYERS], boolean warp_mode) byte single_player_action = action[0]; int x, y; - UpdateEngineValues(mScrollX / TILEX, mScrollY / TILEY); + UpdateEngineValues(mScrollX / TILEX, mScrollY / TILEY, + MurphyScreenXPos / TILEX, MurphyScreenYPos / TILEY); subMainGameLoop_Main(single_player_action, warp_mode); diff --git a/src/tools.c b/src/tools.c index 86ad19b7..2ca18cf6 100644 --- a/src/tools.c +++ b/src/tools.c @@ -192,6 +192,22 @@ static char *print_if_not_empty(int element) return s; } +int correctLevelPosX_EM(int lx) +{ + lx -= 1; + lx -= (BorderElement != EL_EMPTY ? 1 : 0); + + return lx; +} + +int correctLevelPosY_EM(int ly) +{ + ly -= 1; + ly -= (BorderElement != EL_EMPTY ? 1 : 0); + + return ly; +} + static int getFieldbufferOffsetX_RND() { int full_lev_fieldx = lev_fieldx + (BorderElement != EL_EMPTY ? 2 : 0); @@ -288,8 +304,7 @@ static int getLevelFromScreenX_EM(int sx) int px = sx - SX; int lx = LEVELX((px + dx) / TILESIZE_VAR); - lx -= 1; - lx -= (BorderElement != EL_EMPTY ? 1 : 0); + lx = correctLevelPosX_EM(lx); return lx; } @@ -306,8 +321,7 @@ static int getLevelFromScreenY_EM(int sy) int py = sy - SY; int ly = LEVELY((py + dy) / TILESIZE_VAR); - ly -= 1; - ly -= (BorderElement != EL_EMPTY ? 1 : 0); + ly = correctLevelPosY_EM(ly); return ly; } @@ -395,6 +409,7 @@ void DumpTile(int x, int y) printf(" GfxElement: %d\n", GfxElement[x][y]); printf(" GfxAction: %d\n", GfxAction[x][y]); printf(" GfxFrame: %d [%d]\n", GfxFrame[x][y], FrameCounter); + printf(" Player x/y: %d, %d\n", local_player->jx, local_player->jy); printf("\n"); } diff --git a/src/tools.h b/src/tools.h index 8c8ac9c6..c8d351df 100644 --- a/src/tools.h +++ b/src/tools.h @@ -65,6 +65,9 @@ #define REQUEST_WAIT_FOR_INPUT (REQ_ASK | REQ_CONFIRM | REQ_PLAYER) +int correctLevelPosX_EM(int); +int correctLevelPosY_EM(int); + int getLevelFromScreenX(int); int getLevelFromScreenY(int); -- 2.34.1