mike: Now resepcts delta time (dt)
This commit is contained in:
parent
beb04e1451
commit
091e055841
@ -61,10 +61,10 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ball_bounce(player, ball)
|
function ball_bounce(player, ball, dt)
|
||||||
local paddle_hit = false
|
local paddle_hit = false
|
||||||
ball.x = ball.x + ball.x_speed
|
ball.x = ball.x + (ball.x_speed *dt)
|
||||||
ball.y = ball.y + ball.y_speed
|
ball.y = ball.y + (ball.y_speed *dt)
|
||||||
|
|
||||||
--If ball hits screen wall
|
--If ball hits screen wall
|
||||||
if ball.x >= screen.width or ball.x < 0 then
|
if ball.x >= screen.width or ball.x < 0 then
|
||||||
|
@ -33,7 +33,7 @@ function half_speed(object_speed)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function check_keys(object, screen)
|
function check_keys(object, screen, dt)
|
||||||
local newObject = {}
|
local newObject = {}
|
||||||
newObject.x = object.x
|
newObject.x = object.x
|
||||||
newObject.y = object.y
|
newObject.y = object.y
|
||||||
@ -42,11 +42,11 @@ function check_keys(object, screen)
|
|||||||
newObject.speed = object.speed
|
newObject.speed = object.speed
|
||||||
|
|
||||||
if love.keyboard.isDown(MOVE_RIGHT) then
|
if love.keyboard.isDown(MOVE_RIGHT) then
|
||||||
newObject.x = newObject.x + half_speed(newObject.speed)
|
newObject.x = newObject.x + half_speed(newObject.speed * dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
if love.keyboard.isDown(MOVE_LEFT) then
|
if love.keyboard.isDown(MOVE_LEFT) then
|
||||||
newObject.x = newObject.x - half_speed(newObject.speed)
|
newObject.x = newObject.x - half_speed(newObject.speed * dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
if screen_col_detect(newObject, screen) then
|
if screen_col_detect(newObject, screen) then
|
||||||
|
@ -10,9 +10,9 @@ function love.load()
|
|||||||
screen.height = love.graphics.getHeight()
|
screen.height = love.graphics.getHeight()
|
||||||
|
|
||||||
-- Create a table to hold all the player data
|
-- Create a table to hold all the player data
|
||||||
player = create_object(screen.width /2, screen.height - 50, 30, 5, 10)
|
player = create_object(screen.width /2, screen.height - 50, 30, 5, 500)
|
||||||
-- Create a table to hold ball data
|
-- Create a table to hold ball data
|
||||||
ball = create_object(screen.width /2, screen.height /2, 1, 1, 10)
|
ball = create_object(screen.width /2, screen.height /2, 1, 1, 600)
|
||||||
ball.x_speed = (ball.speed /2)
|
ball.x_speed = (ball.speed /2)
|
||||||
ball.y_speed = (ball.speed /2)
|
ball.y_speed = (ball.speed /2)
|
||||||
|
|
||||||
@ -20,8 +20,8 @@ function love.load()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
player = check_keys(player, screen)
|
player = check_keys(player, screen, dt)
|
||||||
ball = ball_bounce(player, ball)
|
ball = ball_bounce(player, ball, dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user