Room fixes, started mapping floors

This commit is contained in:
Pal
2026-01-17 00:00:37 -08:00
parent 3fe45cb3e7
commit 6a62d3d943
72 changed files with 1609 additions and 189 deletions

View File

@@ -30,14 +30,14 @@ public partial class EnemyModelView2D : EnemyModelView, IEnemyModelView
public new void OnReady()
{
Hitbox.AreaEntered += Hitbox_AreaEntered;
base.OnReady();
Hitbox.AreaEntered += Hitbox_AreaEntered;
base.OnReady();
}
public override Vector2 GetSize()
{
return Sprite3D.GetItemRect().Size;
return Sprite3D.GetItemRect().Size;
}
private void Hitbox_AreaEntered(Area3D area) => OnPlayerHit(new AttackEventArgs(AttackData));
@@ -46,102 +46,102 @@ public partial class EnemyModelView2D : EnemyModelView, IEnemyModelView
public override void PlayHitAnimation()
{
LoadShader("res://src/vfx/shaders/DamageHit.gdshader");
var tweener = GetTree().CreateTween();
tweener.TweenMethod(Callable.From((float x) => SetShaderValue(x)), 0.0f, 1.0f, 1.0f);
LoadShader("res://src/vfx/shaders/DamageHit.gdshader");
var tweener = GetTree().CreateTween();
tweener.TweenMethod(Callable.From((float x) => SetShaderValue(x)), 0.0f, 1.0f, 1.0f);
}
public override void PlayDeathAnimation()
{
LoadShader("res://src/vfx/shaders/PixelMelt.gdshader");
var tweener = GetTree().CreateTween();
tweener.TweenMethod(Callable.From((float x) => SetShaderValue(x)), 0.0f, 0.1f, 0.8f);
LoadShader("res://src/vfx/shaders/PixelMelt.gdshader");
var tweener = GetTree().CreateTween();
tweener.TweenMethod(Callable.From((float x) => SetShaderValue(x)), 0.0f, 0.1f, 0.8f);
}
private EnemyDirection GetEnemyDirection(
Basis enemyBasis,
Vector3 cameraDirection,
float rotateUpperThreshold,
float rotateLowerThreshold)
Basis enemyBasis,
Vector3 cameraDirection,
float rotateUpperThreshold,
float rotateLowerThreshold)
{
var enemyForwardDirection = enemyBasis.Z;
var enemyLeftDirection = enemyBasis.X;
var enemyForwardDirection = enemyBasis.Z;
var enemyLeftDirection = enemyBasis.X;
var leftDotProduct = enemyLeftDirection.Dot(cameraDirection);
var forwardDotProduct = enemyForwardDirection.Dot(cameraDirection);
var leftDotProduct = enemyLeftDirection.Dot(cameraDirection);
var forwardDotProduct = enemyForwardDirection.Dot(cameraDirection);
// Check if forward facing. If the dot product is -1, the enemy is facing the camera.
if (forwardDotProduct < _lowerThreshold)
{
SetForward();
return EnemyDirection.Forward;
}
// Check if forward facing. If the dot product is -1, the enemy is facing the camera.
if (forwardDotProduct < _lowerThreshold)
{
SetForward();
return EnemyDirection.Forward;
}
// Check if backward facing. If the dot product is 1, the enemy is facing the same direction as the camera.
else if (forwardDotProduct > rotateUpperThreshold)
{
SetBack();
return EnemyDirection.Backward;
}
else
{
// If the dot product of the perpendicular direction is positive (up to 1), the enemy is facing to the left (since it's mirrored).
if (leftDotProduct < _lowerThreshold)
{
SetRight();
return EnemyDirection.Left;
}
// Check if backward facing. If the dot product is 1, the enemy is facing the same direction as the camera.
else if (forwardDotProduct > rotateUpperThreshold)
{
SetBack();
return EnemyDirection.Backward;
}
else
{
// If the dot product of the perpendicular direction is positive (up to 1), the enemy is facing to the left (since it's mirrored).
if (leftDotProduct < _lowerThreshold)
{
SetRight();
return EnemyDirection.Left;
}
// Check if side facing. If the dot product is close to zero in the positive or negative direction, its close to the threshold for turning.
if (leftDotProduct > rotateUpperThreshold)
{
SetLeft();
return EnemyDirection.Right;
}
}
// Check if side facing. If the dot product is close to zero in the positive or negative direction, its close to the threshold for turning.
if (leftDotProduct > rotateUpperThreshold)
{
SetLeft();
return EnemyDirection.Right;
}
}
return _enemyDirection;
return _enemyDirection;
}
private void LoadShader(string shaderPath)
{
var shader = GD.Load<Shader>(shaderPath);
var sprites = FindChildren("*", "AnimatedSprite2D", true).Cast<AnimatedSprite2D>();
foreach (var sprite in sprites)
{
sprite.Material = new ShaderMaterial();
var shaderMaterial = (ShaderMaterial)sprite.Material;
shaderMaterial.Shader = shader;
}
var shader = GD.Load<Shader>(shaderPath);
var sprites = FindChildren("*", "AnimatedSprite2D", true).Cast<AnimatedSprite2D>();
foreach (var sprite in sprites)
{
sprite.Material = new ShaderMaterial();
var shaderMaterial = (ShaderMaterial)sprite.Material;
shaderMaterial.Shader = shader;
}
}
private void SetShaderValue(float shaderValue)
{
var sprites = FindChildren("*", "AnimatedSprite2D", true).Cast<AnimatedSprite2D>();
foreach (var sprite in sprites)
{
var shaderMaterial = (ShaderMaterial)sprite.Material;
shaderMaterial.SetShaderParameter("progress", shaderValue);
}
var sprites = FindChildren("*", "AnimatedSprite2D", true).Cast<AnimatedSprite2D>();
foreach (var sprite in sprites)
{
var shaderMaterial = (ShaderMaterial)sprite.Material;
shaderMaterial.SetShaderParameter("progress", shaderValue);
}
}
private void SetForward()
{
_enemyDirection = EnemyDirection.Forward;
_enemyDirection = EnemyDirection.Forward;
}
private void SetLeft()
{
_enemyDirection = EnemyDirection.Left;
_enemyDirection = EnemyDirection.Left;
}
private void SetRight()
{
_enemyDirection = EnemyDirection.Right;
_enemyDirection = EnemyDirection.Right;
}
private void SetBack()
{
_enemyDirection = EnemyDirection.Backward;
_enemyDirection = EnemyDirection.Backward;
}
}