Love:Mike: cleaned up formatting
This commit is contained in:
parent
ea0bf0a56c
commit
23bbad4f2b
@ -6,7 +6,6 @@ function GameState.save(tbl)
|
||||
return saved_table
|
||||
end
|
||||
|
||||
|
||||
function GameState.load(SAVE_FILE)
|
||||
-- placeholder is the name of our placeholder variable
|
||||
-- so we can do things like "actors = GameState.load"
|
||||
|
@ -3,18 +3,13 @@ function screen_col_detect(object, display)
|
||||
object.x <= (display.width - object.width)) then
|
||||
return false
|
||||
end
|
||||
|
||||
if not (object.y >= -1 and
|
||||
object.y <= (display.height - object.height)) then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
function create_object(start_x, start_y, width, height, speed)
|
||||
local object = {}
|
||||
object.x = start_x
|
||||
@ -32,10 +27,8 @@ function num_is_pos(number)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Inspired by https://love2d.org/wiki/BoundingBox.lua
|
||||
-- Returns true if boxes overlap
|
||||
|
||||
function hitbox_collision(x1, y1, width1, height1,
|
||||
x2, y2, width2, height2)
|
||||
return x1 < x2 + width2 and
|
||||
@ -44,13 +37,11 @@ function hitbox_collision(x1, y1, width1, height1,
|
||||
y2 < y1 + height1
|
||||
end
|
||||
|
||||
|
||||
-- Takes a string "left" or "right"
|
||||
function bounce(str, ball)
|
||||
if str == "right" and
|
||||
not num_is_pos(ball.x_speed) then
|
||||
ball.x_speed = ball.x_speed *-1
|
||||
|
||||
elseif
|
||||
str == "left" and
|
||||
num_is_pos(ball.x_speed) then
|
||||
@ -59,8 +50,6 @@ function bounce(str, ball)
|
||||
return ball
|
||||
end
|
||||
|
||||
|
||||
|
||||
function ball_bounce(player, ball, dt)
|
||||
local paddle_hit = false
|
||||
ball.x = ball.x + (ball.x_speed *dt)
|
||||
@ -81,14 +70,10 @@ function ball_bounce(player, ball, dt)
|
||||
ball.y_speed = ball.y_speed * -1
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- If ball hits paddle
|
||||
|
||||
if hitbox_collision(ball.x, ball.y, ball.width, ball.height,
|
||||
player.x, player.y, player.width, player.height) then
|
||||
|
||||
|
||||
-- We don't need to check left limits because we already know
|
||||
-- there was a collision, so just bounce left if the ball is
|
||||
-- left of center on the paddle
|
||||
|
@ -18,7 +18,6 @@ function love.keyreleased(key)
|
||||
|
||||
-- Load
|
||||
elseif key == LOAD_KEY then
|
||||
|
||||
save_exists = love.filesystem.exists(SAVE_FILE)
|
||||
|
||||
if save_exists then
|
||||
@ -47,11 +46,9 @@ function check_keys(object, screen, dt)
|
||||
if love.keyboard.isDown(MOVE_RIGHT) then
|
||||
newObject.x = newObject.x + half_speed(newObject.speed * dt)
|
||||
end
|
||||
|
||||
if love.keyboard.isDown(MOVE_LEFT) then
|
||||
newObject.x = newObject.x - half_speed(newObject.speed * dt)
|
||||
end
|
||||
|
||||
if screen_col_detect(newObject, screen) then
|
||||
return newObject
|
||||
else
|
||||
|
@ -18,7 +18,7 @@ function love.load()
|
||||
actors.ball.y_speed = (-actors.ball.speed /2)
|
||||
actors.ball.score = 0
|
||||
|
||||
|
||||
-- Timer vars (see keys.lua for loaded timer vars)
|
||||
actors.start = love.timer.getTime()
|
||||
actors.end_timer = 0
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user