diff --git a/cards/playing_card.gd b/cards/playing_card.gd index d65b72d..2d16924 100644 --- a/cards/playing_card.gd +++ b/cards/playing_card.gd @@ -17,15 +17,23 @@ func _ready() -> void: func move_to(new_x_position: float) -> void: #self.position.x = new_x_position - var tween = create_tween() - tween.set_trans(Tween.TRANS_BACK) - tween.set_ease(Tween.EASE_OUT) - tween.tween_property(self, "position:x", new_x_position, move_duration) + _get_new_tween().tween_property(self, "position:x", new_x_position, move_duration) + +func select() -> void: + _get_new_tween().tween_property(self, "position:y", 0.36, move_duration) + +func unselect() -> void: + _get_new_tween().tween_property(self, "position:y", 0.0, move_duration) func set_front_texture(texture: Texture) -> void: card_mesh.get_surface_override_material(0).albedo_texture = front_texture +func _get_new_tween() -> Tween: + var tween = create_tween() + tween.set_trans(Tween.TRANS_BACK) + tween.set_ease(Tween.EASE_OUT) + return tween + func _on_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void: - if event.is_action_pressed("left_mouse_button"): - print("yahaha!") + if event.is_action_released("left_mouse_button"): card_clicked.emit(self) diff --git a/elements/player_hand.gd b/elements/player_hand.gd index 916ddcd..e035ef4 100644 --- a/elements/player_hand.gd +++ b/elements/player_hand.gd @@ -16,13 +16,15 @@ extends Node3D @export_range(0, 20, 0.1, "radians_as_degrees") var card_angle: float +var _selected_card: PlayingCard = null + func _ready() -> void: _arrange_cards() for i in test_card_count: var card: PlayingCard = card_scene.instantiate() card.card_clicked.connect(_on_card_clicked) add_card(card) - await get_tree().create_timer(0.24).timeout + await get_tree().create_timer(0.2).timeout func add_card(card: PlayingCard) -> void: self.add_child(card) @@ -41,7 +43,6 @@ func _arrange_cards() -> void: var desired_width: float = (card_distance * (cards.size() - 1)) var card_position = -desired_width / 2.0 for card in cards: - #card.position.x = card_position card.move_to(card_position) card_position += card_distance card.rotation.y = card_angle @@ -50,4 +51,10 @@ func _get_card_distance(card_count: int) -> float: return card_distance_min + ((card_distance_max - card_distance_min) * (1.0 - (float(card_count) / 19.0))) func _on_card_clicked(playing_card: PlayingCard) -> void: - pass + if _selected_card: + _selected_card.unselect() + if _selected_card == playing_card: + _selected_card = null + else: + _selected_card = playing_card + playing_card.select() diff --git a/elements/player_hand.tscn b/elements/player_hand.tscn index 2358909..ba29ad7 100644 --- a/elements/player_hand.tscn +++ b/elements/player_hand.tscn @@ -5,6 +5,6 @@ [node name="PlayerHand" type="Node3D"] script = ExtResource("1_ank64") -test_card_count = 20 +test_card_count = 5 card_scene = ExtResource("2_11xsc") card_angle = 0.125664