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()
|
||||||
|
|
|
||||||
|
|
@ -10,46 +10,46 @@ var hand_size: int = 5
|
||||||
|
|
||||||
# Card costs for shop
|
# Card costs for shop
|
||||||
const CARD_BASE_COSTS = {
|
const CARD_BASE_COSTS = {
|
||||||
Card.Rank.RANK_0: 100,
|
Card.Rank.RANK_0: 100,
|
||||||
Card.Rank.RANK_1: 75,
|
Card.Rank.RANK_1: 75,
|
||||||
Card.Rank.RANK_2: 50,
|
Card.Rank.RANK_2: 50,
|
||||||
Card.Rank.RANK_3: 25
|
Card.Rank.RANK_3: 25
|
||||||
}
|
}
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
initializeStartingDeck()
|
initializeStartingDeck()
|
||||||
|
|
||||||
func initializeStartingDeck():
|
func initializeStartingDeck():
|
||||||
deck.clear();
|
deck.clear();
|
||||||
# for i in range(2):
|
# for i in range(2):
|
||||||
# deck.append(DoubleTimeCard.new())
|
# deck.append(DoubleTimeCard.new())
|
||||||
deck.append(FieryCapeCard.new())
|
deck.append(FieryCapeCard.new())
|
||||||
deck.append(FieryTrailCard.new())
|
deck.append(FieryTrailCard.new())
|
||||||
deck.append(ExplosiveBootsCard.new())
|
deck.append(ExplosiveBootsCard.new())
|
||||||
deck.append(DoubleTimeCard.new())
|
deck.append(DoubleTimeCard.new())
|
||||||
deck.append(DrunkDrivingCard.new())
|
deck.append(DrunkDrivingCard.new())
|
||||||
deck.append(HopscotchCard.new())
|
deck.append(HopscotchCard.new())
|
||||||
deck.append(SupernovaCard.new())
|
deck.append(SupernovaCard.new())
|
||||||
shuffleDeck()
|
shuffleDeck()
|
||||||
drawStartingHand()
|
drawStartingHand()
|
||||||
|
|
||||||
func shuffleDeck():
|
func shuffleDeck():
|
||||||
deck.shuffle()
|
deck.shuffle()
|
||||||
|
|
||||||
func drawStartingHand():
|
func drawStartingHand():
|
||||||
for i in range(min(hand_size, deck.size())):
|
for i in range(min(hand_size, deck.size())):
|
||||||
drawCard()
|
drawCard()
|
||||||
|
|
||||||
func drawCard():
|
func drawCard():
|
||||||
if deck.is_empty() && !discard.is_empty():
|
if deck.is_empty() && !discard.is_empty():
|
||||||
deck = discard.duplicate()
|
deck = discard.duplicate()
|
||||||
discard.clear()
|
discard.clear()
|
||||||
shuffleDeck()
|
shuffleDeck()
|
||||||
|
|
||||||
if !deck.is_empty() && hand.size() < hand_size:
|
if !deck.is_empty() && hand.size() < hand_size:
|
||||||
hand.append(deck.pop_back())
|
hand.append(deck.pop_back())
|
||||||
|
|
||||||
emit_signal("hand_updated", hand)
|
emit_signal("hand_updated", hand)
|
||||||
|
|
||||||
|
|
||||||
signal hand_updated
|
signal hand_updated
|
||||||
|
|
@ -57,128 +57,128 @@ signal hand_updated
|
||||||
|
|
||||||
|
|
||||||
func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = null, avoidHand = false):
|
func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = null, avoidHand = false):
|
||||||
if !avoidHand and !hand.has(card):
|
if !avoidHand and !hand.has(card):
|
||||||
# print("Failed Play Card 1")
|
# print("Failed Play Card 1")
|
||||||
return false
|
return false
|
||||||
if card.duration > 0:
|
if card.duration > 0:
|
||||||
attached_cards[target_piece.get_instance_id()] = card
|
attached_cards[target_piece.get_instance_id()] = card
|
||||||
|
|
||||||
if card.apply_effect(target_piece, board_flow, game_state):
|
if card.apply_effect(target_piece, board_flow, game_state):
|
||||||
if card.duration > 0:
|
if card.duration > 0:
|
||||||
attached_cards[target_piece.get_instance_id()] = card
|
attached_cards[target_piece.get_instance_id()] = card
|
||||||
hand.erase(card)
|
hand.erase(card)
|
||||||
emit_signal("hand_updated", hand)
|
emit_signal("hand_updated", hand)
|
||||||
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
# print("Failed Play Card 2")
|
# print("Failed Play Card 2")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
func playEffect(card: Card, target_piece: Pawn, board_flow = null, game_state = null):
|
func playEffect(card: Card, target_piece: Pawn, board_flow = null, game_state = null):
|
||||||
|
|
||||||
var key = target_piece.get_instance_id();
|
var key = target_piece.get_instance_id();
|
||||||
if !attached_effects.has(key):
|
if !attached_effects.has(key):
|
||||||
attached_effects[key] = []
|
attached_effects[key] = []
|
||||||
else:
|
else:
|
||||||
for existing_card in attached_effects[key]:
|
for existing_card in attached_effects[key]:
|
||||||
if existing_card.cardName == card.cardName:
|
if existing_card.cardName == card.cardName:
|
||||||
# Card already exists, don't add it again
|
# Card already exists, don't add it again
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if card.apply_effect(target_piece, board_flow, game_state):
|
if card.apply_effect(target_piece, board_flow, game_state):
|
||||||
if card.duration > 0:
|
if card.duration > 0:
|
||||||
attached_effects[key].append(card)
|
attached_effects[key].append(card)
|
||||||
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
# print("Failed Play Card 2")
|
# print("Failed Play Card 2")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
func updateEffectDurations():
|
func updateEffectDurations():
|
||||||
var expired_entries = [] # Store [piece_id, card_id] pairs to remove
|
var expired_entries = [] # Store [piece_id, card_id] pairs to remove
|
||||||
|
|
||||||
for piece_id in attached_effects:
|
for piece_id in attached_effects:
|
||||||
var cards_to_remove = [] # Track which cards to remove from this piece's array
|
var cards_to_remove = [] # Track which cards to remove from this piece's array
|
||||||
|
|
||||||
for card in attached_effects[piece_id]:
|
for card in attached_effects[piece_id]:
|
||||||
card.update_duration()
|
card.update_duration()
|
||||||
if card.remaining_turns <= 0:
|
if card.remaining_turns <= 0:
|
||||||
cards_to_remove.append(card)
|
cards_to_remove.append(card)
|
||||||
else:
|
else:
|
||||||
var piece_node = instance_from_id(piece_id)
|
var piece_node = instance_from_id(piece_id)
|
||||||
if is_instance_valid(piece_node):
|
if is_instance_valid(piece_node):
|
||||||
piece_node.update_appearance()
|
piece_node.update_appearance()
|
||||||
|
|
||||||
# Remove expired cards from this piece's array
|
# Remove expired cards from this piece's array
|
||||||
for card in cards_to_remove:
|
for card in cards_to_remove:
|
||||||
attached_effects[piece_id].erase(card)
|
attached_effects[piece_id].erase(card)
|
||||||
|
|
||||||
# If no cards left for this piece, mark the piece_id for removal
|
# If no cards left for this piece, mark the piece_id for removal
|
||||||
if attached_effects[piece_id].is_empty():
|
if attached_effects[piece_id].is_empty():
|
||||||
expired_entries.append(piece_id)
|
expired_entries.append(piece_id)
|
||||||
var piece_node = instance_from_id(piece_id)
|
var piece_node = instance_from_id(piece_id)
|
||||||
if is_instance_valid(piece_node):
|
if is_instance_valid(piece_node):
|
||||||
piece_node.update_appearance()
|
piece_node.update_appearance()
|
||||||
|
|
||||||
# Remove empty entries
|
# Remove empty entries
|
||||||
for piece_id in expired_entries:
|
for piece_id in expired_entries:
|
||||||
attached_effects.erase(piece_id)
|
attached_effects.erase(piece_id)
|
||||||
|
|
||||||
func updateCardDurations():
|
func updateCardDurations():
|
||||||
var expired_cards = []
|
var expired_cards = []
|
||||||
for piece_id in attached_cards:
|
for piece_id in attached_cards:
|
||||||
var card = attached_cards[piece_id]
|
var card = attached_cards[piece_id]
|
||||||
card.update_duration()
|
card.update_duration()
|
||||||
# print("Card: ", card.id, " | ", card.cardName, " | ", card.remaining_turns)
|
# print("Card: ", card.id, " | ", card.cardName, " | ", card.remaining_turns)
|
||||||
if card.remaining_turns <= 0:
|
if card.remaining_turns <= 0:
|
||||||
expired_cards.append(piece_id)
|
expired_cards.append(piece_id)
|
||||||
|
|
||||||
|
|
||||||
match card.rank:
|
match card.rank:
|
||||||
Card.Rank.RANK_0:
|
Card.Rank.RANK_0:
|
||||||
print("Rank 3 Burned permanently")
|
print("Rank 3 Burned permanently")
|
||||||
pass
|
pass
|
||||||
Card.Rank.RANK_1:
|
Card.Rank.RANK_1:
|
||||||
print("Rank 3 Burned until next match")
|
print("Rank 3 Burned until next match")
|
||||||
pass
|
pass
|
||||||
Card.Rank.RANK_2:
|
Card.Rank.RANK_2:
|
||||||
print("Rank 2 add to Discard")
|
print("Rank 2 add to Discard")
|
||||||
discard.append(card)
|
discard.append(card)
|
||||||
pass
|
pass
|
||||||
Card.Rank.RANK_3:
|
Card.Rank.RANK_3:
|
||||||
deck.append(card)
|
deck.append(card)
|
||||||
print("Rank 3 add to Deck")
|
print("Rank 3 add to Deck")
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
var piece_node = instance_from_id(piece_id)
|
var piece_node = instance_from_id(piece_id)
|
||||||
if is_instance_valid(piece_node):
|
if is_instance_valid(piece_node):
|
||||||
piece_node.update_appearance()
|
piece_node.update_appearance()
|
||||||
for piece_id in expired_cards:
|
for piece_id in expired_cards:
|
||||||
attached_cards.erase(piece_id)
|
attached_cards.erase(piece_id)
|
||||||
var piece_node = instance_from_id(piece_id)
|
var piece_node = instance_from_id(piece_id)
|
||||||
if is_instance_valid(piece_node):
|
if is_instance_valid(piece_node):
|
||||||
piece_node.update_appearance()
|
piece_node.update_appearance()
|
||||||
|
|
||||||
# print("updateCardDurations", attached_cards)
|
# print("updateCardDurations", attached_cards)
|
||||||
|
|
||||||
# Shop functionality
|
# Shop functionality
|
||||||
func getShopCards(num_cards: int = 3) -> Array:
|
func getShopCards(num_cards: int = 3) -> Array:
|
||||||
var shop_cards = []
|
var shop_cards = []
|
||||||
# Generate random shop selection
|
# Generate random shop selection
|
||||||
#for i in range(num_cards):
|
#for i in range(num_cards):
|
||||||
#var card = generate_random_card()
|
#var card = generate_random_card()
|
||||||
#shop_cards.append({
|
#shop_cards.append({
|
||||||
#"card": card,
|
#"card": card,
|
||||||
#"cost": calculateCardCost(card)
|
#"cost": calculateCardCost(card)
|
||||||
#})
|
#})
|
||||||
return shop_cards
|
return shop_cards
|
||||||
|
|
||||||
func calculateCardCost(card: Card) -> int:
|
func calculateCardCost(card: Card) -> int:
|
||||||
var base_cost = CARD_BASE_COSTS[card.rank]
|
var base_cost = CARD_BASE_COSTS[card.rank]
|
||||||
# Add modifiers based on card effects
|
# Add modifiers based on card effects
|
||||||
return base_cost
|
return base_cost
|
||||||
|
|
||||||
func upgradeCard(card: Card) -> bool:
|
func upgradeCard(card: Card) -> bool:
|
||||||
# Implement card upgrading logic
|
# Implement card upgrading logic
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -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