Имплементация энергии фонаря, уменьшение энергии со временем, возможности восполнить энергию, а также шейдера для симуляции прозрачности (ослабления света фонаря) с помощью дизеринга
This commit is contained in:
parent
434493578c
commit
fdb4fc40cc
6 changed files with 97 additions and 28 deletions
|
@ -1,12 +1,14 @@
|
|||
using Godot;
|
||||
using Godot;
|
||||
|
||||
public static class Constants
|
||||
{
|
||||
public static readonly Vector2 ScreenSize = new(256, 192);
|
||||
public static readonly Vector2 HalfScreenSize = ScreenSize / 2;
|
||||
public static readonly Vector2 ScreenSize = new(256, 192);
|
||||
public static readonly Vector2 HalfScreenSize = ScreenSize / 2;
|
||||
|
||||
public const float MaxFlashlightRadius = 32;
|
||||
public const float MinFlashlightRadius = 8;
|
||||
public const float MaxFlashlightDistance = 96;
|
||||
public const float MinFlashlightDistance = 16;
|
||||
}
|
||||
public const float MaxFlashlightRadius = 32;
|
||||
public const float MinFlashlightRadius = 8;
|
||||
public const float MaxFlashlightDistance = 96;
|
||||
public const float MinFlashlightDistance = 16;
|
||||
public const float MaxFlashlightEnergy = 100;
|
||||
public const float FlashlightEneregyPerCharge = 5;
|
||||
}
|
||||
|
|
|
@ -13,9 +13,14 @@ public partial class Flashlight : Node
|
|||
[Export] public CollisionShape2D CollisionCircle;
|
||||
[Export] public CollisionShape2D CollisionPlayerCircle;
|
||||
[Export] public CollisionPolygon2D CollisionPolygon;
|
||||
|
||||
[Export] public CanvasGroup FlashlightGroup;
|
||||
|
||||
[Export] public Curve BrightnessCurve;
|
||||
|
||||
private float FlashlightRadius = Constants.MaxFlashlightRadius;
|
||||
|
||||
private float FlashlightEnergy = Constants.MaxFlashlightEnergy;
|
||||
private float FlashlightChargeTimeout = 1;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
@ -26,7 +31,7 @@ public partial class Flashlight : Node
|
|||
throw new Exception("Invalid collision shape on the player circle");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var playerScreenCenterPosition = Player.Position - Camera.Position;
|
||||
var flashlightScreenCenterPosition = Camera.FlashlightPosition - Camera.Position;
|
||||
|
@ -68,5 +73,14 @@ public partial class Flashlight : Node
|
|||
Polygon.Polygon = polygon;
|
||||
CollisionPolygon.Polygon = polygon;
|
||||
}
|
||||
|
||||
FlashlightChargeTimeout = Mathf.Clamp(FlashlightChargeTimeout-(float)delta,0,1);
|
||||
if (Input.IsActionJustPressed("flashlight_charge") && FlashlightChargeTimeout <= 0){
|
||||
FlashlightChargeTimeout = 1;
|
||||
FlashlightEnergy+=Constants.FlashlightEneregyPerCharge;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@ using System;
|
|||
[Tool]
|
||||
public partial class PointLight2DWorkaround : PointLight2D
|
||||
{
|
||||
[Export] public Viewport LightViewport;
|
||||
[Export] public Viewport LightViewport;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
base._Process(delta);
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
base._Process(delta);
|
||||
|
||||
Texture = null;
|
||||
Texture = LightViewport.GetTexture();
|
||||
}
|
||||
Texture = null;
|
||||
Texture = LightViewport.GetTexture();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue