perspective_transform.lua
u_execDependencyScript("ohvrvanilla", "base", "vittorio romeo", "utils.lua")
u_execDependencyScript("ohvrvanilla", "base", "vittorio romeo", "common.lua")
u_execDependencyScript("ohvrvanilla", "base", "vittorio romeo", "commonpatterns.lua")
u_execDependencyScript("library_pseudogame", "pseudogame", "Baum", "main.lua")
s_set3dDepth(0)
PseudoGame.hide_default_game()
local game = PseudoGame.game.Game:new({
components = {
background = true,
walls = true,
player = true,
pivot = true,
pseudo3d = false,
},
})
game:overwrite()
local function perspective(x, y, z)
if z < 1e-9 then
z = 1e-9
end
return x / z, y / z
end
local transformed_collections = {}
local function transform_and_draw_collection(collection, depth, r, g, b, a)
local animation_factor = math.sin(l_getLevelTime())
local rotate = PseudoGame.graphics.effects:rotate(math.rad(animation_factor * 45))
local width = PseudoGame.graphics.screen:get_width()
local height = PseudoGame.graphics.screen:get_height()
local function transformation(x, y, ...)
x = x / width
y = y / height
y = y + animation_factor * 0.6
local z = depth + 0.5 * (1.2 - math.abs(animation_factor))
y, z = rotate(y, z)
x, y = perspective(x, y, z)
if r then
return x * width, y * height, r, g, b, a
end
return x * width, y * height, ...
end
transformed_collections[collection] = transformed_collections[collection]
or PseudoGame.graphics.PolygonCollection:new()
local transformed = transformed_collections[collection]
local gen = transformed:generator()
for polygon in collection:iter() do
gen():copy_data_transformed(polygon, transformation)
end
PseudoGame.graphics.screen:draw_polygon_collection(transformed)
end
local custom3D = PseudoGame.graphics.PolygonCollection:new()
function onInput(frametime, movement, focus, swap)
game:update(frametime, movement, focus, swap)
custom3D:clear()
custom3D:ref_add(game.component_collections.walls)
custom3D:ref_add(game.pivot.polygon_collection)
custom3D:ref_add(game.component_collections.player)
transform_and_draw_collection(game.component_collections.background, 1.2)
transform_and_draw_collection(custom3D, 1.2, game.style:get_layer_color(3))
transform_and_draw_collection(custom3D, 1.0, game.style:get_layer_color(2))
transform_and_draw_collection(custom3D, 0.8, game.style:get_layer_color(1))
transform_and_draw_collection(game.component_collections.walls, 0.6)
transform_and_draw_collection(game.component_collections.pivot, 0.6)
transform_and_draw_collection(game.component_collections.player, 0.6)
PseudoGame.graphics.screen:update()
end
function onDeath()
game.death_effect:death()
end
function onPreDeath()
game.death_effect:invincible_death()
end
function onRenderStage(render_stage, frametime)
game.death_effect:ensure_tickrate(render_stage, frametime, function(new_frametime)
onInput(new_frametime, 0, false, false)
end)
end
function addPattern(mKey)
if mKey == 0 then
pAltBarrage(u_rndInt(3, 5), 2)
elseif mKey == 1 then
pMirrorSpiral(u_rndInt(2, 5), getHalfSides() - 3)
elseif mKey == 2 then
pBarrageSpiral(u_rndInt(0, 3), 1, 1)
elseif mKey == 3 then
pInverseBarrage(0)
elseif mKey == 4 then
pTunnel(u_rndInt(1, 3))
elseif mKey == 5 then
pSpiral(l_getSides() * u_rndInt(1, 2), 0)
end
end
keys = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 5 }
shuffle(keys)
index = 0
achievementUnlocked = false
function onInit()
l_setSpeedMult(1.55)
l_setSpeedInc(0.125)
l_setSpeedMax(3.5)
l_setRotationSpeed(0.07)
l_setRotationSpeedMax(0.75)
l_setRotationSpeedInc(0.04)
l_setDelayMult(1.0)
l_setDelayInc(-0.01)
l_setFastSpin(0.0)
l_setSides(6)
l_setSidesMin(5)
l_setSidesMax(6)
l_setIncTime(15)
l_setPulseMin(80)
l_setPulseMax(80)
l_setPulseSpeed(1.2)
l_setPulseSpeedR(1)
l_setPulseDelayMax(23.9)
l_setBeatPulseMax(0)
l_setBeatPulseDelayMax(24.8)
enableSwapIfDMGreaterThan(2.5)
disableIncIfDMGreaterThan(3)
end
function onLoad()
e_messageAdd("welcome to the 13th PseudoGame example level", 150)
e_messageAdd("Here transformations are used in a more\nadvanced way to create a 3D effect!", 200)
e_messageAdd(
"This doesn't really demonstrate any new\nfeatures though, it's still all just basic transformations.",
400
)
end
function onStep()
addPattern(keys[index])
index = index + 1
if index - 1 == #keys then
index = 1
shuffle(keys)
end
end
function onIncrement()
end
function onPreUnload()
game:restore()
end
function onUpdate(mFrameTime)
end