player is shooting knifes now
parent
1631e9199b
commit
7356168b6f
|
@ -20,6 +20,7 @@ void mob_systems(ecs_world_t *ecs) {
|
|||
//NOTE(DavoSK): weapons
|
||||
ECS_SYSTEM_TICKED(ecs, WeaponKnifeMechanic, EcsPostUpdate, components.WeaponKnife, components.Position, components.Input);
|
||||
ECS_SYSTEM_TICKED(ecs, WeaponProjectileExpire, EcsPostUpdate, components.WeaponProjectile, components.Position);
|
||||
|
||||
//ECS_OBSERVER(ecs, MobDetectPlayers1, EcsOnAdd, components.Mob);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#define WEAPON_KNIFE_SPAWN_DELAY 20
|
||||
#define WEAPON_PROJECTILE_POS_OFFSET 3.2f
|
||||
#define WEAPON_PROJECTILE_SPEED 10.0f
|
||||
#define WEAPON_PROJECTILE_RANGE_LIFETIME 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) {
|
||||
|
@ -22,18 +22,22 @@ void WeaponKnifeMechanic(ecs_iter_t *it) {
|
|||
|
||||
for(int j = 0; j < weapon[i].projectile_count; j++) {
|
||||
ecs_entity_t e = entity_spawn(EKIND_WEAPON);
|
||||
ecs_set(it->world, e, WeaponProjectile, { .damage=weapon[i].damage });
|
||||
ecs_set(it->world, e, Sprite, { .spritesheet=0, .frame=2347 });
|
||||
ecs_set(it->world, e, InAir, {0});
|
||||
ecs_set(it->world, e, TriggerOnly, { 0 });
|
||||
ecs_set(it->world, e, WeaponProjectile, {
|
||||
.damage=weapon[i].damage,
|
||||
.origin_x=pos[i].x,
|
||||
.origin_y=pos[i].y
|
||||
});
|
||||
|
||||
ecs_set(it->world, e, Velocity, {
|
||||
.x=input[i].x*WEAPON_PROJECTILE_SPEED,
|
||||
.y=input[i].y*WEAPON_PROJECTILE_SPEED
|
||||
.x=input[i].hx*WEAPON_PROJECTILE_SPEED,
|
||||
.y=input[i].hy*WEAPON_PROJECTILE_SPEED*-1
|
||||
});
|
||||
|
||||
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->x=pos[i].x;
|
||||
dest->y=pos[i].y+get_rand_between(-WEAPON_PROJECTILE_POS_OFFSET, WEAPON_PROJECTILE_POS_OFFSET);
|
||||
}
|
||||
|
||||
weapon[i].spawn_delay = WEAPON_KNIFE_SPAWN_DELAY;
|
||||
|
@ -47,8 +51,10 @@ void WeaponProjectileExpire(ecs_iter_t *it) {
|
|||
for (int i = 0; i < it->count; i++) {
|
||||
zpl_vec2 v_origin = { .x = weapon[i].origin_x, .y = weapon[i].origin_y };
|
||||
zpl_vec2 v_pos = { .x = pos[i].x, .y = pos[i].y };
|
||||
const float d = zpl_vec2_mag(v_origin, v_pos);
|
||||
|
||||
zpl_vec2 v_dist;
|
||||
zpl_vec2_sub(&v_dist, v_origin, v_pos);
|
||||
|
||||
const float d = zpl_vec2_mag(v_dist);
|
||||
if(d > WEAPON_PROJECTILE_RANGE_LIFETIME) {
|
||||
entity_despawn(it->entities[i]);
|
||||
}
|
||||
|
@ -56,5 +62,6 @@ void WeaponProjectileExpire(ecs_iter_t *it) {
|
|||
}
|
||||
|
||||
void WeaponProjectileHit(ecs_iter_t *it) {
|
||||
|
||||
//TODO(DavoSK): hit entity, attach take damage component
|
||||
//remove projectile
|
||||
}
|
Loading…
Reference in New Issue