added card attachement to peices, and timer to transiton certain states (attach cards)
This commit is contained in:
parent
54d6e33c8c
commit
61e4cd88ba
10 changed files with 203 additions and 93 deletions
|
|
@ -3,10 +3,10 @@ class_name Card
|
||||||
|
|
||||||
enum Rank {RANK_0, RANK_1, RANK_2, RANK_3}
|
enum Rank {RANK_0, RANK_1, RANK_2, RANK_3}
|
||||||
enum EffectType {
|
enum EffectType {
|
||||||
MOVEMENT_MODIFIER,
|
MOVEMENT_MODIFIER,
|
||||||
BOARD_EFFECT,
|
BOARD_EFFECT,
|
||||||
PIECE_EFFECT,
|
PIECE_EFFECT,
|
||||||
SPECIAL_ACTION
|
SPECIAL_ACTION
|
||||||
}
|
}
|
||||||
|
|
||||||
var card_name: String
|
var card_name: String
|
||||||
|
|
@ -18,9 +18,11 @@ var burned: bool = false
|
||||||
var effect_type: EffectType
|
var effect_type: EffectType
|
||||||
var remaining_turns: int = 0
|
var remaining_turns: int = 0
|
||||||
var unit_whitelist: Array[String] = [] # List of piece types this card can be attached to
|
var unit_whitelist: Array[String] = [] # List of piece types this card can be attached to
|
||||||
|
var id: String = Utils.generate_guid()
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
remaining_turns = duration
|
remaining_turns = duration
|
||||||
|
# print(id)
|
||||||
|
|
||||||
func can_attach_to_piece(piece: Pawn) -> bool:
|
func can_attach_to_piece(piece: Pawn) -> bool:
|
||||||
if unit_whitelist.is_empty():
|
if unit_whitelist.is_empty():
|
||||||
|
|
|
||||||
|
|
@ -3,27 +3,30 @@ class_name CardDisplay
|
||||||
|
|
||||||
var card_displays = []
|
var card_displays = []
|
||||||
var selected_card = null
|
var selected_card = null
|
||||||
const CARD_WIDTH = 100
|
const CARD_WIDTH = 150
|
||||||
const CARD_HEIGHT = 150
|
const CARD_HEIGHT = 250
|
||||||
const CARD_MARGIN = 10
|
const CARD_MARGIN = 10
|
||||||
var container: HBoxContainer
|
@onready var container: HBoxContainer
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
container = HBoxContainer.new()
|
container = HBoxContainer.new()
|
||||||
container.name = "CardContainer"
|
container.name = "Hand"
|
||||||
container.set_position(Vector2(10, 500))
|
container.set_position(Vector2(10, 500))
|
||||||
add_child(container)
|
add_child(container)
|
||||||
|
|
||||||
func update_hand(hand: Array):
|
func update_hand(hand: Array):
|
||||||
clear_cards()
|
clear_cards()
|
||||||
|
print("update_hand")
|
||||||
for card in hand:
|
for card in hand:
|
||||||
|
print(card.id)
|
||||||
add_card_display(card)
|
add_card_display(card)
|
||||||
|
|
||||||
func add_card_display(card: Card):
|
func add_card_display(card):
|
||||||
var card_panel = PanelContainer.new()
|
var card_panel = PanelContainer.new()
|
||||||
card_panel.custom_minimum_size = Vector2(CARD_WIDTH, CARD_HEIGHT)
|
card_panel.custom_minimum_size = Vector2(CARD_WIDTH, CARD_HEIGHT)
|
||||||
|
|
||||||
var vbox = VBoxContainer.new()
|
var vbox = VBoxContainer.new()
|
||||||
|
vbox.set_meta("card_id", card.id)
|
||||||
card_panel.add_child(vbox)
|
card_panel.add_child(vbox)
|
||||||
|
|
||||||
var name_label = Label.new()
|
var name_label = Label.new()
|
||||||
|
|
@ -42,22 +45,48 @@ func add_card_display(card: Card):
|
||||||
desc_label.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
desc_label.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
||||||
vbox.add_child(desc_label)
|
vbox.add_child(desc_label)
|
||||||
|
|
||||||
|
var id_label = Label.new()
|
||||||
|
id_label.text = card.id
|
||||||
|
id_label.autowrap_mode = true
|
||||||
|
id_label.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
||||||
|
vbox.add_child(id_label)
|
||||||
|
|
||||||
|
|
||||||
|
card_panel.gui_input.connect(func(event): _on_card_clicked(event, card))
|
||||||
|
|
||||||
card_displays.append(card_panel)
|
card_displays.append(card_panel)
|
||||||
container.add_child(card_panel)
|
container.add_child(card_panel)
|
||||||
|
|
||||||
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:
|
||||||
selected_card = card
|
if selected_card == null || selected_card.id != card.id:
|
||||||
highlight_selected_card(card)
|
selected_card = card
|
||||||
|
container.emit_signal("card_pressed", card)
|
||||||
|
elif selected_card.id == card.id:
|
||||||
|
selected_card = null
|
||||||
|
highlight_selected_card(selected_card)
|
||||||
|
# selected_card = card
|
||||||
|
# highlight_selected_card(card)
|
||||||
|
# container.emit_signal("card_pressed", card)
|
||||||
|
|
||||||
func highlight_selected_card(selected: Card):
|
func highlight_selected_card(selected: Card) -> void:
|
||||||
for display in card_displays:
|
for display in card_displays:
|
||||||
var style = StyleBoxFlat.new()
|
var style = StyleBoxFlat.new()
|
||||||
style.bg_color = Color(0.2, 0.2, 0.2, 1)
|
style.bg_color = Color(0.2, 0.2, 0.2, 1) # Default color
|
||||||
if display.get_child(0).get_child(0).text == selected.card_name:
|
|
||||||
style.bg_color = Color(0.4, 0.6, 0.4, 1)
|
var vbox = display.get_child(0)
|
||||||
|
if selected && vbox.get_meta("card_id") == selected.id:
|
||||||
|
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:
|
||||||
|
for display in card_displays:
|
||||||
|
var vbox = display.get_child(0)
|
||||||
|
if vbox.get_meta("card_id") == uuid:
|
||||||
|
return selected_card
|
||||||
|
return null
|
||||||
|
|
||||||
func get_selected_card() -> Card:
|
func get_selected_card() -> Card:
|
||||||
return selected_card
|
return selected_card
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,25 @@
|
||||||
class DoubleTimeCard extends Card:
|
class_name DoubleTimeCard extends Card
|
||||||
func _init():
|
|
||||||
super._init()
|
|
||||||
card_name = "Double Time"
|
|
||||||
rank = Rank.RANK_2
|
|
||||||
effect_type = EffectType.MOVEMENT_MODIFIER
|
|
||||||
description = "Piece can move twice in one turn"
|
|
||||||
duration = 2 # Lasts for 2 turns
|
|
||||||
|
|
||||||
func modify_moves() -> Dictionary:
|
func _init():
|
||||||
return {
|
super._init()
|
||||||
"extra_moves": 1,
|
# id = Utils.generate_guid()
|
||||||
"move_multiplier": 1
|
card_name = "Double Time"
|
||||||
}
|
rank = Rank.RANK_2
|
||||||
|
effect_type = EffectType.MOVEMENT_MODIFIER
|
||||||
|
description = "Piece can move twice in one turn"
|
||||||
|
duration = 2 # Lasts for 2 turns
|
||||||
|
unit_whitelist = []
|
||||||
|
|
||||||
func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
func modify_moves() -> Dictionary:
|
||||||
if !super.apply_effect(target_piece, board_flow, game_state):
|
return {
|
||||||
return false
|
"extra_moves": 1,
|
||||||
|
"move_multiplier": 1
|
||||||
|
}
|
||||||
|
|
||||||
# Logic to allow second move would be implemented in Game.gd
|
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):
|
||||||
return true
|
return false
|
||||||
|
|
||||||
|
# Logic to allow second move would be implemented in Game.gd
|
||||||
|
attached_piece = target_piece
|
||||||
|
return true
|
||||||
|
|
@ -1,19 +1,20 @@
|
||||||
class DrunkDrivingCard extends Card:
|
class_name DrunkDrivingCard extends Card
|
||||||
func _init():
|
func _init():
|
||||||
super._init()
|
super._init()
|
||||||
card_name = "Drunk Driving"
|
# id = Utils.generate_guid()
|
||||||
rank = Rank.RANK_1
|
card_name = "Drunk Driving"
|
||||||
effect_type = EffectType.SPECIAL_ACTION
|
rank = Rank.RANK_1
|
||||||
description = "Force Rook to move to opposite end"
|
effect_type = EffectType.SPECIAL_ACTION
|
||||||
unit_whitelist = ["Rook"] # Can only be attached to Rooks
|
description = "Force Rook to move to opposite end"
|
||||||
|
unit_whitelist = ["Rook"] # Can only be attached to Rooks
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if target_piece:
|
|
||||||
var current_pos = target_piece.get_parent().name.split("-")
|
|
||||||
var target_x = current_pos[0]
|
|
||||||
var target_y = "0" if target_piece.Item_Color == 0 else "7"
|
|
||||||
return [target_x + "-" + target_y]
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
if target_piece:
|
||||||
|
var current_pos = target_piece.get_parent().name.split("-")
|
||||||
|
var target_x = current_pos[0]
|
||||||
|
var target_y = "0" if target_piece.Item_Color == 0 else "7"
|
||||||
|
return [target_x + "-" + target_y]
|
||||||
|
return false
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
class SupernovaCard extends Card:
|
class_name SupernovaCard extends Card
|
||||||
func _init():
|
func _init():
|
||||||
super._init()
|
super._init()
|
||||||
card_name = "Supernova"
|
# id = Utils.generate_guid()
|
||||||
rank = Rank.RANK_0
|
card_name = "Supernova"
|
||||||
effect_type = EffectType.PIECE_EFFECT
|
rank = Rank.RANK_0
|
||||||
description = "Remove all abilities from enemy pieces"
|
effect_type = EffectType.PIECE_EFFECT
|
||||||
unit_whitelist = ["King"] # Can only be used by Kings
|
description = "Remove all abilities from enemy pieces"
|
||||||
|
unit_whitelist = ["King"] # Can only be used by Kings
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
if board_flow:
|
if board_flow:
|
||||||
for cell in board_flow.get_children():
|
for cell in board_flow.get_children():
|
||||||
if cell.get_child_count() > 0:
|
if cell.get_child_count() > 0:
|
||||||
var piece = cell.get_child(0)
|
var piece = cell.get_child(0)
|
||||||
if piece.Item_Color != target_piece.Item_Color:
|
if piece.Item_Color != target_piece.Item_Color:
|
||||||
pass
|
pass
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
extends Node
|
extends Node
|
||||||
class_name DeckManager
|
class_name DeckManager
|
||||||
|
|
||||||
|
const DoubleTimeCard = preload("res://Systems/Cards/Doubletime.gd")
|
||||||
|
|
||||||
|
|
||||||
var deck: Array = []
|
var deck: Array = []
|
||||||
var hand: Array = []
|
var hand: Array = []
|
||||||
var discard: Array = []
|
var discard: Array = []
|
||||||
|
|
@ -19,9 +22,8 @@ func _init():
|
||||||
initializeStartingDeck()
|
initializeStartingDeck()
|
||||||
|
|
||||||
func initializeStartingDeck():
|
func initializeStartingDeck():
|
||||||
# Add basic Rank 3 and 4 cards as per design doc
|
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
deck.append(Card.new()) # Basic movement cards
|
deck.append(DoubleTimeCard.new())
|
||||||
shuffleDeck()
|
shuffleDeck()
|
||||||
drawStartingHand()
|
drawStartingHand()
|
||||||
|
|
||||||
|
|
@ -49,10 +51,10 @@ signal hand_updated
|
||||||
func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = null):
|
func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = null):
|
||||||
if !hand.has(card):
|
if !hand.has(card):
|
||||||
return false
|
return false
|
||||||
emit_signal("hand_updated", hand)
|
|
||||||
|
|
||||||
if card.apply_effect(target_piece, board_flow, game_state):
|
if card.apply_effect(target_piece, board_flow, game_state):
|
||||||
hand.erase(card)
|
hand.erase(card)
|
||||||
|
emit_signal("hand_updated", hand)
|
||||||
|
|
||||||
match card.rank:
|
match card.rank:
|
||||||
Card.Rank.RANK_0:
|
Card.Rank.RANK_0:
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,13 @@ func initializeDeckSystem() -> void:
|
||||||
cardDisplay = CardDisplay.new()
|
cardDisplay = CardDisplay.new()
|
||||||
add_child(deckManager)
|
add_child(deckManager)
|
||||||
add_child(cardDisplay)
|
add_child(cardDisplay)
|
||||||
|
|
||||||
|
if !deckManager.has_user_signal("card_pressed"):
|
||||||
|
deckManager.add_user_signal("card_pressed")
|
||||||
|
|
||||||
|
if !deckManager.has_user_signal("hand_updated"):
|
||||||
|
deckManager.add_user_signal("hand_updated")
|
||||||
|
|
||||||
cardDisplay.update_hand(deckManager.hand)
|
cardDisplay.update_hand(deckManager.hand)
|
||||||
deckManager.connect("hand_updated", func(hand): cardDisplay.update_hand(hand))
|
deckManager.connect("hand_updated", func(hand): cardDisplay.update_hand(hand))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,63 @@
|
||||||
extends "res://Systems/StateMachine/ChessGameState.gd"
|
extends "res://Systems/StateMachine/ChessGameState.gd"
|
||||||
|
|
||||||
|
const ATTACHMENT_PHASE_DURATION = 30 # Duration in seconds
|
||||||
|
var timer: Timer
|
||||||
|
var tile_pressed_connection: Signal
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
super._ready()
|
||||||
|
timer = Timer.new()
|
||||||
|
timer.one_shot = true
|
||||||
|
timer.timeout.connect(_on_timer_timeout)
|
||||||
|
add_child(timer)
|
||||||
|
|
||||||
func enter(_previous: String, _data := {}) -> void:
|
func enter(_previous: String, _data := {}) -> void:
|
||||||
# finished.emit(Constants.APPLY_CARD_EFFECTS)
|
|
||||||
print("ENTERING STATE ", Constants.ATTACH_CARDS)
|
print("ENTERING STATE ", Constants.ATTACH_CARDS)
|
||||||
if !game.boardContainer.is_connected("card_pressed", handleCardPressed):
|
if !game.boardContainer.is_connected("tile_pressed", handleTilePressed):
|
||||||
print("Connecting card_pressed signal")
|
game.boardContainer.connect("tile_pressed", handleTilePressed)
|
||||||
game.boardContainer.connect("card_pressed", handleCardPressed)
|
|
||||||
|
|
||||||
|
timer.start(ATTACHMENT_PHASE_DURATION)
|
||||||
|
if game.deckManager.hand.is_empty():
|
||||||
|
complete_attachment_phase()
|
||||||
|
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
if game.boardContainer.is_connected("card_pressed", handleCardPressed):
|
|
||||||
game.boardContainer.disconnect("card_pressed", handleCardPressed)
|
|
||||||
|
|
||||||
|
if game.boardContainer.is_connected("tile_pressed", handleTilePressed):
|
||||||
|
game.boardContainer.disconnect("tile_pressed", handleTilePressed)
|
||||||
|
|
||||||
func handleCardPressed(location: String) -> void:
|
game.cardDisplay.selected_card = null
|
||||||
print("HANDLING MOVEMENT ", location)
|
game.selectedNode = ""
|
||||||
var node = game.get_node("Flow/" + location)
|
game.resetHighlights()
|
||||||
|
|
||||||
|
func handleTilePressed(location: String) -> void:
|
||||||
|
print("HANDLING Tile PRESSED ", location)
|
||||||
|
var targetNode = game.get_node("Flow/" + location)
|
||||||
|
|
||||||
|
if targetNode.get_child_count() == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
var piece = targetNode.get_child(0)
|
||||||
|
var selectedCard = game.cardDisplay.get_selected_card()
|
||||||
|
|
||||||
|
if selectedCard and piece:
|
||||||
|
var isCorrectColor = (piece.Item_Color == 0 and game.currentPlayer == game.WHITE) or \
|
||||||
|
(piece.Item_Color == 1 and game.currentPlayer == game.BLACK)
|
||||||
|
|
||||||
|
if isCorrectColor and selectedCard.can_attach_to_piece(piece) and \
|
||||||
|
!game.deckManager.attached_cards.has(piece.get_instance_id()):
|
||||||
|
if game.deckManager.playCard(selectedCard, piece, game.boardContainer, game):
|
||||||
|
print("Successfully attached card ", selectedCard.card_name, " to ", piece.name)
|
||||||
|
if game.deckManager.hand.is_empty():
|
||||||
|
complete_attachment_phase()
|
||||||
|
else:
|
||||||
|
print("Failed to attach card")
|
||||||
|
|
||||||
|
func _on_timer_timeout() -> void:
|
||||||
|
print("Card attachment phase timed out")
|
||||||
|
finished.emit(Constants.APPLY_CARD_EFFECTS)
|
||||||
|
|
||||||
|
func complete_attachment_phase() -> void:
|
||||||
|
if timer.time_left > 0:
|
||||||
|
timer.stop()
|
||||||
|
_on_timer_timeout()
|
||||||
|
|
||||||
23
Utils/Utils.gd
Normal file
23
Utils/Utils.gd
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
class_name Utils
|
||||||
|
extends Object
|
||||||
|
|
||||||
|
static func generate_guid() -> String:
|
||||||
|
var guid = ""
|
||||||
|
var time = Time.get_ticks_msec()
|
||||||
|
var rng = RandomNumberGenerator.new()
|
||||||
|
rng.randomize()
|
||||||
|
|
||||||
|
# Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
||||||
|
guid += "%08x" % time
|
||||||
|
guid += "-"
|
||||||
|
guid += "%04x" % rng.randi()
|
||||||
|
guid += "-"
|
||||||
|
guid += "4"
|
||||||
|
guid += "%03x" % rng.randi()
|
||||||
|
guid += "-"
|
||||||
|
guid += "%x" % (8 + rng.randi() % 4)
|
||||||
|
guid += "%03x" % rng.randi()
|
||||||
|
guid += "-"
|
||||||
|
guid += "%012x" % rng.randi()
|
||||||
|
|
||||||
|
return guid
|
||||||
|
|
@ -72,7 +72,7 @@ offset_top = 65.0
|
||||||
offset_right = 1142.0
|
offset_right = 1142.0
|
||||||
offset_bottom = 104.0
|
offset_bottom = 104.0
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
[node name="Hand" type="HBoxContainer" parent="."]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 7
|
anchors_preset = 7
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue