Отображение в редакторе при изменении экспортированных переменных, музыка на все дни, звуки дверей, NPC.
This commit is contained in:
parent
fec3f22665
commit
3c1619ee9f
47 changed files with 657 additions and 89 deletions
|
@ -4,6 +4,8 @@ using Godot;
|
|||
|
||||
public partial class AudioCollection : Node
|
||||
{
|
||||
[Signal] public delegate void FinishedEventHandler();
|
||||
|
||||
private enum State
|
||||
{
|
||||
Error,
|
||||
|
@ -46,6 +48,7 @@ public partial class AudioCollection : Node
|
|||
if (!_currentPlayer.IsPlaying())
|
||||
{
|
||||
_state = State.Timeout;
|
||||
EmitSignal(SignalName.Finished);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -72,7 +75,7 @@ public partial class AudioCollection : Node
|
|||
player.PitchScale = RandomPitch ? _rng.RandfRange(PitchStart, PitchEnd) : 1;
|
||||
player.Play();
|
||||
_state = State.Playing;
|
||||
_currentChild = Shuffle ? _rng.RandiRange(0, _count) : 0;
|
||||
_currentChild = Shuffle ? _rng.RandiRange(0, _count) : (_currentChild + 1) % _count;
|
||||
_currentPlayer = player;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -4,9 +4,12 @@ using System;
|
|||
public partial class Door : Node2D
|
||||
{
|
||||
[Export] public Door Exit;
|
||||
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
[Tool]
|
||||
public partial class Interactable : Node2D
|
||||
{
|
||||
private const double Tolerance = 1e-6;
|
||||
|
||||
[Signal]
|
||||
public delegate void PlayerNearByEventHandler(Player player);
|
||||
[Signal]
|
||||
|
@ -15,18 +18,34 @@ public partial class Interactable : Node2D
|
|||
|
||||
private CollisionShape2D _areaMesh;
|
||||
|
||||
private CircleShape2D _collisionCircle;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_areaMesh = (CollisionShape2D)FindChild("CollisionShape2D");
|
||||
_sprite.Position += SpriteOffset;
|
||||
((CircleShape2D)_areaMesh.Shape).Radius = AreaRadius;
|
||||
_sprite.Position = SpriteOffset;
|
||||
_collisionCircle =(CircleShape2D)_areaMesh.Shape;
|
||||
_collisionCircle.Radius = AreaRadius;
|
||||
if (Engine.IsEditorHint())
|
||||
{
|
||||
_sprite.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_sprite.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Engine.IsEditorHint())
|
||||
{
|
||||
if (_sprite.Position != SpriteOffset) _sprite.Position = SpriteOffset;
|
||||
if (Math.Abs(_collisionCircle.Radius - AreaRadius) > Tolerance) _collisionCircle.Radius = AreaRadius;
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_area_2d_body_entered(Node2D body)
|
||||
|
|
|
@ -2,7 +2,7 @@ using Godot;
|
|||
using System;
|
||||
using Godot.Collections;
|
||||
|
||||
|
||||
[Tool]
|
||||
public partial class NPC : Node2D
|
||||
{
|
||||
[Export] public string NPCName;
|
||||
|
@ -14,7 +14,7 @@ public partial class NPC : Node2D
|
|||
public override void _Ready()
|
||||
{
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_sprite.SpriteFrames = Frames;
|
||||
if (Frames is not null) _sprite.SpriteFrames = Frames;
|
||||
_sprite.Play("default");
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,14 @@ public partial class NPC : Node2D
|
|||
{
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (Engine.IsEditorHint())
|
||||
{
|
||||
if (Frames is not null && _sprite.SpriteFrames != Frames) _sprite.SpriteFrames = Frames;
|
||||
}
|
||||
}
|
||||
|
||||
public void test()
|
||||
{
|
||||
if (_sprite.Animation == "walk")
|
||||
|
|
|
@ -9,6 +9,7 @@ public partial class Player : CharacterBody2D
|
|||
public enum State
|
||||
{
|
||||
Normal,
|
||||
Wait,
|
||||
Transition,
|
||||
ReadChat
|
||||
}
|
||||
|
@ -20,10 +21,10 @@ public partial class Player : CharacterBody2D
|
|||
get => _state;
|
||||
private set
|
||||
{
|
||||
_state = value;
|
||||
switch (_state)
|
||||
switch (value)
|
||||
{
|
||||
case State.Normal:
|
||||
if (_state == State.Transition) DoorSounds.Play();
|
||||
Visible = true;
|
||||
break;
|
||||
case State.Transition:
|
||||
|
@ -32,9 +33,12 @@ public partial class Player : CharacterBody2D
|
|||
case State.ReadChat:
|
||||
// ChatLog.Visible = !ChatLog.Visible;
|
||||
break;
|
||||
case State.Wait:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
_state = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +74,8 @@ public partial class Player : CharacterBody2D
|
|||
protected PanelContainer ChatLog;
|
||||
protected Camera2D Camera;
|
||||
protected AudioCollection Footsteps;
|
||||
|
||||
protected AudioCollection DoorSounds;
|
||||
|
||||
private Vector2 _newPosition;
|
||||
private double _currentTransitionTime = 0;
|
||||
private double _currentCameraTransitionTime = 0;
|
||||
|
@ -84,6 +89,7 @@ public partial class Player : CharacterBody2D
|
|||
ChatLog = (PanelContainer)FindChild("ChatLog");
|
||||
Camera = (Camera2D)FindChild("Camera2D");
|
||||
Footsteps = (AudioCollection)FindChild("Footsteps");
|
||||
DoorSounds = (AudioCollection)FindChild("DoorSounds");
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
|
@ -172,6 +178,8 @@ public partial class Player : CharacterBody2D
|
|||
}
|
||||
}
|
||||
break;
|
||||
case State.Wait:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
@ -189,9 +197,10 @@ public partial class Player : CharacterBody2D
|
|||
|
||||
if (InteractableObject is Door door)
|
||||
{
|
||||
DoorSounds.Play();
|
||||
_previousPosition = GlobalPosition;
|
||||
_nextPosition = door.Exit.GlobalPosition;
|
||||
CurrentState = State.Transition;
|
||||
CurrentState = State.Wait;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,4 +217,12 @@ public partial class Player : CharacterBody2D
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_door_opened()
|
||||
{
|
||||
if (CurrentState == State.Wait)
|
||||
{
|
||||
CurrentState = State.Transition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue