mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
Game Pausing
This commit is contained in:
parent
401d944ab4
commit
e86e9a2bf7
8 changed files with 160 additions and 22 deletions
1
Dialogue/Timelines/testintro.dtl
Normal file
1
Dialogue/Timelines/testintro.dtl
Normal file
|
|
@ -0,0 +1 @@
|
|||
Cirno: Test message intro
|
||||
|
|
@ -1,3 +1,2 @@
|
|||
join Cirno left
|
||||
Cirno: asdf
|
||||
Cirno: fdsg
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
||||
|
|
@ -7,13 +8,17 @@ public partial class DialogueStarter : Activable
|
|||
|
||||
[Export] private string _trackName = "timeline";
|
||||
|
||||
[Export] private Node2D _dialogueEndActivationTarget;
|
||||
[Export] private Array<Node2D> _dialogueEndActivationTargets;
|
||||
|
||||
private Node _dialogic;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
_gameManager = this.GetGameManager();
|
||||
|
||||
_dialogic = GetNode("/root/Dialogic");
|
||||
|
||||
|
|
@ -27,6 +32,7 @@ public partial class DialogueStarter : Activable
|
|||
|
||||
public override void Activate()
|
||||
{
|
||||
_gameManager.ChangeState(GameState.Dialogue);
|
||||
_dialogic.Call("start", _trackName);
|
||||
// Script dialogic = ResourceLoader.Load("res://addons/dialogic/Other/DialogicClass.gd") as Script;
|
||||
// var dialog = (Node) dialogic.Call("start","timeline");
|
||||
|
|
@ -34,17 +40,26 @@ public partial class DialogueStarter : Activable
|
|||
//if (Dialogic)
|
||||
}
|
||||
|
||||
private bool DialogueEndAction()
|
||||
private void DialogueEndAction()
|
||||
{
|
||||
if (_dialogueEndActivationTarget is not IActivable target)
|
||||
_gameManager.ChangeState(GameState.Playing);
|
||||
foreach (var activationTarget in _dialogueEndActivationTargets)
|
||||
{
|
||||
GD.PrintErr($"Target {_dialogueEndActivationTarget.Name} is not activable");
|
||||
ActivateTarget(activationTarget);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ActivateTarget(Node2D activationTarget)
|
||||
{
|
||||
if (activationTarget is not IActivable target)
|
||||
{
|
||||
GD.PrintErr($"Target {activationTarget.Name} is not activable");
|
||||
return false;
|
||||
}
|
||||
|
||||
target?.Activate();
|
||||
|
||||
GD.Print($"{_dialogueEndActivationTarget.Name} activated");
|
||||
GD.Print($"{activationTarget.Name} activated");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ public partial class GameManager : Node2D
|
|||
|
||||
private PlayerMovement _player;
|
||||
|
||||
public GameState GameState { get; private set; }
|
||||
|
||||
public PlayerMovement Player => _player;
|
||||
|
||||
private Node2D _cameraTarget;
|
||||
|
|
@ -31,6 +33,9 @@ public partial class GameManager : Node2D
|
|||
private Node2D _bulletsContainer;
|
||||
public Node2D BulletsContainer => _bulletsContainer;
|
||||
|
||||
[Signal]
|
||||
public delegate void GameStateChangeEventHandler(GameState state);
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -64,11 +69,17 @@ public partial class GameManager : Node2D
|
|||
|
||||
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
|
||||
}
|
||||
|
||||
GameState = GameState.Playing;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("pause"))
|
||||
{
|
||||
TogglePause();
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnPlayer()
|
||||
|
|
@ -96,4 +107,48 @@ public partial class GameManager : Node2D
|
|||
|
||||
AddChild(_bulletsContainer);
|
||||
}
|
||||
|
||||
public void TogglePause()
|
||||
{
|
||||
if (GameState == GameState.Paused)
|
||||
{
|
||||
Unpause();
|
||||
}
|
||||
else if (GameState == GameState.Playing)
|
||||
{
|
||||
Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (GameState == GameState.Playing)
|
||||
{
|
||||
ChangeState(GameState.Paused);
|
||||
}
|
||||
}
|
||||
|
||||
public void Unpause()
|
||||
{
|
||||
if (GameState == GameState.Paused)
|
||||
{
|
||||
ChangeState(GameState.Playing);
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeState(GameState state)
|
||||
{
|
||||
if (state == GameState) return;
|
||||
GameState = state;
|
||||
EmitSignal(nameof(GameStateChange), (int)GameState);
|
||||
GD.Print($"Game state changed to {state}");
|
||||
}
|
||||
}
|
||||
|
||||
public enum GameState
|
||||
{
|
||||
Menu,
|
||||
Paused,
|
||||
Playing,
|
||||
Dialogue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private bool _isStrafing { get; set; }
|
||||
|
||||
private bool _canMove = true;
|
||||
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float newHealth, float MaxHealth);
|
||||
|
||||
|
|
@ -89,9 +91,11 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
_facingDirection = Vector2.Zero;
|
||||
_rightStickInput = Vector2.Zero;
|
||||
_isStrafing = false;
|
||||
|
||||
_gameManager = GetNode<GameManager>("/root/GameScene");
|
||||
|
||||
_gameManager = this.GetGameManager(); //GetNode<GameManager>("/root/GameScene");
|
||||
|
||||
_gameManager.GameStateChange += GameManagerOnGameStateChange;
|
||||
|
||||
if (SelectorScene != null)
|
||||
{
|
||||
_selector = this.CreateSibling<Selector>(SelectorScene, this.GlobalPosition);
|
||||
|
|
@ -99,6 +103,25 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
}
|
||||
}
|
||||
|
||||
private void GameManagerOnGameStateChange(GameState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case GameState.Menu:
|
||||
break;
|
||||
case GameState.Paused:
|
||||
_canMove = false;
|
||||
break;
|
||||
case GameState.Playing:
|
||||
_canMove = true;
|
||||
break;
|
||||
case GameState.Dialogue:
|
||||
_canMove = false;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*public override _Process(float _delta)
|
||||
{
|
||||
if (Input.IsActionPressed("ui_right"))
|
||||
|
|
@ -113,9 +136,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
HandleShoot();
|
||||
SetAnimation();
|
||||
|
||||
if (!_canMove) return;
|
||||
HandleShoot();
|
||||
FindInteractable();
|
||||
}
|
||||
|
||||
|
|
@ -226,6 +249,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (!_canMove) return;
|
||||
|
||||
_movementDirection = GetInput();
|
||||
|
||||
_isStrafing = Input.IsActionPressed("strafe");
|
||||
|
|
@ -263,9 +288,10 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
//FindInteractable();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void _on_interaction_controller_area_entered(Area2D area)
|
||||
{
|
||||
if (!_canMove) return;
|
||||
// Replace with function body.
|
||||
if (area.IsInGroup("Interactable") && area is Interactable interactable && interactable.CanActivate())
|
||||
{
|
||||
|
|
@ -284,6 +310,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private void _on_interaction_controller_area_exited(Area2D area)
|
||||
{
|
||||
if (!_canMove) return;
|
||||
if (area.IsInGroup("Interactable") && area is Interactable interactable)
|
||||
{
|
||||
Debug.WriteLine($"Interactable {area.Name} Exited");
|
||||
|
|
@ -312,6 +339,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
public void Hit(float damage)
|
||||
{
|
||||
if (!_canMove) return;
|
||||
GD.Print($"Player damaged for {damage}");
|
||||
if (_isDestroyed) return;
|
||||
|
||||
|
|
@ -328,6 +356,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private void _on_damage_hit_box_area_entered(Area2D area)
|
||||
{
|
||||
if (!_canMove) return;
|
||||
if (area is Bullet bullet)
|
||||
{
|
||||
GD.Print("Received damage manually");
|
||||
|
|
|
|||
|
|
@ -61,4 +61,9 @@ public static class Tools
|
|||
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
public static GameManager GetGameManager(this Node2D node)
|
||||
{
|
||||
return node.GetNode<GameManager>("/root/GameScene");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ directories/dch_directory={
|
|||
"Cirno": "res://Dialogue/Characters/Cirno.dch"
|
||||
}
|
||||
directories/dtl_directory={
|
||||
"testintro": "res://Dialogue/Timelines/testintro.dtl",
|
||||
"timeline": "res://Dialogue/timeline.dtl"
|
||||
}
|
||||
glossary/default_case_sensitive=true
|
||||
|
|
@ -170,6 +171,13 @@ dialogic_default_action={
|
|||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
|
||||
]
|
||||
}
|
||||
pause={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194332,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue