-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.gd
77 lines (54 loc) · 1.92 KB
/
test.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
77
extends Node2D
var dun: Dungeon
export (Vector2) var min_size = Vector2(80, 80)
export (Vector2) var max_size = Vector2(100, 100)
export (int) var number_of_rooms = 11
export (Vector2) var min_room_size = Vector2(8,8)
export (Vector2) var max_room_size = Vector2(14,15)
var font = DynamicFont.new()
func _ready():
var rng = RandomNumberGenerator.new()
rng.randomize()
dun = Dungeon.new(min_size, max_size, number_of_rooms, min_room_size, max_room_size, rng)
font.font_data = load("res://fonts/OfficialBook.ttf")
update()
var cell_size = 11
var base_offset = Vector2(20, 10)
var offset = base_offset
func _draw():
var colors = [Color(0,0,0,0), Color(0, 0.98, 0.32), Color(0.88, 0.78, 0), Color(0.9, 0.9, 0.14)]
for x in range(dun.map.size.x):
for y in range(dun.map.size.y):
draw_rect(Rect2(pointToScreen(Vector2(x, y)), Vector2(cell_size, cell_size)), colors[dun.map.matrix[y][x]])
for i in range(len(dun.map.room_centers)):
draw_string(font, pointToScreen(dun.map.room_centers[i]), str(i), Color(0,0,0))
func pointToScreen(point: Vector2) -> Vector2:
return offset + point*cell_size
var dragging = false
var pos: Vector2
func _input(event):
if event.is_action_pressed("restart"):
var rng = RandomNumberGenerator.new()
rng.randomize()
dun = Dungeon.new(min_size, max_size, number_of_rooms, min_room_size, max_room_size, rng)
update()
if event.is_action_pressed("scroll_up") and event.control:
cell_size += 1
font.size = cell_size + 15
update()
elif event.is_action_pressed("scroll_down") and event.control:
if cell_size > 1:
cell_size -= 1
font.size = cell_size + 15
update()
if event.is_action_pressed("mouse_click"):
dragging = true
pos = event.position
if event.is_action_released("mouse_click"):
base_offset = offset
dragging = false
func _process(delta):
if dragging:
var current = get_viewport().get_mouse_position()
offset = base_offset + current - pos
update()