-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriend.lua
65 lines (52 loc) · 1.12 KB
/
friend.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
--
-- friend.lua
-- defines the Friend class
--
Friend = {}
Friend.__index = Friend
function Friend.new(type, x, y)
local self = {}
setmetatable(self, Friend)
f = friends[type]
-- position
self.x = x
self.y = y
self.width = f.width
self.height = f.height
self.offset = f.offset
self.rect = HC.rectangle(x+self.offset.x,y+self.offset.y,self.width,self.height)
-- descriptors
self.type = 'friend'
self.name = f.name
self.description = f.description
self.img = f.image
self.health = 0
self.active = true
-- speaking
self.dialogue = f.dialogue
self.speaking = false
self.lineNum = 0
self.text = nil
return self
end
function Friend:update()
-- do nothing
end
function Friend:draw()
love.graphics.draw(self.img, self.x, self.y)
if self.speaking then
self:makeText()
love.graphics.draw(self.text, WINDOW_W - self.text:getWidth(), 10)
end
end
function Friend:makeText()
local words = self.dialogue[self.lineNum]
self.text = love.graphics.newText(fonts['emu'], {black,words})
end
function Friend:isDone()
if self.lineNum >= #self.dialogue+1 then
self.lineNum = 0
return true
end
return false
end