-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map.gd
76 lines (52 loc) · 1.43 KB
/
Map.gd
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
extends Node2D
const wfc = preload("res://wfc_interface_test.gd");
var centerpoS: Vector2 = Vector2(0,0);
var mapW: int = 50;
var mapH: int = 50;
var tileSize: int = 10;
var data: Array[int] = [];
# Called when the node enters the scene tree for the first time.
func _ready():
data.resize(mapW*mapH);
data.fill(-1);
#TODO: MOVE THIS!
wfc.init(mapW*mapH);
#data = wfc.wfc_interface_test(mapW,mapH);
#data = wfc.wfc_v1(mapW,mapH, data, false);
startInterval();
#printDeck();
pass # Replace with function body.
func _draw():
#print('data size: ', data.size());
#print('data: ', data);
for j in mapH:
for i in mapW:
var color = Color(1,.8,.8);
var index = j*mapW+i;
var v = data[index];
#print('index: ', index);
if v == 0:
color = Color(1,1,1);
if v == 1:
color = Color(0,0,0);
if v == 2:
color = Color(1,0,0);
if v == 3:
color = Color(0,1,0);
if v == 4:
color = Color(0,0,1);
#print(index, ' | ', i, ' ', j, ' ', v, ' ', color);
draw_rect(Rect2(i*tileSize, j*tileSize, tileSize, tileSize), color, true);
func nextStep():
data = wfc.wfc_v1(mapW,mapH, data, true);
queue_redraw();
func startInterval():
var _timer = Timer.new();
add_child(_timer)
_timer.connect("timeout", nextStep)
_timer.set_wait_time(0.05)
_timer.set_one_shot(false) # Make sure it loops
_timer.start()
func _input(event):
if (event.is_pressed()):
nextStep()