125 lines
4.1 KiB
C#
125 lines
4.1 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class IQEnemy : CharacterBody2D
|
|
{
|
|
// Misc
|
|
float GlobalTimer;
|
|
|
|
// Enemy Stats
|
|
public int IQ;
|
|
public float HP;
|
|
public float MaxHP;
|
|
float RegenerationAmmount;
|
|
float RegenerationInterval;
|
|
float WalkSpeed;
|
|
float JumpHeight;
|
|
|
|
// Enemy Conditions
|
|
float CurrentYVelocity;
|
|
float PreviousYVelocity;
|
|
bool GroundDetected;
|
|
bool LedgeDetected;
|
|
|
|
// Enemy Abilities
|
|
bool AbilityJump = false;
|
|
bool AbilityMove = false;
|
|
bool AbilityAttack = false;
|
|
bool AbilityDash = false;
|
|
bool AbilityCloak = false;
|
|
bool AbilityTeleport = false;
|
|
bool AbilityRegenerate = false;
|
|
|
|
public override void _Ready()
|
|
{
|
|
// Read & Set Abilities
|
|
if (HasMeta("AbilityJump")) AbilityJump = (bool)GetMeta("AbilityJump");
|
|
if (HasMeta("AbilityMove")) AbilityMove = (bool)GetMeta("AbilityMove");
|
|
if (HasMeta("AbilityAttack")) AbilityAttack = (bool)GetMeta("AbilityAttack");
|
|
if (HasMeta("AbilityDash")) AbilityDash = (bool)GetMeta("AbilityDash");
|
|
if (HasMeta("AbilityCloak")) AbilityCloak = (bool)GetMeta("AbilityCloak");
|
|
if (HasMeta("AbilityTeleport")) AbilityTeleport = (bool)GetMeta("AbilityTeleport");
|
|
if (HasMeta("AbilityRegenerate")) AbilityRegenerate = (bool)GetMeta("AbilityRegenerate");
|
|
if (HasMeta("RegenerationAmmount")) RegenerationAmmount = (float)GetMeta("RegenerationAmmount");
|
|
else RegenerationAmmount = 1.0f;
|
|
if (HasMeta("RegenerationInterval")) RegenerationInterval = (float)GetMeta("RegenerationInterval");
|
|
else RegenerationInterval = 1.0f;
|
|
if (HasMeta("WalkSpeed")) WalkSpeed = (float)GetMeta("WalkSpeed");
|
|
else WalkSpeed = 10.0f;
|
|
if (HasMeta("JumpHeight")) JumpHeight = (float)GetMeta("JumpHeight");
|
|
else JumpHeight = 10.0f;
|
|
|
|
// Read and set stats
|
|
if (HasMeta("MaxHP")) MaxHP = (float)GetMeta("MaxHP");
|
|
|
|
// Set up ground detection
|
|
GetNode<Area2D>("GroundDetector").AreaEntered += OnGroundEntered;
|
|
GetNode<Area2D>("GroundDetector").AreaExited += OnGroundExited;
|
|
|
|
GetNode<Area2D>("LedgeDetector").AreaEntered += OnLedgeEntered;
|
|
GetNode<Area2D>("LedgeDetector").AreaExited += OnLedgeExited;
|
|
|
|
GroundDetected = true;
|
|
LedgeDetected = true;
|
|
|
|
// Apply IQ based permenant modifiers
|
|
IQ = (int)GetMeta("IQ"); // Read IQ
|
|
|
|
if (IQ >= 100) MaxHP += 20;
|
|
HP = MaxHP;
|
|
if (IQ >= 100 && HasMeta("RegenerationInterval")) RegenerationInterval *= 0.9f;
|
|
if (IQ >= 100 && HasMeta("RegenerationAmmount")) RegenerationAmmount *= 1.05f; // 5% increase
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
// Update Timer
|
|
GlobalTimer = GetTree().Root.GetNode<CommonData>("CommonData").GlobalTimer;
|
|
|
|
// Show current hp for testing purposes
|
|
if (HasMeta("CurrentHP")) SetMeta("CurrentHP", HP);
|
|
|
|
// Regenerate Health
|
|
if (AbilityRegenerate){
|
|
if (GlobalTimer % RegenerationInterval == 0){Regenerate(RegenerationAmmount);}
|
|
}
|
|
|
|
// Movement
|
|
// Add gravity.
|
|
if (GroundDetected == false){Velocity = new Vector2(Velocity[0],-1);}
|
|
if (IQ <= 20){ // Goomba ahh diddy blud
|
|
if (GroundDetected && LedgeDetected == false) {Flip("ANY");}
|
|
if (Scale[0] > 0){Velocity = new Vector2(WalkSpeed, Velocity[1]);} // Facing right
|
|
if (Scale[0] < 0){Velocity = new Vector2(-1 * WalkSpeed, Velocity[1]);} // Facing left
|
|
}
|
|
MoveAndSlide();
|
|
}
|
|
|
|
void Flip(string facing){
|
|
if (facing == "ANY") Scale = new Vector2(Scale[0] * -1,1);
|
|
if (facing == "RIGHT") Scale = new Vector2(1,1);
|
|
if (facing =="LEFT") Scale = new Vector2(-1,1);
|
|
}
|
|
|
|
public void Regenerate(float ammount){
|
|
if (HP < MaxHP) HP += ammount;
|
|
if (HP > MaxHP) HP = MaxHP; // Catch errors
|
|
}
|
|
|
|
public void Damage(float ammount){
|
|
HP -= ammount;
|
|
if (HP <= 0) Kill();
|
|
}
|
|
|
|
public void Kill(){
|
|
QueueFree(); // Change to proper death w/ corpse
|
|
}
|
|
|
|
// Ground Detection
|
|
public void OnGroundEntered(Area2D area){if (area.CollisionLayer == 0) GroundDetected = true;}
|
|
public void OnGroundExited(Area2D area){if (area.CollisionLayer == 0) GroundDetected = false;}
|
|
// Ledge Detection
|
|
public void OnLedgeEntered(Area2D area){if (area.CollisionLayer == 0) LedgeDetected = true;}
|
|
public void OnLedgeExited(Area2D area){if (area.CollisionLayer == 0) LedgeDetected = false;}
|
|
}
|