ChessBuilder/addons/Chess/Scripts/Queen.gd

69 lines
1.7 KiB
GDScript

@tool
extends Pawn
class_name Queen
func _ready():
self.texture = load("res://addons/Chess/Textures/WQueen.svg")
Points = 9
func _process(_delta):
if Item_Color != Temp_Color:
Temp_Color = Item_Color
if Item_Color == 0:
self.texture = load("res://addons/Chess/Textures/WQueen.svg")
elif Item_Color == 1:
self.texture = load("res://addons/Chess/Textures/BQueen.svg")
func getValidMoves(board_flow, current_location: String) -> Dictionary:
var moves = {
"regular_moves": [],
"special_moves": []
}
var loc = current_location.split("-")
var x = int(loc[0])
var y = int(loc[1])
# Queen combines rook (straight) and bishop (diagonal) movements
# Straight movements
var straight_dirs = [[0,1], [0,-1], [1,0], [-1,0]]
for dir in straight_dirs:
var curr_x = x
var curr_y = y
while true:
curr_x += dir[0]
curr_y += dir[1]
var new_loc = str(curr_x) + "-" + str(curr_y)
if !is_valid_cell(board_flow, new_loc):
break
if can_move_to_cell(board_flow, new_loc):
moves.regular_moves.append(new_loc)
elif can_move_to_cell(board_flow, new_loc, true):
moves.regular_moves.append(new_loc)
break
else:
break
# Diagonal movements
var diagonal_dirs = [[1,1], [1,-1], [-1,1], [-1,-1]]
for dir in diagonal_dirs:
var curr_x = x
var curr_y = y
while true:
curr_x += dir[0]
curr_y += dir[1]
var new_loc = str(curr_x) + "-" + str(curr_y)
if !is_valid_cell(board_flow, new_loc):
break
if can_move_to_cell(board_flow, new_loc):
moves.regular_moves.append(new_loc)
elif can_move_to_cell(board_flow, new_loc, true):
moves.regular_moves.append(new_loc)
break
else:
break
return moves