Add weapon cycling

This commit is contained in:
Miloslav Číž 2020-10-20 21:00:47 +02:00
parent 0c738d814c
commit 5b518b8024
2 changed files with 20 additions and 1 deletions

19
game.h
View File

@ -51,8 +51,9 @@
#define SFG_KEY_NEXT_WEAPON 12
#define SFG_KEY_PREVIOUS_WEAPON 13
#define SFG_KEY_MENU 14
#define SFG_KEY_CYCLE_WEAPON 15
#define SFG_KEY_COUNT 15 ///< Number of keys.
#define SFG_KEY_COUNT 16 ///< Number of keys.
/* ============================= PORTING =================================== */
@ -422,6 +423,7 @@ struct
which cards should be blinking in the HUD,
the last 2 bits are a blink reset counter. */
uint8_t justTeleported;
int8_t previousWeaponDirection; ///< Direction (+/0/-) of previous weapon.
} SFG_player;
/**
@ -1361,6 +1363,8 @@ void SFG_initPlayer()
SFG_player.health = SFG_PLAYER_START_HEALTH;
SFG_player.previousWeaponDirection = 0;
SFG_player.cards =
#if SFG_UNLOCK_DOOR
0x07;
@ -3054,6 +3058,9 @@ void SFG_gameStepPlaying()
SFG_playerRotateWeapon(1);
else if (SFG_keyJustPressed(SFG_KEY_PREVIOUS_WEAPON) && canSwitchWeapon)
SFG_playerRotateWeapon(0);
else if (SFG_keyJustPressed(SFG_KEY_CYCLE_WEAPON) &&
SFG_player.previousWeaponDirection)
SFG_playerRotateWeapon(SFG_player.previousWeaponDirection > 0);
uint8_t shearingOn = SFG_game.settings & 0x04;
@ -3635,8 +3642,18 @@ void SFG_gameStepPlaying()
}
if (SFG_player.weapon != currentWeapon) // if weapon switched, start cooldown
{
if (SFG_player.weapon == (currentWeapon + 1) % SFG_WEAPONS_TOTAL)
SFG_player.previousWeaponDirection = -1;
else if (currentWeapon == (SFG_player.weapon + 1) % SFG_WEAPONS_TOTAL)
SFG_player.previousWeaponDirection = 1;
else
SFG_player.previousWeaponDirection = 0;
SFG_player.weaponCooldownFrames =
SFG_GET_WEAPON_FIRE_COOLDOWN_FRAMES(SFG_player.weapon) / 2;
}
#if SFG_IMMORTAL == 0
if (SFG_player.health == 0)

View File

@ -216,6 +216,8 @@ int8_t SFG_keyPressed(uint8_t key)
case SFG_KEY_STRAFE_LEFT: return k(A) || k(KP_7); break;
case SFG_KEY_STRAFE_RIGHT: return k(D) || k(KP_9); break;
case SFG_KEY_MAP: return k(TAB); break;
case SFG_KEY_CYCLE_WEAPON: return k(F) ||
(sdlMouseButtonState & SDL_BUTTON_MMASK); break;
case SFG_KEY_TOGGLE_FREELOOK: return sdlMouseButtonState & SDL_BUTTON_RMASK;
break;
case SFG_KEY_NEXT_WEAPON: