71 lines
No EOL
2.6 KiB
GDScript
71 lines
No EOL
2.6 KiB
GDScript
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] |