-
Notifications
You must be signed in to change notification settings - Fork 0
/
temporaryfloorspell.lua
93 lines (67 loc) · 1.68 KB
/
temporaryfloorspell.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
--[[
temporaryfloorspell.lua
February 4th, 2013
]]
require 'spell'
local Object = (require 'object').Object
local love = love
local table
= table
module('objects')
TemporaryFloorSpell = Object{}
--
-- TemporaryFloorSpell constructor
--
function TemporaryFloorSpell:_clone(values)
local o = table.merge(Spell(values),
Object._clone(self,values))
o.TEMPORARYFLOORSPELL = true
o._manaRequired = 100
return o
end
--
-- Update function for the Temporary Floor Spell
--
function TemporaryFloorSpell:update(dt)
Spell.update(self, dt)
if not self._casting then return end
if self._previousTile then
self._previousTile.hilightColor = nil
end
local tile = self._hgc:selectedTile()
if not tile then return end
if tile.filled then
tile.hilightColor = { 255, 0, 0, 128 }
else
tile.hilightColor = { 0, 255, 0, 128 }
end
self._previousTile = tile
end
--
-- Mouse button press handler for the
-- temporary floor spell
--
function TemporaryFloorSpell:onMouseRelease(b)
if not self._casting then return end
local tile = self._hgc:selectedTile()
if not tile then return end
if tile.filled then return end
tile.hilightColor = nil
if self._hgc._mana < self._manaRequired then return end
self._hgc._mana = self._hgc._mana - self._manaRequired
self._casting = false
local oldTileFilled = tile.filled
local oldTileColor = tile.color
tile.filled = true
tile.color = { 255, 0, 255, 255 }
local a = { _floorTime = 3 }
a.update = function(this, dt)
a._floorTime = a._floorTime - dt
if a._floorTime <= 0 then
tile.filled = oldTileFilled
tile.color = oldTileColor
a._scene:removeComponent(a)
end
end
self._scene:addComponent(a)
end