diff --git a/Systems/Game/ChessGame.gd b/Systems/Game/ChessGame.gd index 463b056..4dfa4c2 100644 --- a/Systems/Game/ChessGame.gd +++ b/Systems/Game/ChessGame.gd @@ -68,10 +68,10 @@ func _process(delta: float) -> void: func initializeGame() -> void: setupStyles() - initializeBoard() setupUI() initializeDeckSystem() initializeCardPreview() + initializeBoard() func initializeCardPreview() -> void: cardPreview = CardPreview.new() @@ -224,8 +224,10 @@ func placePiece(position: String, pieceName: String, color: int) -> void: var piece = summonPiece(pieceName, color) # boardContainer.get_node(position).add_child(piece) - var container = boardContainer.get_node(position) - container.set_piece(piece) + var container = boardContainer.get_node(position) as PieceContainer + await container.set_piece(piece, false) + container.remove_piece(true) + container.set_piece(piece, false) var coords = position.split("-") board[int(coords[1])][int(coords[0])] = piece diff --git a/Systems/PieceContainer.gd b/Systems/PieceContainer.gd index a4e293c..0278273 100644 --- a/Systems/PieceContainer.gd +++ b/Systems/PieceContainer.gd @@ -10,12 +10,29 @@ func _init() -> void: effects.name = "Effects" add_child(effects) -func set_piece(new_piece: Pawn) -> void: + +func set_piece(new_piece: Pawn, animate: bool = true) -> void: remove_piece() # Clean up any existing piece piece = new_piece if new_piece != null: - add_child(new_piece) - new_piece.position = Vector2(25, 25) + if animate: + + print("POS ", get_global_position()) + var targetPos = get_global_position() + Vector2(25, 25) + + if new_piece.get_parent(): + new_piece.reparent(self) + else: + add_child(new_piece) + await new_piece.animate_movement(targetPos) + else: + + if new_piece.get_parent(): + new_piece.reparent(self) + else: + add_child(new_piece) + new_piece.position = Vector2(25, 25) + func get_piece() -> Pawn: return piece @@ -23,7 +40,8 @@ func get_piece() -> Pawn: func remove_piece(keep_piece: bool = false) -> Pawn: var old_piece = piece if piece != null: - remove_child(piece) + if piece.get_parent() == self: + remove_child(piece) if !keep_piece: piece.queue_free() old_piece = null diff --git a/Systems/StateMachine/GameStates/Movement.gd b/Systems/StateMachine/GameStates/Movement.gd index 59bb0bf..c931baf 100644 --- a/Systems/StateMachine/GameStates/Movement.gd +++ b/Systems/StateMachine/GameStates/Movement.gd @@ -213,8 +213,10 @@ func handleCapture(node: PieceContainer) -> void: if moving_piece && captured_piece: game.updatePoints(captured_piece) + await node.set_piece(moving_piece) source_container.remove_piece(true) - node.set_piece(moving_piece) + node.remove_piece(true) + node.set_piece(moving_piece, false) game.currentlyMovingPiece = moving_piece game.resolveMoveEffects() @@ -226,8 +228,10 @@ func handleRegularMove(node: PieceContainer, consume: bool) -> void: var sourceContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer var piece = sourceContainer.get_piece() print("Removing Piece 1") + await node.set_piece(piece) sourceContainer.remove_piece(true) - node.set_piece(piece) + node.remove_piece(true) + node.set_piece(piece, false) game.currentlyMovingPiece = piece if consume: diff --git a/Systems/TileManager.gd b/Systems/TileManager.gd index 25df169..350cd9d 100644 --- a/Systems/TileManager.gd +++ b/Systems/TileManager.gd @@ -102,6 +102,7 @@ func place_random_game_tiles(num_tiles: int = 6) -> void: var tile_type = rng.randi() % 3 var tile: Tile + return match tile_type: 0: # DoubleMovementTile tile tile = WallTile.new(container, is_white, -1) diff --git a/addons/Chess/Scripts/Pawn.gd b/addons/Chess/Scripts/Pawn.gd index 728301c..dafdca7 100644 --- a/addons/Chess/Scripts/Pawn.gd +++ b/addons/Chess/Scripts/Pawn.gd @@ -136,4 +136,20 @@ func can_move_to_cell(board_flow, location: String, is_capture: bool = false) -> if is_capture: var piece = container.get_piece() return piece != null && piece.Item_Color != self.Item_Color - return !container.has_piece() \ No newline at end of file + return !container.has_piece() + +func animate_movement(target_position: Vector2, duration: float = 1) -> void: + # print("--------------STARTING ANIM--------------", position, " ", target_position) + z_index = 1 + var tween = create_tween() + # Make sure the tween is configured properly + tween.set_trans(Tween.TRANS_LINEAR) # or TRANS_CUBIC for smoother movement + tween.set_ease(Tween.EASE_IN_OUT) + + var start_pos = position + tween.tween_property(self, "global_position", target_position, duration) + #.from(start_pos) + + # Wait for animation to complete + await tween.finished + # print("--------------FINISHED ANIM--------------") \ No newline at end of file