Created
December 7, 2012 18:46
-
-
Save osa1/4235436 to your computer and use it in GitHub Desktop.
random walker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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