From 98b9f3431e0f7c958c13fb1fc1f11af5f0f09651 Mon Sep 17 00:00:00 2001 From: DavoSK Date: Thu, 2 Feb 2023 17:49:29 +0100 Subject: [PATCH] random offseting of knifes --- code/games/survival/src/game.c | 2 +- code/games/survival/src/system_weapon.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/code/games/survival/src/game.c b/code/games/survival/src/game.c index 01f5792..2c94ef7 100644 --- a/code/games/survival/src/game.c +++ b/code/games/survival/src/game.c @@ -46,7 +46,7 @@ void game_player_joined(uint64_t ent) { //NOTE(DavoSK): add weapon component for testing ecs_world_t* world = world_ecs(); ecs_set(world, (ecs_entity_t)ent, WeaponKnife, { - .projectile_count = 1, + .projectile_count = 10, .damage = 10, .spawn_delay = WEAPON_KNIFE_SPAWN_DELAY }); diff --git a/code/games/survival/src/system_weapon.c b/code/games/survival/src/system_weapon.c index a399b8e..9a8b71e 100644 --- a/code/games/survival/src/system_weapon.c +++ b/code/games/survival/src/system_weapon.c @@ -1,10 +1,11 @@ #define WEAPON_KNIFE_SPAWN_DELAY 20 -#define WEAPON_PROJECTILE_POS_OFFSET 3.2f +#define WEAPON_PROJECTILE_POS_OFFSET 10.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] */ } @@ -37,7 +38,8 @@ void WeaponKnifeMechanic(ecs_iter_t *it) { Position *dest = ecs_get_mut(world_ecs(), e, Position); dest->x=pos[i].x; - dest->y=pos[i].y+get_rand_between(-WEAPON_PROJECTILE_POS_OFFSET, WEAPON_PROJECTILE_POS_OFFSET); + 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); } weapon[i].spawn_delay = WEAPON_KNIFE_SPAWN_DELAY;