aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiński <harry666t@gmail.com>2016-01-31 18:28:33 +0100
committerKamil Cholewiński <harry666t@gmail.com>2016-01-31 18:28:33 +0100
commit84b991156dc4d6bd4b453a0fb024c149f6473f6d (patch)
treefa8af36ebee3372642347ee45030df4916b1c558
parent5e76a24026349bc9d2a95e7a8098357042cf61df (diff)
downloadpewpew-84b991156dc4d6bd4b453a0fb024c149f6473f6d.zip
pewpew-84b991156dc4d6bd4b453a0fb024c149f6473f6d.tar.gz
pewpew-84b991156dc4d6bd4b453a0fb024c149f6473f6d.tar.bz2
Don't hog CPU
-rw-r--r--main.lua11
1 files changed, 11 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index 7d2ab80..01c5f23 100644
--- a/main.lua
+++ b/main.lua
@@ -11,6 +11,10 @@ local utils = require "utils"
function love.load()
love.graphics.setNewFont(12)
love.graphics.setBackgroundColor(0, 0, 0)
+
+ min_dt = 1 / 60
+ next_time = love.timer.getTime()
+
game = Game.new()
game:spawn(Wall, {x=600, y=0, w=10, h=1210})
game:spawn(Wall, {x=-600, y=0, w=10, h=1210})
@@ -72,9 +76,16 @@ function love.keypressed(key)
end
function love.update(dt)
+ next_time = next_time + min_dt
game:update(dt)
end
function love.draw()
game:draw()
+ local cur_time = love.timer.getTime()
+ if next_time <= cur_time then
+ next_time = cur_time
+ return
+ end
+ love.timer.sleep(next_time - cur_time)
end