Got most basic enemy movement working

This commit is contained in:
=
2026-01-27 08:26:35 -07:00
parent 318397ee29
commit 0506824cf1
3 changed files with 50 additions and 48 deletions

View File

@@ -5,6 +5,7 @@ public partial class IQEnemy : CharacterBody2D
{
// Misc
float GlobalTimer;
Node2D VAH; // Shorthand refrence
// Enemy Stats
public int IQ;
@@ -54,20 +55,21 @@ public partial class IQEnemy : CharacterBody2D
// Read and set stats
if (HasMeta("MaxHP")) MaxHP = (float)GetMeta("MaxHP");
FacingDirection = "RIGHT";
VAH = GetNode<Node2D>("VisualsAndHitboxes");
// Set up collision detection
GetNode<Area2D>("GroundDetector").BodyEntered += OnGroundEntered; // Ground
GetNode<Area2D>("GroundDetector").BodyExited += OnGroundExited;
GetNode<Area2D>("LedgeDetector").BodyEntered += OnLedgeEntered; // Ledge
GetNode<Area2D>("LedgeDetector").BodyExited += OnLedgeExited;
GetNode<Area2D>("WallDetector").BodyEntered += OnWallEntered; // Wall
GetNode<Area2D>("WallDetector").BodyExited += OnWallExited;
VAH.GetNode<Area2D>("GroundDetector").BodyEntered += OnGroundEntered; // Ground
VAH.GetNode<Area2D>("GroundDetector").BodyExited += OnGroundExited;
VAH.GetNode<Area2D>("LedgeDetector").BodyEntered += OnLedgeEntered; // Ledge
VAH.GetNode<Area2D>("LedgeDetector").BodyExited += OnLedgeExited;
VAH.GetNode<Area2D>("WallDetector").BodyEntered += OnWallEntered; // Wall
VAH.GetNode<Area2D>("WallDetector").BodyExited += OnWallExited;
GroundDetected = false;
LedgeDetected = false;
WallDetected = false;
FacingDirection = "RIGHT";
// Apply IQ based permenant modifiers
IQ = (int)GetMeta("IQ"); // Read IQ
@@ -75,6 +77,9 @@ public partial class IQEnemy : CharacterBody2D
HP = MaxHP;
if (IQ >= 100 && HasMeta("RegenerationInterval")) RegenerationInterval *= 0.9f;
if (IQ >= 100 && HasMeta("RegenerationAmmount")) RegenerationAmmount *= 1.05f; // 5% increase
WalkSpeed += IQ / 20;
JumpHeight += IQ / 30;
}
public override void _Process(double delta)
@@ -97,22 +102,17 @@ public partial class IQEnemy : CharacterBody2D
if (IQ <= 20){ // Goomba ahh diddy blud
if (GroundDetected && LedgeDetected == false){Flip();}
if (WallDetected){Flip();}
// Walk
if (GroundDetected){Velocity = new Vector2(WalkSpeed * Scale[0], Velocity[1]);}
if (GroundDetected){Velocity = new Vector2(WalkSpeed * VAH.Scale[0], Velocity[1]);} // Walk
}
MoveAndSlide(); // Updates physics applied this frame
}
void Flip(){
if (FacingDirection == "RIGHT"){
Scale = new Vector2(-1,1);
FacingDirection = "LEFT";
}
else if (FacingDirection == "LEFT")
{
Scale = new Vector2(1,1);
FacingDirection = "RIGHT";
}
VAH.Scale = new Vector2(-1 * VAH.Scale[0],1);
WallDetected = false;
LedgeDetected = true;
if (FacingDirection == "RIGHT"){FacingDirection = "LEFT";}
else if (FacingDirection == "LEFT"){FacingDirection = "RIGHT";}
}
public void Regenerate(float ammount){