Compare commits

..

No commits in common. "75cd2fbe79d37d472d4d2e867906ca33efee9407" and "5d410a02fb45e1e47b9645a7f8d6b75a17a1f4a4" have entirely different histories.

21 changed files with 352 additions and 876 deletions

View file

@ -1,98 +1,95 @@
class_name CardDisplay extends Control extends Control
class_name CardDisplay
const CARD_WIDTH = 150
const CARD_HEIGHT = 250
const CARD_MARGIN = 10
var cardDisplays = [] var cardDisplays = []
var selectedCard = null var selectedCard = null
var container: HBoxContainer const CARD_WIDTH = 150
const CARD_HEIGHT = 250
const CARD_MARGIN = 10
@onready var container: HBoxContainer
func _ready(): func _ready():
# Create the container first container = HBoxContainer.new()
container = HBoxContainer.new() container.name = "Hand"
container.name = "Hand" container.set_position(Vector2(10, 500))
container.position = Vector2(10, 500) add_child(container)
add_child(container)
func update_hand(hand: Array): func update_hand(hand: Array):
clear_cards() clear_cards()
for card in hand: for card in hand:
add_card_display(card) add_card_display(card)
func add_card_display(card): func add_card_display(card):
var cardPanel = PanelContainer.new() var cardPanel = PanelContainer.new()
cardPanel.custom_minimum_size = Vector2(CARD_WIDTH, CARD_HEIGHT) cardPanel.custom_minimum_size = Vector2(CARD_WIDTH, CARD_HEIGHT)
var vbox = VBoxContainer.new() var vbox = VBoxContainer.new()
vbox.set_meta("card_id", card.id) vbox.set_meta("card_id", card.id)
cardPanel.add_child(vbox) cardPanel.add_child(vbox)
var nameLabel = Label.new() var nameLabel = Label.new()
nameLabel.text = card.cardName nameLabel.text = card.cardName
nameLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER nameLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
vbox.add_child(nameLabel) vbox.add_child(nameLabel)
var rankLabel = Label.new() var rankLabel = Label.new()
rankLabel.text = "Rank " + str(card.rank) rankLabel.text = "Rank " + str(card.rank)
rankLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER rankLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
vbox.add_child(rankLabel) vbox.add_child(rankLabel)
var descLabel = Label.new() var descLabel = Label.new()
descLabel.text = card.description descLabel.text = card.description
descLabel.autowrap_mode = TextServer.AUTOWRAP_WORD descLabel.autowrap_mode = TextServer.AUTOWRAP_WORD
descLabel.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0) descLabel.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
vbox.add_child(descLabel) vbox.add_child(descLabel)
var unitWhitelistLabel = Label.new() var idLabel = Label.new()
unitWhitelistLabel.text = ", ".join(card.unitWhitelist) idLabel.text = card.id.substr(card.id.length() - 8, -1)
unitWhitelistLabel.autowrap_mode = TextServer.AUTOWRAP_WORD idLabel.autowrap_mode = true
unitWhitelistLabel.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0) idLabel.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
vbox.add_child(unitWhitelistLabel) vbox.add_child(idLabel)
var idLabel = Label.new()
idLabel.text = card.id.substr(card.id.length() - 8, -1)
idLabel.autowrap_mode = true
idLabel.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
vbox.add_child(idLabel)
cardPanel.gui_input.connect(func(event): _on_card_clicked(event, card)) cardPanel.gui_input.connect(func(event): _on_card_clicked(event, card))
cardDisplays.append(cardPanel) cardDisplays.append(cardPanel)
container.add_child(cardPanel) container.add_child(cardPanel)
func _on_card_clicked(event: InputEvent, card: Card): func _on_card_clicked(event: InputEvent, card: Card):
if event is InputEventMouseButton and event.pressed: if event is InputEventMouseButton and event.pressed:
if selectedCard == null || selectedCard.id != card.id: if selectedCard == null || selectedCard.id != card.id:
selectedCard = card selectedCard = card
container.emit_signal("card_pressed", card) container.emit_signal("card_pressed", card)
elif selectedCard.id == card.id: elif selectedCard.id == card.id:
selectedCard = null selectedCard = null
highlight_selectedCard(selectedCard) highlight_selectedCard(selectedCard)
# selectedCard = card
# highlight_selectedCard(card)
# container.emit_signal("card_pressed", card)
func highlight_selectedCard(selected: Card) -> void: func highlight_selectedCard(selected: Card) -> void:
for display in cardDisplays: for display in cardDisplays:
var style = StyleBoxFlat.new() var style = StyleBoxFlat.new()
style.bg_color = Color(0.2, 0.2, 0.2, 1) # Default color style.bg_color = Color(0.2, 0.2, 0.2, 1) # Default color
var vbox = display.get_child(0) var vbox = display.get_child(0)
if selected && vbox.get_meta("card_id") == selected.id: if selected && vbox.get_meta("card_id") == selected.id:
style.bg_color = Color(0.4, 0.6, 0.4, 1) # Selected color style.bg_color = Color(0.4, 0.6, 0.4, 1) # Selected color
display.add_theme_stylebox_override("panel", style) display.add_theme_stylebox_override("panel", style)
func get_card_by_uuid(uuid: String) -> Card: func get_card_by_uuid(uuid: String) -> Card:
for display in cardDisplays: for display in cardDisplays:
var vbox = display.get_child(0) var vbox = display.get_child(0)
if vbox.get_meta("card_id") == uuid: if vbox.get_meta("card_id") == uuid:
return selectedCard return selectedCard
return null return null
func getSelectedCard() -> Card: func getSelectedCard() -> Card:
return selectedCard return selectedCard
func clear_cards(): func clear_cards():
for display in cardDisplays: for display in cardDisplays:
display.queue_free() display.queue_free()
cardDisplays.clear() cardDisplays.clear()
selectedCard = null selectedCard = null

View file

@ -8,6 +8,7 @@ func _init():
effectType = EffectType.SPECIAL_ACTION effectType = EffectType.SPECIAL_ACTION
description = "Force peice to careen towards the enemy side, capturing all pieces in its path" description = "Force peice to careen towards the enemy side, capturing all pieces in its path"
unitWhitelist = ["Rook", "Queen"] unitWhitelist = ["Rook", "Queen"]
func apply_effect(target_piece = null, board_flow = null, game_state = null): func apply_effect(target_piece = null, board_flow = null, game_state = null):
if !super.apply_effect(target_piece, board_flow, game_state): if !super.apply_effect(target_piece, board_flow, game_state):
return false return false
@ -15,44 +16,43 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
if !target_piece or !board_flow or !game_state: if !target_piece or !board_flow or !game_state:
return false return false
# Get current container and position
var current_container = target_piece.get_parent() as PieceContainer var current_pos = target_piece.get_parent().name.split("-")
var current_pos = current_container.name.split("-")
var current_x = int(current_pos[0]) var current_x = int(current_pos[0])
var current_y = int(current_pos[1]) var current_y = int(current_pos[1])
# Calculate target position
var target_y = 7 if target_piece.Item_Color == 1 else 0 var target_y = 7 if target_piece.Item_Color == 1 else 0
var y_direction = 1 if target_y > current_y else -1 var y_direction = 1 if target_y > current_y else -1
# Generate tiles to check
var tiles_to_check = [] var tiles_to_check = []
var y = current_y + y_direction var y = current_y + y_direction
while y != target_y + y_direction: while y != target_y + y_direction:
tiles_to_check.append(str(current_x) + "-" + str(y)) tiles_to_check.append(str(current_x) + "-" + str(y))
y += y_direction y += y_direction
# Process pieces in path
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 tile = board_flow.get_node(tile_name)
if container.has_piece(): if tile.get_child_count() > 0:
var piece_to_capture = container.get_piece() var piece_to_capture = tile.get_child(0)
game_state.updatePoints(piece_to_capture) game_state.updatePoints(piece_to_capture)
container.remove_piece() piece_to_capture.queue_free()
# Move piece to final position
var final_container = board_flow.get_node(str(current_x) + "-" + str(target_y)) as PieceContainer
# Important: Need to remove the piece from its current container first var final_tile = board_flow.get_node(str(current_x) + "-" + str(target_y))
# AND keep a reference to it target_piece.reparent(final_tile)
target_piece = current_container.get_piece() # Get reference before removing target_piece.position = Vector2(25, 25)
current_container.remove_piece(true) # Remove from current container
final_container.set_piece(target_piece) # Set in new container
game_state.currentlyMovingPiece = target_piece game_state.currentlyMovingPiece = target_piece
burned = true burned = true
game_state.resolveMoveEffects() game_state.resolveMoveEffects();
game_state.stateMachine.transitionToNextState(Constants.POST_MOVE) game_state.stateMachine.transitionToNextState(Constants.POST_MOVE)
return true return true

View file

@ -42,34 +42,32 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
tiles_to_check.append(str(target_x) + "-" + str(target_y)) tiles_to_check.append(str(target_x) + "-" + str(target_y))
# 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 tile = board_flow.get_node(tile_name)
# Handle overlay through container's overlay management var existing_overlay = tile.get_node_or_null("ExplosiveBootsOverlay")
container.remove_overlay("ExplosiveBootsOverlay") if existing_overlay:
existing_overlay.queue_free()
var overlay = ColorRect.new() var overlay = ColorRect.new()
overlay.name = "ExplosiveBootsOverlay" overlay.name = "ExplosiveBootsOverlay"
overlay.color = Color(1, 0, 0, 0.3) overlay.color = Color(1, 0, 0, 0.3)
overlay.size = container.size overlay.size = tile.size
overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE
container.add_overlay(overlay) tile.add_child(overlay)
overlay.show() overlay.show()
# Check for pieces to affect if tile.get_child_count() > 1: # > 1 because we just added the overlay
var piece = container.get_piece() var piece = tile.get_child(0)
if piece != null and piece.Item_Color != target_piece.Item_Color: if piece.Item_Color != target_piece.Item_Color:
game_state.updatePoints(piece) game_state.updatePoints(piece)
container.remove_piece() piece.queue_free()
# Setup timer to remove overlays # Setup timer to remove overlays
var timer = Timer.new() var timer = Timer.new()
board_flow.add_child(timer) board_flow.add_child(timer)
timer.wait_time = 1 timer.wait_time = 0.5
timer.one_shot = true timer.one_shot = true
timer.timeout.connect(func(): timer.timeout.connect(func():
for tile_name in tiles_to_check: for tile_name in tiles_to_check:

View file

@ -1,78 +0,0 @@
class_name FieryCapeCard extends Card
var previous_position: String = ""
var fire_tiles: Array[String] = []
func _init():
super._init()
cardName = "Fiery 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 = ["Pawn", "Bishop", "Queen", "King", "Rook"] # 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,7 +1,6 @@
class_name SupernovaCard extends Card class_name SupernovaCard extends Card
const CAPTURE_RADIUS = 4 const CAPTURE_RADIUS = 4
var valid = false;
func _init(): func _init():
super._init() super._init()
@ -11,17 +10,14 @@ func _init():
duration = 5 duration = 5
description = "All enemy units within 4 radius are captured" description = "All enemy units within 4 radius are captured"
unitWhitelist = ["King"] unitWhitelist = ["King"]
remaining_turns = duration
func apply_effect(target_piece = null, board_flow = null, game_state = null): func apply_effect(target_piece = null, board_flow = null, game_state = null):
attached_piece = target_piece if !super.apply_effect(target_piece, board_flow, game_state):
if !target_piece or !board_flow or !game_state:
print(cardName, " missing input param ")
return false return false
setup_persistent_effect(game_state)
# dont apply on card attachment if !target_piece or !board_flow or !game_state:
if !valid: return false
return true
# Get king's position # Get king's position
var king_pos = target_piece.get_parent().name.split("-") var king_pos = target_piece.get_parent().name.split("-")
var king_x = int(king_pos[0]) var king_x = int(king_pos[0])
@ -52,73 +48,47 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
# Add tile to check list # Add tile to check list
tiles_to_check.append(str(target_x) + "-" + str(target_y)) tiles_to_check.append(str(target_x) + "-" + str(target_y))
# Process each tile and capture pieces
for tile_name in tiles_to_check: for tile_name in tiles_to_check:
var tile = board_flow.get_node(tile_name) as PieceContainer var tile = board_flow.get_node("Flow/" + tile_name)
if tile.get_piece() != null: if tile.get_child_count() > 0:
var piece = tile.get_piece() var piece = tile.get_child(0)
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.updatePoints(piece)
tile.remove_piece() piece.queue_free()
# Process tiles and add overlay
# Visual feedback
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 tile = board_flow.get_node("Flow/" + tile_name)
var style = StyleBoxFlat.new()
style.bg_color = Color(1, 0, 0, 0.3) # Red tint
tile.add_theme_stylebox_override("normal", style)
# Handle overlay through container's overlay management # Remove highlight after delay
container.remove_overlay("SupernovaOverlay") var timer = Timer.new()
board_flow.add_child(timer)
var overlay = ColorRect.new() timer.wait_time = 0.5
overlay.name = "SupernovaOverlay" timer.one_shot = true
overlay.color = Color(1, 0, 0, 0.3) timer.timeout.connect(func():
overlay.size = container.size tile.remove_theme_stylebox_override("normal")
overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE timer.queue_free()
container.add_overlay(overlay) )
overlay.show() timer.start()
# 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()
# Setup timer to remove overlays
var timer = Timer.new()
board_flow.add_child(timer)
timer.wait_time = 1
timer.one_shot = true
timer.timeout.connect(func():
for tile_name in tiles_to_check:
var tile = board_flow.get_node(tile_name)
var overlay = tile.get_node_or_null("SupernovaOverlay")
if overlay:
overlay.queue_free()
timer.queue_free()
)
timer.start()
# game_state.stateMachine.transitionToNextState(Constants.POST_MOVE)
return true return true
func setup_persistent_effect(king, game_state):
func setup_persistent_effect(game_state):
# Connect to the turn change signal if not already connected # Connect to the turn change signal if not already connected
if !game_state.is_connected("turn_changed", Callable(self, "on_turn_changed")): if !game_state.is_connected("turn_changed", Callable(self, "on_turn_changed")):
game_state.connect("turn_changed", Callable(self, "on_turn_changed")) game_state.connect("turn_changed", Callable(self, "on_turn_changed"))
func on_turn_changed(): func on_turn_changed():
if attached_piece and remaining_turns > 0:
if attached_piece.get_parent().get_parent().owner.isPlayerTurn() and attached_piece and remaining_turns > 0: # Reapply the effect at the start of each turn
# print(attached_piece.get_parent().get_parent(), attached_piece.get_parent().get_parent().owner) apply_effect(attached_piece, attached_piece.get_parent().get_parent(), attached_piece.get_parent().get_parent().owner)
var piece = attached_piece remaining_turns -= 1
var flow = attached_piece.get_parent().get_parent() if remaining_turns <= 0:
var state = attached_piece.get_parent().get_parent().owner remove_effect()
# print("Debug values:")
# print("- Piece: ", piece, " is null? ", piece == null)
# print("- Board Flow: ", flow, " is null? ", flow == null)
# print("- Game State: ", state, " is null? ", state == null)
# Now try apply_effect with these values
valid = true
apply_effect(piece, flow, state)
func remove_effect(): func remove_effect():
if attached_piece: if attached_piece:

View file

@ -1,6 +1,11 @@
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 = []
@ -22,7 +27,6 @@ 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(ExplosiveBootsCard.new()) deck.append(ExplosiveBootsCard.new())
deck.append(DoubleTimeCard.new()) deck.append(DoubleTimeCard.new())
deck.append(DrunkDrivingCard.new()) deck.append(DrunkDrivingCard.new())

View file

@ -1,6 +1,5 @@
class_name ChessGame extends Control class_name ChessGame extends Control
const PieceContainer = preload("res://Systems/PieceContainer.gd")
const WHITE = "white" const WHITE = "white"
const BLACK = "black" const BLACK = "black"
signal tile_pressed(location: String) signal tile_pressed(location: String)
@ -8,6 +7,7 @@ signal send_location(location: String)
signal turn_changed signal turn_changed
var currentPlayer: String = WHITE var currentPlayer: String = WHITE
var board: Array var board: Array
var activeEffects: Array
var currentHand: Array var currentHand: Array
var selectedNode: String = "" var selectedNode: String = ""
var locationX: String = "" var locationX: String = ""
@ -25,7 +25,6 @@ var Turn: int = 0
@onready var p1String: RichTextLabel = $Player1Points @onready var p1String: RichTextLabel = $Player1Points
@onready var p2String: RichTextLabel = $Player2Points @onready var p2String: RichTextLabel = $Player2Points
@onready var deckManager: DeckManager @onready var deckManager: DeckManager
@onready var tileManager: TileManager
@onready var cardDisplay: CardDisplay @onready var cardDisplay: CardDisplay
@onready var cardPreview: CardPreview @onready var cardPreview: CardPreview
@ -44,19 +43,9 @@ var highlightStyle = null
func _ready() -> void: func _ready() -> void:
initializeGame() initializeGame()
initializeTiles()
stateMachine.transitionToNextState(Constants.WHITE_TURN) stateMachine.transitionToNextState(Constants.WHITE_TURN)
func initializeTiles() -> void:
tileManager = TileManager.new($Flow, self)
add_child(tileManager)
await get_tree().process_frame
tileManager.initialize(boardContainer)
tileManager.place_random_game_tiles()
func get_base_style(is_white: bool) -> StyleBoxFlat:
return lightStyle if is_white else darkStyle
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:
stateMachine.unhandledInput(event) stateMachine.unhandledInput(event)
@ -133,7 +122,7 @@ func createBoard() -> void:
func createTile(x: int, y: int, isWhite: bool) -> void: func createTile(x: int, y: int, isWhite: bool) -> void:
# print("CreateTile x ", x, " y ", y); # print("CreateTile x ", x, " y ", y);
var tile = PieceContainer.new() var tile = Button.new()
tile.set_custom_minimum_size(Vector2(tileXSize, tileYSize)) tile.set_custom_minimum_size(Vector2(tileXSize, tileYSize))
tile.add_theme_stylebox_override("normal", lightStyle if isWhite else darkStyle) tile.add_theme_stylebox_override("normal", lightStyle if isWhite else darkStyle)
@ -220,10 +209,7 @@ func setupPieces() -> void:
func placePiece(position: String, pieceName: String, color: int) -> void: func placePiece(position: String, pieceName: String, color: int) -> void:
var piece = summonPiece(pieceName, color) var piece = summonPiece(pieceName, color)
# boardContainer.get_node(position).add_child(piece) boardContainer.get_node(position).add_child(piece)
var container = boardContainer.get_node(position)
container.set_piece(piece)
var coords = position.split("-") var coords = position.split("-")
board[int(coords[1])][int(coords[0])] = piece board[int(coords[1])][int(coords[0])] = piece
@ -256,8 +242,8 @@ func summonPiece(pieceName: String, color: int) -> Node:
func clearBoard() -> void: func clearBoard() -> void:
for child in boardContainer.get_children(): for child in boardContainer.get_children():
if child is PieceContainer: if child.get_child_count() > 0:
child.remove_piece() child.get_child(0).queue_free()
# func prepareHand() -> void: # func prepareHand() -> void:
@ -266,11 +252,16 @@ func clearBoard() -> void:
# pass # pass
func updateEffectDurations() -> void: func updateEffectDurations() -> void:
deckManager.updateCardDurations() for effect in activeEffects:
tileManager.update_tile_durations() effect.duration -= 1
if effect.duration <= 0:
activeEffects.erase(effect)
func applyTileEffects() -> void: func applyTileEffects() -> void:
tileManager.apply_tile_effects() for piece in get_tree().get_nodes_in_group("Pieces"):
var tile = piece.get_parent()
if tile.has_effect():
tile.apply_effect(piece)
func applyCardEffects() -> void: func applyCardEffects() -> void:
@ -284,9 +275,8 @@ func evaluatePosition() -> Dictionary:
return status return status
func isValidMove(location: String) -> bool: func isValidMove(location: String) -> bool:
var node = get_node("Flow/" + location) as PieceContainer var node = get_node("Flow/" + location)
var piece = node.get_piece() if node.get_child_count() == 0 || node.get_child(0).Item_Color != Turn:
if piece == null || piece.Item_Color != Turn:
for area in areas: for area in areas:
if area == node.name: if area == node.name:
return true return true
@ -316,8 +306,8 @@ func getMovableAreas() -> void:
resetHighlights() resetHighlights()
areas.clear() areas.clear()
specialArea.clear() specialArea.clear()
var container = get_node("Flow/" + selectedNode) as PieceContainer
var piece = container.get_piece() var piece = get_node("Flow/" + selectedNode).get_child(0)
var piece_id = piece.get_instance_id() var piece_id = piece.get_instance_id()
# print("HIGHLIGHTING getMovableAreas 2") # print("HIGHLIGHTING getMovableAreas 2")
if deckManager.attached_cards.has(piece_id): if deckManager.attached_cards.has(piece_id):
@ -338,45 +328,34 @@ func getMovableAreas() -> void:
highlightValidMoves() highlightValidMoves()
func highlightValidMoves() -> void: func highlightValidMoves() -> void:
# print("HIGHLIGHTING VALID MOVES")
for move in areas: for move in areas:
var button = boardContainer.get_node(move) var button = boardContainer.get_node(move)
var isWhiteSquare = (int(move.split("-")[0]) + int(move.split("-")[1])) % 2 == 0
# If there's an active tile effect, combine with its current style instead var baseStyle = lightStyle if isWhiteSquare else darkStyle
if tileManager && tileManager.get_tile(move): var combinedStyle = StyleBoxFlat.new()
var current_style = button.get_theme_stylebox("normal") combinedStyle.bg_color = baseStyle.bg_color + highlightStyle.bg_color
var highlightedStyle = StyleBoxFlat.new() button.add_theme_stylebox_override("normal", combinedStyle)
highlightedStyle.bg_color = current_style.bg_color + highlightStyle.bg_color
button.add_theme_stylebox_override("normal", highlightedStyle)
else:
# Default chess pattern highlighting
var isWhiteSquare = (int(move.split("-")[0]) + int(move.split("-")[1])) % 2 == 0
var baseStyle = lightStyle if isWhiteSquare else darkStyle
var combinedStyle = StyleBoxFlat.new()
combinedStyle.bg_color = baseStyle.bg_color + highlightStyle.bg_color
button.add_theme_stylebox_override("normal", combinedStyle)
func executeMove(targetLocation: String) -> void: func executeMove(targetLocation: String) -> void:
print("executeMove ", targetLocation) print("executeMove ", targetLocation)
var targetContainer = get_node("Flow/" + targetLocation) as PieceContainer var targetNode = get_node("Flow/" + targetLocation)
var sourceContainer = get_node("Flow/" + selectedNode) as PieceContainer var piece = get_node("Flow/" + selectedNode).get_child(0)
var piece = sourceContainer.get_piece() # print("piece", piece)
var old_location = selectedNode
# Handle capture if there's a piece in target location if targetNode.get_child_count() != 0:
if targetContainer.has_piece(): var capturedPiece = targetNode.get_child(0)
var capturedPiece = targetContainer.get_piece()
if Turn == 0: if Turn == 0:
p1Points += capturedPiece.Points p1Points += capturedPiece.Points
p1String.text = str(p1Points) p1String.text = str(p1Points)
else: else:
p2Points += capturedPiece.Points p2Points += capturedPiece.Points
p2String.text = str(p2Points) p2String.text = str(p2Points)
targetContainer.remove_piece() # This handles freeing the captured piece capturedPiece.free()
# Move piece to new location
sourceContainer.remove_piece(true)
targetContainer.set_piece(piece)
piece.reparent(targetNode)
piece.position = Vector2(25, 25)
# print("piece2", piece)
hasMoved = true hasMoved = true
currentlyMovingPiece = piece currentlyMovingPiece = piece
resetHighlights() resetHighlights()
@ -411,11 +390,6 @@ func resetHighlights():
for button in boardContainer.get_children(): for button in boardContainer.get_children():
if !button.name.contains("-"): if !button.name.contains("-"):
continue continue
# Skip if this tile has an active effect
if tileManager && tileManager.get_tile(button.name):
continue
var coord = button.name.split("-") var coord = button.name.split("-")
var isWhiteSquare = (int(coord[0]) + int(coord[1])) % 2 == 0 var isWhiteSquare = (int(coord[0]) + int(coord[1])) % 2 == 0
if isWhiteSquare: if isWhiteSquare:

View file

@ -1,56 +0,0 @@
class_name PieceContainer extends Button
var piece: Pawn = null
var effects: Node # Keep effects as a sub-node
var overlay_nodes: Array[Node] = []
func _init() -> void:
# Setup effects node
effects = Node.new()
effects.name = "Effects"
add_child(effects)
func set_piece(new_piece: Pawn) -> void:
remove_piece() # Clean up any existing piece
piece = new_piece
if new_piece != null:
add_child(new_piece)
new_piece.position = Vector2(25, 25)
func get_piece() -> Pawn:
return piece
func remove_piece(keep_piece: bool = false) -> Pawn:
var old_piece = piece
if piece != null:
remove_child(piece)
if !keep_piece:
piece.queue_free()
old_piece = null
piece = null
return old_piece
func add_overlay(overlay: Node) -> void:
if overlay is ColorRect:
overlay.size = size
overlay.position = Vector2.ZERO
overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(overlay)
overlay_nodes.append(overlay)
func remove_overlay(overlay_name: String) -> void:
for overlay in overlay_nodes:
if overlay.name == overlay_name:
remove_child(overlay)
overlay_nodes.erase(overlay)
overlay.queue_free()
break
func get_overlay(overlay_name: String) -> Node:
for overlay in overlay_nodes:
if overlay.name == overlay_name:
return overlay
return null
func has_piece() -> bool:
return piece != null

View file

@ -1,6 +1,6 @@
extends "res://Systems/StateMachine/ChessGameState.gd" extends "res://Systems/StateMachine/ChessGameState.gd"
const ATTACHMENT_PHASE_DURATION = 5 # Duration in seconds const ATTACHMENT_PHASE_DURATION = 15 # Duration in seconds
var timer: Timer var timer: Timer
var tile_pressed_connection: Signal var tile_pressed_connection: Signal
@ -34,12 +34,12 @@ func exit() -> void:
func handleTilePressed(location: String) -> void: func handleTilePressed(location: String) -> void:
# print("HANDLING Tile PRESSED ", location) # print("HANDLING Tile PRESSED ", location)
var container = game.get_node("Flow/" + location) as PieceContainer var targetNode = game.get_node("Flow/" + location)
var piece = container.get_piece() if targetNode.get_child_count() == 0:
if piece == null:
return return
var piece = targetNode.get_child(0)
var piece_id = piece.get_instance_id() var piece_id = piece.get_instance_id()
var selectedCard = game.cardDisplay.getSelectedCard() var selectedCard = game.cardDisplay.getSelectedCard()
if game.deckManager.attached_cards.has(piece_id): if game.deckManager.attached_cards.has(piece_id):
@ -70,3 +70,5 @@ func complete_attachment_phase() -> void:
if timer.time_left > 0: if timer.time_left > 0:
timer.stop() timer.stop()
_on_timer_timeout() _on_timer_timeout()

View file

@ -33,23 +33,9 @@ func handleMovement(location: String) -> void:
# maybe once u start nmoving a peice global stat var is set # maybe once u start nmoving a peice global stat var is set
# and any moving peice needs ot match that # and any moving peice needs ot match that
print("HANDLING MOVEMENT ", location, " | ", multiMoving, " | ", game.selectedNode) print("HANDLING MOVEMENT ", location, " | ", multiMoving, " | ", game.selectedNode)
var node = game.get_node("Flow/" + location) as PieceContainer var node = game.get_node("Flow/" + location)
# Only try to get piece if we have a selected node
if game.selectedNode == "":
# If no node is selected, we might want to select this one if it has a piece
var piece = node.get_piece()
if piece != null && piece.Item_Color == game.Turn:
game.selectedNode = location
game.getMovableAreas()
return
# Now we know we have a selected node, get its piece
var sourceContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer
var piece = sourceContainer.get_piece()
if piece == null:
return
var piece = game.get_node("Flow/" + game.selectedNode).get_child(0)
var piece_id = piece.get_instance_id() var piece_id = piece.get_instance_id()
print(piece_id) print(piece_id)
var is_multi_moving = piece_id in moves_remaining and moves_remaining[piece_id] > 1 var is_multi_moving = piece_id in moves_remaining and moves_remaining[piece_id] > 1
@ -57,15 +43,15 @@ func handleMovement(location: String) -> void:
if multiMoving.length() > 0: if multiMoving.length() > 0:
if node.get_piece() != null and is_instance_valid(node.get_piece()): if node.get_child_count() > 0 and is_instance_valid(node.get_child(0)):
var attempting_piece = node.get_piece() var attempting_piece = node.get_child(0)
print("Checking Str comp ", str(attempting_piece.get_instance_id()), " ", multiMoving) print("Checking Str comp ", str(attempting_piece.get_instance_id()), " ", multiMoving)
# Only block if it's a different piece of the same color # Only block if it's a different piece of the same color
if str(attempting_piece.get_instance_id()) != multiMoving and attempting_piece.Item_Color == game.Turn: if str(attempting_piece.get_instance_id()) != multiMoving and attempting_piece.Item_Color == game.Turn:
print("early return - can't select different piece of same color during multi-move") print("early return - can't select different piece of same color during multi-move")
return return
if game.selectedNode == "": if game.selectedNode == "":
if node.get_piece() != null && node.get_piece().Item_Color == game.Turn: if node.get_child_count() != 0 && node.get_child(0).Item_Color == game.Turn:
print("SELECTED NODE ", location) print("SELECTED NODE ", location)
game.selectedNode = location game.selectedNode = location
game.getMovableAreas() game.getMovableAreas()
@ -109,7 +95,6 @@ func handleMovement(location: String) -> void:
else: else:
if game.isValidMove(location): if game.isValidMove(location):
# executeMove(location) # executeMove(location)
handleRegularMove(node, consumeMove) handleRegularMove(node, consumeMove)
if consumeMove: if consumeMove:
multiMoving = "" multiMoving = ""
@ -133,114 +118,99 @@ func handleMovement(location: String) -> void:
func isCastlingMove(node: PieceContainer, location: String) -> bool: func isCastlingMove(node: Node, location: String) -> bool:
return game.selectedNode != "" && node.get_piece() != null && node.get_piece().Item_Color == game.Turn && node.get_piece().name == "Rook" return game.selectedNode != "" && node.get_child_count() != 0 && node.get_child(0).Item_Color == game.Turn && node.get_child(0).name == "Rook"
func isEnPassantMove(node: PieceContainer, location: String) -> bool: func isEnPassantMove(node: Node, location: String) -> bool:
return game.selectedNode != "" && node.get_piece() != null && node.get_piece().Item_Color != game.Turn && \ return game.selectedNode != "" && node.get_child_count() != 0 && node.get_child(0).Item_Color != game.Turn && \
node.get_piece().name == "Pawn" && game.specialArea.size() != 0 && game.specialArea[0] == node.name && \ node.get_child(0).name == "Pawn" && game.specialArea.size() != 0 && game.specialArea[0] == node.name && \
node.get_piece().get("En_Passant") == true node.get_child(0).get("En_Passant") == true
func isReselectMove(node: PieceContainer) -> bool: func isReselectMove(node: Node) -> bool:
return game.selectedNode != "" && node.get_piece() != null && node.get_piece().Item_Color == game.Turn return game.selectedNode != "" && node.get_child_count() != 0 && node.get_child(0).Item_Color == game.Turn
func isCaptureMove(node: PieceContainer) -> bool: func isCaptureMove(node: Node) -> bool:
return game.selectedNode != "" && node.get_piece() != null && node.get_piece().Item_Color != game.Turn return game.selectedNode != "" && node.get_child_count() != 0 && node.get_child(0).Item_Color != game.Turn
func isRegularMove(node: PieceContainer) -> bool: func isRegularMove(node: Node) -> bool:
return game.selectedNode != "" && node.get_piece() != null return game.selectedNode != "" && node.get_child_count() == 0
func handleCastling(node: PieceContainer) -> void: func handleCastling(node: Node) -> void:
print("handleCastling") print("handleCastling")
for i in game.areas: for i in game.areas:
if i == node.name: if i == node.name:
var kingContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer var king = game.get_node("Flow/" + game.selectedNode).get_child(0)
var rookContainer = node as PieceContainer var rook = node.get_child(0)
var kingTargetContainer = game.get_node("Flow/" + game.specialArea[1]) as PieceContainer king.reparent(game.get_node("Flow/" + game.specialArea[1]))
var rookTargetContainer = game.get_node("Flow/" + game.specialArea[0]) as PieceContainer rook.reparent(game.get_node("Flow/" + game.specialArea[0]))
king.position = Vector2(25, 25)
var king = kingContainer.get_piece() rook.position = Vector2(25, 25)
var rook = rookContainer.get_piece()
kingContainer.remove_piece(true)
rookContainer.remove_piece(true)
kingTargetContainer.set_piece(king)
rookTargetContainer.set_piece(rook)
game.currentlyMovingPiece = king game.currentlyMovingPiece = king
game.resolveMoveEffects() game.resolveMoveEffects()
func handleEnPassant(node: PieceContainer) -> void: func handleEnPassant(node: Node) -> void:
print("handleEnPassant") print("handleEnPassant")
for i in game.specialArea: for i in game.specialArea:
if i == node.name: if i == node.name:
var targetContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer var pawn = game.get_node("Flow/" + game.selectedNode).get_child(0)
var pawn = (game.get_node("Flow/" + game.selectedNode) as PieceContainer).get_piece() node.get_child(0).free()
node.remove_piece() pawn.reparent(game.get_node("Flow/" + game.specialArea[1]))
targetContainer.set_piece(pawn) pawn.position = Vector2(25, 25)
game.currentlyMovingPiece = pawn game.currentlyMovingPiece = pawn
game.resolveMoveEffects() game.resolveMoveEffects()
func handleCapture(node: PieceContainer) -> void: func handleCapture(node: Node) -> void:
print("handleCapture") print("handleCapture")
for i in game.areas: for i in game.areas:
if i == node.name: if i == node.name:
var piece = game.get_node("Flow/" + game.selectedNode).get_child(0)
var capturedPiece = node.get_child(0)
var source_container = game.get_node("Flow/" + game.selectedNode) as PieceContainer piece.reparent(node)
piece.position = Vector2(25, 25)
piece.position = Vector2(25, 25)
game.currentlyMovingPiece = piece
game.resolveMoveEffects()
game.updatePoints(capturedPiece)
capturedPiece.free()
func handleRegularMove(node: Node, consume: bool) -> void:
var moving_piece = source_container.get_piece() print("handleRegularMove", node)
var captured_piece = node.get_piece()
if moving_piece && captured_piece:
game.updatePoints(captured_piece)
source_container.remove_piece(true)
node.set_piece(moving_piece)
game.currentlyMovingPiece = moving_piece
game.resolveMoveEffects()
func handleRegularMove(node: PieceContainer, consume: bool) -> void:
print("handleRegularMove", node, game.selectedNode)
for i in game.areas: for i in game.areas:
if i == node.name: if i == node.name:
print(i) var piece = game.get_node("Flow/" + game.selectedNode).get_child(0)
var sourceContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer piece.reparent(node)
var piece = sourceContainer.get_piece() piece.position = Vector2(25, 25)
print("Removing Piece 1")
sourceContainer.remove_piece(true)
node.set_piece(piece)
game.currentlyMovingPiece = piece
if consume: if consume:
game.currentlyMovingPiece = piece
game.resolveMoveEffects() game.resolveMoveEffects()
else: else:
game.togglePieceChessEffect() game.currentlyMovingPiece = piece
game.togglePieceChessEffect();
func executeMove(targetLocation: String) -> void: func executeMove(targetLocation: String) -> void:
print("executeMove ", targetLocation) print("executeMove ", targetLocation)
var targetContainer = game.get_node("Flow/" + targetLocation) as PieceContainer var targetNode = game.get_node("Flow/" + game.targetLocation)
var sourceContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer var piece = game.get_node("Flow/" + game.selectedNode).get_child(0)
var piece = sourceContainer.get_piece() # print("piece", piece)
# Handle capture if there's a piece in the target location if targetNode.get_child_count() != 0:
if targetContainer.has_piece(): var capturedPiece = targetNode.get_child(0)
var capturedPiece = targetContainer.get_piece()
if game.Turn == 0: if game.Turn == 0:
game.p1Points += capturedPiece.Points game.p1Points += capturedPiece.Points
game.p1String.text = str(game.p1Points) game.p1String.text = str(game.p1Points)
else: else:
game.p2Points += capturedPiece.Points game.p2Points += capturedPiece.Points
game.p2String.text = str(game.p2Points) game.p2String.text = str(game.p2Points)
targetContainer.remove_piece() # This will handle freeing the captured piece capturedPiece.free()
# Move piece to new location
sourceContainer.remove_piece(true)
targetContainer.set_piece(piece)
piece.reparent(targetNode)
piece.position = Vector2(25, 25)
# print("piece2", piece)
game.hasMoved = true game.hasMoved = true
game.currentlyMovingPiece = piece game.currentlyMovingPiece = piece
game.resetHighlights() game.resetHighlights()

View file

@ -5,7 +5,5 @@ func enter(_previous: String, _data := {}) -> void:
# game.resolveMoveEffects() # game.resolveMoveEffects()
if (game.isPlayerTurn()): if (game.isPlayerTurn()):
game.updateEffectDurations() game.deckManager.updateCardDurations()
# 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

@ -1,72 +0,0 @@
class_name Tile
extends Resource
enum TileType {
GENERAL, # Affects any unit
SPECIFIC, # Affects specific unit type
GLOBAL # Affects all units of a color while active
}
enum TileOwner {
PLAYER, # White player
ENEMY, # Black player
GAME # Neutral/game-owned
}
var game: ChessGame
var tile_name: String = ""
var description: String = ""
var duration: int = -1 # -1 for permanent tiles
var remaining_turns: int = 0
var tile_owner: TileOwner = TileOwner.GAME
var type: TileType = TileType.GENERAL
var target_piece_type: String = "" # For SPECIFIC type tiles
var base_button: Button # Reference to the tile button
var base_is_white: bool # Original tile color
signal effect_expired
func _init(button: Button, is_white: bool, d: int) -> void:
base_button = button
base_is_white = is_white
remaining_turns = d
func is_effect_active() -> bool:
return duration == -1 || remaining_turns > 0
func update_duration() -> void:
if duration != -1:
remaining_turns -= 1
if remaining_turns <= 0:
effect_expired.emit()
func can_affect_piece(piece: Pawn) -> bool:
match type:
TileType.SPECIFIC:
return piece.name == target_piece_type
TileType.GLOBAL, TileType.GENERAL:
# Check owner alignment
match tile_owner:
TileOwner.PLAYER:
return piece.Item_Color == 1 # White
TileOwner.ENEMY:
return piece.Item_Color == 0 # Black
TileOwner.GAME:
return true
return false
func apply_effect(piece: Pawn = null) -> void:
# Override in child classes
pass
func remove_effect(piece: Pawn = null) -> void:
# Override in child classes
pass
func update_appearance() -> void:
restore_base_appearance()
func restore_base_appearance() -> void:
if base_button:
var style = StyleBoxFlat.new()
style.bg_color = Color(0.8, 0.8, 0.8, 1) if base_is_white else Color(0.2, 0.2, 0.2, 1)
base_button.add_theme_stylebox_override("normal", style)

View file

@ -1,117 +0,0 @@
class_name TileManager
extends Node
var active_tiles: Dictionary = {} # location: Tile
var board_flow: FlowContainer
var game: ChessGame
const DoubleMovementTile = preload("res://Systems/Tiles/DoubleMovement.gd")
const FireWallTile = preload("res://Systems/Tiles/FireWall.gd")
const PawnBoostTile = preload("res://Systems/Tiles/PawnBoost.gd")
func _init(flow: FlowContainer = null, chess_game: ChessGame = null) -> void:
if flow:
initialize(flow)
game = chess_game
func initialize(flow: FlowContainer) -> void:
board_flow = flow
clear_tiles()
func add_tile(location: String, tile: Tile) -> void:
if !board_flow:
push_error("TileManager not initialized with board_flow")
return
var container = board_flow.get_node_or_null(location) as PieceContainer
if !container:
push_error("Container not found at location: " + location)
return
# Remove any existing tile
remove_tile(location)
tile.game = game
# Add new tile
active_tiles[location] = tile
tile.effect_expired.connect(func(): remove_tile(location))
tile.update_appearance()
func remove_tile(location: String) -> void:
if active_tiles.has(location):
var tile = active_tiles[location]
tile.restore_base_appearance()
active_tiles.erase(location)
func get_tile(location: String) -> Tile:
return active_tiles.get(location, null)
func update_tile_durations() -> void:
if active_tiles.is_empty():
return
var expired_locations = []
var locations = active_tiles.keys()
for location in locations:
var tile = active_tiles[location]
tile.update_duration()
if !tile.is_effect_active():
expired_locations.append(location)
for location in expired_locations:
remove_tile(location)
func apply_tile_effects() -> void:
if active_tiles.is_empty():
return
for location in active_tiles:
var tile = active_tiles[location]
var container = board_flow.get_node(location) as PieceContainer
if container && container.has_piece():
var piece = container.get_piece()
if tile.can_affect_piece(piece):
tile.apply_effect(piece)
func clear_tiles() -> void:
var locations = active_tiles.keys()
for location in locations:
remove_tile(location)
# Function to place random game tiles at the start of each match
func place_random_game_tiles(num_tiles: int = 6) -> void:
if !board_flow:
push_error("TileManager not initialized with board_flow")
return
var available_positions = []
for x in range(8):
for y in range(8):
if y > 1 && y < 6: # Don't place on starting rows
available_positions.append(str(x) + "-" + str(y))
available_positions.shuffle()
for i in range(min(num_tiles, available_positions.size())):
var pos = available_positions[i]
var container = board_flow.get_node(pos) as PieceContainer
if !container:
continue
var is_white = (int(pos.split("-")[0]) + int(pos.split("-")[1])) % 2 == 0
# Randomly choose a tile type
var rng = RandomNumberGenerator.new()
rng.randomize()
var tile_type = rng.randi() % 3
var tile: Tile
match tile_type:
0: # DoubleMovementTile tile
tile = FireWallTile.new(container, is_white, 3)
1: # FireWallTile
tile = FireWallTile.new(container, is_white, 3)
2: # PawnBoostTile tile
tile = FireWallTile.new(container, is_white, 3)
add_tile(pos, tile)

View file

@ -1,34 +0,0 @@
class_name DoubleMovementTile
extends Tile
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 = 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
var double_time = DoubleTimeCard.new()
double_time.duration = 2
deck_manager.playCard(double_time, piece)
func update_appearance() -> void:
if is_effect_active() && base_button:
var style = StyleBoxFlat.new()
var tile_color = Color(0, 0.8, 0.8) # Cyan for speed
var base_color = Color(0.8, 0.8, 0.8) if base_is_white else Color(0.2, 0.2, 0.2)
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
)
base_button.add_theme_stylebox_override("normal", style)
else:
restore_base_appearance()

View file

@ -1,50 +0,0 @@
class_name FireWallTile
extends Tile
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 = d
tile_owner = owner
func apply_effect(piece: Pawn = null) -> void:
if piece && is_effect_active():
# Only affect enemy pieces based on tile owner
var is_enemy = false
print("--------___CHECKING FIREWALL")
print(tile_owner, " ", piece.Item_Color)
match tile_owner:
TileOwner.PLAYER: # White
print("PLAYER OWNER")
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:
game.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) # 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
)
# Apply the style using theme override
base_button.add_theme_stylebox_override("normal", style)
else:
restore_base_appearance()

View file

@ -1,33 +0,0 @@
class_name PawnBoostTile
extends Tile
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 = 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
func update_appearance() -> void:
if is_effect_active() && base_button:
var style = StyleBoxFlat.new()
var tile_color = Color(0, 0.8, 0) # Green for boost
var base_color = Color(0.8, 0.8, 0.8) if base_is_white else Color(0.2, 0.2, 0.2)
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
)
base_button.add_theme_stylebox_override("normal", style)
else:
restore_base_appearance()

View file

@ -61,15 +61,17 @@ func check_kingside_castle(board_flow, x: int, y: int) -> bool:
var check_pos = str(x + i) + "-" + str(y) var check_pos = str(x + i) + "-" + str(y)
if !is_valid_cell(board_flow, check_pos) || !can_move_to_cell(board_flow, check_pos): if !is_valid_cell(board_flow, check_pos) || !can_move_to_cell(board_flow, check_pos):
return false return false
var container = board_flow.get_node(check_pos) as PieceContainer
if container.has_piece():
return false
# Check if rook is in position and hasn't moved
var rook_pos = str(x + 3) + "-" + str(y) var rook_pos = str(x + 3) + "-" + str(y)
if !is_valid_cell(board_flow, rook_pos): if !is_valid_cell(board_flow, rook_pos):
return false return false
var rook_container = board_flow.get_node(rook_pos) as PieceContainer
var rook = rook_container.get_piece() var rook_node = board_flow.get_node(rook_pos)
if rook_node.get_child_count() != 1:
return false
var rook = rook_node.get_child(0)
return rook.name == "Rook" && rook.Castling && rook.Item_Color == self.Item_Color return rook.name == "Rook" && rook.Castling && rook.Item_Color == self.Item_Color
func check_queenside_castle(board_flow, x: int, y: int) -> bool: func check_queenside_castle(board_flow, x: int, y: int) -> bool:
@ -78,15 +80,15 @@ func check_queenside_castle(board_flow, x: int, y: int) -> bool:
var check_pos = str(x - i) + "-" + str(y) var check_pos = str(x - i) + "-" + str(y)
if !is_valid_cell(board_flow, check_pos) || !can_move_to_cell(board_flow, check_pos): if !is_valid_cell(board_flow, check_pos) || !can_move_to_cell(board_flow, check_pos):
return false return false
var container = board_flow.get_node(check_pos) as PieceContainer
if container.has_piece():
return false
# Check if rook is in position and hasn't moved # Check if rook is in position and hasn't moved
var rook_pos = str(x - 4) + "-" + str(y) var rook_pos = str(x - 4) + "-" + str(y)
if !is_valid_cell(board_flow, rook_pos): if !is_valid_cell(board_flow, rook_pos):
return false return false
var rook_container = board_flow.get_node(rook_pos) as PieceContainer var rook_node = board_flow.get_node(rook_pos)
var rook = rook_container.get_piece() if rook_node.get_child_count() != 1:
return false
var rook = rook_node.get_child(0)
return rook.name == "Rook" && rook.Castling && rook.Item_Color == self.Item_Color return rook.name == "Rook" && rook.Castling && rook.Item_Color == self.Item_Color

View file

@ -21,111 +21,110 @@ const EFFECT_TINT_COLOR = Color(0.3, 0.8, 0.3, 0.5) # Green tint for card effec
var id: String = Utils.generate_guid() var id: String = Utils.generate_guid()
func _ready(): func _ready():
modulate = Color.WHITE if Item_Color == 0 else Color.BLACK modulate = Color.WHITE if Item_Color == 0 else Color.BLACK
func _init() -> void: func _init() -> void:
self.texture = load("res://addons/Chess/Textures/WPawn.svg") self.texture = load("res://addons/Chess/Textures/WPawn.svg")
var background_style = StyleBoxFlat.new() var background_style = StyleBoxFlat.new()
background_style.bg_color = Color.WHITE background_style.bg_color = Color.WHITE
background_style.corner_radius_top_left = 2 background_style.corner_radius_top_left = 2
background_style.corner_radius_top_right = 2 background_style.corner_radius_top_right = 2
background_style.corner_radius_bottom_left = 2 background_style.corner_radius_bottom_left = 2
background_style.corner_radius_bottom_right = 2 background_style.corner_radius_bottom_right = 2
background_style.content_margin_left = 2 background_style.content_margin_left = 2
background_style.content_margin_right = 2 background_style.content_margin_right = 2
background_style.content_margin_top = 1 background_style.content_margin_top = 1
background_style.content_margin_bottom = 1 background_style.content_margin_bottom = 1
duration_label = Label.new() duration_label = Label.new()
duration_label.add_theme_stylebox_override("normal", background_style) duration_label.add_theme_stylebox_override("normal", background_style)
duration_label.add_theme_color_override("font_color", Color.BLACK) duration_label.add_theme_color_override("font_color", Color.BLACK)
duration_label.position = Vector2(-20, -20) # Position above the piece duration_label.position = Vector2(-20, -20) # Position above the piece
add_child(duration_label) add_child(duration_label)
duration_label.hide() duration_label.hide()
func update_appearance() -> void: func update_appearance() -> void:
# print("update_appearance") # print("update_appearance")
if !is_instance_valid(get_tree()) || !get_tree().get_root().has_node("Board"): if !is_instance_valid(get_tree()) || !get_tree().get_root().has_node("Board"):
return return
var chess_game = get_tree().get_root().get_node("Board") var chess_game = get_tree().get_root().get_node("Board")
if !chess_game.deckManager: if !chess_game.deckManager:
return return
var deck_manager = chess_game.deckManager var deck_manager = chess_game.deckManager
var has_card = deck_manager.attached_cards.has(get_instance_id()) var has_card = deck_manager.attached_cards.has(get_instance_id())
if has_card: if has_card:
# Apply tint while keeping the piece color # Apply tint while keeping the piece color
var base_color = Color.WHITE if Item_Color == 0 else Color.BLACK var base_color = Color.WHITE if Item_Color == 0 else Color.BLACK
modulate = base_color * EFFECT_TINT_COLOR modulate = base_color * EFFECT_TINT_COLOR
# Update duration display # Update duration display
var card = deck_manager.attached_cards[get_instance_id()] var card = deck_manager.attached_cards[get_instance_id()]
if is_instance_valid(duration_label): if is_instance_valid(duration_label):
duration_label.text = str(card.remaining_turns) duration_label.text = str(card.remaining_turns)
duration_label.show() duration_label.show()
else: else:
# Reset to normal color # Reset to normal color
modulate = Color.WHITE if Item_Color == 0 else Color.BLACK modulate = Color.WHITE if Item_Color == 0 else Color.BLACK
if is_instance_valid(duration_label): if is_instance_valid(duration_label):
duration_label.hide() duration_label.hide()
func on_card_effect_changed() -> void: func on_card_effect_changed() -> void:
update_appearance() update_appearance()
# Movement interface method that all pieces will implement # Movement interface method that all pieces will implement
# In Pawn.gd # In Pawn.gd
func getValidMoves(board_flow, current_location: String) -> Dictionary: func getValidMoves(board_flow, current_location: String) -> Dictionary:
var moves = { var moves = {
"regular_moves": [], "regular_moves": [],
"special_moves": [] "special_moves": []
} }
var loc = current_location.split("-") var loc = current_location.split("-")
var x = int(loc[0]) var x = int(loc[0])
var y = int(loc[1]) var y = int(loc[1])
# Movement direction based on color # Movement direction based on color
var direction = -1 if Item_Color == 0 else 1 var direction = -1 if Item_Color == 0 else 1
# Forward movement # Forward movement
var forward = str(x) + "-" + str(y + direction) var forward = str(x) + "-" + str(y + direction)
if is_valid_cell(board_flow, forward) && can_move_to_cell(board_flow, forward): if is_valid_cell(board_flow, forward) && can_move_to_cell(board_flow, forward):
moves.regular_moves.append(forward) moves.regular_moves.append(forward)
# Double move on first turn # Double move on first turn
var double_forward = str(x) + "-" + str(y + (direction * 2)) var double_forward = str(x) + "-" + str(y + (direction * 2))
if Double_Start && is_valid_cell(board_flow, double_forward) && can_move_to_cell(board_flow, double_forward): if Double_Start && is_valid_cell(board_flow, double_forward) && can_move_to_cell(board_flow, double_forward):
moves.regular_moves.append(double_forward) moves.regular_moves.append(double_forward)
# Diagonal captures # Diagonal captures
for dx in [-1, 1]: for dx in [-1, 1]:
var capture = str(x + dx) + "-" + str(y + direction) var capture = str(x + dx) + "-" + str(y + direction)
if is_valid_cell(board_flow, capture) && can_move_to_cell(board_flow, capture, true): if is_valid_cell(board_flow, capture) && can_move_to_cell(board_flow, capture, true):
moves.regular_moves.append(capture) moves.regular_moves.append(capture)
# En Passant # En Passant
var adjacent = str(x + dx) + "-" + str(y) var adjacent = str(x + dx) + "-" + str(y)
if is_valid_cell(board_flow, adjacent) && is_valid_cell(board_flow, capture): if is_valid_cell(board_flow, adjacent) && is_valid_cell(board_flow, capture):
var adjacent_cell = board_flow.get_node(adjacent) as PieceContainer var adjacent_cell = board_flow.get_node(adjacent)
if adjacent_cell.get_piece() != null: if adjacent_cell.get_child_count() == 1:
var adjacent_piece = adjacent_cell.get_piece() var adjacent_piece = adjacent_cell.get_child(0)
if adjacent_piece.name == "Pawn" && adjacent_piece.En_Passant && adjacent_piece.Item_Color != self.Item_Color: if adjacent_piece.name == "Pawn" && adjacent_piece.En_Passant && adjacent_piece.Item_Color != self.Item_Color:
moves.special_moves.append([adjacent, capture]) moves.special_moves.append([adjacent, capture])
return moves return moves
# Helper method for all pieces # Helper method for all pieces
func is_valid_cell(board_flow, location: String) -> bool: func is_valid_cell(board_flow, location: String) -> bool:
var node = board_flow.get_node_or_null(location) var node = board_flow.get_node_or_null(location)
return node != null return node != null
# Helper for checking if cell is empty or contains enemy # Helper for checking if cell is empty or contains enemy
func can_move_to_cell(board_flow, location: String, is_capture: bool = false) -> bool: func can_move_to_cell(board_flow, location: String, is_capture: bool = false) -> bool:
var container = board_flow.get_node(location) as PieceContainer var node = board_flow.get_node(location)
if is_capture: if is_capture:
var piece = container.get_piece() return node.get_child_count() == 1 && node.get_child(0).Item_Color != self.Item_Color
return piece != null && piece.Item_Color != self.Item_Color return node.get_child_count() == 0
return !container.has_piece()

View file

@ -51,10 +51,10 @@ func getValidMoves(board_flow, current_location: String) -> Dictionary:
for direction in [-4, 3]: # Check both sides for king for direction in [-4, 3]: # Check both sides for king
var king_pos = str(x + direction) + "-" + str(y) var king_pos = str(x + direction) + "-" + str(y)
if is_valid_cell(board_flow, king_pos): if is_valid_cell(board_flow, king_pos):
var king_container = board_flow.get_node(king_pos) as PieceContainer var king_node = board_flow.get_node(king_pos)
var piece = king_container.get_piece() if king_node.get_child_count() == 1:
if piece != null && piece.name == "King" && piece.Castling && piece.Item_Color == self.Item_Color: var piece = king_node.get_child(0)
moves.special_moves.append([king_pos, current_location]) if piece.name == "King" && piece.Castling && piece.Item_Color == self.Item_Color:
moves.special_moves.append([king_pos, current_location])
return moves return moves

View file

@ -76,8 +76,10 @@ layout_mode = 1
anchors_preset = 1 anchors_preset = 1
anchor_left = 1.0 anchor_left = 1.0
anchor_right = 1.0 anchor_right = 1.0
offset_left = -129.0 offset_left = -78.0
offset_bottom = 39.0 offset_top = 1.0
offset_right = 51.0
offset_bottom = 40.0
grow_horizontal = 0 grow_horizontal = 0
[node name="Hand" type="HBoxContainer" parent="."] [node name="Hand" type="HBoxContainer" parent="."]