]> Untitled Git - lightcycles-love.git/commitdiff
Added player names and stub for collision detection
authorClifton James Palmer <clifton.palmer@gmail.com>
Sat, 8 Dec 2018 16:19:27 +0000 (10:19 -0600)
committerClifton James Palmer <clifton.palmer@gmail.com>
Sat, 8 Dec 2018 16:19:27 +0000 (10:19 -0600)
player.lua
players/1.lua
players/2.lua
scene.lua

index 387b54f303c8bdd7f1a79afb9934ffbd0fa63d6f..ed4f2106adb72c53de5f168649db5ffb72a24984 100644 (file)
@@ -1,7 +1,7 @@
 require 'vec2'
 
 Player = {}
 require 'vec2'
 
 Player = {}
-Player.name = 'player'
+Player.name = 'none'
 Player.color = {255, 0, 0}
 Player.width = 5
 Player.height = 5
 Player.color = {255, 0, 0}
 Player.width = 5
 Player.height = 5
@@ -30,6 +30,10 @@ function Player:new(o)
     return o
 end
 
     return o
 end
 
+function Player:__tostring()
+    return self.name
+end
+
 function Player:drawPath()
     if #self.path >= 4 then
         love.graphics.setLineWidth(2)
 function Player:drawPath()
     if #self.path >= 4 then
         love.graphics.setLineWidth(2)
index 5d8477accec8c43984c887080fef4bb5d20809ed..1ab74fbe6a8971ec4473b146e7706a3e89f4108d 100644 (file)
@@ -4,6 +4,7 @@ require 'vec2'
 require 'player'
 
 return Player:new({
 require 'player'
 
 return Player:new({
+    name='Player 1',
     position=vec2:new(100,100),
     vector=Player.vectors.right,
     path={},
     position=vec2:new(100,100),
     vector=Player.vectors.right,
     path={},
index 2539bc94c56f3a9773ec2b218d6de95267c99032..2b34fdbd80201e5af8b5967e7607a35911a8a654 100644 (file)
@@ -7,6 +7,7 @@ local width = love.graphics.getWidth()
 local height = love.graphics.getHeight()
 
 return Player:new({
 local height = love.graphics.getHeight()
 
 return Player:new({
+    name='Player 2',
     position=vec2:new(width-100,height-100),
     vector=Player.vectors.left,
     path={},
     position=vec2:new(width-100,height-100),
     vector=Player.vectors.left,
     path={},
index 3460899aa5dfe11add47fa59fad7b8bfc2f944c4..73164e335115a455e7f799ecb5059298b1726d7d 100644 (file)
--- a/scene.lua
+++ b/scene.lua
@@ -50,13 +50,37 @@ function scene:updatePlayers(dt)
     end
 end
 
     end
 end
 
+function doesLineIntersectPlayerPaths(path, x1, y1, x2, y2)
+    return false
+end
+
+function scene:handleCollisions()
+    -- calculate the last line for each player from current position
+    -- check if line intersects any other path line
+    -- if so, raise collision event for player
+    for _,player in pairs(self.players) do
+        local x1 = player.path[#player.path-1]
+        local y1 = player.path[#player.path]
+        local x2 = player.position.x
+        local y2 = player.position.y
+
+        -- check intersection against each existing path
+        for _,player2 in pairs(self.players) do
+            if doesLineIntersectPlayerPaths(player2.path, x1, y1, x2, y2) then
+                love.event.push('collision', player)
+            end
+        end
+    end
+end
+
 function scene:update(dt)
     self:updatePlayers(dt)
 function scene:update(dt)
     self:updatePlayers(dt)
+    self:handleCollisions()
 end
 
 -- quit
 function scene:quit()
 end
 
 -- quit
 function scene:quit()
-    for i,player in pairs(self.players) do
-        print('Player '..i..' generated '.. #player.path / 2 .. ' path points')
+    for _,player in pairs(self.players) do
+        print(tostring(player)..' generated '.. #player.path / 2 .. ' path points')
     end
 end
     end
 end