implement random wandering
This commit is contained in:
parent
2de74dfa36
commit
29b6af5592
21
src/app.zig
21
src/app.zig
@ -165,6 +165,8 @@ const Entity = struct {
|
||||
minion_throw_cooldown: Nanoseconds = 0,
|
||||
minion_carried_wood_head: ?EntityId = null,
|
||||
minion_carried_wood_len: u32 = 0,
|
||||
minion_wander_target: ?Vec2 = null,
|
||||
minion_wander_cooldown: Nanoseconds = 0,
|
||||
|
||||
tree_health: u32 = 0,
|
||||
tree_max_health: u32 = 0,
|
||||
@ -606,6 +608,25 @@ fn minionLogic(self: *App, plt: Platform.Frame, minion_id: EntityId) !void {
|
||||
|
||||
switch (minion.minion_state) {
|
||||
.wander => {
|
||||
if (minion.minion_wander_cooldown == 0) {
|
||||
const rand = self.prng.random();
|
||||
minion.minion_wander_cooldown = rand.intRangeAtMost(Nanoseconds, 1000, 3000) * std.time.ns_per_ms;
|
||||
// TODO: Add limits/walls
|
||||
minion.minion_wander_target = .init(
|
||||
minion.pos.x + ((rand.float(f32)-0.5)*2) * 200,
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
if (minion.minion_wander_target) |target| {
|
||||
if (minion.pos.distance(target) < goal_distance) {
|
||||
minion.minion_wander_cooldown = @max(minion.minion_wander_cooldown - plt.dt, 0);
|
||||
}
|
||||
} else {
|
||||
minion.minion_wander_cooldown = 0;
|
||||
}
|
||||
|
||||
walk_goal = minion.minion_wander_target;
|
||||
},
|
||||
.goto_tree_station => {
|
||||
if (minion.target_entity) |tree_station_id| {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user