Fix jumping

This commit is contained in:
Miloslav Číž 2020-03-28 17:34:09 +01:00
parent 7fcbd9d838
commit 26a8f4adab
3 changed files with 30 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -34,7 +34,7 @@
/** /**
Initial upwards speed of player's jump, in squares per second. Initial upwards speed of player's jump, in squares per second.
*/ */
#define SFG_PLAYER_JUMP_SPEED 80 #define SFG_PLAYER_JUMP_SPEED 5
/** /**
Melee and close-up attack range, in RCL_Units. Melee and close-up attack range, in RCL_Units.
@ -261,6 +261,13 @@
#define SFG_GRAVITY_SPEED_INCREASE_PER_FRAME 1 #define SFG_GRAVITY_SPEED_INCREASE_PER_FRAME 1
#endif #endif
#define SFG_PLAYER_JUMP_OFFSET_PER_FRAME \
((SFG_PLAYER_JUMP_SPEED * RCL_UNITS_PER_SQUARE) / SFG_FPS)
#if SFG_PLAYER_JUMP_OFFSET_PER_FRAME == 0
#define SFG_PLAYER_JUMP_OFFSET_PER_FRAME 1
#endif
#define SFG_HEADBOB_FRAME_INCREASE_PER_FRAME \ #define SFG_HEADBOB_FRAME_INCREASE_PER_FRAME \
(SFG_HEADBOB_SPEED / SFG_FPS) (SFG_HEADBOB_SPEED / SFG_FPS)

24
main.c
View File

@ -280,6 +280,7 @@ struct
uint32_t lastFrameTimeMs; uint32_t lastFrameTimeMs;
uint8_t selectedMenuItem; uint8_t selectedMenuItem;
uint8_t selectedLevel; ///< Level to play selected in the main menu. uint8_t selectedLevel; ///< Level to play selected in the main menu.
uint8_t antiSpam; ///< Prevents log message spamming.
} SFG_game; } SFG_game;
/** /**
@ -1370,6 +1371,7 @@ void SFG_init()
SFG_game.rayConstraints.maxHits = SFG_RAYCASTING_MAX_HITS; SFG_game.rayConstraints.maxHits = SFG_RAYCASTING_MAX_HITS;
SFG_game.rayConstraints.maxSteps = SFG_RAYCASTING_MAX_STEPS; SFG_game.rayConstraints.maxSteps = SFG_RAYCASTING_MAX_STEPS;
SFG_game.antiSpam = 0;
SFG_LOG("computing average texture colors") SFG_LOG("computing average texture colors")
@ -2763,7 +2765,7 @@ void SFG_gameStepPlaying()
) && ) &&
(SFG_player.verticalSpeed == 0) && (SFG_player.verticalSpeed == 0) &&
(SFG_player.previousVerticalSpeed == 0)) ? (SFG_player.previousVerticalSpeed == 0)) ?
SFG_PLAYER_JUMP_SPEED : SFG_PLAYER_JUMP_OFFSET_PER_FRAME : // jump
(SFG_player.verticalSpeed - SFG_GRAVITY_SPEED_INCREASE_PER_FRAME); (SFG_player.verticalSpeed - SFG_GRAVITY_SPEED_INCREASE_PER_FRAME);
#endif #endif
@ -3021,6 +3023,18 @@ void SFG_gameStepPlaying()
SFG_player.squarePosition[0], SFG_player.squarePosition[0],
SFG_player.squarePosition[1]); SFG_player.squarePosition[1]);
if ( // squeezer check
(SFG_ceilingHeightAt(
SFG_player.squarePosition[0],SFG_player.squarePosition[1]) -
SFG_floorHeightAt(
SFG_player.squarePosition[0],SFG_player.squarePosition[1]))
<
(RCL_CAMERA_COLL_HEIGHT_ABOVE + RCL_CAMERA_COLL_HEIGHT_BELOW))
{
SFG_LOG("player is squeezed");
SFG_player.health = 0;
}
SFG_updateLevel(); SFG_updateLevel();
#if SFG_IMMORTAL == 0 #if SFG_IMMORTAL == 0
@ -3944,8 +3958,14 @@ void SFG_mainLoopBody()
steps++; steps++;
} }
if (steps > 1) if ((steps > 1) && (SFG_game.antiSpam == 0))
{
SFG_LOG("Failed to reach target FPS! Consider setting a lower value.") SFG_LOG("Failed to reach target FPS! Consider setting a lower value.")
SFG_game.antiSpam = 30;
}
if (SFG_game.antiSpam > 0)
SFG_game.antiSpam--;
// render noly once // render noly once
SFG_draw(); SFG_draw();