Consolodated jump logic
This commit is contained in:
@@ -10,25 +10,32 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
// Enemy Stats
|
// Enemy Stats
|
||||||
public int IQ;
|
public int IQ;
|
||||||
public float HP;
|
public float HP;
|
||||||
float MaxHP, RegenerationAmmount, RegenerationInterval, WalkSpeed, JumpHeight, DetectionRange;
|
float MaxHP, RegenerationAmmount, RegenerationInterval, WalkSpeed, JumpHeight, JumpInterval, DetectionRange;
|
||||||
|
|
||||||
// Enemy Conditions
|
// Enemy Conditions
|
||||||
bool GroundDetected, LedgeDetected, WallDetected;
|
bool GroundDetected, LedgeDetected, WallDetected, CanJump;
|
||||||
String FacingDirection;
|
String FacingDirection;
|
||||||
|
|
||||||
// Enemy Abilities
|
// Enemy Abilities
|
||||||
bool AbilityJump, AbilityMove, AbilityAttack, AbilityDash, AbilityCloak, AbilityTeleport, AbilityRegenerate = false;
|
bool AbilityJump, AbilityMove, AbilityAttack, AbilityDash, AbilityCloak, AbilityTeleport, AbilityRegenerate;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
// Read & Set Abilities
|
// Read & Set Abilities
|
||||||
if (HasMeta("AbilityJump")) AbilityJump = (bool)GetMeta("AbilityJump");
|
if (HasMeta("AbilityJump")) AbilityJump = (bool)GetMeta("AbilityJump");
|
||||||
|
else AbilityJump = true;
|
||||||
if (HasMeta("AbilityMove")) AbilityMove = (bool)GetMeta("AbilityMove");
|
if (HasMeta("AbilityMove")) AbilityMove = (bool)GetMeta("AbilityMove");
|
||||||
|
else AbilityMove = true;
|
||||||
if (HasMeta("AbilityAttack")) AbilityAttack = (bool)GetMeta("AbilityAttack");
|
if (HasMeta("AbilityAttack")) AbilityAttack = (bool)GetMeta("AbilityAttack");
|
||||||
|
else AbilityAttack = true;
|
||||||
if (HasMeta("AbilityDash")) AbilityDash = (bool)GetMeta("AbilityDash");
|
if (HasMeta("AbilityDash")) AbilityDash = (bool)GetMeta("AbilityDash");
|
||||||
|
else AbilityDash = false;
|
||||||
if (HasMeta("AbilityCloak")) AbilityCloak = (bool)GetMeta("AbilityCloak");
|
if (HasMeta("AbilityCloak")) AbilityCloak = (bool)GetMeta("AbilityCloak");
|
||||||
|
else AbilityCloak = false;
|
||||||
if (HasMeta("AbilityTeleport")) AbilityTeleport = (bool)GetMeta("AbilityTeleport");
|
if (HasMeta("AbilityTeleport")) AbilityTeleport = (bool)GetMeta("AbilityTeleport");
|
||||||
|
else AbilityTeleport = false;
|
||||||
if (HasMeta("AbilityRegenerate")) AbilityRegenerate = (bool)GetMeta("AbilityRegenerate");
|
if (HasMeta("AbilityRegenerate")) AbilityRegenerate = (bool)GetMeta("AbilityRegenerate");
|
||||||
|
else AbilityRegenerate = true;
|
||||||
if (HasMeta("RegenerationAmmount")) RegenerationAmmount = (float)GetMeta("RegenerationAmmount");
|
if (HasMeta("RegenerationAmmount")) RegenerationAmmount = (float)GetMeta("RegenerationAmmount");
|
||||||
else RegenerationAmmount = 1.0f;
|
else RegenerationAmmount = 1.0f;
|
||||||
if (HasMeta("RegenerationInterval")) RegenerationInterval = (float)GetMeta("RegenerationInterval");
|
if (HasMeta("RegenerationInterval")) RegenerationInterval = (float)GetMeta("RegenerationInterval");
|
||||||
@@ -37,6 +44,8 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
else WalkSpeed = 20.0f;
|
else WalkSpeed = 20.0f;
|
||||||
if (HasMeta("JumpHeight")) JumpHeight = (float)GetMeta("JumpHeight");
|
if (HasMeta("JumpHeight")) JumpHeight = (float)GetMeta("JumpHeight");
|
||||||
else JumpHeight = 250.0f;
|
else JumpHeight = 250.0f;
|
||||||
|
if (HasMeta("JumpInterval")) JumpInterval = (float)GetMeta("JumpInterval");
|
||||||
|
else JumpInterval = 1.0f;
|
||||||
if (HasMeta("DetectionRange")) DetectionRange = (float)GetMeta("DetectionRange");
|
if (HasMeta("DetectionRange")) DetectionRange = (float)GetMeta("DetectionRange");
|
||||||
else DetectionRange = 100.0f;
|
else DetectionRange = 100.0f;
|
||||||
JumpHeight *= -1;
|
JumpHeight *= -1;
|
||||||
@@ -58,6 +67,7 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
GroundDetected = false;
|
GroundDetected = false;
|
||||||
LedgeDetected = false;
|
LedgeDetected = false;
|
||||||
WallDetected = false;
|
WallDetected = false;
|
||||||
|
CanJump = AbilityJump;
|
||||||
|
|
||||||
// Apply IQ based permenant modifiers
|
// Apply IQ based permenant modifiers
|
||||||
IQ = (int)GetMeta("IQ"); // Read IQ
|
IQ = (int)GetMeta("IQ"); // Read IQ
|
||||||
@@ -83,12 +93,17 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
if (AbilityRegenerate){
|
if (AbilityRegenerate){
|
||||||
if (GlobalTimer % RegenerationInterval == 0) Regenerate(RegenerationAmmount);
|
if (GlobalTimer % RegenerationInterval == 0) Regenerate(RegenerationAmmount);
|
||||||
}
|
}
|
||||||
|
// Jump Cooldown
|
||||||
|
if (AbilityJump){
|
||||||
|
if (GlobalTimer % JumpInterval == 0) CanJump = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Movement
|
// Movement
|
||||||
// Add gravity.
|
// Add gravity.
|
||||||
if (GroundDetected == false) Velocity = new Vector2(Velocity[0],Velocity[1] + 10);
|
if (GroundDetected == false) Velocity = new Vector2(Velocity[0],Velocity[1] + 10);
|
||||||
|
|
||||||
#region 20IQ
|
#region 20IQ
|
||||||
|
if (AbilityMove){
|
||||||
if (IQ >= 0 && IQ <= 20){ // Goomba ahh diddy blud
|
if (IQ >= 0 && IQ <= 20){ // Goomba ahh diddy blud
|
||||||
if (GroundDetected && LedgeDetected == false) Flip(); // Flip when presented with a ledge
|
if (GroundDetected && LedgeDetected == false) Flip(); // Flip when presented with a ledge
|
||||||
if (WallDetected) Flip(); // Flip when comeing in contact with a wall
|
if (WallDetected) Flip(); // Flip when comeing in contact with a wall
|
||||||
@@ -98,16 +113,16 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
#region 30IQ
|
#region 30IQ
|
||||||
if (IQ > 20 && IQ <= 30){ // Goomba w/ hopps (no judy)
|
if (IQ > 20 && IQ <= 30){ // Goomba w/ hopps (no judy)
|
||||||
Velocity = new Vector2(WalkSpeed * VAH.Scale[0], Velocity[1]); // Walk
|
Velocity = new Vector2(WalkSpeed * VAH.Scale[0], Velocity[1]); // Walk
|
||||||
if (WallDetected && GroundDetected && Velocity[1] == 0) Velocity = new Vector2(Velocity[0], JumpHeight); // Jump
|
if (WallDetected && GroundDetected && Velocity[1] == 0) Jump();
|
||||||
if (WallDetected && GroundDetected && Velocity[1] > 0) Flip(); // Wall too high
|
if (WallDetected && GroundDetected && Velocity[1] > 0) Flip(); // Wall too high
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#region 40IQ
|
#region 40IQ
|
||||||
if (IQ > 30 && IQ <= 40){ // Adds jumping when reaching edge as feature (also adding directional x force)
|
if (IQ > 30 && IQ <= 40){ // Adds jumping when reaching edge as feature (also adding directional x force)
|
||||||
Velocity = (GroundDetected) ? new Vector2(WalkSpeed * VAH.Scale[0], Velocity[1]) : new Vector2(WalkSpeed * VAH.Scale[0] / 2, Velocity[1]); // Walk on air or ground
|
Velocity = (GroundDetected) ? new Vector2(WalkSpeed * VAH.Scale[0], Velocity[1]) : new Vector2(WalkSpeed * VAH.Scale[0] / 2, Velocity[1]); // Walk on air or ground
|
||||||
if (WallDetected && GroundDetected && Velocity[1] == 0) Velocity = new Vector2(Velocity[0], JumpHeight); // Jump
|
if (WallDetected && GroundDetected && Velocity[1] == 0) Jump();
|
||||||
//if (GroundDetected && LedgeDetected == false && Velocity[1] == 0) Velocity = new Vector2(Velocity[0] * 50, JumpHeight); // Jump at ledge
|
//if (GroundDetected && LedgeDetected == false && Velocity[1] == 0) Velocity = new Vector2(Velocity[0] * 50, JumpHeight); // Jump at ledge with x motion
|
||||||
if (GroundDetected && LedgeDetected == false && Velocity[1] == 0) Velocity = new Vector2(Velocity[0], JumpHeight); // Jump at ledge
|
if (GroundDetected && LedgeDetected == false && Velocity[1] == 0) Jump(); // Jump at ledge
|
||||||
if (WallDetected && GroundDetected && Velocity[1] > 0) Flip(); // Wall too high
|
if (WallDetected && GroundDetected && Velocity[1] > 0) Flip(); // Wall too high
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -118,15 +133,15 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
float DistanceFromPlayerX = GlobalPosition[0] - CurrentLevel[2].GetNode<Node2D>("Player").GlobalPosition[0];
|
float DistanceFromPlayerX = GlobalPosition[0] - CurrentLevel[2].GetNode<Node2D>("Player").GlobalPosition[0];
|
||||||
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(); // left of player
|
||||||
if (DistanceFromPlayerX < (-30.0f / (IQ / 4))) if (VAH.Scale[0] < 0)Flip(); // right 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[0] > CurrentLevel[2].GetNode<Node2D>("Player").GlobalPosition[1]) Velocity = new Vector2(Velocity[0], JumpHeight); // Jump when player is overhead
|
if (DistanceFromPlayerX < (-30.0f / (IQ / 4)) && GroundDetected && GlobalPosition[0] > CurrentLevel[2].GetNode<Node2D>("Player").GlobalPosition[1]) Jump(); // Jump when player is overhead
|
||||||
} else { // Patrol
|
} else { // Patrol
|
||||||
if (WallDetected && GroundDetected && Velocity[1] > 0)Flip(); // Wall too high
|
if (WallDetected && GroundDetected && Velocity[1] > 0)Flip(); // Wall too high
|
||||||
}
|
}
|
||||||
// Common Behaviors
|
// Common Behaviors
|
||||||
Velocity = (GroundDetected) ? new Vector2(WalkSpeed * VAH.Scale[0], Velocity[1]) : new Vector2(WalkSpeed * VAH.Scale[0] / 2, Velocity[1]); // Walk on air or ground
|
Velocity = (GroundDetected) ? new Vector2(WalkSpeed * VAH.Scale[0], Velocity[1]) : new Vector2(WalkSpeed * VAH.Scale[0] / 2, Velocity[1]); // Walk on air or ground
|
||||||
if (WallDetected && GroundDetected && Velocity[1] == 0) Velocity = new Vector2(Velocity[0], JumpHeight); // Jump
|
if (WallDetected && GroundDetected && Velocity[1] == 0) Jump(); // Jump
|
||||||
//if (GroundDetected && LedgeDetected == false && Velocity[1] == 0) Velocity = new Vector2(Velocity[0] * 50, JumpHeight); // Jump at ledge
|
//if (GroundDetected && LedgeDetected == false && Velocity[1] == 0) Velocity = new Vector2(Velocity[0] * 50, JumpHeight); // Jump at ledge with x motion
|
||||||
if (GroundDetected && LedgeDetected == false && Velocity[1] == 0) Velocity = new Vector2(Velocity[0], JumpHeight); // Jump at ledge
|
if (GroundDetected && LedgeDetected == false && Velocity[1] == 0) Jump(); // Jump at ledge
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#region 80IQ
|
#region 80IQ
|
||||||
@@ -144,6 +159,7 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
#region 140IQ
|
#region 140IQ
|
||||||
if (IQ > 120 && IQ <= 140){ // Advanced movement options
|
if (IQ > 120 && IQ <= 140){ // Advanced movement options
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
MoveAndSlide(); // Updates physics applied this frame
|
MoveAndSlide(); // Updates physics applied this frame
|
||||||
}
|
}
|
||||||
@@ -156,6 +172,11 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
else if (FacingDirection == "LEFT"){FacingDirection = "RIGHT";}
|
else if (FacingDirection == "LEFT"){FacingDirection = "RIGHT";}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Jump(){
|
||||||
|
if (GroundDetected && CanJump) {Velocity = new Vector2(Velocity[0], JumpHeight);
|
||||||
|
CanJump = false;}
|
||||||
|
}
|
||||||
|
|
||||||
bool DetectsPlayer(){
|
bool DetectsPlayer(){
|
||||||
var CurrentLevel = GetTree().Root.GetChildren();
|
var CurrentLevel = GetTree().Root.GetChildren();
|
||||||
return (GlobalPosition.DistanceTo(CurrentLevel[2].GetNode<Node2D>("Player").GlobalPosition) <= DetectionRange) ? true : false;
|
return (GlobalPosition.DistanceTo(CurrentLevel[2].GetNode<Node2D>("Player").GlobalPosition) <= DetectionRange) ? true : false;
|
||||||
|
|||||||
Reference in New Issue
Block a user