-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcursor.lua
55 lines (43 loc) · 1.05 KB
/
cursor.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
47
48
49
50
51
52
53
54
55
local Sprite = require("sprite")
local Cursor = {}
Cursor.__index = Cursor
function Cursor.create(x,y,player)
local self = setmetatable({}, Cursor)
self.x, self.y = x,y
self.offsetx, self.offsety = 0,0
self.player = player
local img = ResMgr.getImage("cursor"..player..".png")
self.sprite = Sprite.create(img)
self.sprite:setOffset(2, 2)
self.inputs = {}
return self
end
--- Moves cursor
-- @param dx Movement on x-axis
-- @param dy Movement on y-axis
-- @param absolute True if coordinates are absolute, not relative
function Cursor:move(dx, dy, absolute)
if absolute == true then
self.x = dx
self.y = dy
else
self.x = self.x + dx
self.y = self.y + dy
end
self.x = math.cap(self.x, 0, WIDTH)
self.y = math.cap(self.y, 0, HEIGHT)
end
function Cursor:draw()
self.sprite:draw(math.floor(self.x+self.offsetx), math.floor(self.y+self.offsety))
end
function Cursor:addInput(i)
table.insert(self.inputs, i)
end
function Cursor:getInputs()
return self.inputs
end
function Cursor:setOffset(x,y)
self.offsetx = x
self.offsety = y
end
return Cursor