-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayer.lua
46 lines (37 loc) · 1.27 KB
/
Layer.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Layer = Class {}
-- gives layers the attributes it needs
function Layer:init(x, y, width, height, speed)
self.x = x
self.y = y
self.width = width
self.height = height
self.speed = speed
end
function Layer:moveUp(dt)
self.y = math.max(0, self.y - self.speed * dt)
end
function Layer:moveDown(dt)
self.y = math.min(VIRTUAL_HEIGHT, self.y + self.speed *dt)
end
function Layer:moveLeft(dt)
self.x = math.max(0, self.x - self.speed * dt)
end
function Layer:moveRight(dt)
self.x = math.min(VIRTUAL_WIDTH, self.x + self.speed * dt)
end
function Layer:setXY(x,y)
self.x = x
self.y = y
end
function Layer:render()
vertices = {}
vertices[1],vertices[2] = self.x-self.width-self.height,self.y -- bottom left
vertices[3],vertices[4] = self.x-self.width,self.y-self.height -- top left
vertices[5],vertices[6] = self.x+self.width,self.y-self.height -- top right
vertices[7],vertices[8] = self.x+self.width+self.height,self.y -- bottom right
love.graphics.setColor(0,1,0)
love.graphics.polygon('fill', vertices)
--[[love.graphics.setColor(1,1,0)
love.graphics.circle('fill',vertices[1]+10,vertices[2]-5,15)
love.graphics.circle('fill',vertices[7]-10,vertices[8]-5,15)--]]
end