Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tgw3ff
2021-SP-CS4096-97-TDG
Commits
22c7b79a
Commit
22c7b79a
authored
Mar 29, 2021
by
tgw3ff
Browse files
Tidy Up Tilemap.gd
parent
a5ed8d1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
CS 4096-97 Top Down Game/src/Tilemap.gd
View file @
22c7b79a
...
...
@@ -8,6 +8,25 @@ export var height = 40
var
grid
=
[]
# Called when the node enters the scene tree for the first time.
func
_ready
():
generate_map
()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func
_process
(
delta
):
pass
# Repkace with function body.
# # #####
## ## ## ##### # # ###### # # ###### ##### ## ##### #### #####
# # # # # # # # # # ## # # # # # # # # # # #
# # # # # # # # #### ##### # # # ##### # # # # # # # # #
# # ###### ##### # # # # # # # ##### ###### # # # #####
# # # # # # # # # ## # # # # # # # # # #
# # # # # ##### ###### # # ###### # # # # # #### # #
# Prepares grid by sizing it and filling with random 1's or 0's (according to fill_percent)
func
initialize_grid
():
randomize
()
...
...
@@ -79,22 +98,12 @@ func print_get_cell_autotile_coord(x, y):
print
(
"Cell x
%s
y
%s
=
%s
,
%s
"
%
[
x
,
y
,
get_cell
(
x
,
y
),
get_cell_autotile_coord
(
x
,
y
)])
# Called when the node enters the scene tree for the first time.
func
_ready
():
generate_map
()
# Generate a new map on keypress
func
_unhandled_input
(
event
):
if
event
.
is_action_pressed
(
"generate_map"
):
generate_map
()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func
_process
(
delta
):
pass
# Repkace with function body.
func
get_value
(
x
,
y
):
# If it is outside the grid, clamp the coordinates,
# effectively returning the value of the nearest element in the grid.
...
...
@@ -107,6 +116,15 @@ func is_wall(x, y):
return
get_value
(
x
,
y
)
==
1
####### ######
# # # ###### # # # ## #### ###### #####
# # # # # # # # # # # # # #
# # # ##### ###### # # # # ##### # #
# # # # # # ###### # # #####
# # # # # # # # # # # # #
# # ###### ###### # ###### # # #### ###### # #
func
update_tile
(
x
,
y
):
var
index
:
=
-
1
var
autotile
:
=
Vector2
.
ZERO
...
...
@@ -134,6 +152,7 @@ func update_tile(x, y):
# # # #
# o . o
# (where 'o' means we don't care about the value of that neighbor.)
#
#
# - Inner corner - Exactly one diagonal neighbor is non-wall, and the
# rest are walls:
...
...
@@ -147,6 +166,22 @@ func update_tile(x, y):
# o # #
# . # #
# . . o
# - After some tests, this pattern was also found to be a valid
# outer corner arrangement in the case that an opposite facing
# outer corner is adjecent to the corner in question:
# o # #
# . # #
# # . o
# - Thus, this configuration will be used to determine outer corners
# instead:
# o # #
# . # #
# o . o
# - Isolated wall - This configuration is a catch all for any walls that
# do not fall into the previous configurations:
# o o o
# o # o
# o o o
#
# These neighbor states are flattened into an array of 8 booleans,
# starting with the north neighbor and going around clockwise.
...
...
@@ -169,7 +204,7 @@ func update_tile(x, y):
match
[
n
,
ne
,
e
,
se
,
s
,
sw
,
w
,
nw
]:
[
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
]:
# Surrounded by walls - revert to a blank tile.
index
=
-
1
autotile
=
Vector2
(
4
,
2
)
[
true
,
_
,
true
,
_
,
false
,
_
,
true
,
_
]:
# North-facing straight
autotile
=
Vector2
(
1
,
0
)
...
...
@@ -194,21 +229,21 @@ func update_tile(x, y):
[
true
,
true
,
true
,
false
,
true
,
true
,
true
,
true
]:
# North-west inward
autotile
=
Vector2
(
0
,
0
)
[
true
,
true
,
true
,
_
,
false
,
false
,
false
,
_
]:
[
true
,
true
,
true
,
_
,
false
,
_
,
false
,
_
]:
# North-east outward
autotile
=
Vector2
(
3
,
1
)
[
false
,
_
,
true
,
true
,
true
,
_
,
false
,
false
]:
[
false
,
_
,
true
,
true
,
true
,
_
,
false
,
_
]:
# South-east outward
autotile
=
Vector2
(
3
,
0
)
[
false
,
false
,
false
,
_
,
true
,
true
,
true
,
_
]:
[
false
,
_
,
false
,
_
,
true
,
true
,
true
,
_
]:
# South-west outward
autotile
=
Vector2
(
4
,
0
)
[
true
,
_
,
false
,
false
,
false
,
_
,
true
,
true
]:
[
true
,
_
,
false
,
_
,
false
,
_
,
true
,
true
]:
# North-west outward
autotile
=
Vector2
(
4
,
1
)
_
:
print
(
'
Missing tile for '
,
x
,
'
,'
,
y
)
autotile
=
Vector2
(
1
,
1
)
autotile
=
Vector2
(
3
,
2
)
if
grid
[
x
][
y
]
==
0
:
index
=
0
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment