Crank sound

This commit is contained in:
Иван Кузьменко 2023-08-16 21:19:00 +03:00
parent 51eb5aa15a
commit 384e8560f6
5 changed files with 53 additions and 19 deletions

View file

@ -14,13 +14,15 @@ public partial class Flashlight : Node
[Export] public CollisionShape2D CollisionPlayerCircle;
[Export] public CollisionPolygon2D CollisionPolygon;
[Export] public CanvasGroup FlashlightGroup;
[Export] public Curve BrightnessCurve;
[Export] public AudioStreamPlayer CrankSoundPlayer;
private float FlashlightRadius = Constants.MaxFlashlightRadius;
private float FlashlightEnergy = Constants.MaxFlashlightEnergy;
private float FlashlightChargeTimeout = 1;
public override void _Ready()
{
base._Ready();
@ -44,7 +46,7 @@ public partial class Flashlight : Node
FlashlightRadius = Mathf.Lerp(Constants.MinFlashlightRadius, Constants.MaxFlashlightRadius,
Mathf.Clamp(d - Constants.MinFlashlightDistance, 0,
Constants.MaxFlashlightDistance - Constants.MinFlashlightDistance) / Constants.MaxFlashlightDistance);
var flashlightScreenPosition = flashlightScreenCenterPosition + Constants.HalfScreenSize;
var flashlightScale = FlashlightRadius / Constants.MaxFlashlightRadius;
Circle.Position = flashlightScreenPosition;
@ -67,20 +69,26 @@ public partial class Flashlight : Node
var xy3 = a * new Vector2(Mathf.Cos(dslkhjdsflkhjsdfhlkjdfsjlk), Mathf.Sin(dslkhjdsflkhjsdfhlkjdfsjlk));
var dslkhjdsflkhjsdfhlkjdfsjlk2 = angle - arcsinRd;
var xy4 = a * new Vector2(Mathf.Cos(dslkhjdsflkhjsdfhlkjdfsjlk2), Mathf.Sin(dslkhjdsflkhjsdfhlkjdfsjlk2));
var polygon = new[]
{ playerScreenPosition, playerScreenPosition + xy3, playerScreenPosition + xy4 };
Polygon.Polygon = polygon;
CollisionPolygon.Polygon = polygon;
}
FlashlightChargeTimeout = Mathf.Clamp(FlashlightChargeTimeout-(float)delta,0,1);
if (Input.IsActionJustPressed("flashlight_charge") && FlashlightChargeTimeout <= 0){
FlashlightChargeTimeout = Mathf.Clamp(FlashlightChargeTimeout - (float)delta, 0, 1);
if (Input.IsActionJustPressed("flashlight_charge") && FlashlightChargeTimeout <= 0)
{
FlashlightChargeTimeout = 1;
FlashlightEnergy+=Constants.FlashlightEneregyPerCharge;
FlashlightEnergy += Constants.FlashlightEneregyPerCharge;
var rng = new RandomNumberGenerator();
CrankSoundPlayer.PitchScale = rng.RandfRange(1f, 1.15f);
CrankSoundPlayer.Play();
}
FlashlightEnergy = Mathf.Clamp(FlashlightEnergy-(float)delta, 0, Constants.MaxFlashlightEnergy);
FlashlightGroup.Modulate = new Color(BrightnessCurve.Sample(FlashlightEnergy/Constants.MaxFlashlightEnergy), 1, 1, 1);
CollisionCircle.Enabled = CollisionPlayerCircle.Enabled = CollisionPolygon.Enabled = FlashlightEnergy >= 10;
FlashlightEnergy = Mathf.Clamp(FlashlightEnergy - (float)delta, 0, Constants.MaxFlashlightEnergy);
FlashlightGroup.Modulate =
new Color(BrightnessCurve.Sample(FlashlightEnergy / Constants.MaxFlashlightEnergy), 1, 1, 1);
CollisionCircle.Disabled = CollisionPlayerCircle.Disabled = CollisionPolygon.Disabled = FlashlightEnergy < 10;
}
}