-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCell.gd
36 lines (25 loc) · 776 Bytes
/
Cell.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
class_name Cell
extends Spatial
enum {W = 1, E = 2, N = 4, S = 8}
var _free := 0
func can_go(dir: int) -> bool:
return _free & dir == dir
func remove_walls(walls: int) -> void:
if walls & W > 0 and not can_go(W):
$WallW.queue_free()
_free |= W
if walls & E > 0 and not can_go(E):
$WallE.queue_free()
_free |= E
if walls & N > 0 and not can_go(N):
$WallN.queue_free()
_free |= N
if walls & S > 0 and not can_go(S):
$WallS.queue_free()
_free |= S
func set_color(color: Color) -> void:
for wall in [$WallE/MeshInstance, $WallN/MeshInstance, $WallS/MeshInstance, $WallW/MeshInstance]:
if wall:
var material: SpatialMaterial = wall.get_surface_material(0).duplicate()
material.albedo_color = color
wall.set_surface_material(0, material)