-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_terrain.py
77 lines (54 loc) · 1.49 KB
/
show_terrain.py
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
# tests terrain generator
from __future__ import division
import terragen, pygame, sys;
Biomes = terragen.Biomes
pygame.init()
w = 21
h = 110
squareSize = 7
approach = 30
screenWidth = w*squareSize
screenHeight = h*squareSize
screen = pygame.display.set_mode( (screenWidth,screenHeight) );
def Main():
map = terragen.Map(w, h, approach//squareSize)
DrawMap(map)
screen.fill((128,0,255), ((0,screenHeight-approach), (screenWidth,2)))
pygame.display.flip()
while True:
ProcessEvents()
def DrawMap(map):
for row in map.grid:
for tile in row:
if tile.biome == Biomes.Ocean:
color = (0,255,255)#(0,255-(map.waterLevel-tile.height)*255,255)
elif tile.biome == Biomes.Sand:
color = (255,255,200)
elif tile.biome == Biomes.Grass:
color = (0,255,0)
elif tile.biome == Biomes.Trees:
color = (0,200,0)
elif tile.biome == Biomes.Dirt:
color = (128,64,0)
elif tile.biome == Biomes.Hill:
color = (100,60,20)
elif tile.biome == Biomes.Gap:
color = (0,0,0)
elif tile.biome == Biomes.Mountain:
color = (128,128,128)
elif tile.biome == Biomes.Snow:
color = (255,255,255)
elif tile.biome == Biomes.DeepOcean:
color = (0,0,255)
else:
color = (255,0,255)
try:
screen.fill(color, ((tile.x*squareSize, tile.y*squareSize), (squareSize,squareSize)))
except TypeError:
print "bad color:", color
return
def ProcessEvents():
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
Main()