Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion entities/game/card_template/scenes/CardTemplate.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ script = ExtResource("18_8fn1p")
visible = false
z_index = 1001
position = Vector2(0, 25)
amount = 1600
amount = 800
texture = ExtResource("20_ja01p")
lifetime = 3.0
preprocess = 1.5
Expand All @@ -231,6 +231,7 @@ volume = -15.0
[connection signal="hide_card" from="." to="CardBack" method="toggle_on"]
[connection signal="input_active" from="." to="CardBack" method="input_active"]
[connection signal="input_active" from="." to="FocusEffect" method="toggle_state"]
[connection signal="remove_requested" from="." to="CardBack" method="removal_planed"]
[connection signal="show_card" from="." to="CardContentGroup" method="show_card_content"]
[connection signal="show_card" from="." to="CardBack" method="toggle_off"]
[connection signal="ready_for_destruction" from="CardContentGroup" to="." method="destory_now"]
Expand Down
67 changes: 60 additions & 7 deletions entities/game/card_template/scripts/CardTemplate.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ signal card_text_changed(new_text: String)
signal card_tooltip_changed(new_tooltip: String)
signal deck_changed(deck: MemoryDeckResource)

signal remove_requested()

@export var is_ghost: bool = false

@export_group("Visuals")
Expand All @@ -31,6 +33,7 @@ signal deck_changed(deck: MemoryDeckResource)
@export_range(0,0.25) var card_flip_animation_min_time_delay: float = 0.1
@export_range(0,0.5) var card_flip_animation_max_time_delay: float = 0.5
@export var matching_animation_scale: float = 1.5
@export var shrink_animation_scale: float = 0.3

@export_group("Debug")
@export var debug_remove: bool = false:
Expand All @@ -51,6 +54,22 @@ var _getting_removed: bool = false
var _playing_animation: bool = false

var _valid_game_state: bool = false
var _memory_game: MemoryGame:
get():
if _memory_game == null:
_memory_game = get_tree().get_first_node_in_group("game_scene")
return _memory_game

var _ui_information: UiInformationSystem:
get():
if _ui_information == null:
if _memory_game == null:
return _ui_information
for system: Node in _memory_game.get_systems().get_systems():
if system is UiInformationSystem:
_ui_information = system
break
return _ui_information

var _game_manager: GameManager:
get():
Expand Down Expand Up @@ -157,31 +176,65 @@ func is_turned() -> bool:
return _was_clicked

func remove_from_board(was_ai: bool) -> void:
top_level = true
z_index = 100
_getting_removed = true
remove_requested.emit()
var settings: SettingsResource = SettingsRepository.load_settings()
_playing_animation = true

if not settings.animate_card_matches or was_ai:
_trigger_remove()
_fast_match_animation(settings)
return
_player_match_animation(settings)

func _fast_match_animation(settings: SettingsResource) -> void:
var remove_tween: Tween = create_tween()
remove_tween.tween_property(self, "scale", scale, settings.animation_time)
remove_tween.tween_property(self, "scale", Vector2(shrink_animation_scale, shrink_animation_scale), settings.animation_time / 2)
remove_tween.parallel()
remove_tween.tween_method(_move_to_player_ui, 0.0, 1.0, settings.animation_time * 1.5)
remove_tween.finished.connect(_trigger_remove)

func _player_match_animation(settings: SettingsResource) -> void:
var camera: Camera2D = get_viewport().get_camera_2d()
var center: Vector2 = _game_manager._get_viewport_size() / 2.0
var additional_scale: float = 1
if camera != null:
center = camera.get_screen_center_position()
additional_scale = 1.0 / camera.zoom.x
z_index = 100

var target_scale: Vector2 = Vector2(matching_animation_scale * additional_scale, matching_animation_scale * additional_scale)
_playing_animation = true

var remove_tween: Tween = create_tween()
remove_tween.tween_property(self, "scale", scale, settings.animation_time)

remove_tween.tween_property(self, "global_position", center, settings.animation_time)
remove_tween.tween_method(_move_to_center, 0.0, 1.0, settings.animation_time)
remove_tween.parallel()
remove_tween.tween_property(self, "scale", target_scale, settings.animation_time)
## Wait for some time to display card
remove_tween.tween_property(self, "scale", target_scale, settings.animation_time)
remove_tween.tween_property(self, "scale", Vector2(shrink_animation_scale, shrink_animation_scale), settings.animation_time / 2)
remove_tween.parallel()
remove_tween.tween_method(_move_to_player_ui, 0.0, 1.0, settings.animation_time / 2)
remove_tween.finished.connect(_trigger_remove)

func _move_to_center(lerp_weight: float) -> void:
var center: Vector2 = _game_manager._get_viewport_size() / 2.0
var camera: Camera2D = get_viewport().get_camera_2d()
if camera != null:
center = camera.get_screen_center_position()

global_position = lerp(global_position, center, lerp_weight)

func _move_to_player_ui(lerp_weight: float) -> void:
var target_position: Vector2 = _get_global_player_ui_position()

global_position = lerp(global_position, target_position, lerp_weight)

func _get_global_player_ui_position() -> Vector2:
if _ui_information == null:
return global_position
var player_overlay: PlayerGameOverlay = _ui_information.get_ui_element("PlayersOverlay")
return player_overlay.get_global_position_of_current_player()

func _trigger_remove() -> void:
for group: String in get_groups():
remove_from_group(group)
Expand Down
8 changes: 7 additions & 1 deletion entities/game/card_template/scripts/ToggleCardVisibility.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var currently_in_focus: bool = false
var collider: Area2D
var removal_requested: bool = false
var can_remove: bool = false
var removal_planned: bool = false
var currently_ai: bool = false

var animation_tween: Tween = null
Expand Down Expand Up @@ -116,6 +117,8 @@ func update_toggle_material(progress: float) -> void:
func is_focused() -> void:
if animation_tween != null && animation_tween.is_running():
return
if visibility == VisibilityEnum.TRANSITION:
return
for card: Node in get_tree().get_nodes_in_group("game_card"):
if card is CardTemplate and card.card_is_focused():
card.lost_focus()
Expand Down Expand Up @@ -152,8 +155,11 @@ func is_currently_in_focus() -> bool:
func remove_from_board() -> void:
removal_requested = true

func removal_planed() -> void:
removal_planned = true

func _process(_delta: float) -> void:
if removal_requested && can_remove:
if removal_planned && can_remove:
ready_for_removal.emit()
queue_free()

Expand Down
5 changes: 0 additions & 5 deletions entities/game/finish_game/scripts/PlayerScoreList.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ extends VBoxContainer

var _win_sound_played: bool = false

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.

func build_player_statistic(players: Array[PlayerResource], winners: Array[PlayerResource]) -> void:
players.sort_custom(sort_by_score)
for player: PlayerResource in players:
Expand All @@ -21,7 +17,6 @@ func build_player_statistic(players: Array[PlayerResource], winners: Array[Playe
break
player_node.set_player(player, did_win)
add_child(player_node)


func sort_by_score(a: PlayerResource, b: PlayerResource) -> bool:
return a.score > b.score
Expand Down
7 changes: 6 additions & 1 deletion entities/game/finish_game/scripts/ReplayGame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ func _ready() -> void:

func _pressed() -> void:
get_tree().paused = false
GlobalGameManagerAccess.get_game_manager().play_game_with_position(finish_game_node.manager.get_players(), finish_game_node.played_deck, get_screen_position())
var players: Array[PlayerResource] = finish_game_node.manager.get_players()
players.sort_custom(sort_by_id)
GlobalGameManagerAccess.get_game_manager().play_game_with_position(players, finish_game_node.played_deck, get_screen_position())

func sort_by_id(a: PlayerResource, b: PlayerResource) -> bool:
return a.id < b.id

func was_multiplayer_game() -> bool:
return not multiplayer.multiplayer_peer is OfflineMultiplayerPeer
15 changes: 12 additions & 3 deletions entities/game/memory_game/scenes/MemoryGame.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[ext_resource type="PackedScene" uid="uid://csamt2tu6hlpo" path="res://entities/game/finish_game/scenes/FinishGame.tscn" id="4_6f670"]
[ext_resource type="Script" uid="uid://bxjrl2ikqn4tk" path="res://entities/game/memory_game/scripts/systems/PlayerSystem.gd" id="4_n744t"]
[ext_resource type="AudioStream" uid="uid://dq3rmjoitwi1a" path="res://assets/audio/effect/confirmation_001.ogg" id="6_a3528"]
[ext_resource type="Script" uid="uid://cetyf2kvhh70r" path="res://entities/game/memory_game/scripts/Systems.gd" id="7_8jbv8"]
[ext_resource type="PackedScene" uid="uid://d0vijthhc3d38" path="res://entities/game/players_overlay/scenes/PlayersOverlay.tscn" id="7_a7rnv"]
[ext_resource type="Script" uid="uid://bmwi41kseslkw" path="res://entities/game/memory_game/scripts/systems/GameStateSystem.gd" id="7_j82c0"]
[ext_resource type="Script" uid="uid://bglvkbo4aydsy" path="res://entities/game/memory_game/scripts/Background.gd" id="7_kxmqb"]
Expand All @@ -34,6 +35,7 @@
[ext_resource type="PackedScene" uid="uid://laeqw1xjwd1b" path="res://entities/game/debug_tool/scenes/DebugPanel.tscn" id="33_j82c0"]
[ext_resource type="Script" uid="uid://c1wsjd5pkvtiq" path="res://entities/game/debug_tool/scripts/DebugFunctionality.gd" id="34_4hsit"]
[ext_resource type="Script" uid="uid://ce067cc441ff1" path="res://entities/game/debug_tool/scripts/FinishGameFunction.gd" id="35_imof5"]
[ext_resource type="Script" uid="uid://b34wu88vlg03e" path="res://entities/game/memory_game/scripts/systems/UiInformationSystem.gd" id="36_m766l"]
[ext_resource type="Script" uid="uid://p5xd1ppjr4ph" path="res://entities/game/memory_game/scripts/systems/TutorialStateSystem.gd" id="40_1resq"]

[sub_resource type="Resource" id="Resource_kihnp"]
Expand Down Expand Up @@ -76,9 +78,11 @@ finished_game_template = ExtResource("4_6f670")
game_menu_template = ExtResource("12_dfx06")
game_nodes_to_show = [NodePath("UI"), NodePath("World/Background")]
card_target_node = NodePath("World/Cards")
sound_effect = ExtResource("6_a3528")

[node name="Systems" type="Node" parent="." unique_id=1597793066]
[node name="Systems" type="Node" parent="." unique_id=1325794078]
unique_name_in_owner = true
script = ExtResource("7_8jbv8")
metadata/_custom_type_script = "uid://cetyf2kvhh70r"

[node name="GameStateSystem" type="Node" parent="Systems" unique_id=2091663874]
script = ExtResource("7_j82c0")
Expand Down Expand Up @@ -124,6 +128,11 @@ card_template = ExtResource("3_ihyl6")
place_offset = Vector2(250, 250)
metadata/_custom_type_script = "uid://btm576yjkyt4j"

[node name="UiInformationSystem" type="Node" parent="Systems" unique_id=1812178848]
unique_name_in_owner = true
script = ExtResource("36_m766l")
metadata/_custom_type_script = "uid://b34wu88vlg03e"

[node name="World" type="Node2D" parent="." unique_id=997333008]
unique_name_in_owner = true

Expand All @@ -138,6 +147,7 @@ camera_node = NodePath("../Camera2D")
unique_name_in_owner = true
script = ExtResource("19_ploi3")
state_machine = NodePath("../../Systems/GameStateSystem")
matching_card_sound_effect = ExtResource("6_a3528")

[node name="CardTemplateGhost" parent="World" unique_id=155356654 groups=["game_initialize_scene"] instance=ExtResource("3_ihyl6")]
position = Vector2(-11367, -8587)
Expand Down Expand Up @@ -224,7 +234,6 @@ debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")]

[connection signal="game_paused" from="." to="Systems/PlayerInputSystem" method="game_paused"]
[connection signal="game_paused" from="." to="World/Camera2D" method="game_paused"]
[connection signal="game_was_finished" from="." to="World/Camera2D" method="queue_free"]
[connection signal="load_game" from="." to="Systems/CardSpawnerSystem" method="place_cards_from_deck"]
[connection signal="request_popup" from="." to="Systems/PopupSystem" method="add_and_show_popup"]
[connection signal="force_close_popup" from="Systems/GameStateSystem" to="Systems/PopupSystem" method="force_close_popup_with_id"]
Expand Down
2 changes: 2 additions & 0 deletions entities/game/memory_game/scripts/GameCardGrid.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ signal board_empty()
signal card_activated()

@export var state_machine: GameStateSystem
@export var matching_card_sound_effect: AudioStream

var current_card: CardTemplate

Expand Down Expand Up @@ -142,6 +143,7 @@ func remove_cards_from_board(grid_positions: Array[Point]) -> void:
if card.is_playing_animation():
await card.about_to_get_delete
all_matching_cards_removed.emit()
GlobalSoundManager.play_sound_effect(matching_card_sound_effect)

func remove_card_from_board(grid_position: Point) -> void:
for child: CardTemplate in _get_game_card_templates_children():
Expand Down
20 changes: 15 additions & 5 deletions entities/game/memory_game/scripts/MemoryGame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ const CARDS_PER_PLAYER: int = 2
@export var game_nodes_to_show: Array[Node]
@export var card_target_node: Node2D

@export_group("Effect Setup")
@export var sound_effect: AudioStream

#var current_game_state: int
var player_node: PlayerSystem
var triggered_cards: int
Expand All @@ -34,10 +31,19 @@ var auto_close_popup: PackedScene = preload("res://entities/game/auto_close_popu
var last_message_banner_id: int = -1

var _is_local_only: bool = true
var _game_scene_group_name: String = "game_scene"
var _systems: Systems:
get():
if _systems == null:
_systems = get_node("%Systems")
return _systems

func _init() -> void:
add_to_group(_game_scene_group_name)

func _ready() -> void:
process_mode = PROCESS_MODE_DISABLED
player_node = get_node("%PlayerSystem")
player_node = get_node("%PlayerSystem")

func start_loading_data() -> void:
load_game.emit(card_deck)
Expand All @@ -58,6 +64,7 @@ func show_initial_setup() -> bool:
return true

func show_game_end_screen() -> void:
remove_from_group(_game_scene_group_name)
var finish_node: GameFinished = finished_game_template.instantiate() as GameFinished
finish_node.high_priority = true
finish_node.set_player_manager(player_node)
Expand Down Expand Up @@ -106,4 +113,7 @@ func all_cards_placed() -> void:
for child: Node in get_tree().get_nodes_in_group("game_initialize_scene"):
child.queue_free()
GlobalSoundManager.stop_all_sounds()
process_mode = Node.PROCESS_MODE_INHERIT
process_mode = Node.PROCESS_MODE_INHERIT

func get_systems() -> Systems:
return _systems
4 changes: 4 additions & 0 deletions entities/game/memory_game/scripts/Systems.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class_name Systems extends Node

func get_systems() -> Array[Node]:
return get_children()
1 change: 1 addition & 0 deletions entities/game/memory_game/scripts/Systems.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cetyf2kvhh70r
1 change: 0 additions & 1 deletion entities/game/memory_game/scripts/systems/AiAgentSystem.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func game_state_changed(game_state: GameEnum.State) -> void:
timer.stop()
return


func get_all_card_positions() -> Array[Point]:
return cards_node.get_all_card_positions()

Expand Down
20 changes: 20 additions & 0 deletions entities/game/memory_game/scripts/systems/UiInformationSystem.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class_name UiInformationSystem extends Node

var _elements: Dictionary[String, Control] = {}

func register_ui_element(element_name: String, control: Control) -> bool:
if _elements.has(element_name):
return false
_elements.set(element_name, control)
return true

func get_ui_element(searched_name: String) -> Control:
if _elements.has(searched_name):
return _elements.get(searched_name)
return null

func get_all_elements() -> Dictionary[String, Control]:
return _elements

func get_all_names() -> Array[String]:
return _elements.keys()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://b34wu88vlg03e
Loading
Loading