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
|
Cursor = Tile:extend {
image = 'data/cursor.png',
inTargetArea = function(self)
-- TODO: memoize this per-tick
local mouseAngle = math.atan2(
love.mouse.getY() - the.app.height/2,
love.mouse.getX() - the.app.width/2
)
local mouseVsShipAbs = math.abs(the.player.rotation - mouseAngle)
local mouseVsShip = math.min(2*math.pi - mouseVsShipAbs,
mouseVsShipAbs)
return mouseVsShip < 0.75
end,
onUpdate = function(self)
if self:inTargetArea() then
self.image = 'data/cursor-target.png'
else
self.image = 'data/cursor.png'
end
end,
onEndFrame = function(self)
self.x = love.mouse.getX() + 8 + the.player.x - the.app.width / 2
self.y = love.mouse.getY() + 8 + the.player.y - the.app.height / 2
end
}
|