diff --git a/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg b/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg index beea37665ebfb99b06ab1fd4b1dda18e6ed5bd9d..1c808c5d134883258cbfbc190268831b8c4a4f23 100644 --- a/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg +++ b/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg @@ -175,4 +175,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/Node2D")]) +selected_nodes=Array[NodePath]([]) diff --git a/.godot/global_script_class_cache.cfg b/.godot/global_script_class_cache.cfg index 9cec9a219d38e9683baf917cb767ca8ce201977a..8a3d5335d028cfc25f4b6abc36c53678465d21dc 100644 --- a/.godot/global_script_class_cache.cfg +++ b/.godot/global_script_class_cache.cfg @@ -5,12 +5,6 @@ list=Array[Dictionary]([{ "language": &"GDScript", "path": "res://scripts/Bishop.gd" }, { -"base": &"Sprite2D", -"class": &"Board", -"icon": "", -"language": &"GDScript", -"path": "res://scripts/board.gd" -}, { "base": &"Piece", "class": &"King", "icon": "", diff --git a/scripts/Knight.gd b/scripts/Knight.gd index fd49fc15211f693ac8580f2dc5b0efa778fba875..1c3057ed36bc2ef4e5097b1c08790cd92b2aeb5b 100644 --- a/scripts/Knight.gd +++ b/scripts/Knight.gd @@ -23,6 +23,7 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]: Vector2(x + 1, y + 2), Vector2(x + 1, y - 2), Vector2(x - 1, y + 2), Vector2(x - 1, y - 2) ] + # Check for LONGER_L_MOVE upgrade if Upgrade.LONGER_L_MOVE in upgrades: moves += [ diff --git a/scripts/Pawn.gd b/scripts/Pawn.gd index bfd4848e2879f4fd488ab2d0f5c580a9d4b053a8..7d8a05394a3d2a9f04eda614561df035a0c1d061 100644 --- a/scripts/Pawn.gd +++ b/scripts/Pawn.gd @@ -7,8 +7,8 @@ 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) + upgrades.append(Upgrade.DOUBLE_MOVE) + upgrades.append(Upgrade.DIAGONAL_MOVE) func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]: @@ -16,6 +16,8 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]: var x = pos.x var y = pos.y + # TODO: Add En passant move + if is_white: # Check if the pawn is at the starting position if (y == 7 or Upgrade.DOUBLE_MOVE in upgrades) and board_state[x][y - 1] == null: diff --git a/scripts/board.gd b/scripts/board.gd deleted file mode 100644 index 36b4359b438fa667ede3459410b1a877de38979b..0000000000000000000000000000000000000000 --- a/scripts/board.gd +++ /dev/null @@ -1,90 +0,0 @@ -extends Sprite2D -class_name Board - -const BOARD_SIZE = 8 -const CELL_WIDTH = 18 - -# piece textures -const BLACK_BISHOP = preload("res://assets/temp_assets/black_bishop.png") -const BLACK_KING = preload("res://assets/temp_assets/black_king.png") -const BLACK_KNIGHT = preload("res://assets/temp_assets/black_knight.png") -const BLACK_PAWN = preload("res://assets/temp_assets/black_pawn.png") -const BLACK_QUEEN = preload("res://assets/temp_assets/black_queen.png") -const BLACK_ROOK = preload("res://assets/temp_assets/black_rook.png") -const WHITE_BISHOP = preload("res://assets/temp_assets/white_bishop.png") -const WHITE_KING = preload("res://assets/temp_assets/white_king.png") -const WHITE_KNIGHT = preload("res://assets/temp_assets/white_knight.png") -const WHITE_PAWN = preload("res://assets/temp_assets/white_pawn.png") -const WHITE_QUEEN = preload("res://assets/temp_assets/white_queen.png") -const WHITE_ROOK = preload("res://assets/temp_assets/white_rook.png") - -const TEXTURE_HOLDER = preload("res://scenes/texture_holder.tscn") - -@onready var pieces: Node2D = $Pieces -@onready var dots: Node2D = $Dots - -# Variables -var board: Array -var white: bool -var state: bool -var moves = [] -var selected_piece: Vector2 - -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - board.append([4,2,3,5,6,3,2,4]) - board.append([1,1,1,1,1,1,1,1]) - board.append([0,0,0,0,0,0,0,0]) - board.append([0,0,0,0,0,0,0,0]) - board.append([0,0,0,0,0,0,0,0]) - board.append([0,0,0,0,0,0,0,0]) - board.append([-1,-1,-1,-1,-1,-1,-1,-1]) - board.append([-4,-2,-3,-5,-6,-3,-2,-4]) - - display_board() - -func _input(event): - if (event is InputEventMouseButton && event.pressed): - if (event.button_index == MOUSE_BUTTON_LEFT): - if is_mouse_out(): - return - - var mouse_position: Vector2 = get_global_mouse_position() - var x_click = snapped(mouse_position.x, 0) / CELL_WIDTH - var y_click = abs(snapped(mouse_position.y, 0)) / CELL_WIDTH - - print(x_click, y_click) - -# Checks if mouse input is on the board -func is_mouse_out() -> bool: - var mouse_position: Vector2 = get_global_mouse_position() - - if (mouse_position.x < 0 || mouse_position.x > 144 || mouse_position.y > 0 || mouse_position.y < -144): - return true - - return false - -# Displays board and instantiates "piece holders" -func display_board() -> void: - for i in BOARD_SIZE: - for j in BOARD_SIZE: - # Instantiate texture holders, scene that holds pieces - var holder = TEXTURE_HOLDER.instantiate() - pieces.add_child(holder) - holder.global_position = Vector2(j * CELL_WIDTH + (CELL_WIDTH / 2), -i * CELL_WIDTH - (CELL_WIDTH / 2)) - - # Looks at board array and matches pieces with its respective value - match board[i][j]: - -6: holder.texture = BLACK_KING - -5: holder.texture = BLACK_QUEEN - -4: holder.texture = BLACK_ROOK - -3: holder.texture = BLACK_BISHOP - -2: holder.texture = BLACK_KNIGHT - -1: holder.texture = BLACK_PAWN - 0: holder.texture = null - 6: holder.texture = WHITE_KING - 5: holder.texture = WHITE_QUEEN - 4: holder.texture = WHITE_ROOK - 3: holder.texture = WHITE_BISHOP - 2: holder.texture = WHITE_KNIGHT - 1: holder.texture = WHITE_PAWN diff --git a/scripts/game.gd b/scripts/game.gd index 5a3fdd23766a6e58d234785bc223b5de49400515..06aa3a7768d64075927d2d0b6904458f981ddac9 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -35,7 +35,7 @@ var sprite: Sprite2D func _ready() -> void: DisplayServer.window_set_min_size(Vector2(1152, 648)) # Set minimum window size - #creates 2D array for board, with empty ('0') spaces + #creates 2D array for board, with empty (null) spaces for x in range(X): board.append([]) for y in range(Y): @@ -126,8 +126,6 @@ func draw_pieces(): elif board[x][y] is Knight: piece_scene = preload("res://scenes/Knight.tscn") - # Add other piece types here (e.g., Knight, Bishop, Queen, King) - if piece_scene: var piece_instance = piece_scene.instantiate() piece_instance.position = Vector2((x * tile_size) + tile_size/2, (y * tile_size) + tile_size/2) @@ -295,7 +293,7 @@ func remove_piece(x,y): #iterate through the pieces in piece_container, if that piece is at location x,y, remove it for child in piece_container.get_children(): #translate x,y index values to screen coordinates - if child.position == Vector2(x*tile_size+32, y*tile_size+32): + if child.position == Vector2(x*tile_size + 32, y*tile_size + 32): explosion_effect.position = child.position + translate() explosion_effect.restart() piece_container.remove_child(child) @@ -374,5 +372,3 @@ func move_selected_piece(x,y): remove_highlight() - -