forked from TecProg-grupo4-2018-2/panel-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimulatedOpponent.lua
74 lines (62 loc) · 1.75 KB
/
SimulatedOpponent.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
local logger = require("logger")
-- A simulated opponent sends attacks and takes damage from a player, it "loses" if it takes too many attacks.
SimulatedOpponent =
class(
function(self, health, character, positionX, positionY, mirror)
self.health = health
self.character = character
self.frameOriginX = positionX / GFX_SCALE
self.frameOriginY = positionY / GFX_SCALE
self.panelOriginX = self.frameOriginX
self.panelOriginY = self.frameOriginY
self.mirror_x = mirror
self.clock = 0
end
)
function SimulatedOpponent:setAttackEngine(attackEngine)
self.attackEngine = attackEngine
end
function SimulatedOpponent:stackCanvasWidth()
return 288
end
function SimulatedOpponent:run()
if self.health then
self.health:run()
end
if not self:isDefeated() then
if self.attackEngine then
self.attackEngine:run()
end
self.clock = self.clock + 1
end
end
function SimulatedOpponent:isDefeated()
if not self.health then
return false
end
return self.health:isFullyDepleted()
end
function SimulatedOpponent:drawCharacter()
local characterObject = characters[self.character]
characterObject:drawPortrait(2, self.frameOriginX, self.frameOriginY, 0)
end
local healthBarXOffset = -56
function SimulatedOpponent.render(self)
if self.health then
self:drawCharacter()
self.health:render(self.frameOriginX * GFX_SCALE + healthBarXOffset)
end
if self.attackEngine then
self.attackEngine:render()
end
end
function SimulatedOpponent:receiveGarbage(frameToReceive, garbageList)
if self.health and self.health:isFullyDepleted() == false then
self.health:receiveGarbage(frameToReceive, garbageList)
end
end
function SimulatedOpponent:deinit()
if self.health then
self.health:deinit()
end
end