little bit more charm to clicking them versus dragging them

This commit is contained in:
Jill 2023-06-01 19:14:40 +03:00
parent be3e13794e
commit d198bcc5e6
Signed by: oat
GPG Key ID: 33489AA58A955108
1 changed files with 90 additions and 8 deletions

View File

@ -8,6 +8,16 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
["INTERLOPER!", "WELCOME", "BUT ALSO PLEASE DO NOT BOTHER ME", "VERY BUSY"]
]
STAY_ARRAY = [
"OK I'LL BE HERE"
]
TOUCH_ARRAY = [
"HI INTERLOPER!",
"HELLO!",
"HI!"
]
getter renderer : FunfriendRenderer
property chatter_timer : Float64 = 1.0
property chatter_index : Int32 = 0
@ -15,8 +25,10 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
property held : Bool = false
property held_at : NamedTuple(x: Int32, y: Int32) = {x: 0, y: 0}
property started_holding_at : NamedTuple(x: Int32, y: Int32) = {x: 0, y: 0}
STAY_STILL_AFTER_HELD = 1.0
property held_timer : Float64 = 0.0
property waiting_for_stable_pos : Bool = false
property static_pos : NamedTuple(x: Int32, y: Int32)
@ -52,6 +64,10 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
x: window.cursor.position[:x].to_i,
y: window.cursor.position[:y].to_i,
}
if @held_timer <= 0
@started_holding_at = window.position
LOG.info { "starting holding at #{started_holding_at}" }
end
@held_timer = STAY_STILL_AFTER_HELD
window.cursor Window::Cursor::Shape::Hand
elsif event.action.release?
@ -90,17 +106,37 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
renderer.render(dt, window_size[:width], window_size[:height])
end
def goto(pos : NamedTuple(x: Int32, y: Int32), dur : Float64)
def goto(pos : NamedTuple(x: Int32, y: Int32), dur : Float64, set_as_static : Bool = true)
@easing_t = 0.0
@easing_dur = dur
@easing_from = window.position
@easing_to = pos
if set_as_static
@static_pos = @easing_to
end
LOG.info { "going from #{easing_from} to #{easing_to}" }
end
enum Behavior
Wander
Follow
Stay
end
FOLLOW_DIST = 120
def behavior : Behavior
speaking ? Behavior::Follow : Behavior::Wander
end
def moving
@easing_dur != 0.0 && @easing_t <= @easing_dur
end
def update_wander(dt : Float64)
if @easing_dur != 0.0 && @easing_t <= @easing_dur
if moving
@easing_t = @easing_t + dt
a = Ease.inOutSine(@easing_t / @easing_dur)
@ -111,12 +147,35 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
@wander_timer = WANDER_TIMER
else
@wander_timer = @wander_timer - dt
if @wander_timer <= 0
goto({
x: @static_pos[:x] + (-40 .. 40).sample,
y: @static_pos[:y] + (-40 .. 40).sample,
}, 4.0)
case behavior
when .wander?
@wander_timer = @wander_timer - dt
if @wander_timer <= 0
goto({
x: @static_pos[:x] + (-40 .. 40).sample,
y: @static_pos[:y] + (-40 .. 40).sample,
}, 4.0, set_as_static: false)
end
when .follow?
if !moving
x_dist = window.cursor.position[:x]
y_dist = window.cursor.position[:y]
x_target = window.position[:x]
y_target = window.position[:y]
if x_dist.abs > FOLLOW_DIST
x_target = window.position[:x] + x_dist - FOLLOW_DIST * x_dist.sign
end
if y_dist.abs > FOLLOW_DIST
y_target = window.position[:y] + y_dist - FOLLOW_DIST * y_dist.sign
end
goto({
x: x_target.to_i,
y: y_target.to_i,
}, 1.0)
end
end
end
end
@ -132,6 +191,25 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
@held_timer = @held_timer - dt
if @held_timer <= 0
update_wander(dt)
if @waiting_for_stable_pos
@waiting_for_stable_pos = false
stable_pos_dist = (@static_pos[:x] - @started_holding_at[:x]).abs + (@static_pos[:y] - @started_holding_at[:y]).abs
LOG.info { "travelled #{stable_pos_dist}" }
if !speaking
if stable_pos_dist > 50
# moved quite a bit from initial point
say STAY_ARRAY.sample
else
# just touched
say TOUCH_ARRAY.sample
end
end
end
else
@waiting_for_stable_pos = true
end
end
end
@ -151,6 +229,10 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
SoundMan.play_sound("assets/sfx/talk#{(1..8).sample}.ogg")
end
def speaking
@chatter_array && @chatter_index < @chatter_array.not_nil!.size
end
def update(dt : Float64)
@chatter_timer = @chatter_timer - dt
if @chatter_timer <= 0.0