steak dancers

This commit is contained in:
veclavtalica
2025-01-26 23:16:13 +03:00
commit 62487c61ed
11 changed files with 127 additions and 0 deletions

48
data/scripts/game.lua Normal file
View File

@ -0,0 +1,48 @@
local traxx = require "traxx"
require "utils"
require "string"
require "math"
function start_blasting(track)
local blast = table.shallow_copy(traxx[track])
blast.channel = "blast"
ctx.udata.blast = blast
ctx.udata.last_beat = ctx.udata.time + 60 / blast.bpm
audio_play(ctx.udata.blast)
end
function game_tick()
if ctx.initialization_needed then
ctx.udata = {
time = 0,
beat = 0
}
start_blasting("mod22")
end
local state = ctx.udata
draw_rectangle {
rect = { w = 960, h = 540 },
color = { r = 125, a = 255 }
}
state.time = state.time + ctx.frame_duration
if state.time - state.last_beat > 60 / state.blast.bpm then
state.last_beat = state.last_beat + 60 / state.blast.bpm
state.beat = state.beat + 1
-- draw_rectangle {
-- rect = { w = 64, h = 64 },
-- color = { r = 255, a = 255 }
-- }
end
local wobble = sinease(12, state.time - state.beat * (60 / state.blast.bpm) , (60 / state.blast.bpm) / 1.5, 0)
for i = 0,10 do
draw_sprite {
texture = "art/creatures/meathead/" .. string.format("dance-%s.png", pingpong(state.beat, 3)),
rect = { w = 64, h = 64 + wobble, x = 300 + i * 32, y = 300 - wobble }
}
end
end

14
data/scripts/traxx.lua Normal file
View File

@ -0,0 +1,14 @@
-- listing of all traxx to blast
return {
mod4 = {
audio = "traxx/mod4.xm",
bpm = 101.5,
loops = true,
},
mod22 = {
audio = "traxx/mod22.xm",
bpm = 177 / 2,
loops = true,
},
}

30
data/scripts/utils.lua Normal file
View File

@ -0,0 +1,30 @@
require "math"
function table.shallow_copy(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = v
end
return t2
end
function thisorthat(c, a, b)
if c then return a else return b end
end
function pingpong(at, over)
local c = (over - 1) * 2
if math.fmod(at, c) >= over then
return c - math.fmod(at, c)
else
return math.fmod(at, c)
end
end
function linease(c, t, d, b)
return c * t / d + b
end
function sinease(c, t, d, b)
return -c*math.cos(t/d*(math.pi/2)) + c + b
end