-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntity.elm
More file actions
256 lines (183 loc) · 3.87 KB
/
Entity.elm
File metadata and controls
256 lines (183 loc) · 3.87 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
module Entity exposing (Entity(..), view, describe, position, wall, floor, coin, player, monster, door, upstairs, downstairs, memory, entrance, crystal, imaginary, isCreature, item, grass)
import Point exposing (Point)
import Item
import Creature
import Warrior
import String
import Graphics
import Palette
import Language exposing (Language)
import Svg
-- types
type Entity = Monster Creature.Model
| Player Warrior.Model
| Wall Point
| Coin Point
| Floor Point
| Door Point
| StairsUp Point
| StairsDown Point
| Memory Entity
| Entrance Bool Point
| Imaginary Entity
| Item Item.Item
| Grass Point
-- constructors
wall point =
Wall point
coin point =
Coin point
floor point =
Floor point
door point =
Door point
player warrior =
Player warrior
monster creature =
Monster creature
upstairs point =
StairsUp point
downstairs point =
StairsDown point
memory entity =
Memory entity
crystal pt =
Item (Item.init pt Item.crystal -1)
entrance open pt =
Entrance open pt
imaginary entity =
Imaginary entity
item item' =
Item item'
grass pt =
Grass pt
isCreature entity =
case entity of
Monster _ ->
True
_ ->
False
-- helpers
describe : Language -> Language -> Entity -> String
describe vocab language entity =
case entity of
Monster creature ->
Creature.describe creature
Player player ->
"a nameless warrior"
Wall _ ->
"a sturdy wall"
Coin _ ->
"a golden coin"
Floor _ ->
"a cobblestone floor"
Door _ ->
"a creaky door"
Grass _ ->
"a patch of grass"
StairsUp _ ->
"an upward-curving staircase"
StairsDown _ ->
"a downward-curving staircase"
Memory entity ->
"You saw " ++ (describe vocab language entity) ++ " here"
Imaginary entity ->
"You imagine there is " ++ (describe vocab language entity) ++ " here"
Entrance open _ ->
if open then
"an open heavy metal gateway and daylight beyond"
else
"a closed heavy metal gateway"
Item item ->
Item.describe vocab language item
-- view
view : Entity -> Svg.Svg a
view entity =
Graphics.render (glyph entity) (position entity) (color entity)
color : Entity -> String
color entity =
case entity of
Player _ ->
Palette.bright
Monster _ ->
Palette.dim
Item _ ->
Palette.secondaryLight
Coin _ ->
Palette.alert
Wall _ ->
Palette.dim
Floor _ ->
Palette.primary
Entrance open _ ->
Palette.bright
Door _ ->
Palette.tertiaryLight
StairsUp _ ->
Palette.bright
StairsDown _ ->
Palette.bright
Grass _ ->
Palette.accent
Memory _ ->
Palette.primary' 2 0.5
Imaginary _ ->
Palette.secondary' 2 0.5
position : Entity -> Point.Point
position entity =
case entity of
Monster creature ->
creature.position
Player player ->
player.position
Door point ->
point
Wall point ->
point
Coin point ->
point
Floor point ->
point
StairsUp point ->
point
StairsDown point ->
point
Entrance _ pt ->
pt
Memory entity ->
position entity
Imaginary entity ->
position entity
Item item ->
item.position
Grass pt ->
pt
glyph : Entity -> String
glyph entity =
case entity of
Monster creature ->
String.fromChar creature.glyph
Player _ ->
"@"
Wall _ ->
"#"
Coin _ ->
"*"
Floor _ ->
"."
Door _ ->
"+"
StairsUp _ ->
">"
StairsDown _ ->
"<"
Memory e ->
glyph e
Imaginary e ->
glyph e
Entrance _ _ ->
"="
Grass _ ->
"\""
Item item ->
Item.glyph item