From a412ab90e69369e7f83268b0c0f3d8e90029fd6b Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Sun, 9 Feb 2025 01:11:53 -0600 Subject: [PATCH] added portal tiles --- Systems/TileManager.gd | 76 +++++++++++++++++++++++++++++++++++------ Systems/Tiles/Portal.gd | 71 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 Systems/Tiles/Portal.gd diff --git a/Systems/TileManager.gd b/Systems/TileManager.gd index 350cd9d..37c791d 100644 --- a/Systems/TileManager.gd +++ b/Systems/TileManager.gd @@ -4,6 +4,7 @@ extends Node var active_tiles: Dictionary = {} # location: Tile var board_flow: FlowContainer var game: ChessGame +const PortalTile = preload("res://Systems/Tiles/Portal.gd") func _init(flow: FlowContainer = null, chess_game: ChessGame = null) -> void: if flow: initialize(flow) @@ -87,7 +88,8 @@ func place_random_game_tiles(num_tiles: int = 6) -> void: 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 @@ -95,20 +97,72 @@ func place_random_game_tiles(num_tiles: int = 6) -> void: 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 - return match tile_type: - 0: # DoubleMovementTile tile - tile = WallTile.new(container, is_white, -1) - 1: # FireWallTile - tile = DoubleWallTile.new(container, is_white, -1) - 2: # PawnBoostTile tile - tile = DoubleWallTile.new(container, is_white, -1) + 0: # Wall tile + # tile = WallTile.new(container, is_white, -1) + # add_tile(pos, tile) + continue + 1: # Double Wall + # tile = DoubleWallTile.new(container, is_white, -1) + # add_tile(pos, tile) + continue + 2: # Portal pair + # Only create portal pair if this isn't the last tile + if i < available_positions.size() - 1: + var next_pos = available_positions[i + 1] + var next_container = board_flow.get_node(next_pos) as PieceContainer + if next_container: + var next_is_white = (int(next_pos.split("-")[0]) + int(next_pos.split("-")[1])) % 2 == 0 + + # Create portal pair with alternating blue/orange colors + # var portal_color = Color.ORANGE if (i % 2 == 0) else Color.BLUE + var portals = PortalTile.create_portal_pair( + container, is_white, + next_container, next_is_white, + -1, # permanent duration + i, # pair id + Color.ORANGE, + Color.BLUE + ) + + # Add both portals + add_tile(pos, portals[0]) + add_tile(next_pos, portals[1]) + + # Skip the next position since we used it for the portal pair + i += 1 + else: + # If we can't make a pair, fall back to a wall tile + tile = WallTile.new(container, is_white, -1) + add_tile(pos, tile) + +# func place_portal_pair(location1: String, location2: String, duration: int = -1) -> void: +# var container1 = board_flow.get_node(location1) as PieceContainer +# var container2 = board_flow.get_node(location2) as PieceContainer + +# if container1 && container2: +# var is_white1 = (int(location1.split("-")[0]) + int(location1.split("-")[1])) % 2 == 0 +# var is_white2 = (int(location2.split("-")[0]) + int(location2.split("-")[1])) % 2 == 0 - add_tile(pos, tile) +# # Generate a unique color for this pair +# var portal_color = Color(randf(), randf(), 1.0) # Blue-ish random color + +# # Create portal pair +# var portals = PortalTile.create_portal_pair( +# container1, is_white1, +# container2, is_white2, +# duration, +# active_tiles.size(), # Use current size as unique pair ID +# portal_color +# ) + +# # Add both portals to active tiles +# add_tile(location1, portals[0]) +# add_tile(location2, portals[1]) diff --git a/Systems/Tiles/Portal.gd b/Systems/Tiles/Portal.gd new file mode 100644 index 0000000..036655c --- /dev/null +++ b/Systems/Tiles/Portal.gd @@ -0,0 +1,71 @@ +class_name PortalTile +extends Tile + +var pair_id: int # To identify which portals are paired +var other_portal: PortalTile = null # Reference to paired portal +var portal_color: Color # Each pair should have a distinct color +var teleported_pieces: Array[int] = [] # Track pieces that have already been teleported +var last_piece : Pawn = null +func _init(button: Button, is_white: bool, d: int, id: int, color: Color) -> void: + super._init(button, is_white, d) + tile_name = "Portal" + description = "Teleports pieces to its paired portal on first contact" + type = TileType.GENERAL + tile_owner = TileOwner.GAME + duration = d + pair_id = id + portal_color = color + passable = true + jumpable = true + +func apply_effect(piece: Pawn = null) -> void: + if !piece || !is_effect_active() || !other_portal || !other_portal.is_effect_active(): + return + if last_piece and last_piece.id == piece.id: + return + + # Check if partner portal tile has a piece on it + var partner_container = other_portal.base_button as PieceContainer + if partner_container && partner_container.has_piece(): + return + + print("APPLY PortalTile teleporting to pair") + var current_container = piece.get_parent() as PieceContainer + if current_container: + var target_container = other_portal.base_button as PieceContainer + if target_container: + # last_piece = piece + other_portal.last_piece = piece + # Move the piece + target_container.animate_movement(current_container, piece); + +func update_appearance() -> void: + if is_effect_active() && base_button: + var style = StyleBoxFlat.new() + var base_color = Utils.LIGHT_CELL if base_is_white else Utils.DARK_CELL + + # Blend portal color with base tile color + style.bg_color = Color( + (base_color.r + portal_color.r) / 2, + (base_color.g + portal_color.g) / 2, + (base_color.b + portal_color.b) / 2 + ) + base_button.add_theme_stylebox_override("normal", style) + else: + restore_base_appearance() + +# Static method to create a pair of portals +static func create_portal_pair( + button1: Button, is_white1: bool, + button2: Button, is_white2: bool, + duration: int, pair_id: int, + color1: Color, color2: Color, +) -> Array[PortalTile]: + var portal1 = PortalTile.new(button1, is_white1, duration, pair_id, color1) + var portal2 = PortalTile.new(button2, is_white2, duration, pair_id, color2) + + # Link the portals together + portal1.other_portal = portal2 + portal2.other_portal = portal1 + + return [portal1, portal2] \ No newline at end of file