]> Untitled Git - lightcycles-love.git/commitdiff
Added player path
authorClifton James Palmer <clifton.palmer@gmail.com>
Sat, 8 Dec 2018 00:18:22 +0000 (18:18 -0600)
committerClifton James Palmer <clifton.palmer@gmail.com>
Sat, 8 Dec 2018 00:28:33 +0000 (18:28 -0600)
main.lua
player.lua

index 804c413d7249eaf9e63139610690bfa4b9056812..e6fe8fbe412e8560781e1bf7d3ceaa234d8ee83c 100644 (file)
--- a/main.lua
+++ b/main.lua
@@ -35,3 +35,8 @@ function love.update(dt)
     end
     player:update(dt)
 end
     end
     player:update(dt)
 end
+
+function love.quit()
+    print('Thanks for playing!')
+    print('Recorded ' .. #player.path / 2 .. ' player path points')
+end
index 0bf699053cc20f3c239d3989e9c3f24952fd58d0..6c38099e06c5f8ecebb102b151279166dd668b06 100644 (file)
@@ -6,28 +6,54 @@ Player.height = 5
 Player.acceleration = 100
 Player.position = {x=0, y=0}
 Player.vector = {x=0, y=0}
 Player.acceleration = 100
 Player.position = {x=0, y=0}
 Player.vector = {x=0, y=0}
+Player.path = {}
 
 function Player:new(o)
     o = o or {}
     setmetatable(o, self)
     self.__index = self
 
 function Player:new(o)
     o = o or {}
     setmetatable(o, self)
     self.__index = self
+    o:recordPosition()
+    o.vector = {x=o.acceleration, y=0}
     return o
 end
 
     return o
 end
 
+function Player:drawPath()
+    if #self.path >= 4 then
+        love.graphics.setColor(self.color)
+        love.graphics.line(self.path)
+    end
+end
+
 function Player:draw()
     love.graphics.setColor(self.color)
     love.graphics.rectangle('fill', self.position.x, self.position.y, self.width, self.height)
 function Player:draw()
     love.graphics.setColor(self.color)
     love.graphics.rectangle('fill', self.position.x, self.position.y, self.width, self.height)
+
+    -- add current position
+    self:recordPosition()
+    self:drawPath()
+    table.remove(self.path)
+    table.remove(self.path)
+end
+
+function Player:recordPosition()
+    print(self.position.x .. ', ' .. self.position.y)
+    table.insert(self.path, self.position.x + self.width/2)
+    table.insert(self.path, self.position.y + self.height/2)
 end
 
 function Player:update(dt)
     if love.keyboard.isDown("w") then
         self.vector = {x=0, y=-self.acceleration}
 end
 
 function Player:update(dt)
     if love.keyboard.isDown("w") then
         self.vector = {x=0, y=-self.acceleration}
+        self:recordPosition()
     elseif love.keyboard.isDown("s") then
         self.vector = {x=0, y=self.acceleration}
     elseif love.keyboard.isDown("s") then
         self.vector = {x=0, y=self.acceleration}
+        self:recordPosition()
     elseif love.keyboard.isDown("a") then
         self.vector = {x=-self.acceleration, y=0}
     elseif love.keyboard.isDown("a") then
         self.vector = {x=-self.acceleration, y=0}
+        self:recordPosition()
     elseif love.keyboard.isDown("d") then
         self.vector = {x=self.acceleration, y=0}
     elseif love.keyboard.isDown("d") then
         self.vector = {x=self.acceleration, y=0}
+        self:recordPosition()
     end
 
     self.position.x = self.position.x + self.vector.x * dt
     end
 
     self.position.x = self.position.x + self.vector.x * dt