cleaned up game tile size ref

This commit is contained in:
2ManyProjects 2025-02-08 17:01:01 -06:00
parent fc9768d622
commit 7e12f1dc22
2 changed files with 8 additions and 6 deletions

View file

@ -45,6 +45,7 @@ var darkStyle = null
var highlightStyle = null
func _ready() -> void:
add_to_group("ChessGame")
DisplayServer.window_set_size(Vector2i(windowXSize, windowYSize))
initializeGame()
initializeTiles()

View file

@ -97,26 +97,27 @@ func animate_movement(target_position: Vector2, duration: float = 0.5) -> void:
var total_delta = target_position - start_pos
var mid_pos: Vector2
var cell_delta_x = int(total_delta.x / 50)
var cell_delta_y = int(total_delta.y / 50)
var game = get_tree().get_first_node_in_group("ChessGame") as ChessGame
var cell_delta_x = int(total_delta.x / game.tileXSize)
var cell_delta_y = int(total_delta.y / game.tileYSize)
if abs(cell_delta_x) > abs(cell_delta_y):
# Moving more horizontally ([-2, ±1])
mid_pos = Vector2(
start_pos.x + (cell_delta_x * 50),
start_pos.x + (cell_delta_x * game.tileXSize),
start_pos.y
)
else:
# Moving more vertically ([±1, -2])
mid_pos = Vector2(
start_pos.x,
start_pos.y + (cell_delta_y * 50)
start_pos.y + (cell_delta_y * game.tileYSize)
)
# First move (longer distance)
tween.tween_property(self, "global_position", mid_pos, duration/2)
tween.tween_property(self, "global_position", mid_pos, duration / 3 * 2)
# Second move (shorter distance)
tween.tween_property(self, "global_position", target_position, duration/2)
tween.tween_property(self, "global_position", target_position, duration / 3 * 1)
await tween.finished
z_index = 0