Skip to content

Instantly share code, notes, and snippets.

@subtra3t
Created February 24, 2021 10:32
Show Gist options
  • Save subtra3t/ba5bc9024f43c6ad8feb55b485f9cd4a to your computer and use it in GitHub Desktop.
Save subtra3t/ba5bc9024f43c6ad8feb55b485f9cd4a to your computer and use it in GitHub Desktop.
Simple enlarging rectangle
-- A simple enlarging rectangle that stays in the middle of the screen
-- Made with the LOVE 2D framework in Lua
data = {
x = 300,
y = 250,
width = 200,
height = 100,
speed = 50
}
function love.draw()
love.graphics.rectangle("line", data.x, data.y, data.width, data.height)
end
function love.update(dt)
if data.width > data.height then
data.x = data.x - ((data.speed / 2) * dt)
data.width = data.width + (data.speed * dt)
data.y = data.y - ((data.speed / 2) * dt)
data.height = data.height + (data.speed * dt)
else
data.x = data.x - ((data.speed / 2) * dt)
data.width = data.width + (data.speed * dt)
data.y = data.y - ((data.speed / 2) * dt)
data.height = data.height + (data.speed * dt)
end
if love.keyboard.isDown("up") then
data.speed = data.speed * 1.1
elseif love.keyboard.isDown("down") then
data.speed = data.speed / 1.1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment