From 5b60e6cfa04f560bb9c202c0de43a90bc393ae09 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 9 Mar 2019 20:41:28 -0600 Subject: [PATCH] Vision improvement and stupidity fixes --- conf.lua | 2 +- main.lua | 5 ++++- src/world.lua | 8 +++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/conf.lua b/conf.lua index ba4463c..20228a8 100644 --- a/conf.lua +++ b/conf.lua @@ -46,7 +46,7 @@ local PLAYER_COLOR = { 0.3, 0.3, 0.7 } local ENEMY_COLOR = { 1, 0, 0 } local BULLET_COLOR = { 0.6, 0.6, 1.0 } -local PLAYER_VISION_SEGMENTS = 32 +local PLAYER_VISION_SEGMENTS = 16 local PLAYER_VISION_DISTANCE = 20 local ENEMY_SIZE = 20 diff --git a/main.lua b/main.lua index 8244bbf..fbb26b0 100644 --- a/main.lua +++ b/main.lua @@ -10,7 +10,7 @@ local world, player local input function love.load() world, player = World:new() - for i = 1, 10 do + for i = 1, 100 do local enemy = Enemy:new(math.random(800), math.random(600)) world:add_entity(enemy) end @@ -38,4 +38,7 @@ end function love.draw() world:draw() + + love.graphics.setColor(0, 0, 0) + love.graphics.printf(tostring(love.timer.getFPS()) .. " FPS", 0, 0, 800, "center") end diff --git a/src/world.lua b/src/world.lua index 7ec943b..457683d 100644 --- a/src/world.lua +++ b/src/world.lua @@ -152,7 +152,7 @@ function Player:get_distances(world) local dy = math.sin(a) * CONF.ENEMY_SIZE local hit_entity = false - for j = 0, CONF.PLAYER_VISION_DISTANCE - 1 do + for j = 1, CONF.PLAYER_VISION_DISTANCE do local tx = self.x + dx * j local ty = self.y + dy * j @@ -160,15 +160,17 @@ function Player:get_distances(world) if e.ENTITY_TYPE == "Enemy" and math.rectcontains(e:get_rect(), tx, ty) then local ent_rect = e:get_rect() - for k = 0, 4 do + local toggle = false + for k = 0, 20 do dx = dx / 2 dy = dy / 2 tx = tx - dx ty = ty - dy - if not math.rectcontains(ent_rect, tx, ty) then + if math.rectcontains(ent_rect, tx, ty) == toggle then dx = dx * -1 dy = dy * -1 + toggle = not toggle end end -- 2.25.1