41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using Godot;
|
|
using GodotHostTest.Helpers;
|
|
using GodotHostTest.Interfaces;
|
|
using OwofGames.AetherBind;
|
|
using R3;
|
|
|
|
namespace GodotHostTest.Game.Score;
|
|
|
|
public partial class Score : Control
|
|
{
|
|
[Export] private AnimationPlayer _animationPlayer = null!;
|
|
|
|
[Inject] private ICurrentLevel _currentLevel = null!;
|
|
[Export] private Label _label = null!;
|
|
[Inject] private IScore _score = null!;
|
|
|
|
public override void _Ready()
|
|
{
|
|
// update the score label whenever the score changes
|
|
_score.Score
|
|
.Subscribe(UpdateScore)
|
|
.AddTo(this);
|
|
|
|
// run an animation whenever the score decreases
|
|
_score.Score
|
|
.Chunk(2, 1)
|
|
.Where(values => values.Length == 2 && values[1] < values[0])
|
|
.Subscribe(OnScoreDecreasing)
|
|
.AddTo(this);
|
|
}
|
|
|
|
private void OnScoreDecreasing<T>(T _)
|
|
{
|
|
_animationPlayer.Play("wiggle");
|
|
}
|
|
|
|
private void UpdateScore(int newScore)
|
|
{
|
|
_label.Text = $"Level {_currentLevel.LevelNumber} - Score: {newScore}";
|
|
}
|
|
} |