|
@@ -0,0 +1,51 @@
|
|
1
|
+import random, noise from love.math
|
|
2
|
+
|
|
3
|
+class World
|
|
4
|
+ new: =>
|
|
5
|
+ @generateSeed!
|
|
6
|
+ get: (x, y) =>
|
|
7
|
+ map = @map
|
|
8
|
+ unless map[x]
|
|
9
|
+ map[x] = {}
|
|
10
|
+ unless map[x][y]
|
|
11
|
+ p = @precipitation(x, y)
|
|
12
|
+ -- map[x][y] = { 1 - p, 1 - p, 1, 1 }
|
|
13
|
+ h = @height(x, y)
|
|
14
|
+ -- map[x][y] = { h, h, h, 1 }
|
|
15
|
+ t = @temperature(x, y)
|
|
16
|
+ -- map[x][y] = { t, 0, 0, 1 }
|
|
17
|
+ map[x][y] = { t, h, p, 1 }
|
|
18
|
+ return map[x][y]
|
|
19
|
+ generateSeed: =>
|
|
20
|
+ @map = {}
|
|
21
|
+ @precipitationXOffset = random! * 256
|
|
22
|
+ @precipitationYOffset = random! * 256
|
|
23
|
+ @precipitationScale = random! * 0.009 + 0.001
|
|
24
|
+ @temperatureXOffset = random! * 256
|
|
25
|
+ @temperatureYOffset = random! * 256
|
|
26
|
+ @temperatureScale = random! * 0.009 + 0.001
|
|
27
|
+ @heightXOffset = random! * 256
|
|
28
|
+ @heightYOffset = random! * 256
|
|
29
|
+ @heightScale = random! * 0.009 + 0.001
|
|
30
|
+ @heightAmplitude = random! * 0.9 + 0.1 -- max: 1, min: 0.1
|
|
31
|
+ @heightXOffset2 = random! * 256
|
|
32
|
+ @heightYOffset2 = random! * 256
|
|
33
|
+ @heightScale2 = random! * 0.012 + 0.008
|
|
34
|
+ @heightAmplitude2 = random! * 0.09 + 0.01 -- max: 0.1, min: 0.01
|
|
35
|
+ @heightXOffset3 = random! * 256
|
|
36
|
+ @heightYOffset3 = random! * 256
|
|
37
|
+ @heightScale3 = random! * 0.092 + 0.01
|
|
38
|
+ @heightAmplitude3 = random! * 0.009 + 0.001 -- max: 0.01, min: 0.001
|
|
39
|
+ precipitation: (x, y) =>
|
|
40
|
+ return noise((x + @precipitationXOffset) * @precipitationScale, (y + @precipitationYOffset) * @precipitationScale)
|
|
41
|
+ temperature: (x, y) =>
|
|
42
|
+ return noise((x + @temperatureXOffset) * @temperatureScale, (y + @temperatureYOffset) * @temperatureScale)
|
|
43
|
+ height: (x, y) =>
|
|
44
|
+ h = noise((x + @heightXOffset) * @heightScale, (y + @heightYOffset) * @heightScale) * @heightAmplitude +
|
|
45
|
+ noise((x + @heightXOffset2) * @heightScale2, (y + @heightYOffset2) * @heightScale2) * @heightAmplitude2 +
|
|
46
|
+ noise((x + @heightXOffset3) * @heightScale3, (y + @heightYOffset3) * @heightScale3) * @heightAmplitude3
|
|
47
|
+ -- max: 1.11, min: 0.111
|
|
48
|
+ -- slope = (output_end - output_start) / (input_end - input_start)
|
|
49
|
+ -- output = output_start + slope * (input - input_start)
|
|
50
|
+ slope = 1 / (1.11 - 0.111)
|
|
51
|
+ return slope * (h - 0.111)
|