From ed9d250a37e65e4a24316a140d6f516a62fa44a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 19 Nov 2019 17:33:34 +0100 Subject: [PATCH] Minor edits (VERY minor) - Remove tabs for alignment - Move together a few * and / for readability --- entities.lua | 10 +++++----- lib/graphics.lua | 11 ++++++----- lib/text.lua | 8 ++++---- main.lua | 17 ++++++++++------- movement.lua | 22 +++++++++++----------- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/entities.lua b/entities.lua index b8bde95..fc3482d 100644 --- a/entities.lua +++ b/entities.lua @@ -57,9 +57,9 @@ function spawn(object_type, args) enemy.shape = c.makeRect(enemy.x, enemy.y, enemy.width, enemy.height) enemy.x_speed = get_value(args, "x_speed", - math.random(enemy.min_speed, enemy.max_speed)) + math.random(enemy.min_speed, enemy.max_speed)) enemy.y_speed = get_value(args, "y_speed", - math.random(enemy.min_speed, enemy.max_speed)) + math.random(enemy.min_speed, enemy.max_speed)) return enemy elseif object_type == "shot" then local shot = {} @@ -100,7 +100,7 @@ function spawn_shot() local args = {} args.x = player.x args.y = player.y - args.rotation = player.rotation - math.pi / 2 + args.rotation = player.rotation - math.pi/2 shots[#shots + 1] = spawn("shot", args) end @@ -122,13 +122,13 @@ function spawn_enemy() end -- to move towards the other end of the screen - if args.x < win_w / 2 then + if args.x < win_w/2 then args.x_dir = 1 else args.x_dir = -1 end - if args.y < win_h / 2 then + if args.y < win_h/2 then args.y_dir = 1 else args.y_dir = -1 diff --git a/lib/graphics.lua b/lib/graphics.lua index 4419507..f5b9d3e 100644 --- a/lib/graphics.lua +++ b/lib/graphics.lua @@ -26,7 +26,8 @@ function draw_single_rectangle(object) love.graphics.push() love.graphics.translate(object.x, object.y) love.graphics.rotate(object.rotation) - love.graphics.rectangle(object.filling, - (object.width / 2), - (object.height / 2), object.width, object.height) + love.graphics.rectangle(object.filling, - (object.width / 2), - (object.height / 2), + object.width, object.height) love.graphics.pop() end @@ -35,8 +36,8 @@ function draw_ellipse(object) love.graphics.translate(object.x, object.y) love.graphics.rotate(object.rotation) function sub_ellipse(x, y, w, h) - love.graphics.rectangle(object.filling, x, y, w, h, - object.width / 2, object.height / 2) + love.graphics.rectangle(object.filling, x, y, w, h, + object.width / 2, object.height / 2) end draw_subs(object, sub_ellipse) love.graphics.pop() @@ -52,8 +53,8 @@ function draw_triangle(object) local s = 1 - hurt / player.max_damage local diff = 1.1 vertices = {0, - h0 + diff*s*h0, - w0 - diff*s*w0, h0 - s*h0, - - w0 + diff*s*w0, h0 - s*h0} + w0 - diff*s*w0, h0 - s*h0, + -(w0 + diff*s*w0, h0 - s*h0)} love.graphics.polygon(object.filling, vertices) end love.graphics.pop() diff --git a/lib/text.lua b/lib/text.lua index c54c26c..c9ff98e 100644 --- a/lib/text.lua +++ b/lib/text.lua @@ -5,9 +5,9 @@ local yf_font = "res/yf16font.ttf" big_font = love.graphics.newFont(yf_font, 55) medium_font = love.graphics.newFont(yf_font, 35) small_font = love.graphics.newFont(yf_font, 15) -small_font:setFilter( "nearest", "nearest" ) -medium_font:setFilter( "nearest", "nearest" ) -big_font:setFilter( "nearest", "nearest" ) +small_font:setFilter("nearest", "nearest") +medium_font:setFilter("nearest", "nearest") +big_font:setFilter("nearest", "nearest") function write_centered(text, font, y, win_w) local w = font:getWidth(text) @@ -28,7 +28,7 @@ function write(text, font, x, y) end function time_to_string(time) - time = math.ceil((time * 100)) / 100 + time = math.ceil(time * 100) / 100 local time = ""..time if #time == 1 then return time..".00" diff --git a/main.lua b/main.lua index 98878ef..a105343 100644 --- a/main.lua +++ b/main.lua @@ -21,6 +21,7 @@ function love.load() key_see = "1" key_move = "2" key_attack = "3" + -- "none", "rot", "move" pressed_keys = {left = "none", right = "none", up = "none", down = "none"} @@ -70,7 +71,7 @@ function love.keypressed(key) elseif state == "death" then - if key == "space" or key == "return"or key == "escape" then + if key == "space" or key == "return" or key == "escape" then state = "start" end @@ -214,9 +215,10 @@ function show_startscreen() love.graphics.rectangle("line", x - dist, y, w, h, w/2, h/2) love.graphics.rectangle("line", x, y, w, h, 0) - love.graphics.polygon("line", {x + dist, y, - x + dist, y + h, - x + w + dist, y + h/2}) + love.graphics.polygon("line", { + x + dist, y, + x + dist, y + h, + x + w + dist, y + h/2}) end function show_infoscreen() @@ -246,8 +248,9 @@ function show_infoscreen() love.graphics.rectangle("line", x - dist, y, w, h, w/2, h/2) love.graphics.rectangle("line", x, y, w, h, 0) - love.graphics.polygon("line", {x + dist, y, - x + dist, y + h, - x + w + dist, y + h/2}) + love.graphics.polygon("line", { + x + dist, y, + x + dist, y + h, + x + w + dist, y + h/2}) write_centered("Press to start game (and shoot)!", small_font, 3.2*win_h / 4, win_w) end diff --git a/movement.lua b/movement.lua index f5d674d..77e5e7b 100644 --- a/movement.lua +++ b/movement.lua @@ -1,17 +1,17 @@ function move_player(player, dt) - if (player.x + player.x_dir * player.x_speed * dt) + player.width / 2 > win_w then - player.x = win_w - player.width / 2 + if (player.x + player.x_dir * player.x_speed * dt) + player.width/2 > win_w then + player.x = win_w - player.width/2 return false - elseif player.x + player.x_dir * player.x_speed * dt < player.width / 2 then - player.x = player.width / 2 + elseif player.x + player.x_dir * player.x_speed * dt < player.width/2 then + player.x = player.width/2 return false end - if (player.y + player.y_dir * player.y_speed * dt) + player.height / 2 > win_h then + if (player.y + player.y_dir * player.y_speed * dt) + player.height/2 > win_h then -- TODO player gets "stuck" here return false - elseif player.y + player.y_dir * player.y_speed * dt < player.height / 2 then - player.y = player.height / 2 + elseif player.y + player.y_dir * player.y_speed * dt < player.height/2 then + player.y = player.height/2 return false end move(player, dt) @@ -26,10 +26,10 @@ function move_shot(shot, dt) end function move_enemy(enemy, dt) - if enemy.x - enemy.width * 2 > win_w or - enemy.y - enemy.height * 2 > win_h or - enemy.x + enemy.width * 2 < 0 or - enemy.y + enemy.height * 2 < 0 then return false end + if enemy.x - enemy.width*2 > win_w or + enemy.y - enemy.height*2 > win_h or + enemy.x + enemy.width*2 < 0 or + enemy.y + enemy.height*2 < 0 then return false end move(enemy, dt) return true end