Skip to content

Commit

Permalink
[1.0.0b] Fixed tick rate error by using https://github.com/bjornbytes…
Browse files Browse the repository at this point in the history
  • Loading branch information
zzxzzk115 committed May 26, 2022
1 parent 1655aa5 commit 60a9416
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ entityConfig = {
['type'] = 'MoveAround',
['mass'] = 1.5,
['bonus'] = 2,
['speed'] = 0.25,
['speed'] = 1,
['width'] = MOLE_WIDTH,
['height'] = MOLE_HEIGHT,
['moveRange'] = 135,
Expand All @@ -82,7 +82,7 @@ entityConfig = {
['type'] = 'MoveAround',
['mass'] = 1.5,
['bonus'] = 602,
['speed'] = 0.25,
['speed'] = 1,
['width'] = MOLE_WIDTH,
['height'] = MOLE_HEIGHT,
['moveRange'] = 135,
Expand Down
3 changes: 0 additions & 3 deletions conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ COLOR_ORANGE = {239/255, 108/255, 0/255}
COLOR_DEEP_ORANGE = {194/255, 136/255, 4/255}
COLOR_GREEN = {67/255, 160/255, 71/255}

TOTAL_LEVEL_COUNT = 3

DEBUG_MODE = false
SHOW_BOUNDING_VOLUME = false
TEST_LEVEL = false
Expand All @@ -49,5 +47,4 @@ function love.conf(t)
t.window.borderless = true -- Remove all border visuals from the window (boolean)
t.window.resizable = false -- Let the window be user-resizable (boolean)
t.window.fullscreen = false -- Enable fullscreen (boolean)
t.window.vsync = 1 -- Vertical sync mode (number)
end
4 changes: 4 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ Gamestate = require 'hump.gamestate'
Class = require 'hump.class'
vector = require 'hump.vector'
lume = require 'lume'
tick = require 'tick'
require 'Util'
require 'GameStates'
require 'Animation'

function love.load()
-- Set FPS
tick.framerate = 60

-- Init fonts
defaultFont = love.graphics.getFont()
infoFont = love.graphics.newFont('fonts/Pixel-Square-10-1.ttf', 10)
Expand Down
70 changes: 70 additions & 0 deletions tick.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-- tick
-- https://github.com/bjornbytes/tick
-- MIT License

local tick = {
framerate = nil,
rate = .03,
timescale = 1,
sleep = .001,
dt = 0,
accum = 0,
tick = 1,
frame = 1
}

local timer = love.timer
local graphics = love.graphics

love.run = function()
if not timer then
error('love.timer is required for tick')
end

if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
timer.step()
local lastframe = 0

if love.update then love.update(0) end

return function()
tick.dt = timer.step() * tick.timescale
tick.accum = tick.accum + tick.dt
while tick.accum >= tick.rate do
tick.accum = tick.accum - tick.rate

if love.event then
love.event.pump()
for name, a, b, c, d, e, f in love.event.poll() do
if name == 'quit' then
if not love.quit or not love.quit() then
return a or 0
end
end

love.handlers[name](a, b, c, d, e, f)
end
end

tick.tick = tick.tick + 1
if love.update then love.update(tick.rate) end
end

while tick.framerate and timer.getTime() - lastframe < 1 / tick.framerate do
timer.sleep(.0005)
end

lastframe = timer.getTime()
if graphics and graphics.isActive() then
graphics.origin()
graphics.clear(graphics.getBackgroundColor())
tick.frame = tick.frame + 1
if love.draw then love.draw() end
graphics.present()
end

timer.sleep(tick.sleep)
end
end

return tick

0 comments on commit 60a9416

Please sign in to comment.