-
Notifications
You must be signed in to change notification settings - Fork 0
/
room_class.gd
59 lines (43 loc) · 1.17 KB
/
room_class.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
extends Node
# A graph based representation of the rooms
class Room:
var Type: String
var RoomFile: String
var X: int
var Y: int
var Upgrade: String
var UpgradePrice: int
var UpgradeTaken: bool
# Neighbooring rooms
var Neighboors: Array
var Cleared: bool
var sprite: Sprite2D
static func create(type: String, x: int, y: int) -> Room:
var room = Room.new()
room.Type = type
room.X = x
room.Y = y
room.Neighboors = [null, null, null, null]
room.Cleared = false
return room
func allRooms() -> Array[Room]:
var visited: Array[Room]
var stack = [self]
while stack.size() > 0:
var currentRoom = stack.pop_back()
if currentRoom in visited:
continue
visited.append(currentRoom)
# Check each neighboor room
for i in range(4):
var r = currentRoom.Neighboors[i]
if r && r not in visited:
stack.append(r)
return visited
# Create a new room that neighboors this room
func newRoom(dir: int, x: int, y: int, type: String) -> Room:
var newRoom: Room
Neighboors[dir] = Room.create(type, x, y)
var oppositeDir = (dir + 2) % 4
Neighboors[dir].Neighboors[oppositeDir] = self
return Neighboors[dir]