added card which create tiles

This commit is contained in:
2ManyProjects 2025-02-05 17:50:42 -06:00
parent 7012ea4f16
commit e8042a2c44
9 changed files with 132 additions and 43 deletions

View file

@ -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()

View file

@ -1,11 +1,6 @@
extends Node extends Node
class_name DeckManager 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 deck: Array = []
var hand: Array = [] var hand: Array = []
var discard: Array = [] var discard: Array = []
@ -27,6 +22,7 @@ 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(FireyCapeCard.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())

View file

@ -5,5 +5,7 @@ func enter(_previous: String, _data := {}) -> void:
# game.resolveMoveEffects() # game.resolveMoveEffects()
if (game.isPlayerTurn()): if (game.isPlayerTurn()):
game.deckManager.updateCardDurations() game.updateEffectDurations()
# if (game.isPlayerTurn()):
# game.deckManager.updateCardDurations()
finished.emit(Constants.EVALUATE_POSITION) finished.emit(Constants.EVALUATE_POSITION)

View file

@ -2,5 +2,5 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
func enter(_previous: String, _data := {}) -> void: func enter(_previous: String, _data := {}) -> void:
print("ENTERING STATE ", Constants.PERSISTENT_EFFECTS) print("ENTERING STATE ", Constants.PERSISTENT_EFFECTS)
game.updateEffectDurations()
finished.emit(Constants.TILE_EFFECTS) finished.emit(Constants.TILE_EFFECTS)

View file

@ -25,10 +25,10 @@ var base_is_white: bool # Original tile color
signal effect_expired 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_button = button
base_is_white = is_white base_is_white = is_white
remaining_turns = duration remaining_turns = d
func is_effect_active() -> bool: func is_effect_active() -> bool:
return duration == -1 || remaining_turns > 0 return duration == -1 || remaining_turns > 0
@ -47,9 +47,9 @@ func can_affect_piece(piece: Pawn) -> bool:
# Check owner alignment # Check owner alignment
match tile_owner: match tile_owner:
TileOwner.PLAYER: TileOwner.PLAYER:
return piece.Item_Color == 0 # White return piece.Item_Color == 1 # White
TileOwner.ENEMY: TileOwner.ENEMY:
return piece.Item_Color == 1 # Black return piece.Item_Color == 0 # Black
TileOwner.GAME: TileOwner.GAME:
return true return true
return false return false

View file

@ -47,7 +47,8 @@ func update_tile_durations() -> void:
return return
var expired_locations = [] var expired_locations = []
for location in active_tiles: var locations = active_tiles.keys()
for location in locations:
var tile = active_tiles[location] var tile = active_tiles[location]
tile.update_duration() tile.update_duration()
if !tile.is_effect_active(): if !tile.is_effect_active():
@ -74,7 +75,7 @@ func clear_tiles() -> void:
remove_tile(location) remove_tile(location)
# Function to place random game tiles at the start of each match # 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: if !board_flow:
push_error("TileManager not initialized with board_flow") push_error("TileManager not initialized with board_flow")
return return
@ -102,11 +103,11 @@ func place_random_game_tiles(num_tiles: int = 3) -> void:
var tile: Tile var tile: Tile
match tile_type: match tile_type:
0: # Double Movement tile 0: # DoubleMovementTile tile
tile = DoubleMovementTile.new(container, is_white) tile = FireWallTile.new(container, is_white, 3)
1: # FireWallTile 1: # FireWallTile
tile = FireWallTile.new(container, is_white) tile = FireWallTile.new(container, is_white, 3)
2: # Pawn Boost tile 2: # PawnBoostTile tile
tile = PawnBoostTile.new(container, is_white) tile = FireWallTile.new(container, is_white, 3)
add_tile(pos, tile) add_tile(pos, tile)

View file

@ -1,15 +1,16 @@
class_name DoubleMovementTile class_name DoubleMovementTile
extends Tile extends Tile
func _init(button: Button, is_white: bool) -> void: func _init(button: Button, is_white: bool, d: int) -> void:
super._init(button, is_white) super._init(button, is_white, d)
tile_name = "Double Movement" tile_name = "Double Movement"
description = "Any unit that starts its turn here gets double movement for 2 turns" description = "Any unit that starts its turn here gets double movement for 2 turns"
type = TileType.GENERAL type = TileType.GENERAL
tile_owner = TileOwner.GAME tile_owner = TileOwner.GAME
duration = -1 # Permanent tile duration = d # Permanent tile
func apply_effect(piece: Pawn = null) -> void: func apply_effect(piece: Pawn = null) -> void:
print("APPLY DoubleMovementTile")
if piece && is_effect_active(): if piece && is_effect_active():
# Add double movement effect to the piece # Add double movement effect to the piece
var deck_manager = piece.get_parent().get_parent().get_parent().deckManager 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_color.b + tile_color.b) / 2
) )
base_button.add_theme_stylebox_override("normal", style) base_button.add_theme_stylebox_override("normal", style)
else:
restore_base_appearance()

View file

@ -1,41 +1,46 @@
class_name FireWallTile class_name FireWallTile
extends Tile extends Tile
func _init(button: Button, is_white: bool) -> void: func _init(button: Button, is_white: bool, d: int, owner: TileOwner = TileOwner.GAME) -> void:
super._init(button, is_white) super._init(button, is_white, d)
tile_name = "Fire Wall" tile_name = "Fire Wall"
description = "Captures any piece that moves through" description = "Captures any piece that moves through"
type = TileType.GENERAL type = TileType.GENERAL
duration = 3 duration = d
func apply_effect(piece: Pawn = null) -> void: func apply_effect(piece: Pawn = null) -> void:
if piece && is_effect_active(): if piece && is_effect_active():
# Get the parent container and remove the piece # Only affect enemy pieces based on tile owner
var container = piece.get_parent() as PieceContainer var is_enemy = false
if container: match tile_owner:
var board = container.get_parent().get_parent() as ChessGame TileOwner.PLAYER: # White
board.updatePoints(piece) is_enemy = piece.Item_Color == 1 # Black pieces are enemy
container.remove_piece() 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: func update_appearance() -> void:
if is_effect_active() && base_button: if is_effect_active() && base_button:
var style = StyleBoxFlat.new() 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) 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( style.bg_color = Color(
(base_color.r + tile_color.r) / 2, (base_color.r + tile_color.r) / 2,
(base_color.g + tile_color.g) / 2, (base_color.g + tile_color.g) / 2,
(base_color.b + tile_color.b) / 2 (base_color.b + tile_color.b) / 2
) )
# Add overlay effect for fire # Apply the style using theme override
var overlay = ColorRect.new() base_button.add_theme_stylebox_override("normal", style)
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)
else: else:
restore_base_appearance() restore_base_appearance()

View file

@ -1,16 +1,17 @@
class_name PawnBoostTile class_name PawnBoostTile
extends Tile extends Tile
func _init(button: Button, is_white: bool) -> void: func _init(button: Button, is_white: bool, d: int) -> void:
super._init(button, is_white) super._init(button, is_white, d)
tile_name = "Pawn Boost" tile_name = "Pawn Boost"
description = "While a Bishop is here, friendly pawns can move 2 spots" description = "While a Bishop is here, friendly pawns can move 2 spots"
type = TileType.GLOBAL type = TileType.GLOBAL
target_piece_type = "Bishop" target_piece_type = "Bishop"
tile_owner = TileOwner.GAME tile_owner = TileOwner.GAME
duration = -1 duration = d
func apply_effect(piece: Pawn = null) -> void: func apply_effect(piece: Pawn = null) -> void:
print("APPLY PawnBoostTile")
if piece && is_effect_active() && piece.name == "Bishop": if piece && is_effect_active() && piece.name == "Bishop":
# This would be implemented in the pawn movement calculation # This would be implemented in the pawn movement calculation
pass pass
@ -26,4 +27,7 @@ func update_appearance() -> void:
(base_color.g + tile_color.g) / 2, (base_color.g + tile_color.g) / 2,
(base_color.b + tile_color.b) / 2 (base_color.b + tile_color.b) / 2
) )
base_button.add_theme_stylebox_override("normal", style) base_button.add_theme_stylebox_override("normal", style)
else:
restore_base_appearance()