Fix menu bug

This commit is contained in:
Miloslav Číž 2020-11-11 14:16:01 +01:00
parent b2773ee9af
commit 5b5a7a15f3
2 changed files with 19 additions and 21 deletions

View File

@ -1,6 +1,5 @@
general: general:
- When selecting continue from menu, the player shoots - fix!
- Profile, epsecially Pokitto, small periodical tearing can be noticed (some - Profile, epsecially Pokitto, small periodical tearing can be noticed (some
periodical updates probably). periodical updates probably).
- Compile Pokitto overclocked version. - Compile Pokitto overclocked version.
@ -221,6 +220,7 @@ done:
- make SFML frontend - make SFML frontend
- Add FOV options. RCL doesn't project sprites with different FOV correctly - - Add FOV options. RCL doesn't project sprites with different FOV correctly -
FIX! FIX!
- When selecting continue from menu, the player shoots - fix!
scratched: scratched:
- option for disabling wall transparency, for performance? - option for disabling wall transparency, for performance?

38
game.h
View File

@ -347,7 +347,7 @@ typedef struct
struct struct
{ {
uint8_t state; ///< Current game state. uint8_t state; ///< Current game state.
uint32_t stateChangeTime; ///< Time in ms at which the state was changed. uint32_t stateTime; ///< Time in ms from last state change.
uint8_t currentRandom; ///< for RNG uint8_t currentRandom; ///< for RNG
uint8_t spriteAnimationFrame; uint8_t spriteAnimationFrame;
uint8_t soundsPlayedThisFrame; /**< Each bit says whether given sound was uint8_t soundsPlayedThisFrame; /**< Each bit says whether given sound was
@ -1474,7 +1474,7 @@ void SFG_setGameState(uint8_t state)
{ {
SFG_LOG("changing game state"); SFG_LOG("changing game state");
SFG_game.state = state; SFG_game.state = state;
SFG_game.stateChangeTime = SFG_game.frameTime; SFG_game.stateTime = 0;
} }
void SFG_setAndInitLevel(uint8_t levelNumber) void SFG_setAndInitLevel(uint8_t levelNumber)
@ -2986,8 +2986,7 @@ void SFG_drawText(
void SFG_drawLevelStartOverlay() void SFG_drawLevelStartOverlay()
{ {
uint8_t stage = ((SFG_game.frameTime - SFG_game.stateChangeTime) * 4) / uint8_t stage = (SFG_game.stateTime * 4) / SFG_LEVEL_START_DURATION;
SFG_LEVEL_START_DURATION;
// fade in: // fade in:
@ -3474,7 +3473,9 @@ void SFG_gameStepPlaying()
if ( if (
SFG_keyIsDown(SFG_KEY_A) && SFG_keyIsDown(SFG_KEY_A) &&
!SFG_keyIsDown(SFG_KEY_C) && !SFG_keyIsDown(SFG_KEY_C) &&
(SFG_player.weaponCooldownFrames == 0)) (SFG_player.weaponCooldownFrames == 0) &&
(SFG_game.stateTime > 400) // don't immediately shoot if returning from menu
)
{ {
/* Player attack/shoot/fire, this has to be done AFTER the player is moved, /* Player attack/shoot/fire, this has to be done AFTER the player is moved,
otherwise he could shoot himself while running forward. */ otherwise he could shoot himself while running forward. */
@ -3876,7 +3877,7 @@ void SFG_gameStep()
SFG_updateLevel(); // let monsters and other things continue moving SFG_updateLevel(); // let monsters and other things continue moving
SFG_updatePlayerHeight(); // in case player is on elevator SFG_updatePlayerHeight(); // in case player is on elevator
int32_t t = SFG_game.frameTime - SFG_game.stateChangeTime; int32_t t = SFG_game.stateTime;
RCL_Unit h = SFG_floorHeightAt(SFG_player.squarePosition[0], RCL_Unit h = SFG_floorHeightAt(SFG_player.squarePosition[0],
SFG_player.squarePosition[1]); SFG_player.squarePosition[1]);
@ -3907,7 +3908,7 @@ void SFG_gameStep()
SFG_updateLevel(); SFG_updateLevel();
int32_t t = SFG_game.frameTime - SFG_game.stateChangeTime; int32_t t = SFG_game.stateTime;
if (t > SFG_WIN_ANIMATION_DURATION) if (t > SFG_WIN_ANIMATION_DURATION)
{ {
@ -3954,8 +3955,8 @@ void SFG_gameStep()
break; break;
case SFG_GAME_STATE_OUTRO: case SFG_GAME_STATE_OUTRO:
if (((SFG_game.frameTime - SFG_game.stateChangeTime) > if ((SFG_game.stateTime > SFG_STORYTEXT_DURATION) &&
SFG_STORYTEXT_DURATION) && (SFG_keyIsDown(SFG_KEY_A) || (SFG_keyIsDown(SFG_KEY_A) ||
SFG_keyIsDown(SFG_KEY_B))) SFG_keyIsDown(SFG_KEY_B)))
{ {
SFG_setGameState(SFG_GAME_STATE_MENU); SFG_setGameState(SFG_GAME_STATE_MENU);
@ -3973,8 +3974,7 @@ void SFG_gameStep()
SFG_getMouseOffset(&x,&y); // this keeps centering the mouse SFG_getMouseOffset(&x,&y); // this keeps centering the mouse
if ((SFG_game.frameTime - SFG_game.stateChangeTime) >= if (SFG_game.stateTime >= SFG_LEVEL_START_DURATION)
SFG_LEVEL_START_DURATION)
SFG_setGameState(SFG_GAME_STATE_PLAYING); SFG_setGameState(SFG_GAME_STATE_PLAYING);
break; break;
@ -3983,6 +3983,8 @@ void SFG_gameStep()
default: default:
break; break;
} }
SFG_game.stateTime += SFG_MS_PER_FRAME;
} }
void SFG_fillRectangle( void SFG_fillRectangle(
@ -4110,10 +4112,8 @@ void SFG_drawStoryText()
while (text[textLen] != 0) while (text[textLen] != 0)
textLen++; textLen++;
uint16_t drawLen = uint16_t drawLen = RCL_min(
RCL_min(textLen, textLen,(SFG_game.stateTime * textLen) / SFG_STORYTEXT_DURATION + 1);
((SFG_game.frameTime - SFG_game.stateChangeTime) * textLen) /
SFG_STORYTEXT_DURATION + 1);
#define CHAR_SIZE (SFG_FONT_SIZE_SMALL * (SFG_FONT_CHARACTER_SIZE + 1)) #define CHAR_SIZE (SFG_FONT_SIZE_SMALL * (SFG_FONT_CHARACTER_SIZE + 1))
#define LINE_LENGTH (SFG_GAME_RESOLUTION_X / CHAR_SIZE) #define LINE_LENGTH (SFG_GAME_RESOLUTION_X / CHAR_SIZE)
@ -4409,8 +4409,7 @@ void SFG_drawMenu()
void SFG_drawWinOverlay() void SFG_drawWinOverlay()
{ {
uint32_t t = RCL_min(SFG_WIN_ANIMATION_DURATION, uint32_t t = RCL_min(SFG_WIN_ANIMATION_DURATION,SFG_game.stateTime);
SFG_game.frameTime - SFG_game.stateChangeTime);
uint32_t t2 = RCL_min(t,SFG_WIN_ANIMATION_DURATION / 4); uint32_t t2 = RCL_min(t,SFG_WIN_ANIMATION_DURATION / 4);
@ -4557,9 +4556,8 @@ void SFG_draw()
{ {
// player die animation // player die animation
int32_t t = SFG_game.frameTime - SFG_game.stateChangeTime; weaponBobOffset =
(SFG_WEAPON_IMAGE_SCALE * SFG_TEXTURE_SIZE * SFG_game.stateTime) /
weaponBobOffset = (SFG_WEAPON_IMAGE_SCALE * SFG_TEXTURE_SIZE * t) /
SFG_LOSE_ANIMATION_DURATION; SFG_LOSE_ANIMATION_DURATION;
} }