summaryrefslogtreecommitdiff
path: root/src/controllers/mouse_keyboard.moon
diff options
context:
space:
mode:
Diffstat (limited to 'src/controllers/mouse_keyboard.moon')
-rw-r--r--src/controllers/mouse_keyboard.moon86
1 files changed, 81 insertions, 5 deletions
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