-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerateWorld.py
53 lines (39 loc) · 1.48 KB
/
generateWorld.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
import random
import os
GROUND = -2
WALL_HEIGHT = 2
WORLD_WIDTH = 10 # width in both directions from start
WORLD_DEPTH = 10 # depth in both directions from start
def saveWorld(locations, filename):
o = open("maps" + os.sep + filename, 'w')
for location in locations:
o.write("%d %d %d %s\n" % location)
o.close()
def generateGrassTower(locations):
randomX = random.randrange(-WORLD_WIDTH+1, WORLD_WIDTH-1)
randomZ = random.randrange(-WORLD_DEPTH+1, WORLD_DEPTH-1)
for i in range(1, 4):
locations.append((randomX, GROUND+i, randomZ, "GRASS"))
return locations
def generateFlatWorld(locations):
# Make the flat ground
for i in range(-WORLD_WIDTH, WORLD_WIDTH):
for j in range(-WORLD_DEPTH, WORLD_DEPTH):
locations.append((i, GROUND, j, "STONE"))
# Put walls around the outside
for i in range(-2, WALL_HEIGHT):
for j in range(-WORLD_DEPTH, WORLD_DEPTH):
locations.append((-WORLD_WIDTH, i, j, "STONE"))
locations.append((WORLD_WIDTH, i, j, "STONE"))
for j in range(-WORLD_WIDTH, WORLD_WIDTH):
locations.append((j, i, -WORLD_DEPTH, "STONE"))
locations.append((j, i, WORLD_DEPTH, "STONE"))
return locations
def generateGameWorld(filename):
locs = []
locs = generateFlatWorld(locs)
for i in range(10):
locs = generateGrassTower(locs)
saveWorld(locs, filename)
if __name__=="__main__":
generateGameWorld("test.txt")