--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.008 local MAXSPEED = 1.0 local t, x, y, dx, dy, ddx, ddy local function Update() t = love.timer.getTime() dx = (1.0 - FRICTION) * dx + FRICTION * ddx dy = (1.0 - FRICTION) * dy + FRICTION * ddy local xf = x + dx * step * MAXSPEED local yf = y + dy * step * MAXSPEED end local function OnKey() ddx = (love.keyboard.isScancodeDown( "d" ) and 1.0 or 0.0) - (love.keyboard.isScancodeDown( "a" ) and 1.0 or 0.0) ddy = (love.keyboard.isScancodeDown( "s" ) and 1.0 or 0.0) - (love.keyboard.isScancodeDown( "w" ) and 1.0 or 0.0) local n = math.sqrt( ddx * ddx + ddy * ddy ) if n < 0.001 then return end ddx, ddy = ddx / n, ddy / n end local function Draw() local dt = love.timer.getTime() - t 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 y = 0 dx = 0 dy = 0 ddx = 0 ddy = 0 end Reset() return { Update = Update, OnKey = OnKey, Draw = Draw, Impact = Impact, Reset = Reset, }