-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWaveFunctionCollapse.py
More file actions
60 lines (48 loc) · 1.52 KB
/
WaveFunctionCollapse.py
File metadata and controls
60 lines (48 loc) · 1.52 KB
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
import pygame
from ClassWorld import World
from ClassDrawWorld import DrawWorld
from Config import *
# INTERACTIVE = True
INTERACTIVE = True
INTERACTIVE_KEYPRESS = False
pygame.init()
clock = pygame.time.Clock()
displaySurface = pygame.display.set_mode((WORLD_X * TILESIZE * SCALETILE, WORLD_Y * TILESIZE * SCALETILE))
pygame.display.set_caption("Wave Function Collapse")
world = World(WORLD_X, WORLD_Y)
drawWorld = DrawWorld(world)
done = False
if not INTERACTIVE:
while not done:
result = world.waveFunctionCollapse()
if result == 0:
done = True
print("\nGenerated tile type map:")
for y in range(WORLD_Y):
row = []
for x in range(WORLD_X):
row.append(str(world.getType(x, y)))
print(" ".join(row))
drawWorld.update()
isRunning = True
while isRunning:
for event in pygame.event.get():
if event.type == pygame.QUIT:
isRunning = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
isRunning = False
if event.key == pygame.K_SPACE:
if INTERACTIVE and INTERACTIVE_KEYPRESS:
world.waveFunctionCollapse()
drawWorld.update()
if INTERACTIVE and not INTERACTIVE_KEYPRESS:
if not done:
result = world.waveFunctionCollapse()
if result == 0:
done = True
drawWorld.update()
drawWorld.draw(displaySurface)
pygame.display.flip()
clock.tick(60)
pygame.quit()