Character controller, render trail

This commit is contained in:
yaw-man 2023-01-13 17:34:01 -04:00
parent 31f7c5c0c7
commit 79e9090c7e
2 changed files with 47 additions and 8 deletions

View File

@ -134,15 +134,21 @@ end
function love.draw()
local w, h = love.graphics.getDimensions()
love.graphics.setColor(1.0, 1.0, 1.0)
love.graphics.print( state.beat.mu or 0, 0)
love.graphics.print( state.beat.t or 0, 0, 10)
love.graphics.print( state.beatScoreThreshold, 0, 20)
love.graphics.print( state.lastBeatScore, 0, 30 )
love.graphics.setColor( 91 / 255, 206 / 255, 250 / 255 )
love.graphics.circle("fill", w / 2, h / 2, 200)
sitelenpona.Draw( text.tok[state.currentBeat] )
marble.Draw()
love.graphics.setColor(0.5, 0.2, 0.8, 0.5)
love.graphics.circle("fill", 0, 0, 10)
end

View File

@ -1,8 +1,10 @@
--Character controller. Renders point particle.
local love = love
local oldBuffer = love.graphics.newCanvas()
local newBuffer = love.graphics.newCanvas()
local step = assert( step )
local state
local FRICTION = 0.005
local FRICTION = 0.008
local MAXSPEED = 1.0
local t, x, y, dx, dy, ddx, ddy
@ -12,8 +14,8 @@ local function Update()
dx = (1.0 - FRICTION) * dx + FRICTION * ddx
dy = (1.0 - FRICTION) * dy + FRICTION * ddy
x = x + dx * step * MAXSPEED
y = y + dy * step * MAXSPEED
local xf = x + dx * step * MAXSPEED
local yf = y + dy * step * MAXSPEED
end
local function OnKey()
@ -27,15 +29,44 @@ end
local function Draw()
local dt = love.timer.getTime() - t
local rx, ry = x + dt * dx, y + dt * dy
love.graphics.setColor( 0.0, 0.0, 0.0, 0.8 )
love.graphics.circle( "fill", rx, ry, 10 )
local xf, yf = x + dt * dx, y + dt * dy
local w, h = love.graphics.getDimensions()
local xi, yi = 1000.0 * x + 0.5 * w, 1000.0 * y + 0.5 * h
xf, yf = 1000.0 * xf + 0.5 * w, 1000.0 * yf + 0.5 * h
love.graphics.setCanvas( newBuffer )
love.graphics.setColor( 1.0, 1.0, 1.0 , 0.9 ) --Trans blue.
love.graphics.draw( oldBuffer ) --Time-dependent fade: overlay canvas over itself.
--Render latest segment in trail.
love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 ) --White?
love.graphics.circle( "fill", xf, yf, 4.0 ) --TODO: replace with segments.
love.graphics.line( xi, yi, xf, yf )
love.graphics.setCanvas( oldBuffer )
love.graphics.clear( 1.0, 1.0, 1.0, 0.0 )
--Render circle directly to screen.
love.graphics.setCanvas()
love.graphics.draw( newBuffer )
love.graphics.setColor( 245 / 255, 169 / 255, 184 / 255 ) --Trans pink.
love.graphics.circle( "fill", xf, yf, 5.0 )
oldBuffer, newBuffer = newBuffer, oldBuffer
end
local function Impact( impact )
end
--Window resize.
local function Resize()
end
local function Reset()
t = love.timer.getTime()
x = 0
@ -46,6 +77,8 @@ local function Reset()
ddy = 0
end
Reset()
return {