Basic pathfinding working for crying ghosts

This commit is contained in:
2026-01-17 23:37:33 -06:00
parent dd4ce5fcf4
commit 3a63bb6709
46 changed files with 691 additions and 34 deletions

24
Characters/Alien/Alien.cs Normal file
View File

@@ -0,0 +1,24 @@
using Godot;
using System;
public partial class Alien : CharacterBase
{
private AnimatedSprite2D? _animatedSprite;
public override void _Ready()
{
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
}
public override void _Process(double delta)
{
if (IsMoving)
{
_animatedSprite?.Play("walk");
}
else
{
_animatedSprite?.Stop();
}
}
}

View File

@@ -0,0 +1 @@
uid://bi3skhkybwoa7

View File

@@ -0,0 +1,37 @@
[gd_resource type="SpriteFrames" load_steps=5 format=3 uid="uid://bqy3twlyxmhx6"]
[ext_resource type="Texture2D" uid="uid://lja331o88abg" path="res://Characters/Alien/Sprite-0004.png" id="1_gpyw1"]
[sub_resource type="AtlasTexture" id="AtlasTexture_ffiei"]
atlas = ExtResource("1_gpyw1")
region = Rect2(0, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_d4kv8"]
atlas = ExtResource("1_gpyw1")
region = Rect2(0, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_117nm"]
atlas = ExtResource("1_gpyw1")
region = Rect2(16, 0, 16, 32)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ffiei")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_d4kv8")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_117nm")
}],
"loop": true,
"name": &"walk",
"speed": 5.0
}]

View File

@@ -0,0 +1,20 @@
[gd_scene load_steps=4 format=3 uid="uid://lfawbspot0vf"]
[ext_resource type="Script" uid="uid://bi3skhkybwoa7" path="res://Characters/Alien/Alien.cs" id="1_h37a8"]
[ext_resource type="SpriteFrames" uid="uid://bqy3twlyxmhx6" path="res://Characters/Alien/Alien.tres" id="2_5lqdc"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_h37a8"]
radius = 4.0
height = 28.0
[node name="Alien" type="CharacterBody2D" groups=["Player"]]
script = ExtResource("1_h37a8")
Speed = 150.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 1)
shape = SubResource("CapsuleShape2D_h37a8")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = ExtResource("2_5lqdc")
animation = &"walk"

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 B

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://lja331o88abg"
path="res://.godot/imported/Sprite-0004.png-e66795ad74755bd4c94f14c19c9ecbcb.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Characters/Alien/Sprite-0004.png"
dest_files=["res://.godot/imported/Sprite-0004.png-e66795ad74755bd4c94f14c19c9ecbcb.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -18,6 +18,8 @@ public abstract partial class CharacterBase : CharacterBody2D
=> (GetGlobalMousePosition() - GlobalPosition).Angle();
protected bool IsPrimaryOnCooldown
=> primaryCooldown > 0f;
protected bool IsMoving
=> Velocity != Vector2.Zero;
float primaryCooldown;
@@ -34,7 +36,7 @@ public abstract partial class CharacterBase : CharacterBody2D
void HandleInput(double delta)
{
var direction = Input.GetVector(InputLeft, InputRight, InputUp, InputDown);
var direction = Input.GetVector(InputLeft, InputRight, InputUp, InputDown).Normalized();
Velocity = direction * Speed;

View File

@@ -0,0 +1,72 @@
[gd_resource type="SpriteFrames" load_steps=10 format=3 uid="uid://v2dncd7e66ki"]
[ext_resource type="Texture2D" uid="uid://cktqad5dxfmst" path="res://Characters/Crying Ghost/Sprite-0008.png" id="1_pumse"]
[sub_resource type="AtlasTexture" id="AtlasTexture_3x7sv"]
atlas = ExtResource("1_pumse")
region = Rect2(0, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_b8dh6"]
atlas = ExtResource("1_pumse")
region = Rect2(0, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_1m6wj"]
atlas = ExtResource("1_pumse")
region = Rect2(16, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_nxsb8"]
atlas = ExtResource("1_pumse")
region = Rect2(32, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_eav7g"]
atlas = ExtResource("1_pumse")
region = Rect2(48, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_xejkc"]
atlas = ExtResource("1_pumse")
region = Rect2(64, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_xcy63"]
atlas = ExtResource("1_pumse")
region = Rect2(80, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_uxp54"]
atlas = ExtResource("1_pumse")
region = Rect2(96, 0, 16, 32)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_3x7sv")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_b8dh6")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1m6wj")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_nxsb8")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_eav7g")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xejkc")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xcy63")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_uxp54")
}],
"loop": true,
"name": &"idle",
"speed": 5.0
}]

View File

@@ -0,0 +1,38 @@
[gd_scene load_steps=5 format=3 uid="uid://61hp8l06y7ka"]
[ext_resource type="Script" uid="uid://d2mxshuj7um8x" path="res://Characters/Crying Ghost/CryingGhost.cs" id="1_wdx63"]
[ext_resource type="SpriteFrames" uid="uid://v2dncd7e66ki" path="res://Characters/Crying Ghost/Crying Ghost.tres" id="2_6ooq7"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_wdx63"]
radius = 4.0
height = 22.0
[sub_resource type="CircleShape2D" id="CircleShape2D_wdx63"]
radius = 128.0
[node name="CryingGhost" type="CharacterBody2D"]
script = ExtResource("1_wdx63")
Speed = 50.0
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = ExtResource("2_6ooq7")
animation = &"idle"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CapsuleShape2D_wdx63")
[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
path_desired_distance = 4.0
target_desired_distance = 4.0
path_postprocessing = 1
avoidance_enabled = true
radius = 4.0
debug_enabled = true
[node name="DetectionArea" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectionArea"]
shape = SubResource("CircleShape2D_wdx63")
[node name="TargetTimer" type="Timer" parent="."]
wait_time = 0.25

View File

@@ -0,0 +1,78 @@
using Godot;
using System.Diagnostics.CodeAnalysis;
public partial class CryingGhost : CharacterBase
{
private AnimatedSprite2D _animatedSprite = default!;
private NavigationAgent2D _navigationAgent = default!;
private Area2D _detectionArea = default!;
private Timer _targetTimer = default!;
protected Node2D? Target { get; private set; }
[MemberNotNullWhen(true, nameof(Target))]
protected bool HasTarget => Target is not null;
public override void _Ready()
{
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
_navigationAgent = GetNode<NavigationAgent2D>("NavigationAgent2D");
_detectionArea = GetNode<Area2D>("DetectionArea");
_targetTimer = GetNode<Timer>("TargetTimer");
_animatedSprite?.Play("idle");
_detectionArea.BodyEntered += OnBodyEntered;
_detectionArea.BodyExited += OnBodyExited;
_targetTimer.Timeout += OnTimeout;
_navigationAgent.VelocityComputed += OnVelocityComputed;
}
public override void _PhysicsProcess(double delta)
{
if (!HasTarget)
{
Velocity = Vector2.Zero;
}
else
{
var nextPosition = _navigationAgent.GetNextPathPosition();
var direction = (nextPosition - GlobalPosition).Normalized();
_navigationAgent.Velocity = direction * Speed;
}
MoveAndSlide();
}
void OnBodyEntered(Node2D body)
{
if (body.IsInGroup("Player"))
{
Target = body;
_navigationAgent.TargetPosition = Target.GlobalPosition;
_targetTimer.Start();
}
}
void OnBodyExited(Node2D body)
{
if (body == Target)
{
Target = null;
_navigationAgent.TargetPosition = GlobalPosition;
_targetTimer.Stop();
}
}
void OnTimeout()
{
if (HasTarget)
{
_navigationAgent.TargetPosition = Target.GlobalPosition;
}
}
void OnVelocityComputed(Vector2 safeVelocity)
{
Velocity = safeVelocity;
}
}

View File

@@ -0,0 +1 @@
uid://d2mxshuj7um8x

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cktqad5dxfmst"
path="res://.godot/imported/Sprite-0008.png-1fafa4a9bb9b4df1192de33bd2fa3429.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Characters/Crying Ghost/Sprite-0008.png"
dest_files=["res://.godot/imported/Sprite-0008.png-1fafa4a9bb9b4df1192de33bd2fa3429.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -11,7 +11,7 @@ size = Vector2(16, 32)
motion_mode = 1
script = ExtResource("1_8l5bb")
Weapon = ExtResource("2_0fgit")
Speed = 300.0
Speed = 100.0
PrimaryCooldown = 1.0
[node name="Body" type="Sprite2D" parent="."]

View File

@@ -0,0 +1,24 @@
using Godot;
using System;
public partial class Potato : CharacterBase
{
private AnimatedSprite2D? _animatedSprite;
public override void _Ready()
{
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
}
public override void _Process(double delta)
{
if (IsMoving)
{
_animatedSprite?.Play("walk");
}
else
{
_animatedSprite?.Stop();
}
}
}

View File

@@ -0,0 +1 @@
uid://dq1dx56o8k7tg

View File

@@ -0,0 +1,34 @@
[gd_resource type="SpriteFrames" load_steps=5 format=3 uid="uid://drrdnd1kwr7lj"]
[ext_resource type="Texture2D" uid="uid://bvs8vrofgjoag" path="res://Characters/Potato/potato.png" id="1_os4wu"]
[ext_resource type="Texture2D" uid="uid://cjs21sigvksdf" path="res://Characters/Potato/potato_walk.png" id="2_g3cha"]
[sub_resource type="AtlasTexture" id="AtlasTexture_cu4k2"]
atlas = ExtResource("2_g3cha")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_f5v2o"]
atlas = ExtResource("2_g3cha")
region = Rect2(16, 0, 16, 16)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_os4wu")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_cu4k2")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_f5v2o")
}],
"loop": true,
"name": &"walk",
"speed": 5.0
}]

View File

@@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://bqbsh3mejgs18"]
[ext_resource type="Script" uid="uid://dq1dx56o8k7tg" path="res://Characters/Potato/Potato.cs" id="1_nwx1l"]
[ext_resource type="SpriteFrames" uid="uid://drrdnd1kwr7lj" path="res://Characters/Potato/Potato.tres" id="2_sw86o"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_sw86o"]
radius = 4.1781855
height = 15.565589
[node name="Potato" type="CharacterBody2D"]
script = ExtResource("1_nwx1l")
Speed = 100.0
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = ExtResource("2_sw86o")
animation = &"walk"
frame_progress = 0.988052
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 0.61086524
shape = SubResource("CapsuleShape2D_sw86o")

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bvs8vrofgjoag"
path="res://.godot/imported/potato.png-8d8c005bc502d63f08b319ec956f9fa9.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Characters/Potato/potato.png"
dest_files=["res://.godot/imported/potato.png-8d8c005bc502d63f08b319ec956f9fa9.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 B

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cjs21sigvksdf"
path="res://.godot/imported/potato_walk.png-796309b1abb8d979328a6e8ba0383026.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Characters/Potato/potato_walk.png"
dest_files=["res://.godot/imported/potato_walk.png-796309b1abb8d979328a6e8ba0383026.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -2,7 +2,7 @@
[ext_resource type="Texture2D" uid="uid://qi1cvcj41wxr" path="res://Characters/Wizard/Body.png" id="1_pptet"]
[ext_resource type="Script" uid="uid://cx2flf2i3h0rv" path="res://Characters/Wizard/Wizard.cs" id="1_vgyld"]
[ext_resource type="PackedScene" uid="uid://b2u2xirxjo68h" path="res://Abilities/Fireballv3.tscn" id="2_n5kae"]
[ext_resource type="PackedScene" uid="uid://b2u2xirxjo68h" path="res://Abilities/Fireball/Fireballv3.tscn" id="2_n5kae"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_n5kae"]
size = Vector2(16, 32)
@@ -11,7 +11,7 @@ size = Vector2(16, 32)
motion_mode = 1
script = ExtResource("1_vgyld")
Projectile = ExtResource("2_n5kae")
Speed = 300.0
Speed = 75.0
PrimaryCooldown = 0.5
[node name="Body" type="Sprite2D" parent="."]