added non passsable and non jumpable tiles
This commit is contained in:
parent
ff180174f0
commit
cc18ab32d8
17 changed files with 262 additions and 33 deletions
|
|
@ -73,7 +73,7 @@ func _on_card_clicked(event: InputEvent, card: 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 = Utils.DARK_CELL # 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:
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func reset_tile_styles(board_flow, tiles_to_check):
|
||||||
var coords = tile_name.split("-")
|
var coords = tile_name.split("-")
|
||||||
var isWhite = (int(coords[0]) + int(coords[1])) % 2 == 0
|
var isWhite = (int(coords[0]) + int(coords[1])) % 2 == 0
|
||||||
var style = StyleBoxFlat.new()
|
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)
|
tile.add_theme_stylebox_override("normal", style)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ func _init():
|
||||||
cardName = "Fiery Cape"
|
cardName = "Fiery Cape"
|
||||||
rank = Rank.RANK_2
|
rank = Rank.RANK_2
|
||||||
effectType = EffectType.PIECE_EFFECT
|
effectType = EffectType.PIECE_EFFECT
|
||||||
description = "Leaves a trail of fire that lasts 4 turns. Owner's pieces can pass safely."
|
description = "The tile behind the attached peice is on fire, all peices on the tile are captured"
|
||||||
duration = 3 # Card effect lasts 3 turns
|
duration = 5 # Card effect lasts 3 turns
|
||||||
unitWhitelist = ["Pawn", "Bishop", "Queen", "King", "Rook"] # Any piece can wear the cape
|
unitWhitelist = ["Pawn", "Bishop", "Queen", "King", "Rook", "Knight"]
|
||||||
|
|
||||||
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):
|
||||||
|
|
@ -52,7 +52,7 @@ func on_turn_changed():
|
||||||
# Start with the previous position
|
# Start with the previous position
|
||||||
positions_to_mark.append(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):
|
while (x + dx != current_x || y + dy != current_y):
|
||||||
x += dx
|
x += dx
|
||||||
y += dy
|
y += dy
|
||||||
|
|
@ -60,13 +60,14 @@ func on_turn_changed():
|
||||||
|
|
||||||
# Place fire tiles
|
# Place fire tiles
|
||||||
var tile_owner = Tile.TileOwner.PLAYER if piece.Item_Color == 0 else Tile.TileOwner.ENEMY
|
var tile_owner = Tile.TileOwner.PLAYER if piece.Item_Color == 0 else Tile.TileOwner.ENEMY
|
||||||
for pos in positions_to_mark:
|
# only place on last tile
|
||||||
var container = board_flow.get_node(pos) as PieceContainer
|
var pos = positions_to_mark[positions_to_mark.size() - 1]
|
||||||
if container:
|
var container = board_flow.get_node(pos) as PieceContainer
|
||||||
var is_white = (int(pos.split("-")[0]) + int(pos.split("-")[1])) % 2 == 0
|
if container:
|
||||||
var fire_tile = FireWallTile.new(container, is_white, 4, tile_owner)
|
var is_white = (int(pos.split("-")[0]) + int(pos.split("-")[1])) % 2 == 0
|
||||||
board_flow.get_parent().tileManager.add_tile(pos, fire_tile)
|
var fire_tile = FireWallTile.new(container, is_white, 2, tile_owner)
|
||||||
fire_tiles.append(pos)
|
board_flow.get_parent().tileManager.add_tile(pos, fire_tile)
|
||||||
|
fire_tiles.append(pos)
|
||||||
|
|
||||||
previous_position = current_pos
|
previous_position = current_pos
|
||||||
|
|
||||||
|
|
|
||||||
78
Systems/Cards/Fierytrail.gd
Normal file
78
Systems/Cards/Fierytrail.gd
Normal 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()
|
||||||
|
|
@ -24,6 +24,7 @@ func initializeStartingDeck():
|
||||||
# for i in range(2):
|
# for i in range(2):
|
||||||
# deck.append(DoubleTimeCard.new())
|
# deck.append(DoubleTimeCard.new())
|
||||||
deck.append(FieryCapeCard.new())
|
deck.append(FieryCapeCard.new())
|
||||||
|
deck.append(FieryTrailCard.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())
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ var Turn: int = 0
|
||||||
@export var boardYSize = 8
|
@export var boardYSize = 8
|
||||||
@export var tileXSize: int = 50
|
@export var tileXSize: int = 50
|
||||||
@export var tileYSize: int = 50
|
@export var tileYSize: int = 50
|
||||||
|
@export var windowXSize: int = 1280
|
||||||
|
@export var windowYSize: int = 720
|
||||||
|
|
||||||
@onready var boardContainer: FlowContainer = $Flow
|
@onready var boardContainer: FlowContainer = $Flow
|
||||||
@onready var stateMachine: StateMachine = $StateMachine
|
@onready var stateMachine: StateMachine = $StateMachine
|
||||||
|
|
@ -43,6 +45,7 @@ var darkStyle = null
|
||||||
var highlightStyle = null
|
var highlightStyle = null
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
DisplayServer.window_set_size(Vector2i(windowXSize, windowYSize))
|
||||||
initializeGame()
|
initializeGame()
|
||||||
initializeTiles()
|
initializeTiles()
|
||||||
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
||||||
|
|
@ -177,10 +180,9 @@ func parseLocation(location: String) -> void:
|
||||||
|
|
||||||
func setupStyles() -> void:
|
func setupStyles() -> void:
|
||||||
lightStyle = StyleBoxFlat.new()
|
lightStyle = StyleBoxFlat.new()
|
||||||
lightStyle.bg_color = Color(0.5, 0.5, 0.5, 1)
|
lightStyle.bg_color = Utils.LIGHT_CELL
|
||||||
|
|
||||||
darkStyle = StyleBoxFlat.new()
|
darkStyle = StyleBoxFlat.new()
|
||||||
darkStyle.bg_color = Color(0.2, 0.2, 0.2, 1)
|
darkStyle.bg_color = Utils.DARK_CELL
|
||||||
|
|
||||||
highlightStyle = StyleBoxFlat.new()
|
highlightStyle = StyleBoxFlat.new()
|
||||||
highlightStyle.bg_color = Color(0, 0.3, 0, 1)
|
highlightStyle.bg_color = Color(0, 0.3, 0, 1)
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,6 @@ func handleMovement(location: String) -> void:
|
||||||
game.getMovableAreas()
|
game.getMovableAreas()
|
||||||
if game.areas.size() == 0 and game.specialArea.size() == 0:
|
if game.areas.size() == 0 and game.specialArea.size() == 0:
|
||||||
print("Consuming move because no valid moves left")
|
print("Consuming move because no valid moves left")
|
||||||
# handleRegularMove(node, true)
|
|
||||||
game.resolveMoveEffects()
|
game.resolveMoveEffects()
|
||||||
multiMoving = ""
|
multiMoving = ""
|
||||||
game.clearSelection()
|
game.clearSelection()
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@ var type: TileType = TileType.GENERAL
|
||||||
var target_piece_type: String = "" # For SPECIFIC type tiles
|
var target_piece_type: String = "" # For SPECIFIC type tiles
|
||||||
var base_button: Button # Reference to the tile button
|
var base_button: Button # Reference to the tile button
|
||||||
var base_is_white: bool # Original tile color
|
var base_is_white: bool # Original tile color
|
||||||
|
var passable: bool = true
|
||||||
|
var jumpable: bool = true
|
||||||
signal effect_expired
|
signal effect_expired
|
||||||
|
|
||||||
func _init(button: Button, is_white: bool, d: int) -> void:
|
func _init(button: Button, is_white: bool, d: int) -> void:
|
||||||
|
|
@ -68,5 +69,5 @@ func update_appearance() -> void:
|
||||||
func restore_base_appearance() -> void:
|
func restore_base_appearance() -> void:
|
||||||
if base_button:
|
if base_button:
|
||||||
var style = StyleBoxFlat.new()
|
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)
|
base_button.add_theme_stylebox_override("normal", style)
|
||||||
|
|
@ -4,10 +4,6 @@ extends Node
|
||||||
var active_tiles: Dictionary = {} # location: Tile
|
var active_tiles: Dictionary = {} # location: Tile
|
||||||
var board_flow: FlowContainer
|
var board_flow: FlowContainer
|
||||||
var game: ChessGame
|
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:
|
func _init(flow: FlowContainer = null, chess_game: ChessGame = null) -> void:
|
||||||
if flow:
|
if flow:
|
||||||
initialize(flow)
|
initialize(flow)
|
||||||
|
|
@ -108,10 +104,10 @@ func place_random_game_tiles(num_tiles: int = 6) -> void:
|
||||||
var tile: Tile
|
var tile: Tile
|
||||||
match tile_type:
|
match tile_type:
|
||||||
0: # DoubleMovementTile tile
|
0: # DoubleMovementTile tile
|
||||||
tile = PawnBoostTile.new(container, is_white, -1)
|
tile = WallTile.new(container, is_white, -1)
|
||||||
1: # FireWallTile
|
1: # FireWallTile
|
||||||
tile = PawnBoostTile.new(container, is_white, -1)
|
tile = DoubleWallTile.new(container, is_white, -1)
|
||||||
2: # PawnBoostTile tile
|
2: # PawnBoostTile tile
|
||||||
tile = PawnBoostTile.new(container, is_white, -1)
|
tile = DoubleWallTile.new(container, is_white, -1)
|
||||||
|
|
||||||
add_tile(pos, tile)
|
add_tile(pos, tile)
|
||||||
|
|
@ -21,7 +21,7 @@ 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(0, 0.8, 0.8) # Cyan for speed
|
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(
|
style.bg_color = Color(
|
||||||
(base_color.r + tile_color.r) / 2,
|
(base_color.r + tile_color.r) / 2,
|
||||||
|
|
|
||||||
33
Systems/Tiles/DoubleWall.gd
Normal file
33
Systems/Tiles/DoubleWall.gd
Normal 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()
|
||||||
|
|
@ -36,7 +36,7 @@ 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) # Default orange-ish color for effects
|
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
|
# Blend the tile effect color with the base chess board color
|
||||||
style.bg_color = Color(
|
style.bg_color = Color(
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ 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(0, 0.8, 0) # Green for boost
|
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(
|
style.bg_color = Color(
|
||||||
(base_color.r + tile_color.r) / 2,
|
(base_color.r + tile_color.r) / 2,
|
||||||
|
|
|
||||||
32
Systems/Tiles/Wall.gd
Normal file
32
Systems/Tiles/Wall.gd
Normal 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()
|
||||||
|
|
@ -21,3 +21,10 @@ static func generate_guid() -> String:
|
||||||
guid += "%012x" % rng.randi()
|
guid += "%012x" % rng.randi()
|
||||||
|
|
||||||
return guid
|
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)
|
||||||
|
|
@ -13,6 +13,7 @@ func _process(_delta):
|
||||||
self.texture = load("res://addons/Chess/Textures/WKnight.svg")
|
self.texture = load("res://addons/Chess/Textures/WKnight.svg")
|
||||||
elif Item_Color == 1:
|
elif Item_Color == 1:
|
||||||
self.texture = load("res://addons/Chess/Textures/BKnight.svg")
|
self.texture = load("res://addons/Chess/Textures/BKnight.svg")
|
||||||
|
|
||||||
func getValidMoves(board_flow, current_location: String) -> Dictionary:
|
func getValidMoves(board_flow, current_location: String) -> Dictionary:
|
||||||
var moves = {
|
var moves = {
|
||||||
"regular_moves": [],
|
"regular_moves": [],
|
||||||
|
|
@ -22,6 +23,7 @@ func getValidMoves(board_flow, current_location: String) -> Dictionary:
|
||||||
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])
|
||||||
|
var game = board_flow.get_parent() as ChessGame
|
||||||
|
|
||||||
# All possible L-shaped moves
|
# All possible L-shaped moves
|
||||||
var knight_moves = [
|
var knight_moves = [
|
||||||
|
|
@ -32,9 +34,82 @@ func getValidMoves(board_flow, current_location: String) -> Dictionary:
|
||||||
]
|
]
|
||||||
|
|
||||||
for move in knight_moves:
|
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 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)
|
moves.regular_moves.append(new_loc)
|
||||||
|
|
||||||
return moves
|
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
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,10 @@ func is_valid_cell(board_flow, location: String) -> bool:
|
||||||
# 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 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:
|
if is_capture:
|
||||||
var piece = container.get_piece()
|
var piece = container.get_piece()
|
||||||
return piece != null && piece.Item_Color != self.Item_Color
|
return piece != null && piece.Item_Color != self.Item_Color
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue