-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjetpack.lua
More file actions
106 lines (91 loc) · 2.35 KB
/
Copy pathjetpack.lua
File metadata and controls
106 lines (91 loc) · 2.35 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
local class = require('libraries.middleclass')
local helpers = require('helpers')
local Jetpack = class('Jetpack')
function Jetpack:initialize()
self.width = jetpack_image:getWidth()
self.height = jetpack_image:getHeight()
self.x = love.graphics.getWidth() + self.width / 2
self.y = love.graphics.getHeight() / 2
self.speed = 40
self.is_moving_towards_player = true
self.circling_radius = 100
self.circling_angle = 0
self.is_circling = false
self.is_visible = true
self.is_usable = false
self.scale = 0.2
end
function Jetpack:update(dt)
if self.is_circling then
self.cx = player.x
self.cy = player.y
self.x = self.cx + self.circling_radius * math.cos(self.circling_angle)
self.y = self.cy + self.circling_radius * math.sin(self.circling_angle)
self.circling_angle = self.circling_angle + math.pi * dt
if self.is_usable and player then
self.circling_angle = self.circling_angle + math.pi * dt * player.boost_distance / 40
self.circling_radius = player.boost_distance / 5
end
end
if self.is_moving_towards_player then
self.scale = math.min(self.scale + dt / 20, 1)
self.x = self.x - dt * self.speed
end
end
function Jetpack:draw()
if not self.is_visible then return end
love.graphics.draw(
jetpack_image,
self.x,
self.y,
0,
self.scale,
self.scale,
self.width / 2,
self.height / 2
)
end
function Jetpack:is_at_x(x)
return self.x <= x
end
function Jetpack:stop_moving()
self.is_moving_towards_player = false
end
function Jetpack:start_circling(done)
self.cx = self.x
self.cy = self.y
self.circling_timer = timer:tween(
0.5,
self,
{ x = self.x + self.circling_radius },
'in-sine',
function()
self.is_circling = true
self.circling_timer = timer:after(4, function()
self.is_circling = false
self.circling_timer = timer:tween(
0.5,
self,
{ x = self.x - self.circling_radius },
'in-sine',
function()
self.is_circling = true
self.is_visible = false
self.is_usable = true
done()
end
)
end)
end
)
end
function Jetpack:hide()
self.is_visible = false
end
function Jetpack:show()
self.is_visible = true
end
function Jetpack:destroy()
helpers.cancelTimer(self.circling_timer)
end
return Jetpack