X-Git-Url: http://git.purplebirdman.com/lightcycles-love.git/blobdiff_plain/1a561bf43c90fcaf433c846a04c03dde5b8e9a70..efb40087b3a510e92f88763de2e8b4d8da2d347f:/player.lua diff --git a/player.lua b/player.lua index 0bf6990..42c0f62 100644 --- a/player.lua +++ b/player.lua @@ -6,28 +6,52 @@ Player.height = 5 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 + o:recordPosition() 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) + + -- add current position + self:recordPosition() + self:drawPath() + table.remove(self.path) + table.remove(self.path) +end + +function Player:recordPosition() + 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} + self:recordPosition() 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} + self:recordPosition() 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