From e8042a2c4423eedc6ae9436fa60cbf1870f211d0 Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Wed, 5 Feb 2025 17:50:42 -0600 Subject: [PATCH] added card which create tiles --- Systems/Cards/FireyCape.gd | 78 +++++++++++++++++++ Systems/DeckManager.gd | 6 +- .../StateMachine/GameStates/PostMovePhase.gd | 4 +- .../GameStates/ResolvePersistentEffects.gd | 2 +- Systems/Tile.gd | 8 +- Systems/TileManager.gd | 15 ++-- Systems/Tiles/DoubleMovement.gd | 9 ++- Systems/Tiles/FireWall.gd | 41 +++++----- Systems/Tiles/PawnBoost.gd | 12 ++- 9 files changed, 132 insertions(+), 43 deletions(-) create mode 100644 Systems/Cards/FireyCape.gd diff --git a/Systems/Cards/FireyCape.gd b/Systems/Cards/FireyCape.gd new file mode 100644 index 0000000..bf022bb --- /dev/null +++ b/Systems/Cards/FireyCape.gd @@ -0,0 +1,78 @@ +class_name FireyCapeCard extends Card + +var previous_position: String = "" +var fire_tiles: Array[String] = [] + +func _init(): + super._init() + cardName = "Firey Cape" + rank = Rank.RANK_2 + effectType = EffectType.PIECE_EFFECT + description = "Leaves a trail of fire that lasts 4 turns. Owner's pieces can pass safely." + duration = 3 # Card effect lasts 3 turns + unitWhitelist = [] # Any piece can wear the cape + +func apply_effect(target_piece = null, board_flow = null, game_state = null): + if !super.apply_effect(target_piece, board_flow, game_state): + return false + + # Store the current position as previous position + previous_position = target_piece.get_parent().name + setup_persistent_effect(game_state) + return true + +func setup_persistent_effect(game_state): + if !game_state.is_connected("turn_changed", on_turn_changed): + game_state.connect("turn_changed", on_turn_changed) + +func on_turn_changed(): + if !attached_piece || remaining_turns <= 0: + return + + var piece = attached_piece + var board_flow = piece.get_parent().get_parent() + var current_pos = piece.get_parent().name + + # If the piece has moved, place fire tiles + if current_pos != previous_position: + var current_coords = current_pos.split("-") + var prev_coords = previous_position.split("-") + var current_x = int(current_coords[0]) + var current_y = int(current_coords[1]) + var prev_x = int(prev_coords[0]) + var prev_y = int(prev_coords[1]) + + # Calculate all positions between previous and current (excluding current) + var positions_to_mark = [] + var dx = sign(current_x - prev_x) + var dy = sign(current_y - prev_y) + var x = prev_x + var y = prev_y + + # Start with the previous position + positions_to_mark.append(previous_position) + + # Add intermediate positions (but not the final position) + while (x + dx != current_x || y + dy != current_y): + x += dx + y += dy + positions_to_mark.append(str(x) + "-" + str(y)) + + # Place fire tiles + var tile_owner = Tile.TileOwner.PLAYER if piece.Item_Color == 0 else Tile.TileOwner.ENEMY + for pos in positions_to_mark: + var container = board_flow.get_node(pos) as PieceContainer + if container: + var is_white = (int(pos.split("-")[0]) + int(pos.split("-")[1])) % 2 == 0 + var fire_tile = FireWallTile.new(container, is_white, 4, tile_owner) + board_flow.get_parent().tileManager.add_tile(pos, fire_tile) + fire_tiles.append(pos) + + previous_position = current_pos + +func remove_effect(): + if attached_piece: + var game_state = attached_piece.get_parent().get_parent().owner + if game_state.is_connected("turn_changed", on_turn_changed): + game_state.disconnect("turn_changed", on_turn_changed) + super.remove_effect() \ No newline at end of file diff --git a/Systems/DeckManager.gd b/Systems/DeckManager.gd index 13a4645..d521afe 100644 --- a/Systems/DeckManager.gd +++ b/Systems/DeckManager.gd @@ -1,11 +1,6 @@ extends Node class_name DeckManager -const DoubleTimeCard = preload("res://Systems/Cards/Doubletime.gd") -const HopscotchCard = preload("res://Systems/Cards/Hopscotch.gd") -const DrunkDrivingCard = preload("res://Systems/Cards/Drunkdriving.gd") -const SupernovaCard = preload("res://Systems/Cards/Supernova.gd") -const ExplosiveBootsCard = preload("res://Systems/Cards/Explosiveboots.gd") var deck: Array = [] var hand: Array = [] var discard: Array = [] @@ -27,6 +22,7 @@ func initializeStartingDeck(): deck.clear(); # for i in range(2): # deck.append(DoubleTimeCard.new()) + deck.append(FireyCapeCard.new()) deck.append(ExplosiveBootsCard.new()) deck.append(DoubleTimeCard.new()) deck.append(DrunkDrivingCard.new()) diff --git a/Systems/StateMachine/GameStates/PostMovePhase.gd b/Systems/StateMachine/GameStates/PostMovePhase.gd index 91b6471..82c2411 100644 --- a/Systems/StateMachine/GameStates/PostMovePhase.gd +++ b/Systems/StateMachine/GameStates/PostMovePhase.gd @@ -5,5 +5,7 @@ func enter(_previous: String, _data := {}) -> void: # game.resolveMoveEffects() if (game.isPlayerTurn()): - game.deckManager.updateCardDurations() + game.updateEffectDurations() + # if (game.isPlayerTurn()): + # game.deckManager.updateCardDurations() finished.emit(Constants.EVALUATE_POSITION) diff --git a/Systems/StateMachine/GameStates/ResolvePersistentEffects.gd b/Systems/StateMachine/GameStates/ResolvePersistentEffects.gd index 2abf8d4..8eb2be5 100644 --- a/Systems/StateMachine/GameStates/ResolvePersistentEffects.gd +++ b/Systems/StateMachine/GameStates/ResolvePersistentEffects.gd @@ -2,5 +2,5 @@ extends "res://Systems/StateMachine/ChessGameState.gd" func enter(_previous: String, _data := {}) -> void: print("ENTERING STATE ", Constants.PERSISTENT_EFFECTS) - game.updateEffectDurations() + finished.emit(Constants.TILE_EFFECTS) diff --git a/Systems/Tile.gd b/Systems/Tile.gd index 046d6ca..74bb72b 100644 --- a/Systems/Tile.gd +++ b/Systems/Tile.gd @@ -25,10 +25,10 @@ var base_is_white: bool # Original tile color signal effect_expired -func _init(button: Button, is_white: bool) -> void: +func _init(button: Button, is_white: bool, d: int) -> void: base_button = button base_is_white = is_white - remaining_turns = duration + remaining_turns = d func is_effect_active() -> bool: return duration == -1 || remaining_turns > 0 @@ -47,9 +47,9 @@ func can_affect_piece(piece: Pawn) -> bool: # Check owner alignment match tile_owner: TileOwner.PLAYER: - return piece.Item_Color == 0 # White + return piece.Item_Color == 1 # White TileOwner.ENEMY: - return piece.Item_Color == 1 # Black + return piece.Item_Color == 0 # Black TileOwner.GAME: return true return false diff --git a/Systems/TileManager.gd b/Systems/TileManager.gd index 046440c..41306b4 100644 --- a/Systems/TileManager.gd +++ b/Systems/TileManager.gd @@ -47,7 +47,8 @@ func update_tile_durations() -> void: return var expired_locations = [] - for location in active_tiles: + var locations = active_tiles.keys() + for location in locations: var tile = active_tiles[location] tile.update_duration() if !tile.is_effect_active(): @@ -74,7 +75,7 @@ func clear_tiles() -> void: remove_tile(location) # Function to place random game tiles at the start of each match -func place_random_game_tiles(num_tiles: int = 3) -> void: +func place_random_game_tiles(num_tiles: int = 6) -> void: if !board_flow: push_error("TileManager not initialized with board_flow") return @@ -102,11 +103,11 @@ func place_random_game_tiles(num_tiles: int = 3) -> void: var tile: Tile match tile_type: - 0: # Double Movement tile - tile = DoubleMovementTile.new(container, is_white) + 0: # DoubleMovementTile tile + tile = FireWallTile.new(container, is_white, 3) 1: # FireWallTile - tile = FireWallTile.new(container, is_white) - 2: # Pawn Boost tile - tile = PawnBoostTile.new(container, is_white) + tile = FireWallTile.new(container, is_white, 3) + 2: # PawnBoostTile tile + tile = FireWallTile.new(container, is_white, 3) add_tile(pos, tile) \ No newline at end of file diff --git a/Systems/Tiles/DoubleMovement.gd b/Systems/Tiles/DoubleMovement.gd index 00d20e5..59dcb1b 100644 --- a/Systems/Tiles/DoubleMovement.gd +++ b/Systems/Tiles/DoubleMovement.gd @@ -1,15 +1,16 @@ class_name DoubleMovementTile extends Tile -func _init(button: Button, is_white: bool) -> void: - super._init(button, is_white) +func _init(button: Button, is_white: bool, d: int) -> void: + super._init(button, is_white, d) tile_name = "Double Movement" description = "Any unit that starts its turn here gets double movement for 2 turns" type = TileType.GENERAL tile_owner = TileOwner.GAME - duration = -1 # Permanent tile + duration = d # Permanent tile func apply_effect(piece: Pawn = null) -> void: + print("APPLY DoubleMovementTile") if piece && is_effect_active(): # Add double movement effect to the piece var deck_manager = piece.get_parent().get_parent().get_parent().deckManager @@ -29,3 +30,5 @@ func update_appearance() -> void: (base_color.b + tile_color.b) / 2 ) base_button.add_theme_stylebox_override("normal", style) + else: + restore_base_appearance() diff --git a/Systems/Tiles/FireWall.gd b/Systems/Tiles/FireWall.gd index 67ce420..d5a27a3 100644 --- a/Systems/Tiles/FireWall.gd +++ b/Systems/Tiles/FireWall.gd @@ -1,41 +1,46 @@ class_name FireWallTile extends Tile -func _init(button: Button, is_white: bool) -> void: - super._init(button, is_white) +func _init(button: Button, is_white: bool, d: int, owner: TileOwner = TileOwner.GAME) -> void: + super._init(button, is_white, d) tile_name = "Fire Wall" description = "Captures any piece that moves through" type = TileType.GENERAL - duration = 3 + duration = d func apply_effect(piece: Pawn = null) -> void: if piece && is_effect_active(): - # Get the parent container and remove the piece - var container = piece.get_parent() as PieceContainer - if container: - var board = container.get_parent().get_parent() as ChessGame - board.updatePoints(piece) - container.remove_piece() + # Only affect enemy pieces based on tile owner + var is_enemy = false + match tile_owner: + TileOwner.PLAYER: # White + is_enemy = piece.Item_Color == 1 # Black pieces are enemy + TileOwner.ENEMY: # Black + is_enemy = piece.Item_Color == 0 # White pieces are enemy + TileOwner.GAME: + is_enemy = true # Game-owned fire affects all + + if is_enemy: + var container = piece.get_parent() as PieceContainer + if container: + var board = container.get_parent().get_parent() as ChessGame + board.updatePoints(piece) + container.remove_piece() func update_appearance() -> void: if is_effect_active() && base_button: var style = StyleBoxFlat.new() - var tile_color = Color(1, 0.4, 0) # Orange for fire + var tile_color = Color(1, 0.4, 0) # Default orange-ish color for effects var base_color = Color(0.8, 0.8, 0.8) if base_is_white else Color(0.2, 0.2, 0.2) + # Blend the tile effect color with the base chess board color style.bg_color = Color( (base_color.r + tile_color.r) / 2, (base_color.g + tile_color.g) / 2, (base_color.b + tile_color.b) / 2 ) - # Add overlay effect for fire - var overlay = ColorRect.new() - overlay.name = "FireOverlay" - overlay.color = Color(1, 0.4, 0, 0.3) # Semi-transparent orange - overlay.size = base_button.size - overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE - - base_button.add_child(overlay) + # Apply the style using theme override + base_button.add_theme_stylebox_override("normal", style) else: restore_base_appearance() \ No newline at end of file diff --git a/Systems/Tiles/PawnBoost.gd b/Systems/Tiles/PawnBoost.gd index 1eb5121..daaf939 100644 --- a/Systems/Tiles/PawnBoost.gd +++ b/Systems/Tiles/PawnBoost.gd @@ -1,16 +1,17 @@ class_name PawnBoostTile extends Tile -func _init(button: Button, is_white: bool) -> void: - super._init(button, is_white) +func _init(button: Button, is_white: bool, d: int) -> void: + super._init(button, is_white, d) tile_name = "Pawn Boost" description = "While a Bishop is here, friendly pawns can move 2 spots" type = TileType.GLOBAL target_piece_type = "Bishop" tile_owner = TileOwner.GAME - duration = -1 + duration = d func apply_effect(piece: Pawn = null) -> void: + print("APPLY PawnBoostTile") if piece && is_effect_active() && piece.name == "Bishop": # This would be implemented in the pawn movement calculation pass @@ -26,4 +27,7 @@ func update_appearance() -> void: (base_color.g + tile_color.g) / 2, (base_color.b + tile_color.b) / 2 ) - base_button.add_theme_stylebox_override("normal", style) \ No newline at end of file + base_button.add_theme_stylebox_override("normal", style) + else: + restore_base_appearance() +