added capture animation
This commit is contained in:
parent
681f85a2c4
commit
d3eeca5489
8 changed files with 173 additions and 159 deletions
|
|
@ -51,8 +51,7 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||||
var container = board_flow.get_node(tile_name) as PieceContainer
|
var container = board_flow.get_node(tile_name) as PieceContainer
|
||||||
if container.has_piece():
|
if container.has_piece():
|
||||||
var piece_to_capture = container.get_piece()
|
var piece_to_capture = container.get_piece()
|
||||||
game_state.updatePoints(piece_to_capture)
|
game_state.updatePointsAndCapture(piece_to_capture)
|
||||||
container.remove_piece()
|
|
||||||
|
|
||||||
# Move piece to final position
|
# Move piece to final position
|
||||||
var final_container = board_flow.get_node(str(current_x) + "-" + str(final_y)) as PieceContainer
|
var final_container = board_flow.get_node(str(current_x) + "-" + str(final_y)) as PieceContainer
|
||||||
|
|
@ -60,8 +59,6 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||||
# Important: Need to remove the piece from its current container first
|
# Important: Need to remove the piece from its current container first
|
||||||
# AND keep a reference to it
|
# AND keep a reference to it
|
||||||
target_piece = current_container.get_piece() # Get reference before removing
|
target_piece = current_container.get_piece() # Get reference before removing
|
||||||
# current_container.remove_piece(true) # Remove from current container
|
|
||||||
# final_container.set_piece(target_piece) # Set in new container
|
|
||||||
final_container.animate_movement(current_container, target_piece)
|
final_container.animate_movement(current_container, target_piece)
|
||||||
|
|
||||||
game_state.currentlyMovingPiece = target_piece
|
game_state.currentlyMovingPiece = target_piece
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,7 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||||
# Check for pieces to affect
|
# Check for pieces to affect
|
||||||
var piece = container.get_piece()
|
var piece = container.get_piece()
|
||||||
if piece != null and piece.Item_Color != target_piece.Item_Color:
|
if piece != null and piece.Item_Color != target_piece.Item_Color:
|
||||||
game_state.updatePoints(piece)
|
game_state.updatePointsAndCapture(piece)
|
||||||
container.remove_piece()
|
|
||||||
|
|
||||||
# Setup timer to remove overlays
|
# Setup timer to remove overlays
|
||||||
var timer = Timer.new()
|
var timer = Timer.new()
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,7 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||||
if tile.get_piece() != null:
|
if tile.get_piece() != null:
|
||||||
var piece = tile.get_piece()
|
var piece = tile.get_piece()
|
||||||
if piece.Item_Color != target_piece.Item_Color: # Only capture enemy pieces
|
if piece.Item_Color != target_piece.Item_Color: # Only capture enemy pieces
|
||||||
game_state.updatePoints(piece)
|
game_state.updatePointsAndCapture(piece)
|
||||||
tile.remove_piece()
|
|
||||||
# Process tiles and add overlay
|
# Process tiles and add overlay
|
||||||
for tile_name in tiles_to_check:
|
for tile_name in tiles_to_check:
|
||||||
var container = board_flow.get_node(tile_name) as PieceContainer
|
var container = board_flow.get_node(tile_name) as PieceContainer
|
||||||
|
|
@ -79,8 +78,7 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||||
# Check for pieces to affect
|
# Check for pieces to affect
|
||||||
var piece = container.get_piece()
|
var piece = container.get_piece()
|
||||||
if piece != null and piece.Item_Color != target_piece.Item_Color:
|
if piece != null and piece.Item_Color != target_piece.Item_Color:
|
||||||
game_state.updatePoints(piece)
|
game_state.updatePointsAndCapture(piece)
|
||||||
container.remove_piece()
|
|
||||||
|
|
||||||
# Setup timer to remove overlays
|
# Setup timer to remove overlays
|
||||||
var timer = Timer.new()
|
var timer = Timer.new()
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ func clearSelection() :
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func updatePoints(capturedPiece: Node) -> void:
|
func updatePointsAndCapture(capturedPiece: Pawn) -> void:
|
||||||
if Turn == 0:
|
if Turn == 0:
|
||||||
p1Points += capturedPiece.Points
|
p1Points += capturedPiece.Points
|
||||||
p1String.text = str(p1Points)
|
p1String.text = str(p1Points)
|
||||||
|
|
@ -165,10 +165,18 @@ func updatePoints(capturedPiece: Node) -> void:
|
||||||
p2Points += capturedPiece.Points
|
p2Points += capturedPiece.Points
|
||||||
p2String.text = str(p2Points)
|
p2String.text = str(p2Points)
|
||||||
|
|
||||||
|
animatePieceCapture(capturedPiece)
|
||||||
|
|
||||||
|
|
||||||
if capturedPiece.name == "King":
|
if capturedPiece.name == "King":
|
||||||
print("Game Over!")
|
print("Game Over!")
|
||||||
gamecheckMate = true
|
gamecheckMate = true
|
||||||
|
|
||||||
|
func animatePieceCapture(capturedPiece: Pawn) -> void:
|
||||||
|
var container = capturedPiece.get_parent() as PieceContainer
|
||||||
|
await capturedPiece.animate_capture()
|
||||||
|
container.remove_piece()
|
||||||
|
|
||||||
func parseLocation(location: String) -> void:
|
func parseLocation(location: String) -> void:
|
||||||
var number = 0
|
var number = 0
|
||||||
locationX = ""
|
locationX = ""
|
||||||
|
|
|
||||||
|
|
@ -200,9 +200,12 @@ func handleEnPassant(node: PieceContainer) -> void:
|
||||||
if i == node.name:
|
if i == node.name:
|
||||||
var targetContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer
|
var targetContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer
|
||||||
var pawn = (game.get_node("Flow/" + game.selectedNode) as PieceContainer).get_piece()
|
var pawn = (game.get_node("Flow/" + game.selectedNode) as PieceContainer).get_piece()
|
||||||
node.remove_piece()
|
# node.remove_piece()
|
||||||
targetContainer.set_piece(pawn)
|
# targetContainer.set_piece(pawn)
|
||||||
game.currentlyMovingPiece = pawn
|
game.currentlyMovingPiece = pawn
|
||||||
|
|
||||||
|
|
||||||
|
targetContainer.animate_movement(node, pawn);
|
||||||
game.resolveMoveEffects()
|
game.resolveMoveEffects()
|
||||||
|
|
||||||
func handleCapture(node: PieceContainer) -> void:
|
func handleCapture(node: PieceContainer) -> void:
|
||||||
|
|
@ -218,15 +221,10 @@ func handleCapture(node: PieceContainer) -> void:
|
||||||
var captured_piece = node.get_piece()
|
var captured_piece = node.get_piece()
|
||||||
|
|
||||||
if moving_piece && captured_piece:
|
if moving_piece && captured_piece:
|
||||||
game.updatePoints(captured_piece)
|
game.updatePointsAndCapture(captured_piece)
|
||||||
node.animate_movement(source_container, moving_piece);
|
node.animate_movement(source_container, moving_piece);
|
||||||
|
|
||||||
|
|
||||||
# await node.set_piece(moving_piece)
|
|
||||||
# source_container.remove_piece(true)
|
|
||||||
# node.remove_piece(true)
|
|
||||||
# node.set_piece(moving_piece, false)
|
|
||||||
|
|
||||||
game.currentlyMovingPiece = moving_piece
|
game.currentlyMovingPiece = moving_piece
|
||||||
game.resolveMoveEffects()
|
game.resolveMoveEffects()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,7 @@ func apply_effect(piece: Pawn = null) -> void:
|
||||||
var container = piece.get_parent() as PieceContainer
|
var container = piece.get_parent() as PieceContainer
|
||||||
if container:
|
if container:
|
||||||
|
|
||||||
game.updatePoints(piece)
|
game.updatePointsAndCapture(piece)
|
||||||
container.remove_piece()
|
|
||||||
|
|
||||||
func update_appearance() -> void:
|
func update_appearance() -> void:
|
||||||
if is_effect_active() && base_button:
|
if is_effect_active() && base_button:
|
||||||
|
|
|
||||||
|
|
@ -153,3 +153,18 @@ func animate_movement(target_position: Vector2, duration: float = 1) -> void:
|
||||||
# Wait for animation to complete
|
# Wait for animation to complete
|
||||||
await tween.finished
|
await tween.finished
|
||||||
# print("--------------FINISHED ANIM--------------")
|
# print("--------------FINISHED ANIM--------------")
|
||||||
|
|
||||||
|
func animate_capture(duration: float = 0.5) -> void:
|
||||||
|
z_index = 1 # Ensure piece is visible above others during animation
|
||||||
|
var tween = create_tween()
|
||||||
|
tween.set_trans(Tween.TRANS_LINEAR)
|
||||||
|
tween.set_ease(Tween.EASE_IN_OUT)
|
||||||
|
|
||||||
|
# First turn red
|
||||||
|
tween.tween_property(self, "modulate", Color.RED, duration/2)
|
||||||
|
# Then shrink to nothing
|
||||||
|
tween.tween_property(self, "scale", Vector2.ZERO, duration/2)
|
||||||
|
# Finally remove the piece
|
||||||
|
tween.tween_callback(queue_free)
|
||||||
|
|
||||||
|
await tween.finished
|
||||||
Loading…
Reference in a new issue