Last active
March 29, 2023 19:17
-
-
Save legends2k/cabc940d99e160ce41d0b3854f11792a to your computer and use it in GitHub Desktop.
Love -- Object Basics
This file contains hidden or 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
| rect = { | |
| pos = { x = 0, y = 0}, | |
| orientation = 0.7853981634, -- 45° in radians (clockwise) | |
| width = 100, | |
| height = 100, | |
| } | |
| seconds_per_frame = 0 | |
| -- Called every frame; if last frame compute didn’t overshoot | |
| -- it’d be called again in 16.667 ms i.e. 60 times in a second. | |
| function love.update(dt) | |
| rect.pos.x = rect.pos.x + (dt * 50) | |
| rect.pos.y = rect.pos.y + (dt * 50) | |
| -- Uncomment to animate rect by spining | |
| rect.orientation = rect.orientation + (dt * 0.6) | |
| seconds_per_frame = dt | |
| end | |
| function love.draw() | |
| local fps = 1 / seconds_per_frame | |
| love.graphics.setColor{255, 0, 0, 255} | |
| love.graphics.print("FPS: " .. tostring(fps), 400, 10) | |
| love.graphics.setColor{255, 255, 255, 255} | |
| love.graphics.push() | |
| love.graphics.translate(rect.pos.x, rect.pos.y) | |
| love.graphics.rotate(rect.orientation) | |
| love.graphics.rectangle('fill', | |
| -rect.width / 2, | |
| -rect.height / 2, | |
| rect.width, | |
| rect.height) | |
| love.graphics.pop() | |
| end | |
| function love.keypressed(key, scancode, isrepeat) | |
| if scancode == 'escape' then | |
| love.event.quit(0) | |
| end | |
| end | |
| function love.mousepressed( x, y, button, istouch, presses ) | |
| print("Mouse pressed at (" .. x .. ", " .. y .. ")") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment