Refactor delta time
parent
75805b1093
commit
7755bb3885
11
main.lua
11
main.lua
|
|
@ -1,4 +1,5 @@
|
|||
local tau = math.pi * 2
|
||||
local delta_time = 1/120
|
||||
local game = {}
|
||||
|
||||
local function load_level(level, bubble_diameter, row_gap)
|
||||
|
|
@ -181,7 +182,7 @@ function love.load(arg)
|
|||
|
||||
game.bubble_diameter = 60
|
||||
game.bubble_radius = game.bubble_diameter / 2
|
||||
game.bubble_speed = 8 -- px/frame
|
||||
game.bubble_speed = 960 * delta_time -- 960 px/s
|
||||
|
||||
-- vertical distance between bubble center points
|
||||
game.row_gap = math.ceil(math.sqrt(
|
||||
|
|
@ -361,8 +362,8 @@ function love.update(dt)
|
|||
game.falling_bubbles[#game.falling_bubbles+1] = {
|
||||
x = game.bubble_slots[index].x,
|
||||
y = game.bubble_slots[index].y,
|
||||
velocity_x = i % 2 == 0 and -2 or 2,
|
||||
velocity_y = love.math.random(-2.0, -5.0),
|
||||
velocity_x = (i % 2 == 0 and -200 or 200) * delta_time,
|
||||
velocity_y = love.math.random(-200.0, -500.0) * delta_time,
|
||||
bubble_type = game.bubble_slots[index].bubble_type
|
||||
}
|
||||
game.bubble_slots[index].bubble_type = 0
|
||||
|
|
@ -418,7 +419,7 @@ function love.update(dt)
|
|||
bubble.x = bubble.x + bubble.velocity_x
|
||||
bubble.y = bubble.y + bubble.velocity_y
|
||||
bubble.velocity_x = bubble.velocity_x * 0.99
|
||||
bubble.velocity_y = bubble.velocity_y + 0.3 -- gravity 0.3
|
||||
bubble.velocity_y = bubble.velocity_y + 36 * delta_time -- gravity
|
||||
if bubble.x - game.bubble_radius <= game.level_left or
|
||||
bubble.x + game.bubble_radius >= game.level_right then
|
||||
bubble.velocity_x = -bubble.velocity_x
|
||||
|
|
@ -585,7 +586,7 @@ function love.run()
|
|||
|
||||
if love.timer then love.timer.step() end
|
||||
|
||||
local dt = 1/120 -- update 120 times per second
|
||||
local dt = delta_time -- update 120 times per second
|
||||
local accumulator = 0.0
|
||||
|
||||
return function()
|
||||
|
|
|
|||
Loading…
Reference in New Issue