Animate weapons

This commit is contained in:
Miloslav Číž 2019-10-24 00:32:04 +02:00
parent a150314eec
commit 5882b68f79

21
main.c
View File

@ -107,6 +107,10 @@ void SFG_init();
===============================================================================
*/
#define SFG_WEAPON_KNIFE 0
#define SFG_WEAPON_SHOTGUN 1
#define SFG_WEAPON_ROCKER_LAUNCHER 2
#define SFG_GAME_RESOLUTION_X \
(SFG_SCREEN_RESOLUTION_X / SFG_RESOLUTION_SCALEDOWN)
@ -1457,10 +1461,14 @@ void SFG_gameStep()
int8_t shearing = 0;
if (SFG_keyJustPressed(SFG_KEY_B))
if (
SFG_keyIsDown(SFG_KEY_B) &&
(SFG_gameFrame - SFG_player.lastShotFrame >
SFG_WEAPON_SHOTGUN_COOLDOWN_FRAMES))
{
// fire
if (SFG_player.weapon == SFG_WEAPON_ROCKER_LAUNCHER)
SFG_launchProjectile(
SFG_PROJECTILE_FIREBALL,
SFG_player.camera.position,
@ -2133,6 +2141,9 @@ uint8_t SFG_drawNumber(
return 5 - position;
}
/**
Draws the player weapon, handling the shooting animation.
*/
void SFG_drawWeapon(int16_t bobOffset)
{
uint32_t shotAnimationFrame = SFG_gameFrame - SFG_player.lastShotFrame;
@ -2140,6 +2151,13 @@ void SFG_drawWeapon(int16_t bobOffset)
uint32_t animationLength = SFG_WEAPON_SHOTGUN_COOLDOWN_FRAMES;
if (shotAnimationFrame < animationLength)
{
if (SFG_player.weapon == SFG_WEAPON_KNIFE)
{
bobOffset = shotAnimationFrame < animationLength / 2 ? 0 :
2 * SFG_WEAPONBOB_OFFSET_PIXELS ;
}
else
{
bobOffset +=
((animationLength - shotAnimationFrame) * SFG_WEAPON_IMAGE_SCALE * 20)
@ -2151,6 +2169,7 @@ void SFG_drawWeapon(int16_t bobOffset)
SFG_WEAPON_IMAGE_POSITION_Y - (SFG_TEXTURE_SIZE / 3) * SFG_WEAPON_IMAGE_SCALE + bobOffset,
SFG_WEAPON_IMAGE_SCALE);
}
}
SFG_blitImage(SFG_weaponImages[SFG_player.weapon],
SFG_WEAPON_IMAGE_POSITION_X,