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
|
||||
if container.has_piece():
|
||||
var piece_to_capture = container.get_piece()
|
||||
game_state.updatePoints(piece_to_capture)
|
||||
container.remove_piece()
|
||||
game_state.updatePointsAndCapture(piece_to_capture)
|
||||
|
||||
# Move piece to final position
|
||||
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
|
||||
# AND keep a reference to it
|
||||
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)
|
||||
|
||||
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
|
||||
var piece = container.get_piece()
|
||||
if piece != null and piece.Item_Color != target_piece.Item_Color:
|
||||
game_state.updatePoints(piece)
|
||||
container.remove_piece()
|
||||
game_state.updatePointsAndCapture(piece)
|
||||
|
||||
# Setup timer to remove overlays
|
||||
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:
|
||||
var piece = tile.get_piece()
|
||||
if piece.Item_Color != target_piece.Item_Color: # Only capture enemy pieces
|
||||
game_state.updatePoints(piece)
|
||||
tile.remove_piece()
|
||||
game_state.updatePointsAndCapture(piece)
|
||||
# Process tiles and add overlay
|
||||
for tile_name in tiles_to_check:
|
||||
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
|
||||
var piece = container.get_piece()
|
||||
if piece != null and piece.Item_Color != target_piece.Item_Color:
|
||||
game_state.updatePoints(piece)
|
||||
container.remove_piece()
|
||||
game_state.updatePointsAndCapture(piece)
|
||||
|
||||
# Setup timer to remove overlays
|
||||
var timer = Timer.new()
|
||||
|
|
|
|||
|
|
@ -10,46 +10,46 @@ var hand_size: int = 5
|
|||
|
||||
# Card costs for shop
|
||||
const CARD_BASE_COSTS = {
|
||||
Card.Rank.RANK_0: 100,
|
||||
Card.Rank.RANK_1: 75,
|
||||
Card.Rank.RANK_2: 50,
|
||||
Card.Rank.RANK_3: 25
|
||||
Card.Rank.RANK_0: 100,
|
||||
Card.Rank.RANK_1: 75,
|
||||
Card.Rank.RANK_2: 50,
|
||||
Card.Rank.RANK_3: 25
|
||||
}
|
||||
|
||||
func _init():
|
||||
initializeStartingDeck()
|
||||
initializeStartingDeck()
|
||||
|
||||
func initializeStartingDeck():
|
||||
deck.clear();
|
||||
# for i in range(2):
|
||||
# deck.append(DoubleTimeCard.new())
|
||||
deck.append(FieryCapeCard.new())
|
||||
deck.append(FieryTrailCard.new())
|
||||
deck.append(ExplosiveBootsCard.new())
|
||||
deck.append(DoubleTimeCard.new())
|
||||
deck.append(DrunkDrivingCard.new())
|
||||
deck.append(HopscotchCard.new())
|
||||
deck.append(SupernovaCard.new())
|
||||
shuffleDeck()
|
||||
drawStartingHand()
|
||||
deck.clear();
|
||||
# for i in range(2):
|
||||
# deck.append(DoubleTimeCard.new())
|
||||
deck.append(FieryCapeCard.new())
|
||||
deck.append(FieryTrailCard.new())
|
||||
deck.append(ExplosiveBootsCard.new())
|
||||
deck.append(DoubleTimeCard.new())
|
||||
deck.append(DrunkDrivingCard.new())
|
||||
deck.append(HopscotchCard.new())
|
||||
deck.append(SupernovaCard.new())
|
||||
shuffleDeck()
|
||||
drawStartingHand()
|
||||
|
||||
func shuffleDeck():
|
||||
deck.shuffle()
|
||||
deck.shuffle()
|
||||
|
||||
func drawStartingHand():
|
||||
for i in range(min(hand_size, deck.size())):
|
||||
drawCard()
|
||||
for i in range(min(hand_size, deck.size())):
|
||||
drawCard()
|
||||
|
||||
func drawCard():
|
||||
if deck.is_empty() && !discard.is_empty():
|
||||
deck = discard.duplicate()
|
||||
discard.clear()
|
||||
shuffleDeck()
|
||||
if deck.is_empty() && !discard.is_empty():
|
||||
deck = discard.duplicate()
|
||||
discard.clear()
|
||||
shuffleDeck()
|
||||
|
||||
if !deck.is_empty() && hand.size() < hand_size:
|
||||
hand.append(deck.pop_back())
|
||||
if !deck.is_empty() && hand.size() < hand_size:
|
||||
hand.append(deck.pop_back())
|
||||
|
||||
emit_signal("hand_updated", hand)
|
||||
emit_signal("hand_updated", hand)
|
||||
|
||||
|
||||
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):
|
||||
if !avoidHand and !hand.has(card):
|
||||
# print("Failed Play Card 1")
|
||||
return false
|
||||
if card.duration > 0:
|
||||
attached_cards[target_piece.get_instance_id()] = card
|
||||
if !avoidHand and !hand.has(card):
|
||||
# print("Failed Play Card 1")
|
||||
return false
|
||||
if card.duration > 0:
|
||||
attached_cards[target_piece.get_instance_id()] = card
|
||||
|
||||
if card.apply_effect(target_piece, board_flow, game_state):
|
||||
if card.duration > 0:
|
||||
attached_cards[target_piece.get_instance_id()] = card
|
||||
hand.erase(card)
|
||||
emit_signal("hand_updated", hand)
|
||||
if card.apply_effect(target_piece, board_flow, game_state):
|
||||
if card.duration > 0:
|
||||
attached_cards[target_piece.get_instance_id()] = card
|
||||
hand.erase(card)
|
||||
emit_signal("hand_updated", hand)
|
||||
|
||||
|
||||
return true
|
||||
# print("Failed Play Card 2")
|
||||
return false
|
||||
return true
|
||||
# print("Failed Play Card 2")
|
||||
return false
|
||||
|
||||
|
||||
func playEffect(card: Card, target_piece: Pawn, board_flow = null, game_state = null):
|
||||
|
||||
var key = target_piece.get_instance_id();
|
||||
if !attached_effects.has(key):
|
||||
attached_effects[key] = []
|
||||
else:
|
||||
for existing_card in attached_effects[key]:
|
||||
if existing_card.cardName == card.cardName:
|
||||
# Card already exists, don't add it again
|
||||
return false
|
||||
var key = target_piece.get_instance_id();
|
||||
if !attached_effects.has(key):
|
||||
attached_effects[key] = []
|
||||
else:
|
||||
for existing_card in attached_effects[key]:
|
||||
if existing_card.cardName == card.cardName:
|
||||
# Card already exists, don't add it again
|
||||
return false
|
||||
|
||||
if card.apply_effect(target_piece, board_flow, game_state):
|
||||
if card.duration > 0:
|
||||
attached_effects[key].append(card)
|
||||
if card.apply_effect(target_piece, board_flow, game_state):
|
||||
if card.duration > 0:
|
||||
attached_effects[key].append(card)
|
||||
|
||||
|
||||
return true
|
||||
# print("Failed Play Card 2")
|
||||
return false
|
||||
return true
|
||||
# print("Failed Play Card 2")
|
||||
return false
|
||||
|
||||
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:
|
||||
var cards_to_remove = [] # Track which cards to remove from this piece's array
|
||||
for piece_id in attached_effects:
|
||||
var cards_to_remove = [] # Track which cards to remove from this piece's array
|
||||
|
||||
for card in attached_effects[piece_id]:
|
||||
card.update_duration()
|
||||
if card.remaining_turns <= 0:
|
||||
cards_to_remove.append(card)
|
||||
else:
|
||||
var piece_node = instance_from_id(piece_id)
|
||||
if is_instance_valid(piece_node):
|
||||
piece_node.update_appearance()
|
||||
for card in attached_effects[piece_id]:
|
||||
card.update_duration()
|
||||
if card.remaining_turns <= 0:
|
||||
cards_to_remove.append(card)
|
||||
else:
|
||||
var piece_node = instance_from_id(piece_id)
|
||||
if is_instance_valid(piece_node):
|
||||
piece_node.update_appearance()
|
||||
|
||||
# Remove expired cards from this piece's array
|
||||
for card in cards_to_remove:
|
||||
attached_effects[piece_id].erase(card)
|
||||
# Remove expired cards from this piece's array
|
||||
for card in cards_to_remove:
|
||||
attached_effects[piece_id].erase(card)
|
||||
|
||||
# If no cards left for this piece, mark the piece_id for removal
|
||||
if attached_effects[piece_id].is_empty():
|
||||
expired_entries.append(piece_id)
|
||||
var piece_node = instance_from_id(piece_id)
|
||||
if is_instance_valid(piece_node):
|
||||
piece_node.update_appearance()
|
||||
# If no cards left for this piece, mark the piece_id for removal
|
||||
if attached_effects[piece_id].is_empty():
|
||||
expired_entries.append(piece_id)
|
||||
var piece_node = instance_from_id(piece_id)
|
||||
if is_instance_valid(piece_node):
|
||||
piece_node.update_appearance()
|
||||
|
||||
# Remove empty entries
|
||||
for piece_id in expired_entries:
|
||||
attached_effects.erase(piece_id)
|
||||
# Remove empty entries
|
||||
for piece_id in expired_entries:
|
||||
attached_effects.erase(piece_id)
|
||||
|
||||
func updateCardDurations():
|
||||
var expired_cards = []
|
||||
for piece_id in attached_cards:
|
||||
var card = attached_cards[piece_id]
|
||||
card.update_duration()
|
||||
# print("Card: ", card.id, " | ", card.cardName, " | ", card.remaining_turns)
|
||||
if card.remaining_turns <= 0:
|
||||
expired_cards.append(piece_id)
|
||||
var expired_cards = []
|
||||
for piece_id in attached_cards:
|
||||
var card = attached_cards[piece_id]
|
||||
card.update_duration()
|
||||
# print("Card: ", card.id, " | ", card.cardName, " | ", card.remaining_turns)
|
||||
if card.remaining_turns <= 0:
|
||||
expired_cards.append(piece_id)
|
||||
|
||||
|
||||
match card.rank:
|
||||
Card.Rank.RANK_0:
|
||||
print("Rank 3 Burned permanently")
|
||||
pass
|
||||
Card.Rank.RANK_1:
|
||||
print("Rank 3 Burned until next match")
|
||||
pass
|
||||
Card.Rank.RANK_2:
|
||||
print("Rank 2 add to Discard")
|
||||
discard.append(card)
|
||||
pass
|
||||
Card.Rank.RANK_3:
|
||||
deck.append(card)
|
||||
print("Rank 3 add to Deck")
|
||||
pass
|
||||
else:
|
||||
var piece_node = instance_from_id(piece_id)
|
||||
if is_instance_valid(piece_node):
|
||||
piece_node.update_appearance()
|
||||
for piece_id in expired_cards:
|
||||
attached_cards.erase(piece_id)
|
||||
var piece_node = instance_from_id(piece_id)
|
||||
if is_instance_valid(piece_node):
|
||||
piece_node.update_appearance()
|
||||
match card.rank:
|
||||
Card.Rank.RANK_0:
|
||||
print("Rank 3 Burned permanently")
|
||||
pass
|
||||
Card.Rank.RANK_1:
|
||||
print("Rank 3 Burned until next match")
|
||||
pass
|
||||
Card.Rank.RANK_2:
|
||||
print("Rank 2 add to Discard")
|
||||
discard.append(card)
|
||||
pass
|
||||
Card.Rank.RANK_3:
|
||||
deck.append(card)
|
||||
print("Rank 3 add to Deck")
|
||||
pass
|
||||
else:
|
||||
var piece_node = instance_from_id(piece_id)
|
||||
if is_instance_valid(piece_node):
|
||||
piece_node.update_appearance()
|
||||
for piece_id in expired_cards:
|
||||
attached_cards.erase(piece_id)
|
||||
var piece_node = instance_from_id(piece_id)
|
||||
if is_instance_valid(piece_node):
|
||||
piece_node.update_appearance()
|
||||
|
||||
# print("updateCardDurations", attached_cards)
|
||||
# print("updateCardDurations", attached_cards)
|
||||
|
||||
# Shop functionality
|
||||
func getShopCards(num_cards: int = 3) -> Array:
|
||||
var shop_cards = []
|
||||
# Generate random shop selection
|
||||
#for i in range(num_cards):
|
||||
#var card = generate_random_card()
|
||||
#shop_cards.append({
|
||||
#"card": card,
|
||||
#"cost": calculateCardCost(card)
|
||||
#})
|
||||
return shop_cards
|
||||
var shop_cards = []
|
||||
# Generate random shop selection
|
||||
#for i in range(num_cards):
|
||||
#var card = generate_random_card()
|
||||
#shop_cards.append({
|
||||
#"card": card,
|
||||
#"cost": calculateCardCost(card)
|
||||
#})
|
||||
return shop_cards
|
||||
|
||||
func calculateCardCost(card: Card) -> int:
|
||||
var base_cost = CARD_BASE_COSTS[card.rank]
|
||||
# Add modifiers based on card effects
|
||||
return base_cost
|
||||
var base_cost = CARD_BASE_COSTS[card.rank]
|
||||
# Add modifiers based on card effects
|
||||
return base_cost
|
||||
|
||||
func upgradeCard(card: Card) -> bool:
|
||||
# Implement card upgrading logic
|
||||
return false
|
||||
# Implement card upgrading logic
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ func clearSelection() :
|
|||
|
||||
|
||||
|
||||
func updatePoints(capturedPiece: Node) -> void:
|
||||
func updatePointsAndCapture(capturedPiece: Pawn) -> void:
|
||||
if Turn == 0:
|
||||
p1Points += capturedPiece.Points
|
||||
p1String.text = str(p1Points)
|
||||
|
|
@ -165,10 +165,18 @@ func updatePoints(capturedPiece: Node) -> void:
|
|||
p2Points += capturedPiece.Points
|
||||
p2String.text = str(p2Points)
|
||||
|
||||
animatePieceCapture(capturedPiece)
|
||||
|
||||
|
||||
if capturedPiece.name == "King":
|
||||
print("Game Over!")
|
||||
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:
|
||||
var number = 0
|
||||
locationX = ""
|
||||
|
|
|
|||
|
|
@ -200,9 +200,12 @@ func handleEnPassant(node: PieceContainer) -> void:
|
|||
if i == node.name:
|
||||
var targetContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer
|
||||
var pawn = (game.get_node("Flow/" + game.selectedNode) as PieceContainer).get_piece()
|
||||
node.remove_piece()
|
||||
targetContainer.set_piece(pawn)
|
||||
# node.remove_piece()
|
||||
# targetContainer.set_piece(pawn)
|
||||
game.currentlyMovingPiece = pawn
|
||||
|
||||
|
||||
targetContainer.animate_movement(node, pawn);
|
||||
game.resolveMoveEffects()
|
||||
|
||||
func handleCapture(node: PieceContainer) -> void:
|
||||
|
|
@ -218,15 +221,10 @@ func handleCapture(node: PieceContainer) -> void:
|
|||
var captured_piece = node.get_piece()
|
||||
|
||||
if moving_piece && captured_piece:
|
||||
game.updatePoints(captured_piece)
|
||||
game.updatePointsAndCapture(captured_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.resolveMoveEffects()
|
||||
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ func apply_effect(piece: Pawn = null) -> void:
|
|||
var container = piece.get_parent() as PieceContainer
|
||||
if container:
|
||||
|
||||
game.updatePoints(piece)
|
||||
container.remove_piece()
|
||||
game.updatePointsAndCapture(piece)
|
||||
|
||||
func update_appearance() -> void:
|
||||
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
|
||||
await tween.finished
|
||||
# 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