mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-21 04:54:18 +02:00
os.clock -> ly.clock
This commit is contained in:
parent
cc14fff5c6
commit
364d0e4074
4 changed files with 26 additions and 8 deletions
|
|
@ -6,13 +6,13 @@
|
|||
-- {
|
||||
-- height: number -- The height of the terminal
|
||||
-- width: number -- The width of the terminal
|
||||
-- frame_delay: number -- The amount of frames to delay an update to the animation
|
||||
-- putCell(byte, fg, bg, x, y) -- Put the cell a buffer. This buffer will be drawn
|
||||
-- on screen after draw() is called. It will not clear
|
||||
-- itself automatically, see `ly.clear()`.
|
||||
-- All arguments to this function are numbers, and
|
||||
-- must be in the unsigned 32-bit integer range: 0 to 2^32-1.
|
||||
-- clear() -- Clear the buffer.
|
||||
-- clock() -- The time, in microseconds.
|
||||
-- }
|
||||
--
|
||||
-- A function named `draw()` must be declared in the script. This is ran every frame.
|
||||
|
|
@ -24,7 +24,7 @@ local SQUARE_HEIGHT = 5
|
|||
|
||||
local SQUARE_COUNT = 25
|
||||
|
||||
local FPS = 120
|
||||
local FPS = 60
|
||||
|
||||
local squares = {}
|
||||
|
||||
|
|
@ -42,12 +42,12 @@ for i = 0, SQUARE_COUNT-1 do
|
|||
}
|
||||
end
|
||||
|
||||
local timer = os.clock()
|
||||
local timer = ly.clock()
|
||||
|
||||
function draw()
|
||||
-- Rather than progressing the animation by frame, do it based on
|
||||
-- seconds, like from os.clock().
|
||||
if timer + (1/FPS) < os.clock() then
|
||||
-- seconds, like from ly.clock().
|
||||
if timer + ((1/FPS)*1000000)< ly.clock() then
|
||||
ly.clear()
|
||||
for i, v in ipairs(squares) do
|
||||
v.x = v.x + v.vx
|
||||
|
|
@ -62,6 +62,6 @@ function draw()
|
|||
if v.y <= 0 then v.vy = 1; v.color = math.random(0xFFFFFF) end
|
||||
if v.y + SQUARE_HEIGHT >= ly.height-1 then v.vy = -1; v.color = math.random(0xFFFFFF) end
|
||||
end
|
||||
timer = os.clock()
|
||||
timer = ly.clock()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue