knucklebones/states/game/rolling.lua

41 lines
1.0 KiB
Lua
Raw Normal View History

2023-08-12 11:36:14 +02:00
function state_game_rolling()
--- @type Die
local die
--- @type EventBus
local event_bus
local function roll_die()
die.bouncing = true
local rot = Tween.new(0.7, die, {
angle = (die.angle + math.random(180,360))-- die.angle + (math.random()<.5 and 1 or -1)* math.random(270, 360)
}, "outSine")
local done = false
repeat
done = rot:update(dt)
coroutine.yield()
until done
die.bouncing = false
event_bus:emit(EVENT_SET_STEP, "placing")
end
---@param self any
---@param _die Die
---@param _event_bus EventBus
local _enter = function(self, _die, _event_bus)
assert(_die, "states.game.rolling needs a die")
assert(_event_bus, "states.game.rolling needs an event_bus")
die = _die
event_bus = _event_bus
addcoroutine(roll_die)
end
local update = function(self)
end
return {
_enter = _enter,
update = update
}
end