Kubrick
A library to help organize and execute logic for action sequences in your game. It sits on coroutines and is based on the ideas in this post by Elias Daler: Redirecting to https://edw.is/
kubrick.zip (701 Bytes)
Example project coming soon.
Here's a rough example:
-- cutscene.lua
class("StopPlayerAction").extends(kubrick.Action)
function StopPlayerAction:update(dt, player)
local a <const> = player.acceleration * dt
player.velocity.x += math.cos(player.rotation) * a
player.velocity.y += math.sin(player.rotation) * a
local velocity_magnitude <const> = player.velocity:magnitude()
if velocity_magnitude <= a then
ship.velocity.x = 0
ship.velocity.y = 0
self.finished = true -- Marks the action as finished.
end
end
function cutscene_main(dt)
kubrick.Wait(2.0) -- wait 2 seconds.
StopPlayerAction(globals.player) -- stop player
kubrick.Together(
function()
print("this function gets run")
kubrick.Wait(1.0)
print("in parallel the other functions.")
end,
function()
kubrick.Wait(3.0)
print("This function finishes last because it takes the longest.")
end
) -- run 2 or more routines in parallel.
end
-- main.lua
import "cutscene"
local my_cutscene <const> = kubrick.create(cutscene_main)
local cutscene_started = false
function playdate.update()
if cutscene_started then
kubrick.update(my_cutscene, dt)
if kubrick.finished(my_cutscene) then
cutscene_started = false
end
end
end