1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-22 05:23:14 +00:00

Made the isometric grid code a bit more clear with comments

This commit has no impact on the logic itself, just makes the code a bit easier to understand, hopefully.
This commit is contained in:
OverloadedOrama 2020-08-16 01:21:42 +03:00
parent ff54d2db8e
commit b998c87bcc

View file

@ -264,34 +264,53 @@ func draw_grid(grid_type : int) -> void:
# Doesn't work properly yet # Doesn't work properly yet
if grid_type == Global.Grid_Types.ISOMETRIC || grid_type == Global.Grid_Types.ALL: if grid_type == Global.Grid_Types.ISOMETRIC || grid_type == Global.Grid_Types.ALL:
var approx_30_degrees = 26.565
var approx_60_degrees = 90 - 26.565
var prev_x := 0 var prev_x := 0
var prev_y := 0 var prev_y := 0
# Draw lines starting from the left side, facing down to the right
for y in range(0, size.y + 1, Global.grid_width): for y in range(0, size.y + 1, Global.grid_width):
var yy1 = y + size.y * tan(deg2rad(26.565)) # 30 degrees var yy1 = y + size.y * tan(deg2rad(approx_30_degrees))
# End points touch the right side of the canvas, but not the entire of it
if yy1 <= (size.y + 0.01): if yy1 <= (size.y + 0.01):
draw_line(Vector2(location.x, y), Vector2(size.x, yy1),Global.grid_color) draw_line(Vector2(location.x, y), Vector2(size.x, yy1),Global.grid_color)
# End points touch the bottom side of the canvas
else: else:
var xx1 = (size.x - y) * tan(deg2rad(90 - 26.565)) # 60 degrees var xx1 = (size.x - y) * tan(deg2rad(approx_60_degrees))
draw_line(Vector2(location.x, y), Vector2(xx1, size.y), Global.grid_color) draw_line(Vector2(location.x, y), Vector2(xx1, size.y), Global.grid_color)
# Draw lines starting from the left side, facing up to the right
for y in range(0, size.y + 1, Global.grid_height): for y in range(0, size.y + 1, Global.grid_height):
var xx2 = y * tan(deg2rad(90 - 26.565)) # 60 degrees var xx2 = y * tan(deg2rad(approx_60_degrees))
# End points touch the upper side of the canvas
if xx2 <= (size.x + 0.01): if xx2 <= (size.x + 0.01):
draw_line(Vector2(location.x, y), Vector2(xx2, location.y), Global.grid_color) draw_line(Vector2(location.x, y), Vector2(xx2, location.y), Global.grid_color)
prev_y = location.y prev_y = location.y
# End points touch the right side of the canvas, but not the entire of it
else: else:
var distance = (xx2 - prev_x) / 2 var distance = (xx2 - prev_x) / 2
#var yy2 = (size.y - y) * tan(deg2rad(26.565)) # 30 degrees #var yy2 = (size.y - y) * tan(deg2rad(approx_30_degrees))
var yy2 = prev_y + distance var yy2 = prev_y + distance
draw_line(Vector2(location.x, y), Vector2(size.x, yy2), Global.grid_color) draw_line(Vector2(location.x, y), Vector2(size.x, yy2), Global.grid_color)
prev_y = yy2 prev_y = yy2
prev_x = xx2 prev_x = xx2
# Draw lines from the top side, facing down to the right
# End points touch the right side of the canvas, but not the entire of it
# Problematic when size.y < size.x / 2
for x in range(0, size.x, Global.grid_width * 2): for x in range(0, size.x, Global.grid_width * 2):
if x == 0: if x == 0:
continue continue
var yy1 = (size.x - x) * tan(deg2rad(26.565)) # 30 degrees var yy1 = (size.x - x) * tan(deg2rad(approx_30_degrees))
draw_line(Vector2(x, location.y), Vector2(size.x, yy1), Global.grid_color) draw_line(Vector2(x, location.y), Vector2(size.x, yy1), Global.grid_color)
# Draw lines from the bottom side, facing up to the right.
# End points touch the right side of the canvas, but not the entire of it
# Problematic when size.y < size.x / 2
for x in range(0, size.x, Global.grid_height * 2): for x in range(0, size.x, Global.grid_height * 2):
var yy2 = (size.x - x) * tan(deg2rad(26.565)) # 30 degrees var yy2 = (size.x - x) * tan(deg2rad(approx_30_degrees))
draw_line(Vector2(x, size.y), Vector2(size.x, size.y - yy2), Global.grid_color) draw_line(Vector2(x, size.y), Vector2(size.x, size.y - yy2), Global.grid_color)