3 Player.color = {255, 0, 0}
6 Player.acceleration = 100
7 Player.position = {x=0, y=0}
8 Player.vector = {x=0, y=0}
11 function Player:new(o)
16 o.vector = {x=o.acceleration, y=0}
20 function Player:drawPath()
21 if #self.path >= 4 then
22 love.graphics.setColor(self.color)
23 love.graphics.line(self.path)
27 function Player:draw()
28 love.graphics.setColor(self.color)
29 love.graphics.rectangle('fill', self.position.x, self.position.y, self.width, self.height)
31 -- add current position
34 table.remove(self.path)
35 table.remove(self.path)
38 function Player:recordPosition()
39 print(self.position.x .. ', ' .. self.position.y)
40 table.insert(self.path, self.position.x + self.width/2)
41 table.insert(self.path, self.position.y + self.height/2)
44 function Player:update(dt)
45 if love.keyboard.isDown("w") then
46 self.vector = {x=0, y=-self.acceleration}
48 elseif love.keyboard.isDown("s") then
49 self.vector = {x=0, y=self.acceleration}
51 elseif love.keyboard.isDown("a") then
52 self.vector = {x=-self.acceleration, y=0}
54 elseif love.keyboard.isDown("d") then
55 self.vector = {x=self.acceleration, y=0}
59 self.position.x = self.position.x + self.vector.x * dt
60 self.position.y = self.position.y + self.vector.y * dt