-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrostbolt.lua
131 lines (116 loc) · 3.99 KB
/
frostbolt.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Frostbolt = Class{
init = function(self,collider, player)
--self.bbox = collider:addRectangle(x,y,32,32, facing)
--self.bbox.type = "frostbolt"
--self.bbox.ref = self
self.player = player
self.collider = collider
self.manacost = 50
self.MAXCOOLDOWN = 1
self.cooldown = 0
self.g = anim8.newGrid(30, 30, 68, 34, -2,-2,4)
--self.animation = anim8.newAnimation(self.g('1-2',1), 0.2)
self.activeFrostbolts = {}
end,
}
function Frostbolt:use()
x, y = self.player.bbox:center()
if not self.player.facingRight then
x = x - 8
end
local bbbox = self.collider:addRectangle(x,y-12,16,16)
bbbox.type = "frostbolt"
bbbox.ref = self
bbbox.speed = 350
bbbox.animation = anim8.newAnimation(self.g('1-2',1), 0.2)
bbbox.facingRight =self.player.facingRight
bbbox.ttl = 5
table.insert(self.activeFrostbolts, bbbox)
AudioController:playAndRewindSound("frostboltcast")
--[[
AudioController.sounds["frostboltcast"]:rewind()
AudioController.sounds["frostboltcast"]:play()
]]
end
function Frostbolt:update(dt)
--[[
if self.jumping then
self.velocity.y = self.velocity.y + self.speed/4*dt
end
-- update movement
self.bbox:move(self.velocity.x,self.velocity.y)
]]--
--self.bbox:move(self.velocity.x/dt,self.velocity.y/dt)
--self.animation:update(dt)
if self.cooldown ~= 0 then
self.cooldown = self.cooldown - dt
if self.cooldown <= 0 then
self.cooldown = 0
end
end
local i = 1
while i <= #self.activeFrostbolts do
self.activeFrostbolts[i].ttl = self.activeFrostbolts[i].ttl - dt
if self.activeFrostbolts[i].ttl <= 0 then --TTL is over
self.collider:remove(self.activeFrostbolts[i])
table.remove(self.activeFrostbolts,i)
else
if self.activeFrostbolts[i].facingRight then
self.activeFrostbolts[i]:move(self.activeFrostbolts[i].speed*dt,0)
else
self.activeFrostbolts[i]:move(self.activeFrostbolts[i].speed*-dt,0)
end
self.activeFrostbolts[i].animation:update(dt)
i = i+1
end
end
end
function Frostbolt:removeAllBolts()
local i = 1
while i <= #self.activeFrostbolts do
self.collider:remove(self.activeFrostbolts[i])
table.remove(self.activeFrostbolts,i)
end
end
function Frostbolt:draw()
--x,y = self.bbox:center()
--x,y = x-16,y-16
--self.animation:draw(self.fimage,x, y)
x, y = self.player.bbox:center()
if not self.player.facingRight then
x = x - 16
end
love.graphics.draw(sprites.frostboltHand,x,y-10)
for i = 1, #self.activeFrostbolts do
-- do not draw bounding box
--love.graphics.setColor(0,0,255, 255)
--self.activeFrostbolts[i]:draw("fill")
--love.graphics.setColor(255,255,255, 255)
x,y = self.activeFrostbolts[i]:center()
if self.activeFrostbolts[i].facingRight then
self.activeFrostbolts[i].animation:draw(sprites.frostbolt_animation,x-22, y-15)
else
self.activeFrostbolts[i].animation:draw(sprites.frostbolt_animation,x+22, y-15,0,-1,1)
end
--x,y = x-16,y-16
--self.animation:draw(self.fimage,x, y)
end
end
function Frostbolt:collide(dt, me, other, mtv_x, mtv_y)
if other.type == "tile" or other.type == "skeleton" or other.type == "bat" then
if other.type=="tile" then
AudioController:playAndRewindSound("frostbolthitwalls")
--[[
AudioController.sounds["frostbolthitwalls"]:rewind()
AudioController.sounds["frostbolthitwalls"]:play()
]]
else
AudioController:playAndRewindSound("frostbolthitenemy")
--[[
AudioController.sounds["frostbolthitenemy"]:rewind()
AudioController.sounds["frostbolthitenemy"]:play()
]]
end
me.ttl = 0
end
end