Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b97c226f1 | |||
| b1e78df6c7 | |||
| 5908494977 | |||
| 63529a11ae | |||
| 255b87f991 | |||
| fd3eb35782 |
@@ -123,6 +123,7 @@
|
||||
<Content Include="menus\scripts\level_state.gd.uid" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="ABCs\" />
|
||||
<Folder Include="addons\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
9
interfaces/IDamageMaker.cs
Normal file
9
interfaces/IDamageMaker.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Godot;
|
||||
|
||||
namespace Movementtests.interfaces;
|
||||
|
||||
public interface IDamageMaker
|
||||
{
|
||||
[Export]
|
||||
RDamage GetDamageDealt { get; set; }
|
||||
}
|
||||
1
interfaces/IDamageMaker.cs.uid
Normal file
1
interfaces/IDamageMaker.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://wdqo51131g5
|
||||
8
interfaces/IDamageable.cs
Normal file
8
interfaces/IDamageable.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Godot;
|
||||
|
||||
namespace Movementtests.interfaces;
|
||||
|
||||
public interface IDamageable
|
||||
{
|
||||
void TakeDamage(RDamage damage);
|
||||
}
|
||||
1
interfaces/IDamageable.cs.uid
Normal file
1
interfaces/IDamageable.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cf56b2ep3bu3j
|
||||
6
interfaces/IKillable.cs
Normal file
6
interfaces/IKillable.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Movementtests.interfaces;
|
||||
|
||||
public interface IKillable
|
||||
{
|
||||
|
||||
}
|
||||
1
interfaces/IKillable.cs.uid
Normal file
1
interfaces/IKillable.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bea2kvnu3kuhu
|
||||
6
interfaces/IKnockbackable.cs
Normal file
6
interfaces/IKnockbackable.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Movementtests.interfaces;
|
||||
|
||||
public interface IKnockbackable
|
||||
{
|
||||
|
||||
}
|
||||
1
interfaces/IKnockbackable.cs.uid
Normal file
1
interfaces/IKnockbackable.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bh06s1yefucf7
|
||||
7
interfaces/ISpawnable.cs
Normal file
7
interfaces/ISpawnable.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using Godot;
|
||||
|
||||
|
||||
interface ISpawnable
|
||||
{
|
||||
void TestMethod();
|
||||
}
|
||||
1
interfaces/ISpawnable.cs.uid
Normal file
1
interfaces/ISpawnable.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bethuw2c1at8o
|
||||
12
interfaces/NodeExtensions.cs
Normal file
12
interfaces/NodeExtensions.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
namespace Movementtests.interfaces;
|
||||
|
||||
public static class NodeExtensions
|
||||
{
|
||||
public static IDamageable[] ToIDamageables(this GodotObject[] nodes)
|
||||
{
|
||||
return nodes == null ? System.Array.Empty<IDamageable>() : nodes.OfType<IDamageable>().ToArray();
|
||||
}
|
||||
}
|
||||
1
interfaces/NodeExtensions.cs.uid
Normal file
1
interfaces/NodeExtensions.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bgnncty7axdwd
|
||||
@@ -1,8 +1,19 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://q7uc1h2jpbd2"]
|
||||
[gd_scene load_steps=19 format=3 uid="uid://q7uc1h2jpbd2"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bei4nhkf8lwdo" path="res://player_controller/PlayerController.tscn" id="1_62kkh"]
|
||||
[ext_resource type="Material" uid="uid://31aulub2nqov" path="res://assets/greybox/m_greybox.tres" id="2_3uydm"]
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="2_sysok"]
|
||||
[ext_resource type="PackedScene" uid="uid://dxt0e2ugmttqq" path="res://scenes/enemies/first_enemy.tscn" id="3_3uydm"]
|
||||
[ext_resource type="Script" uid="uid://b2vdwkiqauhk3" path="res://scenes/enemies/EnemyInitInputs.cs" id="4_nd7vd"]
|
||||
[ext_resource type="PackedScene" uid="uid://cmlud1hwkd6sv" path="res://scenes/enemies/flying_enemy.tscn" id="5_8fd2t"]
|
||||
[ext_resource type="Script" uid="uid://do0dic4r3ri0s" path="res://scenes/enemies/FlyingEnemyInputs.cs" id="6_7m3bq"]
|
||||
[ext_resource type="Resource" uid="uid://otfc2snh8umc" path="res://scenes/enemies/first_enemy_damage.tres" id="6_dmw1t"]
|
||||
[ext_resource type="Resource" uid="uid://dgo65k2ceqfvy" path="res://scenes/enemies/flying_enemy_damage.tres" id="9_gp7s3"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_gp7s3"]
|
||||
script = ExtResource("2_sysok")
|
||||
DamageDealt = 3.0
|
||||
metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_0xm2m"]
|
||||
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
|
||||
@@ -26,11 +37,39 @@ ssil_radius = 8.4
|
||||
sdfgi_use_occlusion = true
|
||||
glow_enabled = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_8fd2t"]
|
||||
script = ExtResource("4_nd7vd")
|
||||
Speed = 1.2
|
||||
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_7m3bq"]
|
||||
script = ExtResource("4_nd7vd")
|
||||
Speed = 2.7
|
||||
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_sysok"]
|
||||
script = ExtResource("4_nd7vd")
|
||||
Speed = 4.0
|
||||
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_caohq"]
|
||||
script = ExtResource("6_7m3bq")
|
||||
Speed = 4.0
|
||||
TargetHeight = 10.0
|
||||
metadata/_custom_type_script = "uid://do0dic4r3ri0s"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_dmw1t"]
|
||||
script = ExtResource("6_7m3bq")
|
||||
Speed = 6.0
|
||||
TargetHeight = 15.0
|
||||
metadata/_custom_type_script = "uid://do0dic4r3ri0s"
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_62kkh")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 7.5)
|
||||
TutorialDone = true
|
||||
GetDamageDealt = SubResource("Resource_gp7s3")
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_1bvp3")
|
||||
@@ -95,11 +134,29 @@ material = ExtResource("2_3uydm")
|
||||
[node name="Enemy" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("3_3uydm")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -16.83681)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_8fd2t")
|
||||
GetDamageDealt = ExtResource("6_dmw1t")
|
||||
|
||||
[node name="Enemy2" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("3_3uydm")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3, 0, -16.83681)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_7m3bq")
|
||||
GetDamageDealt = ExtResource("6_dmw1t")
|
||||
|
||||
[node name="Enemy3" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("3_3uydm")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.5, 0, -16.83681)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_sysok")
|
||||
GetDamageDealt = ExtResource("6_dmw1t")
|
||||
|
||||
[node name="FlyingEnemy" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("5_8fd2t")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8, 7, -16)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_caohq")
|
||||
GetDamageDealt = ExtResource("9_gp7s3")
|
||||
|
||||
[node name="FlyingEnemy2" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("5_8fd2t")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 7, -16)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_dmw1t")
|
||||
GetDamageDealt = ExtResource("9_gp7s3")
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
[gd_scene load_steps=50 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||
[gd_scene load_steps=58 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bbbrf5ckydfna" path="res://player_controller/Scripts/PlayerController.cs" id="1_poq2x"]
|
||||
[ext_resource type="PackedScene" uid="uid://cf3rrgr1imvv4" path="res://scenes/path/path.tscn" id="2_6lejt"]
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="2_q14ux"]
|
||||
[ext_resource type="Resource" uid="uid://bl5crtu1gkrtr" path="res://systems/inputs/base_mode/base_mode.tres" id="3_cresl"]
|
||||
[ext_resource type="Resource" uid="uid://cpdaw41ah5gic" path="res://systems/inputs/base_mode/rotate_y.tres" id="4_rxwoh"]
|
||||
[ext_resource type="Resource" uid="uid://ccrb5xsnphc8" path="res://systems/inputs/base_mode/rotate_floorplane.tres" id="5_4u7i3"]
|
||||
[ext_resource type="Script" uid="uid://b6y3ugfydvch0" path="res://resource_definitions/RDamageModifier.cs" id="5_q7bng"]
|
||||
[ext_resource type="Resource" uid="uid://f3vs6l4m623s" path="res://systems/inputs/base_mode/move_left.tres" id="5_q14ux"]
|
||||
[ext_resource type="Resource" uid="uid://t612lts1wi1s" path="res://systems/inputs/base_mode/move_right.tres" id="6_q7bng"]
|
||||
[ext_resource type="Script" uid="uid://cwbvxlfvmocc1" path="res://player_controller/Scripts/StairsSystem.cs" id="7_bmt5a"]
|
||||
@@ -43,12 +45,39 @@
|
||||
[ext_resource type="Texture2D" uid="uid://chvt6g0xn5c2m" path="res://systems/dash/light-ring.jpg" id="32_lgpc8"]
|
||||
[ext_resource type="Script" uid="uid://b4dwolbvt8our" path="res://addons/godot_state_charts/history_state.gd" id="41_ruloh"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_m8gvy"]
|
||||
script = ExtResource("2_q14ux")
|
||||
DamageDealt = 3.0
|
||||
metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_q14ux"]
|
||||
script = ExtResource("5_q7bng")
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_q7bng"]
|
||||
script = ExtResource("5_q7bng")
|
||||
DamageType = 1
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_jb43f"]
|
||||
script = ExtResource("5_q7bng")
|
||||
DamageType = 2
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_cmijs"]
|
||||
script = ExtResource("5_q7bng")
|
||||
DamageType = 3
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_xc2g5"]
|
||||
height = 1.7
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_6lejt"]
|
||||
radius = 0.45
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_q14ux"]
|
||||
radius = 1.0
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_nodcl"]
|
||||
transparency = 1
|
||||
albedo_color = Color(0, 0.627451, 0.6313726, 0.49019608)
|
||||
@@ -72,6 +101,8 @@ blend_mode = 1
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
collision_mask = 272
|
||||
script = ExtResource("1_poq2x")
|
||||
GetDamageDealt = SubResource("Resource_m8gvy")
|
||||
DamageModifiers = Array[Object]([SubResource("Resource_q14ux"), SubResource("Resource_q7bng"), SubResource("Resource_jb43f"), SubResource("Resource_cmijs")])
|
||||
WalkSpeed = 7.5
|
||||
AccelerationFloor = 4.0
|
||||
DecelerationFloor = 3.0
|
||||
@@ -164,6 +195,17 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.6, 0)
|
||||
MantleEndLocationDistanceFromWall = 0.3
|
||||
MantleHeightCastStart = 2.5
|
||||
|
||||
[node name="WeaponHitbox" type="Area3D" parent="HeadSystem"]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.6, 0)
|
||||
collision_layer = 0
|
||||
collision_mask = 16
|
||||
monitorable = false
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="HeadSystem/WeaponHitbox"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -1.5)
|
||||
shape = SubResource("SphereShape3D_q14ux")
|
||||
|
||||
[node name="StairsSystem" type="Node3D" parent="."]
|
||||
script = ExtResource("7_bmt5a")
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@ using System;
|
||||
using Godot;
|
||||
using GodotStateCharts;
|
||||
using Movementtests.addons.godot_state_charts.csharp;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.systems;
|
||||
using Movementtests.player_controller.Scripts;
|
||||
using RustyOptions;
|
||||
|
||||
public partial class PlayerController : CharacterBody3D
|
||||
public partial class PlayerController : CharacterBody3D, IDamageable, IKnockbackable, IDamageMaker
|
||||
{
|
||||
// Enums
|
||||
public enum AllowedInputs
|
||||
@@ -52,11 +53,19 @@ public partial class PlayerController : CharacterBody3D
|
||||
public ShapeCast3D GroundDetector;
|
||||
public ShapeCast3D CeilingDetector;
|
||||
public RayCast3D DirectGroundDetector;
|
||||
public Area3D WeaponHitbox;
|
||||
|
||||
// Inspector stuff
|
||||
[Export] public Marker3D TutorialWeaponTarget;
|
||||
[Export] public bool TutorialDone { get; set; }
|
||||
|
||||
[ExportCategory("Combat")]
|
||||
[ExportGroup("Damage")]
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
[Export]
|
||||
public RDamageModifier[] DamageModifiers { get; set; }
|
||||
|
||||
[ExportCategory("Movement")]
|
||||
[ExportGroup("Ground")]
|
||||
[Export(PropertyHint.Range, "0,20,0.1,or_greater")]
|
||||
@@ -353,6 +362,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
var playerShape = StandingCollider.GetShape() as CapsuleShape3D;
|
||||
_playerHeight = playerShape!.Height;
|
||||
_playerRadius = playerShape.Radius;
|
||||
|
||||
WeaponHitbox = GetNode<Area3D>("%WeaponHitbox");
|
||||
|
||||
// State management
|
||||
_playerState = StateChart.Of(GetNode("StateChart"));
|
||||
@@ -1567,17 +1578,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
DashIndicatorMesh.Visible = false;
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Hit Management ///////
|
||||
///////////////////////////
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
if (_aiming.Active)
|
||||
{
|
||||
ThrowWeapon();
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Parry Management ///////
|
||||
///////////////////////////
|
||||
@@ -1728,4 +1728,30 @@ public partial class PlayerController : CharacterBody3D
|
||||
DashIndicatorNode.LookAt(WeaponSystem.GlobalPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(RDamage damage)
|
||||
{
|
||||
foreach (var damageable in DamageModifiers.ToIDamageables())
|
||||
damageable.TakeDamage(damage);
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Hit Management ///////
|
||||
///////////////////////////
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
if (_aiming.Active && WeaponSystem.InHandState.Active)
|
||||
{
|
||||
ThrowWeapon();
|
||||
}
|
||||
|
||||
if (!WeaponSystem.InHandState.Active) return;
|
||||
|
||||
var bodies = WeaponHitbox.GetOverlappingBodies();
|
||||
foreach (var body in bodies)
|
||||
{
|
||||
if(body is IDamageable spawnable)
|
||||
spawnable.TakeDamage(GetDamageDealt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
resource_definitions/RDamage.cs
Normal file
24
resource_definitions/RDamage.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.systems.damage;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RDamage : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float DamageDealt = 1.0f;
|
||||
|
||||
[Export]
|
||||
public EDamageTypes DamageType = EDamageTypes.Normal;
|
||||
|
||||
public RDamage()
|
||||
{
|
||||
DamageDealt = 1.0f;
|
||||
DamageType = EDamageTypes.Normal;
|
||||
}
|
||||
public RDamage(float damageDealt, EDamageTypes damageType)
|
||||
{
|
||||
DamageDealt = damageDealt;
|
||||
DamageType = damageType;
|
||||
}
|
||||
}
|
||||
1
resource_definitions/RDamage.cs.uid
Normal file
1
resource_definitions/RDamage.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://jitubgv6judn
|
||||
37
resource_definitions/RDamageModifier.cs
Normal file
37
resource_definitions/RDamageModifier.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.systems.damage;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RDamageModifier : Resource, IDamageable
|
||||
{
|
||||
[Signal]
|
||||
delegate void DamageTakenEventHandler(float damage);
|
||||
|
||||
[Export]
|
||||
public EDamageTypes DamageType = EDamageTypes.Normal;
|
||||
[Export]
|
||||
public float Modifier = 1.0f;
|
||||
|
||||
public RDamageModifier()
|
||||
{
|
||||
Modifier = 1.0f;
|
||||
DamageType = EDamageTypes.Normal;
|
||||
}
|
||||
public RDamageModifier(EDamageTypes damageType, float modifier)
|
||||
{
|
||||
Modifier = modifier;
|
||||
DamageType = damageType;
|
||||
}
|
||||
|
||||
public void TakeDamage(RDamage damage)
|
||||
{
|
||||
if (damage.DamageType != DamageType) return;
|
||||
|
||||
var finalDamage = damage.DamageDealt * Modifier;
|
||||
var message = $"Damage of type {DamageType} taken: {finalDamage}";
|
||||
GD.Print(message);
|
||||
EmitSignalDamageTaken(finalDamage);
|
||||
}
|
||||
}
|
||||
1
resource_definitions/RDamageModifier.cs.uid
Normal file
1
resource_definitions/RDamageModifier.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b6y3ugfydvch0
|
||||
18
scenes/enemies/EnemyInitInputs.cs
Normal file
18
scenes/enemies/EnemyInitInputs.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class EnemyInitInputs : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed;
|
||||
|
||||
public EnemyInitInputs()
|
||||
{
|
||||
Speed = 5.0f;
|
||||
}
|
||||
public EnemyInitInputs(float speed)
|
||||
{
|
||||
Speed = speed;
|
||||
}
|
||||
}
|
||||
1
scenes/enemies/EnemyInitInputs.cs.uid
Normal file
1
scenes/enemies/EnemyInitInputs.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b2vdwkiqauhk3
|
||||
@@ -1,20 +1,30 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.player_controller.Scripts;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
public partial class FirstEnemy : CharacterBody3D
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FirstEnemy : CharacterBody3D, IDamageable, IKillable, IKnockbackable, IDamageMaker
|
||||
{
|
||||
[Export]
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed = 5.0f;
|
||||
[Export]
|
||||
public EnemyInitInputs Inputs;
|
||||
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
[Export]
|
||||
public RDamageModifier[] DamageModifiers { get; set; }
|
||||
|
||||
private RayCast3D _wallInFrontRayCast;
|
||||
private Area3D _damageBox;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_wallInFrontRayCast = GetNode<RayCast3D>("WallInFrontRayCast");
|
||||
_damageBox = GetNode<Area3D>("DamageBox");
|
||||
_damageBox.BodyEntered += OnDamageBoxTriggered;
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
@@ -26,15 +36,26 @@ public partial class FirstEnemy : CharacterBody3D
|
||||
LookAt(targetPlane);
|
||||
|
||||
var velocity = Velocity;
|
||||
velocity.X = direction.X * Speed;
|
||||
velocity.Z = direction.Z * Speed;
|
||||
velocity.X = direction.X * Inputs.Speed;
|
||||
velocity.Z = direction.Z * Inputs.Speed;
|
||||
|
||||
if (_wallInFrontRayCast.IsColliding())
|
||||
velocity.Y = Speed;
|
||||
velocity.Y = Inputs.Speed;
|
||||
else if (!IsOnFloor())
|
||||
velocity += GetGravity() * (float)delta;
|
||||
|
||||
Velocity = velocity;
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
if(body is IDamageable damageable) damageable.TakeDamage(GetDamageDealt);
|
||||
}
|
||||
|
||||
public void TakeDamage(RDamage damage)
|
||||
{
|
||||
foreach (var damageable in DamageModifiers.ToIDamageables())
|
||||
damageable.TakeDamage(damage);
|
||||
}
|
||||
}
|
||||
|
||||
92
scenes/enemies/FlyingEnemy.cs
Normal file
92
scenes/enemies/FlyingEnemy.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKnockbackable, IDamageMaker
|
||||
{
|
||||
[Export]
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export]
|
||||
public FlyingEnemyInputs Inputs { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamageModifier[] DamageModifiers { get; set; }
|
||||
|
||||
private RayCast3D _groundDistanceRaycast;
|
||||
private Area3D _damageBox;
|
||||
|
||||
private bool _movingToDesiredHeight = true;
|
||||
private Vector3 _randomDirection;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_groundDistanceRaycast = GetNode<RayCast3D>("GroundDistance");
|
||||
_groundDistanceRaycast.TargetPosition = new Vector3(0, 0, 0);
|
||||
|
||||
_damageBox = GetNode<Area3D>("DamageBox");
|
||||
_damageBox.BodyEntered += OnDamageBoxTriggered;
|
||||
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var target = Target.GlobalPosition;
|
||||
var direction = (target - GlobalPosition).Normalized();
|
||||
Vector3 velocity = Velocity;
|
||||
|
||||
LookAt(target);
|
||||
|
||||
// Check if we have a direct line of sight to the player
|
||||
if (!_movingToDesiredHeight)
|
||||
{
|
||||
velocity = direction * Inputs.Speed;
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count > 0)
|
||||
{
|
||||
_movingToDesiredHeight = true;
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity = _randomDirection * Inputs.Speed;
|
||||
|
||||
var groundQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition, GlobalPosition+Vector3.Down*Inputs.TargetHeight, _groundDistanceRaycast.CollisionMask);
|
||||
var groundResult = spaceState.IntersectRay(groundQuery);
|
||||
if (groundResult.Count == 0)
|
||||
{
|
||||
velocity.Y = 0;
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count == 0)
|
||||
{
|
||||
_movingToDesiredHeight = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Velocity = velocity;
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
if(body is IDamageable damageable) damageable.TakeDamage(GetDamageDealt);
|
||||
}
|
||||
|
||||
public void TakeDamage(RDamage damage)
|
||||
{
|
||||
foreach (var damageable in DamageModifiers.ToIDamageables())
|
||||
damageable.TakeDamage(damage);
|
||||
}
|
||||
}
|
||||
1
scenes/enemies/FlyingEnemy.cs.uid
Normal file
1
scenes/enemies/FlyingEnemy.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cmvep0qi7qlvf
|
||||
23
scenes/enemies/FlyingEnemyInputs.cs
Normal file
23
scenes/enemies/FlyingEnemyInputs.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FlyingEnemyInputs : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed;
|
||||
|
||||
[Export(PropertyHint.Range, "0,100,1,or_greater")]
|
||||
public float TargetHeight;
|
||||
|
||||
public FlyingEnemyInputs()
|
||||
{
|
||||
Speed = 5.0f;
|
||||
TargetHeight = 50.0f;
|
||||
}
|
||||
public FlyingEnemyInputs(float speed, float targetHeight)
|
||||
{
|
||||
Speed = speed;
|
||||
TargetHeight = targetHeight;
|
||||
}
|
||||
}
|
||||
1
scenes/enemies/FlyingEnemyInputs.cs.uid
Normal file
1
scenes/enemies/FlyingEnemyInputs.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://do0dic4r3ri0s
|
||||
@@ -1,6 +1,11 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://dxt0e2ugmttqq"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://dxt0e2ugmttqq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bn7sc6id7n166" path="res://scenes/enemies/FirstEnemy.cs" id="1_4yfjf"]
|
||||
[ext_resource type="Script" uid="uid://b6y3ugfydvch0" path="res://resource_definitions/RDamageModifier.cs" id="2_ylcc3"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_gsmti"]
|
||||
script = ExtResource("2_ylcc3")
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_62kkh"]
|
||||
|
||||
@@ -15,10 +20,14 @@ rings = 4
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_4yfjf"]
|
||||
albedo_color = Color(0.06469653, 0.06469653, 0.06469653, 1)
|
||||
|
||||
[node name="CharacterBody3D" type="CharacterBody3D"]
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_4yfjf"]
|
||||
size = Vector3(1, 2, 2)
|
||||
|
||||
[node name="FirstEnemy" type="CharacterBody3D"]
|
||||
collision_layer = 16
|
||||
collision_mask = 273
|
||||
script = ExtResource("1_4yfjf")
|
||||
DamageModifiers = Array[Object]([SubResource("Resource_gsmti")])
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
@@ -49,3 +58,11 @@ surface_material_override/0 = SubResource("StandardMaterial3D_4yfjf")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0)
|
||||
target_position = Vector3(0, 0, -1.5)
|
||||
collision_mask = 272
|
||||
|
||||
[node name="DamageBox" type="Area3D" parent="."]
|
||||
collision_layer = 0
|
||||
monitorable = false
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="DamageBox"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -0.5)
|
||||
shape = SubResource("BoxShape3D_4yfjf")
|
||||
|
||||
8
scenes/enemies/first_enemy_damage.tres
Normal file
8
scenes/enemies/first_enemy_damage.tres
Normal file
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="RDamage" load_steps=2 format=3 uid="uid://otfc2snh8umc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="1_y415a"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_y415a")
|
||||
DamageDealt = 2.0
|
||||
metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
72
scenes/enemies/flying_enemy.tscn
Normal file
72
scenes/enemies/flying_enemy.tscn
Normal file
@@ -0,0 +1,72 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://cmlud1hwkd6sv"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cmvep0qi7qlvf" path="res://scenes/enemies/FlyingEnemy.cs" id="1_b46rq"]
|
||||
[ext_resource type="Script" uid="uid://b6y3ugfydvch0" path="res://resource_definitions/RDamageModifier.cs" id="2_1bsgx"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_2pnje"]
|
||||
script = ExtResource("2_1bsgx")
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_1bsgx"]
|
||||
script = ExtResource("2_1bsgx")
|
||||
DamageType = 1
|
||||
Modifier = 2.0
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_b46rq"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_1bsgx"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_4yfjf"]
|
||||
radius = 0.05
|
||||
height = 0.1
|
||||
radial_segments = 4
|
||||
rings = 4
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_4yfjf"]
|
||||
albedo_color = Color(0.06469653, 0.06469653, 0.06469653, 1)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_4yfjf"]
|
||||
size = Vector3(1, 1, 1.5)
|
||||
|
||||
[node name="FlyingEnemy" type="CharacterBody3D"]
|
||||
collision_layer = 16
|
||||
collision_mask = 273
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_b46rq")
|
||||
DamageModifiers = Array[Object]([SubResource("Resource_2pnje"), SubResource("Resource_1bsgx")])
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_b46rq")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
layers = 33
|
||||
mesh = SubResource("SphereMesh_1bsgx")
|
||||
|
||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.2, 0, -0.5)
|
||||
layers = 33
|
||||
cast_shadow = 0
|
||||
ignore_occlusion_culling = true
|
||||
mesh = SubResource("SphereMesh_4yfjf")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_4yfjf")
|
||||
|
||||
[node name="MeshInstance3D3" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.2, 0, -0.5)
|
||||
layers = 33
|
||||
cast_shadow = 0
|
||||
ignore_occlusion_culling = true
|
||||
mesh = SubResource("SphereMesh_4yfjf")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_4yfjf")
|
||||
|
||||
[node name="GroundDistance" type="RayCast3D" parent="."]
|
||||
target_position = Vector3(0, 0, 0)
|
||||
collision_mask = 272
|
||||
|
||||
[node name="DamageBox" type="Area3D" parent="."]
|
||||
collision_layer = 0
|
||||
monitorable = false
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="DamageBox"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.75)
|
||||
shape = SubResource("BoxShape3D_4yfjf")
|
||||
8
scenes/enemies/flying_enemy_damage.tres
Normal file
8
scenes/enemies/flying_enemy_damage.tres
Normal file
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="RDamage" load_steps=2 format=3 uid="uid://dgo65k2ceqfvy"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="1_h6law"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_h6law")
|
||||
DamageType = 3
|
||||
metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
61
scenes/spawners/Spawner.cs
Normal file
61
scenes/spawners/Spawner.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Spawner : Node3D
|
||||
{
|
||||
[Export(PropertyHint.NodeType)]
|
||||
public PackedScene SceneToSpawn { get; set; }
|
||||
|
||||
[Export]
|
||||
public Resource Inputs;
|
||||
[Export]
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export(PropertyHint.Range, "0.1, 100, 0.1, or_greater")]
|
||||
public float SpawnInterval { get; set; } = 1.0f;
|
||||
[Export]
|
||||
public bool IsActiveOnStart { get; set; } = true;
|
||||
|
||||
private float _spawnTimer;
|
||||
private bool _isActive;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_isActive = IsActiveOnStart;
|
||||
_spawnTimer = SpawnInterval;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_isActive) return;
|
||||
|
||||
_spawnTimer -= (float) delta;
|
||||
if (_spawnTimer <= 0) Spawn();
|
||||
}
|
||||
|
||||
public void Spawn()
|
||||
{
|
||||
if (SceneToSpawn == null || !SceneToSpawn.CanInstantiate()) return;
|
||||
|
||||
var spawnedInstance = SceneToSpawn.Instantiate() as FirstEnemy;
|
||||
if (spawnedInstance == null) return;
|
||||
|
||||
spawnedInstance.Inputs = Inputs as EnemyInitInputs;
|
||||
spawnedInstance.Target = Target;
|
||||
GetTree().GetCurrentScene().AddChild(spawnedInstance);
|
||||
spawnedInstance.GlobalPosition = GlobalPosition;
|
||||
|
||||
_spawnTimer = SpawnInterval;
|
||||
}
|
||||
|
||||
public void StartSpawning()
|
||||
{
|
||||
_isActive = true;
|
||||
_spawnTimer = SpawnInterval;
|
||||
}
|
||||
|
||||
public void StopSpawning()
|
||||
{
|
||||
_isActive = false;
|
||||
}
|
||||
}
|
||||
1
scenes/spawners/Spawner.cs.uid
Normal file
1
scenes/spawners/Spawner.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://djyspwixi01j5
|
||||
10
scenes/spawners/spawner.tscn
Normal file
10
scenes/spawners/spawner.tscn
Normal file
@@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://c305mfrtumcyq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://djyspwixi01j5" path="res://scenes/spawners/Spawner.cs" id="1_2otbo"]
|
||||
[ext_resource type="PackedScene" uid="uid://dxt0e2ugmttqq" path="res://scenes/enemies/first_enemy.tscn" id="2_2otbo"]
|
||||
|
||||
[node name="Spawner" type="Node3D"]
|
||||
script = ExtResource("1_2otbo")
|
||||
SceneToSpawn = ExtResource("2_2otbo")
|
||||
|
||||
[node name="Marker3D" type="Marker3D" parent="."]
|
||||
9
systems/damage/EDamageTypes.cs
Normal file
9
systems/damage/EDamageTypes.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Movementtests.systems.damage;
|
||||
|
||||
public enum EDamageTypes
|
||||
{
|
||||
Normal,
|
||||
Fire,
|
||||
Ice,
|
||||
Explosion,
|
||||
}
|
||||
1
systems/damage/EDamageTypes.cs.uid
Normal file
1
systems/damage/EDamageTypes.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dubmiwfuunxmu
|
||||
Reference in New Issue
Block a user