ft: wrapping manager overhaul

This commit is contained in:
2026-03-01 14:11:28 +01:00
parent 99de1fc113
commit f83b290f5c
24 changed files with 221 additions and 182 deletions

View File

@@ -0,0 +1,24 @@
extends CharacterBody2D
var desired_rotation: float = self.rotation
@export var speed = 0.5
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
# smoothly rotate
if self.rotation != self.desired_rotation:
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
func move(motion: Vector3, mod: float) -> void:
move_and_collide(Vector2(motion.x, motion.y).normalized() * self.speed * mod) # Moves along the given vector
self.desired_rotation = atan2(motion.y, motion.x)
# Apply boundary to new position
position = GameManager.get_boundaried_position(position)
func duplicate_init() -> void:
var sight = $Sight
remove_child(sight)
sight.queue_free()

View File

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

View File

@@ -1,33 +1,26 @@
extends AbstractPrey2D
extends AbstractPrey
@onready var wrapper: WrappingManager = $WrappingManager
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var collision: CharacterBody2D = $Collision
@onready var sprite: AnimatedSprite2D = $"Collision/Sprite"
@onready var fsm: StateMachine = $StateMachine
@export var speed = 0.5
var desired_rotation: float = self.rotation
var starting_pos
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
health = maxHealth
sprite.play("Healthy")
if starting_pos:
collision.set_position(starting_pos)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
# smoothly rotate
if self.rotation != self.desired_rotation:
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
func _physics_process(delta: float) -> void:
pass
func set_position(pos: Vector2) -> void:
if collision:
collision.set_position(pos)
else:
starting_pos = pos
func move(motion: Vector3, mod: float = 1.0) -> void:
move_and_collide(Vector2(motion.x, motion.y).normalized() * self.speed * mod) # Moves along the given vector
self.desired_rotation = atan2(motion.y, motion.x)
# Apply boundary to new position
position = GameManager.get_boundaried_position(position)
collision.move(motion, mod)
func handle_damage(dmg: int, src: Node) -> void:
health = max(0, health-dmg)
@@ -40,7 +33,7 @@ func handle_damage(dmg: int, src: Node) -> void:
func die() -> void:
sprite.play("Dying")
wrapper.play_sprite("Dying")
GameManager.foodManager._spawn_food(position)
GameManager.foodManager._spawn_food(collision.position)
super.die()
func become_injured() -> void:

View File

@@ -1,10 +1,11 @@
[gd_scene format=3 uid="uid://c3iw2v3x6ngrb"]
[ext_resource type="PackedScene" uid="uid://bvsdg1v3ksixy" path="res://shared/npc/prey2D.tscn" id="1_qvulj"]
[ext_resource type="PackedScene" uid="uid://bvsdg1v3ksixy" path="res://shared/npc/abstractPrey.tscn" id="1_qvulj"]
[ext_resource type="Script" uid="uid://bgossk6xo31gi" path="res://molecular/prey/nucleotide_prey.gd" id="2_0227s"]
[ext_resource type="Texture2D" uid="uid://bhcb5g7g7um8" path="res://molecular/assets/prey/prey-dying-frame0.png" id="2_lkj7f"]
[ext_resource type="Script" uid="uid://bvbc0n0pslq7p" path="res://shared/wrapping_manager.gd" id="3_lecx4"]
[ext_resource type="Texture2D" uid="uid://bxn11avw7dykl" path="res://molecular/assets/prey/prey-dying-frame1.png" id="3_svqyr"]
[ext_resource type="Script" uid="uid://dcd4lhhq8pubb" path="res://molecular/prey/collision.gd" id="3_teu34"]
[ext_resource type="Texture2D" uid="uid://ctkehsavw6ghx" path="res://molecular/assets/prey/prey-healthy-frame0.png" id="4_ee1gb"]
[ext_resource type="Texture2D" uid="uid://uy28y3mkk6nt" path="res://molecular/assets/prey/prey-healthy-frame1.png" id="5_ae5nf"]
[ext_resource type="Texture2D" uid="uid://btnyajci8ptb2" path="res://molecular/assets/prey/prey-injured-frame0.png" id="6_0f87h"]
@@ -51,33 +52,45 @@ animations = [{
}]
[node name="NucleotidePrey" unique_id=740525631 groups=["prey"] instance=ExtResource("1_qvulj")]
collision_layer = 2
collision_mask = 5
motion_mode = 1
script = ExtResource("2_0227s")
speed = 0.5
maxHealth = 20
[node name="WrappingManager" type="Node" parent="." index="0" unique_id=407460873 node_paths=PackedStringArray("sprite", "shape")]
script = ExtResource("3_lecx4")
sprite = NodePath("../AnimatedSprite2D")
shape = NodePath("../CollisionPolygon2D")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="Collision" type="CharacterBody2D" parent="." index="0" unique_id=331517910]
scale = Vector2(0.2, 0.2)
collision_layer = 2
collision_mask = 5
script = ExtResource("3_teu34")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="1" unique_id=788182944]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Collision" index="0" unique_id=1471691984]
light_mask = 2
visibility_layer = 2
position = Vector2(69, 28)
rotation = 0.47415397
scale = Vector2(10, 10)
polygon = PackedVector2Array(-8.700367, -2.2789505, -5.6133537, -2.1772134, -4.1979375, 0.58079255, -5.9151926, 3.1480935, -8.862037, 2.9326901, -10.268076, 0.28495264)
[node name="Sprite" type="AnimatedSprite2D" parent="Collision" index="1" unique_id=788182944]
rotation = 1.5707964
sprite_frames = SubResource("SpriteFrames_66x8p")
animation = &"Healthy"
[node name="CollisionPolygon2D" parent="." index="2"]
[node name="Sight" type="Area2D" parent="Collision" index="2" unique_id=1773478588]
scale = Vector2(0.4, 0.4)
collision_layer = 0
collision_mask = 7
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Collision/Sight" index="0" unique_id=338757598]
light_mask = 2
visibility_layer = 2
position = Vector2(69, 28)
rotation = 0.474154
rotation = 1.5707964
scale = Vector2(10, 10)
polygon = PackedVector2Array(-8.700367, -2.2789505, -5.6133537, -2.1772134, -4.1979375, 0.58079255, -5.9151926, 3.1480935, -8.862037, 2.9326901, -10.268076, 0.28495264)
polygon = PackedVector2Array(3.8686981, -6.2705374, 7.0000973, -0.08602524, 3.5555592, 5.6287766, -3.0986624, 5.589636, -6.1517763, 0.031402588, -2.942093, -6.0748243, -29.993027, -74.37026, -11.10141, -83.6233, 9.332382, -84.00884, 35.163773, -77.06906)
[node name="StateMachine" type="Node" parent="." index="3" unique_id=445822474 node_paths=PackedStringArray("initial_state")]
[node name="WrappingManager" type="Node" parent="." index="1" unique_id=407460873]
script = ExtResource("3_lecx4")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="StateMachine" type="Node" parent="." index="2" unique_id=445822474 node_paths=PackedStringArray("initial_state")]
script = ExtResource("9_xxtgy")
initial_state = NodePath("Idle")
@@ -96,17 +109,6 @@ script = ExtResource("12_ubfhk")
[node name="Timer" type="Timer" parent="StateMachine/Idle" index="0" unique_id=1050348256]
one_shot = true
[node name="Sight" type="Area2D" parent="." index="4" unique_id=1773478588]
collision_layer = 0
collision_mask = 7
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Sight" index="0" unique_id=338757598]
light_mask = 2
visibility_layer = 2
rotation = 1.5707964
scale = Vector2(10, 10)
polygon = PackedVector2Array(3.8686981, -6.2705374, 7.0000973, -0.08602524, 3.5555592, 5.6287766, -3.0986624, 5.589636, -6.1517763, 0.031402588, -2.942093, -6.0748243, -29.993027, -74.37026, -11.10141, -83.6233, 9.332382, -84.00884, 35.163773, -77.06906)
[connection signal="body_entered" from="Collision/Sight" to="." method="_on_sight_body_entered"]
[connection signal="timeout" from="StateMachine/RandomMovement/Timer" to="StateMachine/RandomMovement" method="_on_timer_timeout"]
[connection signal="timeout" from="StateMachine/Idle/Timer" to="StateMachine/Idle" method="_on_timer_timeout"]
[connection signal="body_entered" from="Sight" to="." method="_on_sight_body_entered"]