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)
19 function Player:drawPath()
20 if #self.path >= 4 then
21 love.graphics.setColor(self.color)
22 love.graphics.line(self.path)
26 function Player:draw()
27 love.graphics.setColor(self.color)
28 love.graphics.rectangle('fill', self.position.x, self.position.y, self.width, self.height)
30 -- add current position
33 table.remove(self.path)
34 table.remove(self.path)
37 function Player:recordPosition()
38 table.insert(self.path, self.position.x + self.width/2)
39 table.insert(self.path, self.position.y + self.height/2)
42 function Player:update(dt)
43 if love.keyboard.isDown("w") then
44 self.vector = {x=0, y=-self.acceleration}
46 elseif love.keyboard.isDown("s") then
47 self.vector = {x=0, y=self.acceleration}
49 elseif love.keyboard.isDown("a") then
50 self.vector = {x=-self.acceleration, y=0}
52 elseif love.keyboard.isDown("d") then
53 self.vector = {x=self.acceleration, y=0}
57 self.position.x = self.position.x + self.vector.x * dt
58 self.position.y = self.position.y + self.vector.y * dt