diff options
| author | Alexander M Pickering <alex@cogarr.net> | 2025-01-25 20:40:09 -0600 |
|---|---|---|
| committer | Alexander M Pickering <alex@cogarr.net> | 2025-01-25 20:40:09 -0600 |
| commit | b174b8c00026253fd40ec262e430b0bb764e31ea (patch) | |
| tree | 173d294b98fe14727aef9cd42542f41a940f5ffa /src/controllers/fish.moon | |
| parent | 89a8f94ac0206412c1a2d7b8766d97dbdbd36253 (diff) | |
| download | ggj25-b174b8c00026253fd40ec262e430b0bb764e31ea.tar.gz ggj25-b174b8c00026253fd40ec262e430b0bb764e31ea.tar.bz2 ggj25-b174b8c00026253fd40ec262e430b0bb764e31ea.zip | |
work
Diffstat (limited to 'src/controllers/fish.moon')
| -rw-r--r-- | src/controllers/fish.moon | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/controllers/fish.moon b/src/controllers/fish.moon new file mode 100644 index 0000000..1516574 --- /dev/null +++ b/src/controllers/fish.moon @@ -0,0 +1,54 @@ +ecs = require("ecs") +world = require("world") +controller = {} + +class FishControllerComponent extends ecs.Component + new: () => + print("Fish controller started") + @node = am.group! + join: (entity) => + super(entity) + graphic = entity\get("graphic") + assert(graphic, "Fish controller must have a graphic") + pred_component = entity\get("pred") + assert(pred_component, "Fish controller must have a predicted component") + net_component = entity\get("net") + assert(net_component, "Fish controller must have a net component") + @net = net_component + graphic.node\append(@node) + comp = @ + locpicker = coroutine.create(() => + comp\pick_next_location! + coroutine.yield! + ) + --either "swimming", "waiting", or "catching" + @state = "swimming" + @node\action(coroutine.create(() => + while comp.state == "swimming" + comp.state = "waiting" + start_wait = world.sync_time! + while world.sync_time! - start_wait < 4 + --TODO: look for nearby hooks and get caught + coroutine.yield! + if comp.state == "waiting" + comp\pick_next_location! + comp.state = "swimming" + while math.distance(pred_component.properties.pos, net_component.properties.next_loc) > 0.01 + --print("At ", pred_component.properties.pos, "waiting to get to next location, ", net_component.properties.next_loc, "it is ", math.distance(pred_component.properties.pos, net_component.properties.next_loc), " away") + coroutine.yield! + + )) + pick_next_location: () => + -- Pick somewhere to swim based on where we are? + -- This can only be done on the host. + if @net.properties.pos.x > 10 -- pick somewhere to the right + @net.properties.next_loc = vec2( + math.random(10.3,12), + math.random(-10,10) + ) + @net.properties.next_loc_time = world.sync_time! + --@net.properties.next_loc = @net.properties.pos + vec2(0,1) + --@net.properties.next_loc_time = world.sync_time! + print("Picking next location, it was ", @net.properties.next_loc) + +{:FishControllerComponent} |
