2021-11-01 18:55:13 +00:00
|
|
|
|
|
|
|
#define DEMO_NPC_MOVE_SPEED 500
|
|
|
|
#define DEMO_NPC_STEER_SPEED 300
|
|
|
|
|
2022-07-31 14:34:47 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2021-11-01 18:55:13 +00:00
|
|
|
void DemoNPCMoveAround(ecs_iter_t *it) {
|
2022-07-31 14:34:47 +00:00
|
|
|
Velocity *v = ecs_field(it, Velocity, 1);
|
2021-11-01 18:55:13 +00:00
|
|
|
for (int i = 0; i < it->count; i++) {
|
|
|
|
float d = zpl_quake_rsqrt(v[i].x*v[i].x + v[i].y*v[i].y);
|
2021-11-03 18:04:34 +00:00
|
|
|
v[i].x += (v[i].x*d*DEMO_NPC_MOVE_SPEED*safe_dt(it) + zpl_cos(zpl_to_radians((float)(rand()%360)))*DEMO_NPC_STEER_SPEED*safe_dt(it));
|
|
|
|
v[i].y += (v[i].y*d*DEMO_NPC_MOVE_SPEED*safe_dt(it) + zpl_sin(zpl_to_radians((float)(rand()%360)))*DEMO_NPC_STEER_SPEED*safe_dt(it));
|
2021-11-01 18:55:13 +00:00
|
|
|
}
|
|
|
|
}
|