knucklebones/main.lua
2023-08-12 11:36:14 +02:00

95 lines
2.3 KiB
Lua

-- title: Knucklebones
-- author: Simon Cambier
-- desc: A game of risk and reward, from "The Cult of the Lamb"
-- script: lua
-- Some sprites from https://piiixl.itch.io/frames-1-bit
include "utils.utils"
include "utils.input"
include "utils.tween"
include "coroutines"
include "states.state_manager"
include "states.state_main_menu"
include "states.state_game"
Tween = require_tween()
--- @type StateManager
state_manager = StateManager:new()
local states = {
main_menu = state_main_menu(),
game = state_game()
}
frames = 0
function BOOT()
-- Save original palette
memcpy(0x14e04, 0x3fc0, 48)
state_manager:change_state(states.main_menu, { states = states })
end
function TIC()
dt = (time() - pt) / 1000
pt = time()
frames = frames + 1
cls(13)
Input:update_mouse()
_coresolve()
state_manager:update()
-- mouse position
-- local mx, my = mouse()
-- print_border(mx .. "," .. my, mx + 1, my - 5)
end
-- function BDR(scn)
-- local cl = (math.floor(frames / 1.2) % (135 + 40)) - 20
-- greyGlitch(scn, cl)
-- end
function vhsGlitch(scn, cl)
local height = 10
local ampl = 10
local n = clamp(0, normalize(cl, scn - height, scn + height), 1) * 2 * math.pi
local s = math.cos(n)
local r = math.random() * (s * ampl - ampl) * s * s
-- 0x3ff9: screen offset
poke(0x3ff9, r)
poke(0x3ffa, r / 2)
end
function greyGlitch(scn, cl)
-- Reset rgb values
memcpy(0x3fc0, 0x14e04, 48)
local h = 10
-- If current scanline is in range
if (scn >= cl - h and scn <= cl + h) then
-- Loop through colors in ram
if (math.random() < 0.8) then
if (math.random() > 0.01) then
for i = 0, 16 do
local c = i * 3
local grey =
peek(0x3fc0 + c + 0) * 0.2126 +
peek(0x3fc0 + c + 1) * 0.7152 +
peek(0x3fc0 + c + 2) * 0.0722
-- Alter the color
poke(0x3fc0 + c + 0, grey)
poke(0x3fc0 + c + 1, grey)
poke(0x3fc0 + c + 2, grey)
end
else
-- line(0, scn, SCREEN_WIDTH, scn, RNG.random() * 15)
end
end
end
end