Add projectile table

This commit is contained in:
Miloslav Číž 2019-12-30 21:35:19 +01:00
parent e46f6fda3b
commit b4ceb1603b
3 changed files with 53 additions and 37 deletions

View File

@ -66,11 +66,6 @@
*/
#define SFG_AI_RANDOM_CHANGE_PROBABILITY 40
/**
Speed of rocket projectile, in squares per second.
*/
#define SFG_FIREBALL_SPEED 15
/**
Distance at which level elements (sprites) collide, in RCL_Unit (1024 per
square).
@ -115,13 +110,6 @@
#define SFG_MAX_DOORS 32
#define SFG_PROJECTILE_EXPLOSION 0
#define SFG_PROJECTILE_FIREBALL 1
#define SFG_PROJECTILE_PLASMA 2
#define SFG_PROJECTILE_DUST 3
#define SFG_PROJECTILE_BULLET 4
#define SFG_PROJECTILE_NONE 255
// ----------------------------
// derived constants
@ -167,13 +155,6 @@
#define SFG_PLAYER_MOVE_UNITS_PER_FRAME 1
#endif
#define SFG_FIREBALL_MOVE_UNITS_PER_FRAME \
((SFG_FIREBALL_SPEED * RCL_UNITS_PER_SQUARE) / SFG_FPS)
#if SFG_FIREBALL_MOVE_UNITS_PER_FRAME == 0
#define SFG_FIREBALL_MOVE_UNITS_PER_FRAME 1
#endif
#define SFG_GRAVITY_SPEED_INCREASE_PER_FRAME \
((SFG_GRAVITY_ACCELERATION * RCL_UNITS_PER_SQUARE) / (SFG_FPS * SFG_FPS))
@ -260,9 +241,6 @@
#define SFG_AI_UPDATE_FRAME_INTERVAL 1
#endif
#define SFG_EXPLOSION_DURATION_DOUBLE_FRAMES \
(SFG_EXPLOSION_DURATION / SFG_MS_PER_FRAME)
#if SFG_EXPLOSION_DURATION_DOUBLE_FRAMES == 0
#define SFG_EXPLOSION_DURATION_FRAMES 1
#endif
@ -290,7 +268,7 @@
(SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM + SFG_HUD_MARGIN * 2 + 1)
// ----------------------------
// weapons
// weapons and projectiles
#define SFG_WEAPON_KNIFE 0
#define SFG_WEAPON_SHOTGUN 1
@ -316,7 +294,7 @@
#define SFG_WEAPON_FIRE_TYPE_PLASMA 4
/**
Table of Weapon attributes, each as a byte in format :
Table of weapon attributes, each as a byte in format:
cccccfff
@ -333,4 +311,41 @@ SFG_PROGRAM_MEMORY uint8_t SFG_weaponAttributeTable[SFG_WEAPONS_TOTAL] =
/* plasma */ SFG_WEAPON_ATTRIBUTE(SFG_WEAPON_FIRE_TYPE_PLASMA,350)
};
#define SFG_PROJECTILE_EXPLOSION 0
#define SFG_PROJECTILE_FIREBALL 1
#define SFG_PROJECTILE_PLASMA 2
#define SFG_PROJECTILE_DUST 3
#define SFG_PROJECTILE_BULLET 4
#define SFG_PROJECTILE_NONE 255
#define SFG_PROJECTILES_TOTAL 5
#define SFG_PROJECTILE_ATTRIBUTE(speedSquaresPerSec,timeToLiveMs) \
((uint8_t) \
((((speedSquaresPerSec / 4 == 0) && (speedSquaresPerSec != 0)) ? 1 : speedSquaresPerSec / 4) | \
((timeToLiveMs / (8 * SFG_MS_PER_FRAME)) << 3)))
#define SFG_GET_PROJECTILE_SPEED_UPS(projectileNumber) \
(((SFG_projectileAttributeTable[projectileNumber] & 0x07) * 4 * RCL_UNITS_PER_SQUARE) / SFG_FPS)
#define SFG_GET_PROJECTILE_FRAMES_TO_LIVE(projectileNumber) \
((SFG_projectileAttributeTable[projectileNumber] >> 3) * 8)
/**
Table of projectile attributes, each as a byte in format:
lllllsss
fff: half speed in game squares per second
lllll: eigth of frames to live
*/
SFG_PROGRAM_MEMORY uint8_t SFG_projectileAttributeTable[SFG_PROJECTILES_TOTAL] =
{
/* explosion */ SFG_PROJECTILE_ATTRIBUTE(0,300),
/* fireball */ SFG_PROJECTILE_ATTRIBUTE(18,1000),
/* plasma */ SFG_PROJECTILE_ATTRIBUTE(20,500),
/* dust */ SFG_PROJECTILE_ATTRIBUTE(0,450),
/* bullet */ SFG_PROJECTILE_ATTRIBUTE(28,1000)
};
#endif // guard

22
main.c
View File

@ -1037,7 +1037,8 @@ uint8_t SFG_launchProjectile(
SFG_ProjectileRecord p;
p.type = type;
p.doubleFramesToLive = 255;
p.doubleFramesToLive =
RCL_nonZero(SFG_GET_PROJECTILE_FRAMES_TO_LIVE(type) / 2);
p.position[0] =
shootFrom.x + (direction.x * offsetDistance) / RCL_UNITS_PER_SQUARE;
@ -1048,10 +1049,10 @@ uint8_t SFG_launchProjectile(
p.position[2] = shootFromHeight;
p.direction[0] =
(direction.x * SFG_FIREBALL_MOVE_UNITS_PER_FRAME) / RCL_UNITS_PER_SQUARE;
(direction.x * SFG_GET_PROJECTILE_SPEED_UPS(type)) / RCL_UNITS_PER_SQUARE;
p.direction[1] =
(direction.y * SFG_FIREBALL_MOVE_UNITS_PER_FRAME) / RCL_UNITS_PER_SQUARE;
(direction.y * SFG_GET_PROJECTILE_SPEED_UPS(type)) / RCL_UNITS_PER_SQUARE;
p.direction[2] = verticalSpeed;
@ -1199,7 +1200,8 @@ void SFG_createExplosion(RCL_Unit x, RCL_Unit y, RCL_Unit z)
explosion.direction[1] = 0;
explosion.direction[2] = 0;
explosion.doubleFramesToLive = SFG_EXPLOSION_DURATION_DOUBLE_FRAMES;
explosion.doubleFramesToLive = RCL_nonZero(
SFG_GET_PROJECTILE_FRAMES_TO_LIVE(SFG_PROJECTILE_EXPLOSION) / 2);
SFG_createProjectile(explosion);
@ -1237,7 +1239,8 @@ void SFG_createDust(RCL_Unit x, RCL_Unit y, RCL_Unit z)
dust.direction[1] = 0;
dust.direction[2] = 0;
dust.doubleFramesToLive = SFG_EXPLOSION_DURATION_DOUBLE_FRAMES;
dust.doubleFramesToLive =
RCL_nonZero(SFG_GET_PROJECTILE_FRAMES_TO_LIVE(SFG_PROJECTILE_DUST) / 2);
SFG_createProjectile(dust);
}
@ -1545,7 +1548,7 @@ void SFG_gameStep()
SFG_player.camera.position,
SFG_player.camera.height,
RCL_angleToDirection(SFG_player.camera.direction),
(SFG_player.camera.shear * SFG_FIREBALL_MOVE_UNITS_PER_FRAME) /
(SFG_player.camera.shear * SFG_GET_PROJECTILE_SPEED_UPS(projectile)) /
SFG_CAMERA_MAX_SHEAR_PIXELS,
SFG_ELEMENT_COLLISION_DISTANCE + RCL_CAMERA_COLL_RADIUS
);
@ -2494,14 +2497,17 @@ void SFG_draw()
if (proj->type == SFG_PROJECTILE_EXPLOSION ||
proj->type == SFG_PROJECTILE_DUST)
{
int16_t doubleFramesToLive =
RCL_nonZero(SFG_GET_PROJECTILE_FRAMES_TO_LIVE(proj->type) / 2);
// grow the explosion sprite as an animation
spriteSize =
(
SFG_GAME_RESOLUTION_Y *
RCL_sinInt(
((SFG_EXPLOSION_DURATION_DOUBLE_FRAMES -
((doubleFramesToLive -
proj->doubleFramesToLive) * RCL_UNITS_PER_SQUARE / 4)
/ SFG_EXPLOSION_DURATION_DOUBLE_FRAMES)
/ doubleFramesToLive)
) / RCL_UNITS_PER_SQUARE;
}

View File

@ -125,11 +125,6 @@
*/
#define SFG_CAMERA_MAX_SHEAR 1024
/**
Duration in ms of the explosion animation.
*/
#define SFG_EXPLOSION_DURATION 120
/**
Specifies how quick some sprite animations are, in frames per second.
*/