adjust starting pos of projectile based on direction

efd/v1
DavoSK 2023-02-02 18:52:11 +01:00
parent 98b9f3431e
commit 3a9196d19a
1 changed files with 10 additions and 6 deletions

View File

@ -1,13 +1,11 @@
#define WEAPON_KNIFE_SPAWN_DELAY 20
#define WEAPON_PROJECTILE_POS_OFFSET 10.0f
#define WEAPON_PROJECTILE_POS_OFFSET 200.0f
#define WEAPON_PROJECTILE_SPEED 500.0f
#define WEAPON_PROJECTILE_RANGE_LIFETIME 800.0f
//TODO(DavoSK): move to helpers, add srand
float get_rand_between(float min, float max) {
srand (time ( NULL));
float scale = rand() / (float) RAND_MAX; /* [0, 1.0] */
return min + scale * ( max - min ); /* [min, max] */
return ((float)rand() / (float)RAND_MAX) * (max - min) + min;
}
void WeaponKnifeMechanic(ecs_iter_t *it) {
@ -37,9 +35,15 @@ void WeaponKnifeMechanic(ecs_iter_t *it) {
});
Position *dest = ecs_get_mut(world_ecs(), e, Position);
const float offset = get_rand_between(-WEAPON_PROJECTILE_POS_OFFSET, WEAPON_PROJECTILE_POS_OFFSET);
dest->x=pos[i].x;
dest->y=pos[i].y+(float)rand()/(float)(RAND_MAX/WEAPON_PROJECTILE_POS_OFFSET);
zpl_printf("offset: %f, %d\n", (float)rand()/(float)(RAND_MAX/WEAPON_PROJECTILE_POS_OFFSET), weapon[i].projectile_count);
dest->y=pos[i].y;
if(zpl_abs(input[i].hx) > 0)
dest->y += offset;
if(zpl_abs(input[i].hy) > 0)
dest->x += offset;
}
weapon[i].spawn_delay = WEAPON_KNIFE_SPAWN_DELAY;