Skip to content

Commit

Permalink
Minor edits
Browse files Browse the repository at this point in the history
(VERY minor)
- Remove tabs for alignment
- Move together a few * and / for readability
  • Loading branch information
sornas committed Nov 19, 2019
1 parent cf19f39 commit ee255af
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
10 changes: 5 additions & 5 deletions entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions lib/graphics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions lib/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down
17 changes: 10 additions & 7 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 <space> to start game (and shoot)!", small_font, 3.2*win_h / 4, win_w)
end
22 changes: 11 additions & 11 deletions movement.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down

0 comments on commit ee255af

Please sign in to comment.