From 49e92f1b88dbbdef485bdfd93b78e975fbf6fd20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 12 Oct 2020 15:47:20 +0200 Subject: [PATCH] Fix explosion bug --- TODO.txt | 7 +++---- constants.h | 17 ++++++++++------- game.h | 9 ++++++--- main_sdl.c | 6 +++--- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/TODO.txt b/TODO.txt index 033b7cb..743d223 100644 --- a/TODO.txt +++ b/TODO.txt @@ -127,10 +127,6 @@ level ideas: bugs: -- Player can be thrown inside a wall (by an explosion it seems), seems to happen - near door. If this can't be prevented completely, automatically unstuck the - player into a playable area. - done: - add headbob @@ -205,6 +201,9 @@ done: - Add SW buttons to emscripten version so that it's playable on mobiles. - When SDL level starts without moving the mouse, the camera sometimes rotates wildly. +- Player can be thrown inside a wall (by an explosion it seems), seems to happen + near door. If this can't be prevented completely, automatically unstuck the + player into a playable area. scratched: - option for disabling wall transparency, for performance? diff --git a/constants.h b/constants.h index 8b0a864..08ae02b 100644 --- a/constants.h +++ b/constants.h @@ -86,7 +86,7 @@ Distance at which level elements (sprites) collide, in RCL_Unit (1024 per square). */ -#define SFG_ELEMENT_COLLISION_RADIUS 1900 +#define SFG_ELEMENT_COLLISION_RADIUS 1800 /** Height, in RCL_Units, at which collisions happen with level elements @@ -95,15 +95,18 @@ #define SFG_ELEMENT_COLLISION_HEIGHT 1024 /** - Distance at which explosion does damage and throws away the player and - monsters, in RCL_Units. + Distance at which explosion does damage and throws away the player, in + RCL_Units. Should be higher than SFG_ELEMENT_COLLISION_RADIUS so that + exploded rockets also hurt the target. */ -#define SFG_EXPLOSION_RADIUS 2048 +#define SFG_EXPLOSION_RADIUS 2000 /** - Distance in RCL_Units which the player is pushed away by an explosion. + Distance in RCL_Units which the player is pushed away by an explosion. Watch + out, a slightly higher value can make player go through walls. Rather keep + this under RCL_UNITS_PER_SQUARE; */ -#define SFG_EXPLOSION_PUSH_AWAY_DISTANCE 1200 +#define SFG_EXPLOSION_PUSH_AWAY_DISTANCE 1023 /** How much damage triggers a barrel explosion. @@ -552,7 +555,7 @@ SFG_PROGRAM_MEMORY uint8_t SFG_attackDamageTable[SFG_WEAPON_FIRE_TYPES_TOTAL] = lllll: eigth of frames to live */ -#define LOW_FPS (SFG_FPS < 20) ///< low FPS needs low speeds, because collisions +#define LOW_FPS (SFG_FPS < 24) ///< low FPS needs low speeds, because collisions SFG_PROGRAM_MEMORY uint8_t SFG_projectileAttributeTable[SFG_PROJECTILES_TOTAL] = { diff --git a/game.h b/game.h index cd5448a..e035ba7 100755 --- a/game.h +++ b/game.h @@ -1797,8 +1797,6 @@ uint8_t SFG_pushAway( fromCenter = RCL_angleToDirection(preferredDirection); l = RCL_UNITS_PER_SQUARE; } - else if (l >= distance) - return 0; RCL_Vector2D offset; @@ -2014,8 +2012,13 @@ void SFG_createExplosion(RCL_Unit x, RCL_Unit y, RCL_Unit z) uint8_t damage = SFG_getDamageValue(SFG_WEAPON_FIRE_TYPE_FIREBALL); - if (SFG_pushPlayerAway(x,y,SFG_EXPLOSION_PUSH_AWAY_DISTANCE)) + if (SFG_taxicabDistance(x,y,z,SFG_player.camera.position.x, + SFG_player.camera.position.y,SFG_player.camera.height) + <= SFG_EXPLOSION_RADIUS) + { SFG_playerChangeHealth(-1 * damage); + SFG_pushPlayerAway(x,y,SFG_EXPLOSION_PUSH_AWAY_DISTANCE); + } for (uint16_t i = 0; i < SFG_currentLevel.monsterRecordCount; ++i) { diff --git a/main_sdl.c b/main_sdl.c index d4a6749..7aa93b9 100644 --- a/main_sdl.c +++ b/main_sdl.c @@ -22,10 +22,10 @@ #endif // #define SFG_START_LEVEL 1 -// #define SFG_IMMORTAL 1 -// #define SFG_UNLOCK_DOOR 1 + #define SFG_IMMORTAL 1 + #define SFG_UNLOCK_DOOR 1 // #define SFG_REVEAL_MAP 1 -// #define SFG_INFINITE_AMMO 1 + #define SFG_INFINITE_AMMO 1 // uncomment for perfomance debug //#define SFG_CPU_LOAD(percent) printf("CPU load: %d%\n",percent);