aintnothingbutapeanut/data/scripts/game.lua

68 lines
2.1 KiB
Lua
Raw Normal View History

2025-01-26 20:16:13 +00:00
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,
2025-01-27 00:43:35 +00:00
beat = 0,
2025-01-26 20:16:13 +00:00
}
start_blasting("mod22")
end
local state = ctx.udata
2025-01-27 00:43:35 +00:00
draw_camera {
2025-01-27 01:15:28 +00:00
position = { x=0, y=0, z=0 },
2025-01-27 01:48:00 +00:00
-- direction = { x=-math.sin(math.pi / 4), y=-1, z=math.cos(math.pi / 4) },
direction = { x=-math.sin(ctx.frame_number / 100), y=-1, z=math.cos(ctx.frame_number / 100) },
2025-01-27 00:43:35 +00:00
up = { x=0, y=1, z=0 },
fov = 0,
2025-01-27 01:48:00 +00:00
zoom = 0.15 + math.sin(ctx.frame_number / 100) / 20,
2025-01-26 20:16:13 +00:00
}
2025-01-27 00:43:35 +00:00
-- draw_rectangle {
-- rect = { w = 960, h = 540 },
-- color = { r = 125, a = 255 }
-- }
2025-01-26 20:16:13 +00:00
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)
2025-01-27 00:43:35 +00:00
for i = -10,10 do
draw_quad {
2025-01-26 20:16:13 +00:00
texture = "art/creatures/meathead/" .. string.format("dance-%s.png", pingpong(state.beat, 3)),
2025-01-27 00:43:35 +00:00
texture_region = { w = 32, h = 32 },
2025-01-27 01:15:28 +00:00
v0 = { x = 0, y = (64 + wobble) / 64, z = 0 + i/2 },
v1 = { x = 0, y = 0, z = 0 + i/2 },
v2 = { x = 0, y = 0, z = 0 + i/2 + 1 },
v3 = { x = 0, y = (64 + wobble) / 64, z = 0 + i/2 + 1 },
2025-01-26 20:16:13 +00:00
}
2025-01-27 01:48:00 +00:00
draw_billboard {
texture = "art/creatures/meathead/" .. string.format("dance-%s.png", pingpong(state.beat, 3)),
position = { x = i, y = wobble / 64, z = 0 },
size = { x = 1, y = (64 + wobble) / 64 },
}
2025-01-26 20:16:13 +00:00
end
end