summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex <[email protected]>2026-07-25 16:46:32 +0200
committeralex <[email protected]>2026-07-25 16:46:32 +0200
commit023c4f003d58c27cd2677307abe2c65bb09c2681 (patch)
treed4e67206dadaf5a6433669297bef406b45056afc
parent91fd5d80808fd177f97c4cc7e78b704efb5d6ce3 (diff)
downloadgodot-testing-023c4f003d58c27cd2677307abe2c65bb09c2681.tar.xz
godot-testing-023c4f003d58c27cd2677307abe2c65bb09c2681.zip
added enemy scene and piercing booleans for bullets, will be later refactored to work based on player stats
-rw-r--r--Bullet.cs6
-rw-r--r--Player.cs1
-rw-r--r--enemy.tscn18
-rw-r--r--scripts/Enemy.cs40
-rw-r--r--scripts/Enemy.cs.uid1
-rw-r--r--world.tscn5
6 files changed, 71 insertions, 0 deletions
diff --git a/Bullet.cs b/Bullet.cs
index 4ca9520..db44e2a 100644
--- a/Bullet.cs
+++ b/Bullet.cs
@@ -4,6 +4,8 @@ public partial class Bullet : Area2D
{
[Export] public float Speed { get; set; } = 600.0f;
[Export] public float Damage { get; set; } = 10.0f;
+ [Export] public bool PierceEntity { get; set; } = false;
+ [Export] public bool PierceTerrain { get; set; } = false;
public Vector2 Direction { get; set; } = Vector2.Zero;
public override void _Ready()
@@ -26,6 +28,10 @@ public partial class Bullet : Area2D
{
// If it does, deal damage!
target.TakeDamage(Damage);
+ if(!PierceEntity){QueueFree();}
}
+ else{if(!PierceTerrain){QueueFree();}}
+
+
}
}
diff --git a/Player.cs b/Player.cs
index 11e3aa2..68d7ebc 100644
--- a/Player.cs
+++ b/Player.cs
@@ -10,6 +10,7 @@ public partial class Player : CharacterBody2D, IDamageable
private StatsComponent _stats;
public override void _Ready()
{
+ AddToGroup("player");
_stats = GetNode<StatsComponent>("StatsComponent");
_stats.Initialize(BaseStats);
_sprite = GetNode<Sprite2D>("Sprite2D");
diff --git a/enemy.tscn b/enemy.tscn
new file mode 100644
index 0000000..c4eb0d9
--- /dev/null
+++ b/enemy.tscn
@@ -0,0 +1,18 @@
+[gd_scene format=3 uid="uid://cg808l58igcrq"]
+
+[ext_resource type="Script" uid="uid://cml2xy7flhfn6" path="res://scripts/Enemy.cs" id="1_4gyqm"]
+[ext_resource type="Texture2D" uid="uid://mxuhmaj6nqfw" path="res://2D Pixel Dungeon Asset Pack/Character_animation/monsters_idle/vampire/v2/vampire_v2_1.png" id="2_qi2p4"]
+
+[sub_resource type="RectangleShape2D" id="RectangleShape2D_ovjgd"]
+size = Vector2(12, 14)
+
+[node name="Enemy" type="CharacterBody2D" unique_id=575877799]
+collision_layer = 4
+collision_mask = 7
+script = ExtResource("1_4gyqm")
+
+[node name="Sprite2D" type="Sprite2D" parent="." unique_id=2046016517]
+texture = ExtResource("2_qi2p4")
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1799666271]
+shape = SubResource("RectangleShape2D_ovjgd")
diff --git a/scripts/Enemy.cs b/scripts/Enemy.cs
new file mode 100644
index 0000000..cdbcd38
--- /dev/null
+++ b/scripts/Enemy.cs
@@ -0,0 +1,40 @@
+using Godot;
+using testing.interfaces; // Match your namespace
+
+public partial class Enemy : CharacterBody2D, IDamageable
+{
+ [Export] public float MoveSpeed { get; set; } = 150.0f;
+ [Export] public float MaxHealth { get; set; } = 30.0f;
+
+ private Node2D _player;
+
+ public override void _Ready()
+ {
+ // Find the player automatically using the group we just set up
+ _player = GetTree().GetFirstNodeInGroup("player") as Node2D;
+ }
+
+ public override void _PhysicsProcess(double delta)
+ {
+ if (_player == null) return;
+
+ // Calculate direction vector pointing from the enemy to the player
+ Vector2 direction = GlobalPosition.DirectionTo(_player.GlobalPosition);
+
+ // Move towards the player
+ Velocity = direction * MoveSpeed;
+ MoveAndSlide();
+ }
+
+ public void TakeDamage(float amount)
+ {
+ MaxHealth -= amount;
+ GD.Print($"Enemy took {amount} damage! Health remaining: {MaxHealth}");
+
+ if (MaxHealth <= 0)
+ {
+ GD.Print("Enemy defeated!");
+ QueueFree(); // Removes the enemy from the game
+ }
+ }
+} \ No newline at end of file
diff --git a/scripts/Enemy.cs.uid b/scripts/Enemy.cs.uid
new file mode 100644
index 0000000..dd3ea0c
--- /dev/null
+++ b/scripts/Enemy.cs.uid
@@ -0,0 +1 @@
+uid://cml2xy7flhfn6
diff --git a/world.tscn b/world.tscn
index dcd4853..647dcdb 100644
--- a/world.tscn
+++ b/world.tscn
@@ -2,6 +2,7 @@
[ext_resource type="Texture2D" uid="uid://bhg3yja4bekb7" path="res://2D Pixel Dungeon Asset Pack/character and tileset/Dungeon_Tileset.png" id="1_fj7yv"]
[ext_resource type="PackedScene" uid="uid://dydy08duw2lhf" path="res://player.tscn" id="2_tlwt5"]
+[ext_resource type="PackedScene" uid="uid://cg808l58igcrq" path="res://enemy.tscn" id="3_tlwt5"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_aqk2v"]
texture = ExtResource("1_fj7yv")
@@ -142,3 +143,7 @@ tile_set = SubResource("TileSet_cb62v")
[node name="Player" parent="." unique_id=312289746 instance=ExtResource("2_tlwt5")]
position = Vector2(71, 55)
+
+[node name="Enemy" parent="." unique_id=575877799 instance=ExtResource("3_tlwt5")]
+position = Vector2(128, 33)
+MoveSpeed = 25.0