5 Player.color = {255, 0, 0}
8 Player.acceleration = 100
9 Player.position = vec2:new(0, 0)
10 Player.vector = vec2:new(0, 0)
14 down = vec2:new(0, 1),
15 left = vec2:new(-1, 0),
16 right = vec2:new(1, 0),
25 function Player:new(o)
33 function Player:drawPath()
34 if #self.path >= 4 then
35 love.graphics.setLineWidth(2)
36 love.graphics.setColor(self.color)
37 love.graphics.line(self.path)
41 function Player:draw()
42 love.graphics.setColor(self.color)
43 love.graphics.rectangle('fill', self.position.x, self.position.y, self.width, self.height)
45 -- add current position
48 table.remove(self.path)
49 table.remove(self.path)
52 function Player:recordPosition()
53 table.insert(self.path, self.position.x + self.width/2)
54 table.insert(self.path, self.position.y + self.height/2)
57 function Player:update(dt)
58 for key, name in pairs(self.keys) do
59 if love.keyboard.isDown(key)
60 and self.vector ~= self.vectors[name]
61 and (self.vector + self.vectors[name]):length() > 0
63 self.vector = self.vectors[name]
68 self.position = self.position + self.vector * self.acceleration * dt