]> Untitled Git - lightcycles-love.git/blobdiff - player.lua
Added line intersection highlights
[lightcycles-love.git] / player.lua
index 0e707f82858272a614287e75f29db65000bf852f..0a37a0b8eff4c03102f655a0bd037a1e64b1692d 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)
@@ -40,7 +44,13 @@ end
 
 function Player:draw()
     love.graphics.setColor(self.color)
 
 function Player:draw()
     love.graphics.setColor(self.color)
-    love.graphics.rectangle('fill', self.position.x, self.position.y, self.width, self.height)
+    love.graphics.rectangle(
+        'fill',
+        self.position.x-self.width/2,
+        self.position.y-self.height/2,
+        self.width,
+        self.height
+        )
 
     -- add current position
     self:recordPosition()
 
     -- add current position
     self:recordPosition()
@@ -50,19 +60,31 @@ function Player:draw()
 end
 
 function Player:recordPosition()
 end
 
 function Player:recordPosition()
-    table.insert(self.path, self.position.x + self.width/2)
-    table.insert(self.path, self.position.y + self.height/2)
+    table.insert(self.path, self.position.x)
+    table.insert(self.path, self.position.y)
+end
+
+function Player:multiple_keys_are_pressed()
+    local count = 0
+    for key,_ in pairs(self.keys) do
+        if love.keyboard.isDown(key) then
+            count = count + 1
+        end
+    end
+    return count > 1
 end
 
 function Player:update(dt)
 end
 
 function Player:update(dt)
-    for key, name in pairs(self.keys) do
-        if love.keyboard.isDown(key)
-        and self.vector ~= self.vectors[name]
-        and (self.vector + self.vectors[name]):length() > 0
-        then
-            self.vector = self.vectors[name]
-            self:recordPosition()
-            break
+    if not self:multiple_keys_are_pressed() then
+        for key, name in pairs(self.keys) do
+            if love.keyboard.isDown(key)
+            and self.vector ~= self.vectors[name]
+            and (self.vector + self.vectors[name]):length() > 0
+            then
+                self.vector = self.vectors[name]
+                self:recordPosition()
+                break
+            end
         end
     end
     self.position = self.position + self.vector * self.acceleration * dt
         end
     end
     self.position = self.position + self.vector * self.acceleration * dt