diff --git a/love/mike/lib/GameState.lua b/love/mike/lib/GameState.lua index 93edd03..f471115 100644 --- a/love/mike/lib/GameState.lua +++ b/love/mike/lib/GameState.lua @@ -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" @@ -49,7 +48,7 @@ function print_table(tbl, table_name, only_once) return saved_table end ---Counts contents of tables of tables as well +-- Counts contents of tables of tables as well function tablelength(tbl, count) local count = count or 0 diff --git a/love/mike/lib/functions.lua b/love/mike/lib/functions.lua index 67b68d0..f40f577 100644 --- a/love/mike/lib/functions.lua +++ b/love/mike/lib/functions.lua @@ -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" +-- 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,35 +50,29 @@ 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) 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 ball.x_speed = ball.x_speed * -1 end - --If ball hits screen top + -- If ball hits screen top if ball.y >= screen.height then ball.y_speed = ball.y_speed * -1 ball.score = ball.score + 1 end - --If ball hits screen bottom + -- If ball hits screen bottom if ball.y <= 0 then ball.y_speed = ball.y_speed * -1 end - - - --If ball hits paddle - + -- 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 diff --git a/love/mike/lib/keys.lua b/love/mike/lib/keys.lua index d34991e..bd8bc9b 100644 --- a/love/mike/lib/keys.lua +++ b/love/mike/lib/keys.lua @@ -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 diff --git a/love/mike/main.lua b/love/mike/main.lua index d0470cb..39f73a4 100644 --- a/love/mike/main.lua +++ b/love/mike/main.lua @@ -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 @@ -30,21 +30,21 @@ function love.update(dt) end function love.draw() - --Draw paddle + -- Draw paddle love.graphics.setColor(255,255,255) love.graphics.rectangle("line", actors.player.x, actors.player.y, actors.player.width, actors.player.height) - --Draw ball + -- Draw ball love.graphics.setColor(255,0,0) love.graphics.circle("line", actors.ball.x, actors.ball.y, actors.ball.width, actors.ball.height) - --FPS counter + -- FPS counter love.graphics.setColor(128,72,25) love.graphics.print("FPS: "..tostring(love.timer.getFPS( )), 10, 10) - --Ball Score + -- Ball Score love.graphics.setColor(255,0,0) love.graphics.print("Score: "..actors.ball.score, screen.width -80, 10) - --Timer + -- Timer love.graphics.setColor(125,42,19) love.graphics.print(string.format("Time M: %.2f", actors.end_timer/60), screen.width -85, 50) love.graphics.print(string.format("Time S: %.2f", actors.end_timer), screen.width -85, 30)