added non passsable and non jumpable tiles

This commit is contained in:
2ManyProjects 2025-02-07 22:16:20 -06:00
parent ff180174f0
commit cc18ab32d8
17 changed files with 262 additions and 33 deletions

View file

@ -73,7 +73,7 @@ func _on_card_clicked(event: InputEvent, card: Card):
func highlight_selectedCard(selected: Card) -> void:
for display in cardDisplays:
var style = StyleBoxFlat.new()
style.bg_color = Color(0.2, 0.2, 0.2, 1) # Default color
style.bg_color = Utils.DARK_CELL # Default color
var vbox = display.get_child(0)
if selected && vbox.get_meta("card_id") == selected.id:

View file

@ -95,7 +95,7 @@ func reset_tile_styles(board_flow, tiles_to_check):
var coords = tile_name.split("-")
var isWhite = (int(coords[0]) + int(coords[1])) % 2 == 0
var style = StyleBoxFlat.new()
style.bg_color = Color(0.8, 0.8, 0.8, 1) if isWhite else Color(0.2, 0.2, 0.2, 1)
style.bg_color = Utils.LIGHT_CELL if isWhite else Utils.DARK_CELL
tile.add_theme_stylebox_override("normal", style)

View file

@ -8,9 +8,9 @@ func _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
description = "The tile behind the attached peice is on fire, all peices on the tile are captured"
duration = 5 # Card effect lasts 3 turns
unitWhitelist = ["Pawn", "Bishop", "Queen", "King", "Rook", "Knight"]
func apply_effect(target_piece = null, board_flow = null, game_state = null):
if !super.apply_effect(target_piece, board_flow, game_state):
@ -52,7 +52,7 @@ func on_turn_changed():
# Start with the previous position
positions_to_mark.append(previous_position)
# Add intermediate positions (but not the final position)
# Add intermediate positions
while (x + dx != current_x || y + dy != current_y):
x += dx
y += dy
@ -60,13 +60,14 @@ func on_turn_changed():
# 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)
# only place on last tile
var pos = positions_to_mark[positions_to_mark.size() - 1]
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, 2, tile_owner)
board_flow.get_parent().tileManager.add_tile(pos, fire_tile)
fire_tiles.append(pos)
previous_position = current_pos

View file

@ -0,0 +1,78 @@
class_name FieryTrailCard extends Card
var previous_position: String = ""
var fire_tiles: Array[String] = []
func _init():
super._init()
cardName = "Fiery Trail"
rank = Rank.RANK_1
effectType = EffectType.PIECE_EFFECT
description = "Leaves a trail of fire that lasts 4 turns. Player's pieces can pass safely."
duration = 3 # Card effect lasts 3 turns
unitWhitelist = ["Pawn", "Bishop", "Queen", "King", "Rook"]
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 = stored_board_flow
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 = stored_game_state
if game_state.is_connected("turn_changed", on_turn_changed):
game_state.disconnect("turn_changed", on_turn_changed)
super.remove_effect()

View file

@ -24,6 +24,7 @@ func initializeStartingDeck():
# 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())

View file

@ -33,6 +33,8 @@ var Turn: int = 0
@export var boardYSize = 8
@export var tileXSize: int = 50
@export var tileYSize: int = 50
@export var windowXSize: int = 1280
@export var windowYSize: int = 720
@onready var boardContainer: FlowContainer = $Flow
@onready var stateMachine: StateMachine = $StateMachine
@ -43,6 +45,7 @@ var darkStyle = null
var highlightStyle = null
func _ready() -> void:
DisplayServer.window_set_size(Vector2i(windowXSize, windowYSize))
initializeGame()
initializeTiles()
stateMachine.transitionToNextState(Constants.WHITE_TURN)
@ -177,10 +180,9 @@ func parseLocation(location: String) -> void:
func setupStyles() -> void:
lightStyle = StyleBoxFlat.new()
lightStyle.bg_color = Color(0.5, 0.5, 0.5, 1)
lightStyle.bg_color = Utils.LIGHT_CELL
darkStyle = StyleBoxFlat.new()
darkStyle.bg_color = Color(0.2, 0.2, 0.2, 1)
darkStyle.bg_color = Utils.DARK_CELL
highlightStyle = StyleBoxFlat.new()
highlightStyle.bg_color = Color(0, 0.3, 0, 1)

View file

@ -136,7 +136,6 @@ func handleMovement(location: String) -> void:
game.getMovableAreas()
if game.areas.size() == 0 and game.specialArea.size() == 0:
print("Consuming move because no valid moves left")
# handleRegularMove(node, true)
game.resolveMoveEffects()
multiMoving = ""
game.clearSelection()

View file

@ -22,7 +22,8 @@ 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
var passable: bool = true
var jumpable: bool = true
signal effect_expired
func _init(button: Button, is_white: bool, d: int) -> void:
@ -68,5 +69,5 @@ func update_appearance() -> void:
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)
style.bg_color = Utils.LIGHT_CELL if base_is_white else Utils.DARK_CELL
base_button.add_theme_stylebox_override("normal", style)

View file

@ -4,10 +4,6 @@ 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)
@ -108,10 +104,10 @@ func place_random_game_tiles(num_tiles: int = 6) -> void:
var tile: Tile
match tile_type:
0: # DoubleMovementTile tile
tile = PawnBoostTile.new(container, is_white, -1)
tile = WallTile.new(container, is_white, -1)
1: # FireWallTile
tile = PawnBoostTile.new(container, is_white, -1)
tile = DoubleWallTile.new(container, is_white, -1)
2: # PawnBoostTile tile
tile = PawnBoostTile.new(container, is_white, -1)
tile = DoubleWallTile.new(container, is_white, -1)
add_tile(pos, tile)

View file

@ -21,7 +21,7 @@ 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)
var base_color = Utils.LIGHT_CELL if base_is_white else Utils.DARK_CELL
style.bg_color = Color(
(base_color.r + tile_color.r) / 2,

View file

@ -0,0 +1,33 @@
class_name DoubleWallTile
extends Tile
func _init(button: Button, is_white: bool, d: int, owner: TileOwner = TileOwner.GAME) -> void:
super._init(button, is_white, d)
tile_name = "Double Wall"
description = "No Peice can pass or jump this tile"
type = TileType.GENERAL
duration = d
tile_owner = owner
passable = false
jumpable = false
func apply_effect(_piece: Pawn = null) -> void:
return
func update_appearance() -> void:
if is_effect_active() && base_button:
var style = StyleBoxFlat.new()
var tile_color = Utils.DOUBLE_WALL
var base_color = Utils.LIGHT_CELL if base_is_white else Utils.DARK_CELL
# 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

@ -36,7 +36,7 @@ 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)
var base_color = Utils.LIGHT_CELL if base_is_white else Utils.DARK_CELL
# Blend the tile effect color with the base chess board color
style.bg_color = Color(

View file

@ -42,7 +42,7 @@ 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)
var base_color = Utils.LIGHT_CELL if base_is_white else Utils.DARK_CELL
style.bg_color = Color(
(base_color.r + tile_color.r) / 2,

32
Systems/Tiles/Wall.gd Normal file
View file

@ -0,0 +1,32 @@
class_name WallTile
extends Tile
func _init(button: Button, is_white: bool, d: int, owner: TileOwner = TileOwner.GAME) -> void:
super._init(button, is_white, d)
tile_name = "Wall"
description = "No Peice can pass through, is still jumpable"
type = TileType.GENERAL
duration = d
tile_owner = owner
passable = false
func apply_effect(_piece: Pawn = null) -> void:
return
func update_appearance() -> void:
if is_effect_active() && base_button:
var style = StyleBoxFlat.new()
var tile_color = Utils.WALL_CELL
var base_color = Utils.LIGHT_CELL if base_is_white else Utils.DARK_CELL
# 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

@ -21,3 +21,10 @@ static func generate_guid() -> String:
guid += "%012x" % rng.randi()
return guid
static var LIGHT_CELL = Color(0.5, 0.5, 0.5, 1)
static var DARK_CELL = Color(0.2, 0.2, 0.2, 1)
static var WALL_CELL = Color(0.59, 0.29, 0.0, 1) # Brown (#964B00)
static var DOUBLE_WALL = Color(0.36, 0.17, 0.0, 1) # Dark Brown (#5C2B00)

View file

@ -13,6 +13,7 @@ func _process(_delta):
self.texture = load("res://addons/Chess/Textures/WKnight.svg")
elif Item_Color == 1:
self.texture = load("res://addons/Chess/Textures/BKnight.svg")
func getValidMoves(board_flow, current_location: String) -> Dictionary:
var moves = {
"regular_moves": [],
@ -22,6 +23,7 @@ func getValidMoves(board_flow, current_location: String) -> Dictionary:
var loc = current_location.split("-")
var x = int(loc[0])
var y = int(loc[1])
var game = board_flow.get_parent() as ChessGame
# All possible L-shaped moves
var knight_moves = [
@ -32,9 +34,82 @@ func getValidMoves(board_flow, current_location: String) -> Dictionary:
]
for move in knight_moves:
var new_loc = str(x + move[0]) + "-" + str(y + move[1])
var target_x = x + move[0]
var target_y = y + move[1]
var new_loc = str(target_x) + "-" + str(target_y)
if is_valid_cell(board_flow, new_loc):
if can_move_to_cell(board_flow, new_loc) || can_move_to_cell(board_flow, new_loc, true):
# Check tiles in the path
var path_clear = true
# Check horizontally first, then vertically (or vice versa)
var check_horizontal_first = abs(move[0]) > abs(move[1])
if check_horizontal_first:
# Check horizontal movement
var step_x = sign(move[0])
for i in range(1, abs(move[0]) + 1):
var path_tile_loc = str(x + (i * step_x)) + "-" + str(y)
var tile = game.tileManager.get_tile(path_tile_loc)
if tile && !tile.jumpable:
path_clear = false
break
# Check vertical movement if path still clear
if path_clear:
var step_y = sign(move[1])
var path_tile_loc = str(target_x) + "-" + str(y + step_y)
var tile = game.tileManager.get_tile(path_tile_loc)
if tile && !tile.jumpable:
path_clear = false
else:
# Check vertical movement
var step_y = sign(move[1])
for i in range(1, abs(move[1]) + 1):
var path_tile_loc = str(x) + "-" + str(y + (i * step_y))
var tile = game.tileManager.get_tile(path_tile_loc)
if tile && !tile.jumpable:
path_clear = false
break
# Check horizontal movement if path still clear
if path_clear:
var step_x = sign(move[0])
var path_tile_loc = str(x + step_x) + "-" + str(target_y)
var tile = game.tileManager.get_tile(path_tile_loc)
if tile && !tile.jumpable:
path_clear = false
# Only add the move if the path is clear and the destination is valid
if path_clear && (can_move_to_cell(board_flow, new_loc) || can_move_to_cell(board_flow, new_loc, true)):
moves.regular_moves.append(new_loc)
return moves
# func getValidMoves(board_flow, current_location: String) -> Dictionary:
# var moves = {
# "regular_moves": [],
# "special_moves": []
# }
# var loc = current_location.split("-")
# var x = int(loc[0])
# var y = int(loc[1])
# # All possible L-shaped moves
# var knight_moves = [
# [-2, -1], [-2, 1],
# [-1, -2], [-1, 2],
# [1, -2], [1, 2],
# [2, -1], [2, 1]
# ]
# for move in knight_moves:
# var new_loc = str(x + move[0]) + "-" + str(y + move[1])
# if is_valid_cell(board_flow, new_loc):
# if can_move_to_cell(board_flow, new_loc) || can_move_to_cell(board_flow, new_loc, true):
# moves.regular_moves.append(new_loc)
# return moves

View file

@ -129,6 +129,10 @@ func is_valid_cell(board_flow, location: String) -> bool:
# Helper for checking if cell is empty or contains enemy
func can_move_to_cell(board_flow, location: String, is_capture: bool = false) -> bool:
var container = board_flow.get_node(location) as PieceContainer
var game = board_flow.get_parent() as ChessGame
var tile = game.tileManager.get_tile(location)
if tile && !tile.passable:
return false
if is_capture:
var piece = container.get_piece()
return piece != null && piece.Item_Color != self.Item_Color