Improve weapon switching

This commit is contained in:
Miloslav Číž 2020-09-22 15:58:18 +02:00
parent b3f2204f9d
commit 94821d906d
3 changed files with 30 additions and 16 deletions

View File

@ -4,7 +4,6 @@ general:
- Ability to play SFX slower to e.g. give some monsters lower pitch?
- Rewrite python scripts to C (faster, less bloat).
- Try to recolor textures and give them a bit more of variety.
- Make monsters die when squeezed?
- On Win$hit builds display an anti-windshit text, by macro.
- automatic tests: a frontend that will play the game, check the state, rendered
frames etc.
@ -209,3 +208,4 @@ scratched:
- open door by shooting at them?
- add jump pads?
- add "pletivo" transparent wall texture?
- make monsters die when squeezed?

42
game.h
View File

@ -382,8 +382,7 @@ struct
uint8_t health;
uint32_t weaponCooldownStartFrame; /**< frame from which weapon cooldown is
counted */
uint32_t weaponCooldownFrames; ///< frames left for weapon cooldow
uint32_t lastHurtFrame;
uint32_t lastItemTakenFrame;
@ -1291,7 +1290,7 @@ void SFG_initPlayer()
SFG_playerRotateWeapon(1); // this chooses weapon with ammo available
SFG_player.weaponCooldownStartFrame = SFG_game.frame;
SFG_player.weaponCooldownFrames = 0;
SFG_player.lastHurtFrame = SFG_game.frame;
SFG_player.lastItemTakenFrame = SFG_game.frame;
@ -2919,12 +2918,17 @@ void SFG_gameStepPlaying()
int8_t strafe = 0;
uint8_t currentWeapon = SFG_player.weapon;
#if SFG_HEADBOB_ENABLED
int8_t bobbing = 0;
#endif
int8_t shearing = 0;
if (SFG_player.weaponCooldownFrames > 0)
SFG_player.weaponCooldownFrames--;
if (SFG_keyJustPressed(SFG_KEY_TOGGLE_FREELOOK))
SFG_game.settings = (SFG_game.settings & 0x04) ?
(SFG_game.settings & ~0x0c) : (SFG_game.settings | 0x0c );
@ -2933,9 +2937,7 @@ void SFG_gameStepPlaying()
if (
SFG_keyIsDown(SFG_KEY_B) &&
!SFG_keyIsDown(SFG_KEY_C) &&
(SFG_game.frame - SFG_player.weaponCooldownStartFrame >
RCL_max(SFG_MIN_WEAPON_COOLDOWN_FRAMES,
SFG_GET_WEAPON_FIRE_COOLDOWN_FRAMES(SFG_player.weapon))))
(SFG_player.weaponCooldownFrames == 0))
{
// player: attack/shoot/fire
@ -3058,7 +3060,10 @@ void SFG_gameStepPlaying()
}
}
SFG_player.weaponCooldownStartFrame = SFG_game.frame;
SFG_player.weaponCooldownFrames =
RCL_max(
SFG_GET_WEAPON_FIRE_COOLDOWN_FRAMES(SFG_player.weapon),
SFG_MIN_WEAPON_COOLDOWN_FRAMES);
SFG_getPlayerWeaponInfo(&ammo,&projectileCount,&canShoot);
@ -3079,9 +3084,11 @@ void SFG_gameStepPlaying()
} // attack
#endif // SFG_PREVIEW_MODE == 0
if (SFG_keyJustPressed(SFG_KEY_NEXT_WEAPON))
int8_t canSwitchWeapon = SFG_player.weaponCooldownFrames == 0;
if (SFG_keyJustPressed(SFG_KEY_NEXT_WEAPON) && canSwitchWeapon)
SFG_playerRotateWeapon(1);
else if (SFG_keyJustPressed(SFG_KEY_PREVIOUS_WEAPON))
else if (SFG_keyJustPressed(SFG_KEY_PREVIOUS_WEAPON) && canSwitchWeapon)
SFG_playerRotateWeapon(0);
uint8_t shearingOn = SFG_game.settings & 0x04;
@ -3119,9 +3126,12 @@ void SFG_gameStepPlaying()
if (SFG_keyIsDown(SFG_KEY_C)) // C + AL/BR: weapon switching
{
if (SFG_keyJustPressed(SFG_KEY_LEFT) || SFG_keyJustPressed(SFG_KEY_A))
if ((SFG_keyJustPressed(SFG_KEY_LEFT) || SFG_keyJustPressed(SFG_KEY_A)) &&
canSwitchWeapon)
SFG_playerRotateWeapon(0);
else if (SFG_keyJustPressed(SFG_KEY_RIGHT) || SFG_keyJustPressed(SFG_KEY_B))
else if (
(SFG_keyJustPressed(SFG_KEY_RIGHT) || SFG_keyJustPressed(SFG_KEY_B)) &&
canSwitchWeapon)
SFG_playerRotateWeapon(1);
}
else if (!SFG_keyIsDown(SFG_KEY_A)) // L/R: turning
@ -3496,6 +3506,10 @@ void SFG_gameStepPlaying()
SFG_updateLevel();
if (SFG_player.weapon != currentWeapon) // if weapon switched, start cooldown
SFG_player.weaponCooldownFrames =
SFG_GET_WEAPON_FIRE_COOLDOWN_FRAMES(SFG_player.weapon) / 2;
#if SFG_IMMORTAL == 0
if (SFG_player.health == 0)
{
@ -4008,13 +4022,13 @@ void SFG_drawIndicationBorder(uint16_t width, uint8_t color)
*/
void SFG_drawWeapon(int16_t bobOffset)
{
uint32_t shotAnimationFrame =
SFG_game.frame - SFG_player.weaponCooldownStartFrame;
uint32_t animationLength =
RCL_max(SFG_MIN_WEAPON_COOLDOWN_FRAMES,
SFG_GET_WEAPON_FIRE_COOLDOWN_FRAMES(SFG_player.weapon));
uint32_t shotAnimationFrame =
animationLength - SFG_player.weaponCooldownFrames;
bobOffset -= SFG_HUD_BAR_HEIGHT;
uint8_t fireType = SFG_GET_WEAPON_FIRE_TYPE(SFG_player.weapon);

View File

@ -31,7 +31,7 @@
#define SFG_IMMORTAL 1
#define SFG_UNLOCK_DOOR 1
#define SFG_REVEAL_MAP 1
#define SFG_INFINITE_AMMO 1
// #define SFG_INFINITE_AMMO 1
#define MUSIC_VOLUME 4