Beeg checkin
This commit is contained in:
18
Enemies/Scripts/BasicEnemy.cs
Normal file
18
Enemies/Scripts/BasicEnemy.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Godot;
|
||||
|
||||
public partial class BasicEnemy : Node3D
|
||||
{
|
||||
protected GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
|
||||
}
|
||||
|
||||
public void OnEnemyHit(Node3D node)
|
||||
{
|
||||
var currentLevel = (Level)GetTree().GetFirstNodeInGroup("Level");
|
||||
currentLevel.OnEnemyDefeated(this);
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
14
Enemies/Scripts/GodCircuit.cs
Normal file
14
Enemies/Scripts/GodCircuit.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Godot;
|
||||
|
||||
public partial class GodCircuit : Node3D
|
||||
{
|
||||
private void OnHit(Node3D node)
|
||||
{
|
||||
GD.Print("Hit");
|
||||
var hpComponent = GetNode<HealthPoints>("HP Component");
|
||||
hpComponent.TakeDamage(800000);
|
||||
hpComponent.UpdateHealthbar();
|
||||
if (hpComponent.CurrentHP <= 0)
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
20
Enemies/Scripts/MeleeEnemy.cs
Normal file
20
Enemies/Scripts/MeleeEnemy.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
public partial class MeleeEnemy : BasicEnemy
|
||||
{
|
||||
[Export]
|
||||
private float _speed = 0.4f;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var players = GetTree().GetNodesInGroup("Player");
|
||||
if (players.Any())
|
||||
{
|
||||
var convertedPlayers = players.Select(x => (Node3D)x);
|
||||
var target = convertedPlayers.OrderBy(x => Position.DistanceTo(x.Position)).FirstOrDefault();
|
||||
Position = Position.MoveToward(target.Position, _speed * (float)delta);
|
||||
LookAt(-target.Position, Vector3.Up);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Enemies/Scripts/RangedEnemy.cs
Normal file
17
Enemies/Scripts/RangedEnemy.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
public partial class RangedEnemy : BasicEnemy
|
||||
{
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var players = GetTree().GetNodesInGroup("Player");
|
||||
if (players.Any())
|
||||
{
|
||||
var convertedPlayers = players.Select(x => (Node3D)x);
|
||||
var target = convertedPlayers.OrderBy(x => Position.DistanceTo(x.Position)).FirstOrDefault();
|
||||
var area = GetChildren().OfType<Area3D>().Single();
|
||||
area.LookAt(target.Position, Vector3.Up);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user