-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocks.go
432 lines (384 loc) · 14.4 KB
/
blocks.go
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
package main
import (
"fmt"
"rapidengine/material"
"strconv"
)
var BlockMap map[string]*Block
type Block struct {
Material *material.BasicMaterial
SaveColor [3]int
// Block orientations (16 possible):
// First character - Left/Right (L/R)
// Second character - Top/Bottom (T/B)
// Either can have A (all) or N (none)
OrientEnabled bool
OrientVariation int32
Orientations [16]*material.BasicMaterial
LightBlock float32
Durability float64
}
func (block *Block) GetMaterial(direction string) *material.BasicMaterial {
if block.OrientEnabled {
i, err := strconv.Atoi(OrientationsMap[direction])
if err != nil {
panic(err)
}
return block.Orientations[i]
}
return block.Material
}
func (block *Block) CreateOrientations(orientVariation int32) {
block.OrientEnabled = true
block.OrientVariation = orientVariation
for dir := range OrientationsMap {
newM := *block.Material
newM.AlphaMap = Engine.TextureControl.GetTexture(fmt.Sprintf("%v%s", orientVariation, dir))
newM.AlphaMapLevel = 1
i, _ := strconv.Atoi(OrientationsMap[dir])
block.Orientations[i] = &newM
}
}
func loadBlocks() {
// Main Blocks
Engine.TextureControl.NewTexture("./assets/blocks/dirt/dirt1.png", "dirt", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/grass/grass_g.png", "grass", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/stone/stone1.png", "stone", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/stone/stoneBrick.png", "stoneBrick", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/torch.png", "torch", "pixel")
// Back-Blocks
Engine.TextureControl.NewTexture("./assets/blocks/backblocks/backdirt8.png", "backdirt", "pixel")
// Tree
Engine.TextureControl.NewTexture("./assets/blocks/tree/treeTrunk3.png", "treeTrunk", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/tree/treeLeftRoot.png", "treeLeftRoot", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/tree/treeRightRoot.png", "treeRightRoot", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/tree/treeTrunk3.png", "treeBottomRoot", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/tree/leaves.png", "leaves", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/tree/treeBranchR1.png", "treeBranchR1", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/tree/treeBranchL1.png", "treeBranchL1", "pixel")
// Flora
Engine.TextureControl.NewTexture("./assets/blocks/grass/grasstop.png", "grasstop", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/grass/topGrass1_g.png", "topGrass1", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/grass/topGrass2_g.png", "topGrass2", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/grass/topGrass3_g.png", "topGrass3", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/nature/flower1_o.png", "flower1", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/nature/flower1_y.png", "flower2", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/nature/flower3.png", "flower3", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/nature/pebble.png", "pebble", "pixel")
// Transparency Maps
Engine.TextureControl.NewTexture("./assets/blocks/transparency/LN.png", "0LN", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/RN.png", "0RN", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/NT.png", "0NT", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/NB.png", "0NB", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/LA.png", "0LA", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/RA.png", "0RA", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/AT.png", "0AT", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/AB.png", "0AB", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/NN.png", "0NN", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/AA.png", "0AA", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/LT.png", "0LT", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/LB.png", "0LB", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/RT.png", "0RT", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/RB.png", "0RB", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/AN.png", "0AN", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/NA.png", "0NA", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/LN.png", "1LN", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/RN.png", "1RN", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/NT.png", "1NT", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/NB.png", "1NB", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/LA.png", "1LA", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/RA.png", "1RA", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/AT.png", "1AT", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/AB.png", "1AB", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/NN.png", "1NN", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/AA.png", "1AA", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/LT.png", "1LT", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/LB.png", "1LB", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/RT.png", "1RT", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/RB.png", "1RB", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/AN.png", "1AN", "pixel")
Engine.TextureControl.NewTexture("./assets/blocks/transparency/NA.png", "1NA", "pixel")
dirtMaterial := Engine.MaterialControl.NewBasicMaterial()
dirtMaterial.DiffuseLevel = 1
dirtMaterial.DiffuseMap = Engine.TextureControl.GetTexture("dirt")
stoneMaterial := Engine.MaterialControl.NewBasicMaterial()
stoneMaterial.DiffuseLevel = 1
stoneMaterial.DiffuseMap = Engine.TextureControl.GetTexture("stone")
stoneBrickMaterial := Engine.MaterialControl.NewBasicMaterial()
stoneBrickMaterial.DiffuseLevel = 1
stoneBrickMaterial.DiffuseMap = Engine.TextureControl.GetTexture("stoneBrick")
grassMaterial := Engine.MaterialControl.NewBasicMaterial()
grassMaterial.DiffuseLevel = 1
grassMaterial.DiffuseMap = Engine.TextureControl.GetTexture("grass")
backDirtMaterial := Engine.MaterialControl.NewBasicMaterial()
backDirtMaterial.DiffuseLevel = 1
backDirtMaterial.DiffuseMap = Engine.TextureControl.GetTexture("backdirt")
leavesMaterial := Engine.MaterialControl.NewBasicMaterial()
leavesMaterial.DiffuseLevel = 1
leavesMaterial.DiffuseMap = Engine.TextureControl.GetTexture("leaves")
treeRightRootMaterial := Engine.MaterialControl.NewBasicMaterial()
treeRightRootMaterial.DiffuseLevel = 1
treeRightRootMaterial.DiffuseMap = Engine.TextureControl.GetTexture("treeRightRoot")
treeLeftRootMaterial := Engine.MaterialControl.NewBasicMaterial()
treeLeftRootMaterial.DiffuseLevel = 1
treeLeftRootMaterial.DiffuseMap = Engine.TextureControl.GetTexture("treeLeftRoot")
treeTrunkMaterial := Engine.MaterialControl.NewBasicMaterial()
treeTrunkMaterial.DiffuseLevel = 1
treeTrunkMaterial.DiffuseMap = Engine.TextureControl.GetTexture("treeTrunk")
treeBottomRootMaterial := Engine.MaterialControl.NewBasicMaterial()
treeBottomRootMaterial.DiffuseLevel = 1
treeBottomRootMaterial.DiffuseMap = Engine.TextureControl.GetTexture("treeBottomRoot")
topGrass1Material := Engine.MaterialControl.NewBasicMaterial()
topGrass1Material.DiffuseLevel = 1
topGrass1Material.DiffuseMap = Engine.TextureControl.GetTexture("topGrass1")
topGrass2Material := Engine.MaterialControl.NewBasicMaterial()
topGrass2Material.DiffuseLevel = 1
topGrass2Material.DiffuseMap = Engine.TextureControl.GetTexture("topGrass2")
topGrass3Material := Engine.MaterialControl.NewBasicMaterial()
topGrass3Material.DiffuseLevel = 1
topGrass3Material.DiffuseMap = Engine.TextureControl.GetTexture("topGrass3")
treeBranchR1Material := Engine.MaterialControl.NewBasicMaterial()
treeBranchR1Material.DiffuseLevel = 1
treeBranchR1Material.DiffuseMap = Engine.TextureControl.GetTexture("treeBranchR1")
treeBranchL1Material := Engine.MaterialControl.NewBasicMaterial()
treeBranchL1Material.DiffuseLevel = 1
treeBranchL1Material.DiffuseMap = Engine.TextureControl.GetTexture("treeBranchL1")
flower1Material := Engine.MaterialControl.NewBasicMaterial()
flower1Material.DiffuseLevel = 1
flower1Material.DiffuseMap = Engine.TextureControl.GetTexture("flower1")
flower2Material := Engine.MaterialControl.NewBasicMaterial()
flower2Material.DiffuseLevel = 1
flower2Material.DiffuseMap = Engine.TextureControl.GetTexture("flower2")
flower3Material := Engine.MaterialControl.NewBasicMaterial()
flower3Material.DiffuseLevel = 1
flower3Material.DiffuseMap = Engine.TextureControl.GetTexture("flower3")
pebbleMaterial := Engine.MaterialControl.NewBasicMaterial()
pebbleMaterial.DiffuseLevel = 1
pebbleMaterial.DiffuseMap = Engine.TextureControl.GetTexture("pebble")
torchMaterial := Engine.MaterialControl.NewBasicMaterial()
torchMaterial.DiffuseLevel = 1
torchMaterial.DiffuseMap = Engine.TextureControl.GetTexture("torch")
grasstopMaterial := Engine.MaterialControl.NewBasicMaterial()
grasstopMaterial.DiffuseLevel = 1
grasstopMaterial.DiffuseMap = Engine.TextureControl.GetTexture("grasstop")
BlockMap = make(map[string]*Block)
BlockMap = map[string]*Block{
"sky": &Block{
Material: dirtMaterial,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"dirt": &Block{
Material: dirtMaterial,
LightBlock: 0.1,
SaveColor: [3]int{112, 85, 74},
Durability: 2.0,
},
"grass": &Block{
Material: grassMaterial,
LightBlock: 0.1,
SaveColor: [3]int{115, 173, 87},
Durability: 1.5,
},
"stone": &Block{
Material: stoneMaterial,
LightBlock: 0.15,
SaveColor: [3]int{116, 116, 116},
Durability: 2.5,
},
"backdirt": &Block{
Material: backDirtMaterial,
LightBlock: 0.035,
SaveColor: [3]int{70, 48, 38},
},
"leaves": &Block{
Material: leavesMaterial,
LightBlock: 0,
SaveColor: [3]int{91, 141, 68},
Durability: 1.0,
},
"treeRightRoot": &Block{
Material: treeRightRootMaterial,
LightBlock: 0,
SaveColor: [3]int{87, 66, 59},
},
"treeLeftRoot": &Block{
Material: treeLeftRootMaterial,
LightBlock: 0,
SaveColor: [3]int{87, 66, 59},
},
"treeTrunk": &Block{
Material: treeTrunkMaterial,
LightBlock: 0,
SaveColor: [3]int{87, 66, 59},
},
"treeBottomRoot": &Block{
Material: treeBottomRootMaterial,
LightBlock: 0,
SaveColor: [3]int{87, 66, 59},
},
"topGrass1": &Block{
Material: topGrass1Material,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"topGrass2": &Block{
Material: topGrass2Material,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"topGrass3": &Block{
Material: topGrass3Material,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"treeBranchR1": &Block{
Material: treeBranchR1Material,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"treeBranchL1": &Block{
Material: treeBranchL1Material,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"flower1": &Block{
Material: flower1Material,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"flower2": &Block{
Material: flower2Material,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"flower3": &Block{
Material: flower3Material,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"pebble": &Block{
Material: pebbleMaterial,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"torch": &Block{
Material: torchMaterial,
LightBlock: 0,
SaveColor: [3]int{107, 185, 240},
},
"stoneBrick": &Block{
Material: stoneBrickMaterial,
LightBlock: 0.15,
SaveColor: [3]int{116, 116, 116},
},
"grasstop": &Block{
Material: grasstopMaterial,
LightBlock: 0.15,
SaveColor: [3]int{116, 116, 116},
},
}
BlockMap["dirt"].CreateOrientations(0)
BlockMap["grass"].CreateOrientations(1)
BlockMap["stone"].CreateOrientations(0)
//BlockMap["stoneBrick"].CreateOrientations(0)
BlockMap["leaves"].CreateOrientations(0)
BlockMap["backdirt"].CreateOrientations(1)
InverseOrientationMap = make(map[string]string)
for d, o := range OrientationsMap {
InverseOrientationMap[o] = d
}
}
func GetBlock(name string) *Block {
return BlockMap[name]
}
func GetBlockName(id int) string {
for n, index := range NameToID {
ind, _ := strconv.Atoi(index)
if ind == id {
return n
}
}
return "sky"
}
var NameToID = map[string]string{
"sky": "000",
"dirt": "001",
"grass": "002",
"stone": "003",
"backdirt": "004",
"leaves": "005",
"treeRightRoot": "006",
"treeLeftRoot": "007",
"treeTrunk": "008",
"treeBottomRoot": "009",
"topGrass1": "010",
"topGrass2": "011",
"topGrass3": "012",
"treeBranchR1": "013",
"treeBranchL1": "014",
"flower1": "015",
"flower2": "016",
"flower3": "017",
"pebble": "018",
"torch": "019",
"stoneBrick": "020",
"grasstop": "021",
}
var IDToName = map[string]string{
"000": "sky",
"001": "dirt",
"002": "grass",
"003": "stone",
"004": "backdirt",
"005": "leaves",
"006": "treeRightRoot",
"007": "treeLeftRoot",
"008": "treeTrunk",
"009": "treeBottomRoot",
"010": "topGrass1",
"011": "topGrass2",
"012": "topGrass3",
"013": "treeBranchR1",
"014": "treeBranchL1",
"015": "flower1",
"016": "flower2",
"017": "flower3",
"018": "pebble",
"019": "torch",
"020": "stoneBrick",
"021": "grasstop",
}
func GetIDFromName(name string) string {
return NameToID[name]
}
func GetNameFromID(id string) string {
return IDToName[id]
}
var OrientationsMap = map[string]string{
"LN": "00",
"RN": "01",
"NT": "02",
"NB": "03",
"LA": "04",
"RA": "05",
"AT": "06",
"AB": "07",
"NN": "08",
"AA": "09",
"LT": "10",
"LB": "11",
"RT": "12",
"RB": "13",
"AN": "14",
"NA": "15",
}
var InverseOrientationMap map[string]string
func GetOrientationFromID(id string) string {
for orientation, bid := range OrientationsMap {
if bid == id {
return orientation
}
}
return "NN"
}