-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogue.lua
103 lines (94 loc) · 2.21 KB
/
dialogue.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
selected_conversation = -1
selected_response_index = 1
function show_game_state()
state = "playgame"
end
function show_conversation(collision_object, obj_convo_index)
local counter = 0
for c in all(conversations) do
if (c.sprite == collision_object) then
if counter == obj_convo_index then
state = "dialogue"
selected_conversation = c
selected_response_index = 1
break
else
counter += 1
end
end
end
end
conversations =
{
{
text = { "hello, how are you?" },
responses =
{
{ "i am good.", "show_convo", 2 },
{ "i am not so good.", "show_convo", 1 },
},
sprite = 3,
},
{
text = { "sorry to hear that,", "i hope you feel better soon" },
responses = {
{ "thanks", "end_conversation" }
},
sprite = 3,
},
{
text = { "have a great day." },
responses = {
{ "thanks", "end_conversation" }
},
sprite = 3,
},
{
text = { "go through the door?" },
responses = {
{ "yes", "go_through_door" },
{ "no", "end_conversation" }
},
sprite = 4,
},
}
function update_dialogue()
if btnp(2) then
selected_response_index -= 1
if selected_response_index < 1 then
selected_response_index = #selected_conversation.responses
end
elseif btnp(3) then
selected_response_index += 1
if selected_response_index > #selected_conversation.responses then
selected_response_index = 1
end
end
if btnp(5) then
local action = selected_conversation.responses[selected_response_index][2]
if action == "end_conversation" then
show_game_state()
elseif action == "show_convo" then
show_conversation(selected_conversation.sprite, selected_conversation.responses[selected_response_index][3])
elseif action == "go_through_door" then
move_one_space_in_dir(player, player.prev_move_dir)
move_one_space_in_dir(player, player.prev_move_dir)
show_game_state()
end
end
end
function draw_dialogue()
camera(0,0)
rectfill(0,0,127,127,0)
y_pos = 8
spr(selected_conversation.sprite, 4, y_pos)
for m in all(selected_conversation.text) do
print(m, 16, y_pos, 7)
y_pos += 16
end
for m in all(selected_conversation.responses) do
print(m[1], 16, y_pos, 7)
y_pos += 16
end
print("❎", 4, (#selected_conversation.text + selected_response_index)*16 - 8, 7)
end