Character controls, camera with dead zone, flashlight scale
This commit is contained in:
parent
f307a7ef00
commit
bbc3f0821e
7 changed files with 80 additions and 4 deletions
|
@ -6,4 +6,7 @@ public static class Constants
|
|||
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;
|
||||
}
|
|
@ -19,12 +19,16 @@ public partial class Flashlight : Node
|
|||
var playerScreenPosition = playerScreenCenterPosition + Constants.HalfScreenSize;
|
||||
PlayerCircle.Position = playerScreenPosition;
|
||||
|
||||
var d = Camera.FlashlightPosition.DistanceTo(Player.Position);
|
||||
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;
|
||||
Circle.Scale = new Vector2(flashlightScale, flashlightScale);
|
||||
|
||||
var d = Camera.FlashlightPosition.DistanceTo(Player.Position);
|
||||
if (d <= FlashlightRadius)
|
||||
Polygon.Visible = false;
|
||||
else
|
||||
|
|
|
@ -2,11 +2,41 @@ using Godot;
|
|||
|
||||
public partial class GameCamera : Camera2D
|
||||
{
|
||||
[Export] public Player Player;
|
||||
[Export] public Vector2 CameraBounds;
|
||||
|
||||
/// <summary>
|
||||
/// World position of the flashlight
|
||||
/// </summary>
|
||||
public Vector2 FlashlightPosition;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var relativePlayerPosition = Player.Position - Position;
|
||||
var halfCameraBounds = CameraBounds / 2;
|
||||
float x = 0, y = 0;
|
||||
if (relativePlayerPosition.X > halfCameraBounds.X)
|
||||
{
|
||||
x = relativePlayerPosition.X - halfCameraBounds.X;
|
||||
}
|
||||
else if (relativePlayerPosition.X < -halfCameraBounds.X)
|
||||
{
|
||||
x = relativePlayerPosition.X + halfCameraBounds.X;
|
||||
}
|
||||
if (relativePlayerPosition.Y > halfCameraBounds.Y)
|
||||
{
|
||||
y = relativePlayerPosition.Y - halfCameraBounds.Y;
|
||||
}
|
||||
else if (relativePlayerPosition.Y < -halfCameraBounds.Y)
|
||||
{
|
||||
y = relativePlayerPosition.Y + halfCameraBounds.Y;
|
||||
}
|
||||
|
||||
var difference = new Vector2(x, y);
|
||||
Position += difference;
|
||||
FlashlightPosition += difference;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
base._Input(@event);
|
||||
|
|
|
@ -19,7 +19,7 @@ public partial class Player : CharacterBody2D
|
|||
|
||||
// Get the input direction and handle the movement/deceleration.
|
||||
// As good practice, you should replace UI actions with custom gameplay actions.
|
||||
Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
|
||||
Vector2 direction = Input.GetVector("character_left", "character_right", "character_up", "character_down");
|
||||
if (direction != Vector2.Zero)
|
||||
{
|
||||
velocity.X = direction.X * Speed;
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// https://github.com/godotengine/godot/issues/75868#issuecomment-1524362054 THANK YOU!!!
|
||||
/// </summary>
|
||||
[Tool]
|
||||
public partial class PointLight2DWorkaround : PointLight2D
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue