Vision improvement and stupidity fixes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 10 Mar 2019 02:41:28 +0000 (20:41 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 10 Mar 2019 02:41:28 +0000 (20:41 -0600)
conf.lua
main.lua
src/world.lua

index ba4463cefed176bf5acc09f41ed798110b0d8759..20228a82a1bac18fd483d21e02ee8a00f79f2a84 100644 (file)
--- 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
index 8244bbf859d2b539d8343ec8b37a9dc7873cd5b7..fbb26b0b88d762e704d6459998583b7787261095 100644 (file)
--- 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
index 7ec943bd143bcb48fb2be8a1c97af06074e6003d..457683d8ad0072d62ace54bc0b27e21b87be630d 100644 (file)
@@ -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