From 80a67f16b96aa88a1746473b33e8a42a763dc329 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Tue, 25 Jul 2017 22:19:56 -0700 Subject: [PATCH] mike: Added stupid stuff --- love/mike/lib/functions.lua | 11 +++++++++-- love/mike/main.lua | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/love/mike/lib/functions.lua b/love/mike/lib/functions.lua index e1d1029..67b68d0 100644 --- a/love/mike/lib/functions.lua +++ b/love/mike/lib/functions.lua @@ -71,11 +71,18 @@ function ball_bounce(player, ball, dt) ball.x_speed = ball.x_speed * -1 end - --If ball hits screen top/bottom - if ball.y >= screen.height or ball.y <0 then + --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.y <= 0 then ball.y_speed = ball.y_speed * -1 end + + --If ball hits paddle if hitbox_collision(ball.x, ball.y, ball.width, ball.height, diff --git a/love/mike/main.lua b/love/mike/main.lua index cb05039..461c2f9 100644 --- a/love/mike/main.lua +++ b/love/mike/main.lua @@ -15,16 +15,20 @@ function love.load() -- Create a table to hold all the player data actors.player = create_object(screen.width /2, screen.height - 50, 30, 5, 500) -- Create a table to hold ball data - actors.ball = create_object(screen.width /2, screen.height /2, 5, 10, 600) - actors.ball.x_speed = (actors.ball.speed /2) - actors.ball.y_speed = (actors.ball.speed /2) + actors.ball = create_object(screen.width /2, screen.height /2, 5, 5, 600) + actors.ball.x_speed = (-actors.ball.speed /2) + actors.ball.y_speed = (-actors.ball.speed /2) + actors.ball.score = 0 + actors.start = love.timer.getTime() + local end_timer = 0 end function love.update(dt) actors.player = check_keys(actors.player, screen, dt) actors.ball = ball_bounce(actors.player, actors.ball, dt) + end_timer = love.timer.getTime() - actors.start end function love.draw() @@ -37,5 +41,13 @@ function love.draw() love.graphics.circle("line", actors.ball.x, actors.ball.y, actors.ball.width, actors.ball.height) --FPS counter + love.graphics.setColor(128,72,25) love.graphics.print("FPS: "..tostring(love.timer.getFPS( )), 10, 10) + --Ball Score + love.graphics.setColor(255,0,0) + love.graphics.print("Score: "..actors.ball.score, screen.width -80, 10) + --Timer + love.graphics.setColor(125,42,19) + love.graphics.print(string.format("Time M: %.2f", end_timer/60), screen.width -85, 50) + love.graphics.print(string.format("Time S: %.2f", end_timer), screen.width -85, 30) end