diff options
| author | Alexander M Pickering <alex@cogarr.net> | 2025-01-26 15:21:55 -0600 |
|---|---|---|
| committer | Alexander M Pickering <alex@cogarr.net> | 2025-01-26 15:21:55 -0600 |
| commit | f7a6cb3573957ae617bf88a05f72cb22bb912abd (patch) | |
| tree | 9bd8dabfcbd5808a74d995c93dc6f3f611da13f8 /src/controllers | |
| parent | 5846a4fea8d6a993466a792977128d21a18587bc (diff) | |
| download | ggj25-f7a6cb3573957ae617bf88a05f72cb22bb912abd.tar.gz ggj25-f7a6cb3573957ae617bf88a05f72cb22bb912abd.tar.bz2 ggj25-f7a6cb3573957ae617bf88a05f72cb22bb912abd.zip | |
Revert "final commit"
This reverts commit c39ff632b46c179709101c5b50a061ebd723689f.
Diffstat (limited to 'src/controllers')
| -rw-r--r-- | src/controllers/fish.moon | 33 | ||||
| -rw-r--r-- | src/controllers/mouse_keyboard.moon | 86 |
2 files changed, 85 insertions, 34 deletions
diff --git a/src/controllers/fish.moon b/src/controllers/fish.moon index dc3b1e9..9ba2d83 100644 --- a/src/controllers/fish.moon +++ b/src/controllers/fish.moon @@ -2,16 +2,12 @@ ecs = require("ecs") world = require("world") controller = {} - - - class FishControllerComponent extends ecs.Component new: () => --print("Fish controller started") @node = am.group! join: (entity) => super(entity) - @ent = entity graphic = entity\get("graphic") assert(graphic, "Fish controller must have a graphic") pred_component = entity\get("pred") @@ -31,7 +27,7 @@ class FishControllerComponent extends ecs.Component while comp.state == "swimming" comp.state = "waiting" start_wait = world.sync_time! - while world.sync_time! - start_wait < 8 + while world.sync_time! - start_wait < 4 --TODO: look for nearby hooks and get caught coroutine.yield! if comp.state == "waiting" @@ -45,33 +41,12 @@ class FishControllerComponent extends ecs.Component pick_next_location: () => -- Pick somewhere to swim based on where we are? -- This can only be done on the host. - --TODO: spawn fish on all sides. - -- everything has to be floats so math.random returns a float. if @net.properties.pos.x > 10 -- pick somewhere to the right @net.properties.next_loc = vec2( - math.random(11.1,15), - math.random(-10.1,10) - ) - elseif @net.properties.pos.x < -10 - @net.properties.next_loc = vec2( - math.random(-15.1,-11) - math.random(-10.1,10) + math.random(10.3,12), + math.random(-10,10) ) - elseif @net.properties.pos.y > 10 - @net.properties.next_loc = vec2( - math.random(-10.1,10) - math.random(11.1,15) - ) - elseif @net.properties.pos.y < -10 - @net.properties.next_loc = vec2( - math.random(-10.1,10) - math.random(-15.1,-11) - ) - else - --If none of these apply, we're stuck on land somehow, delete ourselves - @entity\destroy! - - @net.properties.next_loc_time = world.sync_time! + @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) diff --git a/src/controllers/mouse_keyboard.moon b/src/controllers/mouse_keyboard.moon index cc33a72..28c4f58 100644 --- a/src/controllers/mouse_keyboard.moon +++ b/src/controllers/mouse_keyboard.moon @@ -5,7 +5,6 @@ fish = require("spawn_fish") rng = require("rng") us = require("ui.sprites") ui = require("ui") -minigame = require("minigame") assert(fish.Fish, "Failed to find fish from spawn_fish") controller = {} @@ -69,7 +68,6 @@ class MouseKeyboardControllerComponent extends ecs.Component f = ent.bobber.which f.state = "catching" comp\start_minigame(f) - -- TODO: make net destory the fish, not the controller f\destroy! elseif net_component.properties.reeling > 0 print("Reeling in fish!") @@ -90,9 +88,87 @@ class MouseKeyboardControllerComponent extends ecs.Component ) start_minigame: (fish) => @minigame_started = true - pull = () -> - win\mouse_pressed("left") - minigame.run(@net, @bobber, fish, pull) + node = am.group! + hook_location = 0 -- 0 -> 1? + hook_width = 5 + hook_gravity = 5 -- how quickly do we fall + hook_force = 80 -- how quickly do we accelerate + hook_vel = 0 + hook_length = 1 + hook_bounce_damp = 0.2 --how elastic is the bottom and top? + fish_width = fish.width + fish_force = 100 + fish_gravity = 0 + fish_activity = 0.1 + fish_vel = 0 + fish_bounce_damp = 1 -- perfectly elsastic bounce + reel_progress = 0 + escape_progress = 0 + reel_speed = 0.1 + escape_speed = 0.01 + reel_cutoff = 10 + escape_cutoff = 10 + fish_location = math.random(-256,256) + bar_sprite = require("ui.button")(40,-256,64,512,"").node + node\append(bar_sprite) + hook_sprite = am.translate(0,0)\append(am.scale(1)\append(am.sprite(us.hook))) + node\append(hook_sprite) + fish_g_sprite = am.sprite(us.fish_purple) + fish_b_sprite = am.sprite(us.fish_blue) + fish_sprite = am.translate(0,0)\append(am.scale(1)\append(am.group(fish_g_sprite, fish_b_sprite))) + node\append(fish_sprite) + ui.node\append(node) + net = @net + bobber = @bobber + assert(bobber, "Failed to find bobber") + node\action(() => + if win\mouse_pressed("left") + hook_vel += hook_force + else + hook_vel -= hook_gravity + hook_location += hook_vel * am.delta_time + if hook_location < -256 + 16 -- bounce + hook_vel = -hook_vel * hook_bounce_damp + hook_location = -256 + 16 + elseif hook_location > 256 - 16 + hook_vel = -hook_vel * hook_bounce_damp + hook_location = 256 - 16 + if math.random! < fish_activity + fish_vel = fish_force * math.random(-1,1) + fish_location += fish_vel * am.delta_time + if fish_location < -256 + 16 -- bounce + fish_vel = -fish_vel * fish_bounce_damp + fish_location = -256 + 16 + elseif fish_location > 256 - 16 + fish_vel = -fish_vel * fish_bounce_damp + fish_location = 256 - 16 + + if hook_location - hook_width > fish_location - fish_width and hook_location + hook_width < fish_location + fish_width + fish_b_sprite.hidden = true + fish_g_sprite.hidden = false + reel_progress += reel_speed + else + escape_progress += escape_speed + fish_g_sprite.hidden = true + fish_b_sprite.hidden = false + if reel_progress > reel_cutoff + net.properties.fish_caught += 1 + net.properties.casted = false + net.properties.reeling = 0 + ui.node\remove(node) + bobber.which = nil + elseif escape_progress > escape_cutoff + net.properties.casted = false + net.properties.reeling = 0 + ui.node\remove(node) + bobber.which = nil + --print("reel:", reel_progress, "escape:", escape_progress) + -- Updates all sprites at the end? + hook_sprite("translate").y = hook_location + fish_sprite("translate").y = fish_location + + ) + --error("Starting fishing minigame") controller.text_size = 1 controller.Controller = MouseKeyboardControllerComponent |
