Skip to content

Instantly share code, notes, and snippets.

@osa1
Created December 7, 2012 18:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osa1/4235436 to your computer and use it in GitHub Desktop.
Save osa1/4235436 to your computer and use it in GitHub Desktop.
random walker
width = 640
height = 360
function newWalker()
return { x=width/2, y=height/2 }
end
function love.load()
love.graphics.setMode(width, height, false, false, 0)
walker = newWalker()
canvas = love.graphics.newCanvas(width, height)
end
function love.update(dt)
local incx, decx, incy = 0.25, 0.50, 0.75
local mouseX, mouseY = love.mouse.getPosition()
if mouseX < walker.x then
incx = incx - 0.01
else
incx = incx + 0.01
end
if mouseY < walker.y then
incy = incy - 0.01
else
incy = incy + 0.01
end
local choice = math.random()
if choice < incx then
walker.x = walker.x + 1
elseif choice < decx then
walker.x = walker.x - 1
elseif choice < incy then
walker.y = walker.y + 1
else
walker.y = walker.y - 1
end
love.graphics.setCanvas(canvas)
love.graphics.point(walker.x, walker.y)
love.graphics.setCanvas()
end
function love.draw()
love.graphics.draw(canvas, 0, 0, 0, 1, 1, 0, 0)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment