Skip to content

Instantly share code, notes, and snippets.

@subtra3t
Created February 24, 2021 10:32
Show Gist options
  • Select an option

  • Save subtra3t/ba5bc9024f43c6ad8feb55b485f9cd4a to your computer and use it in GitHub Desktop.

Select an option

Save subtra3t/ba5bc9024f43c6ad8feb55b485f9cd4a to your computer and use it in GitHub Desktop.

Revisions

  1. subtra3t created this gist Feb 24, 2021.
    36 changes: 36 additions & 0 deletions main.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    -- 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