diff --git a/scripts/Pawn.gd b/scripts/Pawn.gd index 13dc0b02b4c696c1ff5525a9f67fb8e1c04f1d44..bd1c3047092618d8c54a1c48028dad5e36624cf7 100644 --- a/scripts/Pawn.gd +++ b/scripts/Pawn.gd @@ -2,8 +2,13 @@ extends Piece class_name Pawn +enum Upgrade { DOUBLE_MOVE, DIAGONAL_MOVE } + func _init(is_white: bool, position: Vector2): super._init(is_white, position) + # Testing upgrades + upgrades.append(Upgrade.DOUBLE_MOVE) + upgrades.append(Upgrade.DIAGONAL_MOVE) func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]: @@ -13,7 +18,7 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]: if is_white: # Check if the pawn is at the starting position - if y > 6 and board_state[x][y - 1] == null: + if (y == 7 or Upgrade.DOUBLE_MOVE in upgrades) and board_state[x][y - 1] == null: valid_moves.append(Vector2(x, y - 1)) if board_state[x][y - 2] == null: valid_moves.append(Vector2(x, y - 2)) @@ -25,6 +30,13 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]: valid_moves.append(Vector2(x - 1, y - 1)) if x < 7 and y > 0 and board_state[x + 1][y - 1] != null and not board_state[x + 1][y - 1].is_white: valid_moves.append(Vector2(x + 1, y - 1)) + + # Check if the pawn can move diagonally without capturing + if Upgrade.DIAGONAL_MOVE in upgrades: + if x > 0 and y > 0 and board_state[x - 1][y - 1] == null: + valid_moves.append(Vector2(x - 1, y - 1)) + if x < 7 and y > 0 and board_state[x + 1][y - 1] == null: + valid_moves.append(Vector2(x + 1, y - 1)) else: if y < 1 and board_state[x][y + 1] == null: diff --git a/scripts/Piece.gd b/scripts/Piece.gd index 185059d77ac2147a959f84319755ca4943f26e8a..9a7de828a5dff203aebfa903ef73063e7d5480d1 100644 --- a/scripts/Piece.gd +++ b/scripts/Piece.gd @@ -5,6 +5,11 @@ class_name Piece # Properties var piece_position: Vector2 var is_white: bool + +# Array for upgrades +var upgrades: Array = [] + + # initialization method func _init(is_white: bool, piece_position: Vector2) -> void: self.is_white = is_white