Skip to content
Snippets Groups Projects
Commit 16367bd8 authored by Alan's avatar Alan
Browse files

Added upgrades for pawns

parent db9f8892
No related branches found
No related tags found
1 merge request!1Refactoring game.gd to split up move validation to individual pieces, added...
......@@ -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:
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment