Added Lunge Mechanic
This commit is contained in:
@@ -10,14 +10,14 @@ public partial class IQEnemy : CharacterBody2D
|
||||
// Enemy Stats
|
||||
public int IQ;
|
||||
public float HP;
|
||||
float MaxHP, RegenerationAmmount, RegenerationInterval, WalkSpeed, JumpHeight, JumpInterval, DetectionRange;
|
||||
float MaxHP, RegenerationAmmount, RegenerationInterval, WalkSpeed, JumpHeight, JumpInterval, LungeInterval, DetectionRange;
|
||||
|
||||
// Enemy Conditions
|
||||
bool GroundDetected, LedgeDetected, WallDetected, CanJump;
|
||||
bool GroundDetected, LedgeDetected, WallDetected, CanJump, CanLunge;
|
||||
String FacingDirection;
|
||||
|
||||
// Enemy Abilities
|
||||
bool AbilityJump, AbilityMove, AbilityAttack, AbilityDash, AbilityCloak, AbilityTeleport, AbilityRegenerate;
|
||||
bool AbilityJump, AbilityMove, AbilityAttack, AbilityDash, AbilityLunge, AbilityCloak, AbilityTeleport, AbilityRegenerate;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -30,6 +30,8 @@ public partial class IQEnemy : CharacterBody2D
|
||||
else AbilityAttack = true;
|
||||
if (HasMeta("AbilityDash")) AbilityDash = (bool)GetMeta("AbilityDash");
|
||||
else AbilityDash = false;
|
||||
if (HasMeta("AbilityLunge")) AbilityLunge = (bool)GetMeta("AbilityLunge");
|
||||
else AbilityLunge = false;
|
||||
if (HasMeta("AbilityCloak")) AbilityCloak = (bool)GetMeta("AbilityCloak");
|
||||
else AbilityCloak = false;
|
||||
if (HasMeta("AbilityTeleport")) AbilityTeleport = (bool)GetMeta("AbilityTeleport");
|
||||
@@ -46,6 +48,8 @@ public partial class IQEnemy : CharacterBody2D
|
||||
else JumpHeight = 250.0f;
|
||||
if (HasMeta("JumpInterval")) JumpInterval = (float)GetMeta("JumpInterval");
|
||||
else JumpInterval = 1.0f;
|
||||
if (HasMeta("LungeInterval")) LungeInterval = (float)GetMeta("LungeInterval");
|
||||
else LungeInterval = 1.0f;
|
||||
if (HasMeta("DetectionRange")) DetectionRange = (float)GetMeta("DetectionRange");
|
||||
else DetectionRange = 100.0f;
|
||||
JumpHeight *= -1;
|
||||
@@ -68,6 +72,7 @@ public partial class IQEnemy : CharacterBody2D
|
||||
LedgeDetected = false;
|
||||
WallDetected = false;
|
||||
CanJump = AbilityJump;
|
||||
CanLunge = AbilityLunge;
|
||||
|
||||
// Apply IQ based permenant modifiers
|
||||
IQ = (int)GetMeta("IQ"); // Read IQ
|
||||
@@ -89,6 +94,7 @@ public partial class IQEnemy : CharacterBody2D
|
||||
// Show current hp for testing purposes
|
||||
if (HasMeta("CurrentHP")) SetMeta("CurrentHP", HP);
|
||||
|
||||
// Cooldowns
|
||||
// Regenerate Health
|
||||
if (AbilityRegenerate){
|
||||
if (GlobalTimer % RegenerationInterval == 0) Regenerate(RegenerationAmmount);
|
||||
@@ -97,6 +103,10 @@ public partial class IQEnemy : CharacterBody2D
|
||||
if (AbilityJump){
|
||||
if (GlobalTimer % JumpInterval == 0) CanJump = true;
|
||||
}
|
||||
// Lunge Cooldown
|
||||
if (AbilityLunge){
|
||||
if (GlobalTimer % LungeInterval == 0) CanLunge = true;
|
||||
}
|
||||
|
||||
// Movement
|
||||
// Add gravity.
|
||||
@@ -133,6 +143,7 @@ public partial class IQEnemy : CharacterBody2D
|
||||
if (DistanceFromPlayerX > (30.0f / (IQ / 4))) if (VAH.Scale[0] > 0)Flip(); // left of player
|
||||
if (DistanceFromPlayerX < (-30.0f / (IQ / 4))) if (VAH.Scale[0] < 0)Flip(); // right of player
|
||||
if (DistanceFromPlayerX < (-30.0f / (IQ / 4)) && GroundDetected && GlobalPosition[1] > CurrentLevel[2].GetNode<Node2D>("Player").GlobalPosition[1]) Jump(0.0f); // Jump when player is overhead
|
||||
if (DistanceFromPlayerX > DetectionRange / 2.0f) Lunge(100.0f * VAH.Scale[0]);
|
||||
} else{ // Patrol
|
||||
if (WallDetected && GroundDetected && Velocity[1] > 0)Flip(); // Wall too high (flips when it lands on the ground in front of a wall)
|
||||
}
|
||||
@@ -174,6 +185,11 @@ public partial class IQEnemy : CharacterBody2D
|
||||
if (GroundDetected && CanJump) {Velocity = new Vector2(Velocity[0] + xMagnitude, JumpHeight);
|
||||
CanJump = false;}
|
||||
}
|
||||
|
||||
void Lunge(float xMagnitude){
|
||||
if (GroundDetected && CanLunge) {Velocity = new Vector2(Velocity[0] + xMagnitude, JumpHeight / 2.0f);
|
||||
CanLunge = false;}
|
||||
}
|
||||
|
||||
bool DetectsPlayer(){
|
||||
var CurrentLevel = GetTree().Root.GetChildren();
|
||||
|
||||
Reference in New Issue
Block a user