-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlighting.go
80 lines (70 loc) · 1.96 KB
/
lighting.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
package main
// --------------------------------------------------
// Lighting
// --------------------------------------------------
func CreateLighting(x, y int, light float32) {
if !IsValidPosition(x, y) {
return
}
newLight := light - GetLightBlockAmount(x, y)
if newLight <= WorldMap.GetDarkness(x, y) {
return
}
WorldMap.SetDarkness(x, y, newLight)
CreateLighting(x+1, y, newLight)
CreateLighting(x, y+1, newLight)
CreateLighting(x-1, y, newLight)
CreateLighting(x, y-1, newLight)
}
func CreateLightingLimit(x, y int, light float32, limit int) {
if limit < 1 {
return
}
if !IsValidPosition(x, y) {
return
}
newLight := light - GetLightBlockAmount(x, y)
if newLight <= WorldMap.GetDarkness(x, y) {
return
}
WorldMap.SetDarkness(x, y, newLight)
CreateLightingLimit(x+1, y, newLight, limit-1)
CreateLightingLimit(x, y+1, newLight, limit-1)
CreateLightingLimit(x-1, y, newLight, limit-1)
CreateLightingLimit(x, y-1, newLight, limit-1)
}
func FixLightingAt(x, y int) {
maxLight := float32(0)
if l := WorldMap.GetDarkness(x+1, y); l > maxLight {
maxLight = l - GetLightBlockAmount(x+1, y)
}
if l := WorldMap.GetDarkness(x, y+1); l > maxLight {
maxLight = l - GetLightBlockAmount(x, y+1)
}
if l := WorldMap.GetDarkness(x-1, y); l > maxLight {
maxLight = l - GetLightBlockAmount(x-1, y)
}
if l := WorldMap.GetDarkness(x, y-1); l > maxLight {
maxLight = l - GetLightBlockAmount(x, y-1)
}
WorldMap.SetDarkness(x, y, maxLight-GetLightBlockAmount(x, y))
WorldMap.UpdateBackBlockMaterial(x, y)
WorldMap.UpdateWorldBlockMaterial(x, y)
}
func GetLightBlockAmount(x, y int) float32 {
if WorldMap.GetWorldBlockID(x, y) == "00000" {
return GetBlock(WorldMap.GetBackBlockName(x, y)).LightBlock
}
return GetBlock(WorldMap.GetWorldBlockName(x, y)).LightBlock
}
func IsValidPosition(x, y int) bool {
if x > 0 && x < WorldWidth {
if y > 0 && y < WorldHeight {
if HeightMap[x]+100 < y {
return false
}
return true
}
}
return false
}