ft: wrapping manager overhaul
This commit is contained in:
22
evolve-die-repeat/molecular/predator/collision.gd
Normal file
22
evolve-die-repeat/molecular/predator/collision.gd
Normal file
@@ -0,0 +1,22 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
var desired_rotation: float = self.rotation
|
||||
@export var speed = 0.8
|
||||
|
||||
# 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:
|
||||
self.desired_rotation = atan2(motion.y, motion.x)
|
||||
move_and_collide(Vector2(motion.x, motion.y).normalized() * self.speed * mod) # Moves along the given vector
|
||||
|
||||
# Apply boundary to new position
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
|
||||
func duplicate_init() -> void:
|
||||
var sight = $Sight
|
||||
remove_child(sight)
|
||||
sight.queue_free()
|
||||
1
evolve-die-repeat/molecular/predator/collision.gd.uid
Normal file
1
evolve-die-repeat/molecular/predator/collision.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cus6ogtwxx4v7
|
||||
@@ -1,40 +1,33 @@
|
||||
extends AbstractPredator2D
|
||||
extends AbstractPredator
|
||||
|
||||
# FIXME: (general) tracking across wrapping boundary
|
||||
|
||||
var starting_pos
|
||||
var can_attack: bool = true
|
||||
var desired_rotation: float = self.rotation
|
||||
@onready var sprite = $AnimatedSprite2D
|
||||
@onready var fsm: StateMachine = $StateMachine
|
||||
@onready var attack_cooldown_timer: Timer = $AttackCooldownTimer
|
||||
@onready var wrapper: WrappingManager = $WrappingManager
|
||||
|
||||
@onready var collision: CharacterBody2D = $Collision
|
||||
@onready var sprite = $"Collision/Sprite"
|
||||
@export var damage: int = 15
|
||||
@export var attack_range = 20
|
||||
@export var attack_range = 40
|
||||
@export var sight_range = 200
|
||||
@export var speed = 0.8
|
||||
|
||||
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
|
||||
|
||||
# FIXME: (also goes for prey) this is framerate dependent UNLESS called from a _physics function.
|
||||
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 set_position(pos: Vector2) -> void:
|
||||
if collision:
|
||||
collision.set_position(pos)
|
||||
else:
|
||||
starting_pos = pos
|
||||
|
||||
func try_attack(target: Node) -> void:
|
||||
if not can_attack:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://s4s66oaexava"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://d07cjelbqbiug" path="res://molecular/predator/hammerhead_predator.gd" id="1_xp037"]
|
||||
[ext_resource type="Script" uid="uid://cus6ogtwxx4v7" path="res://molecular/predator/collision.gd" id="2_7qt2q"]
|
||||
[ext_resource type="Texture2D" uid="uid://ch5rddsumyyhm" path="res://molecular/assets/predator/predator-healthy.png" id="2_34kwa"]
|
||||
[ext_resource type="Texture2D" uid="uid://30uwkdbnuu3h" path="res://molecular/assets/predator/hammerheadRibozyme-hunting.png" id="3_0ts4d"]
|
||||
[ext_resource type="Script" uid="uid://cygrmt03sx0k1" path="res://molecular/predator/state_machine.gd" id="3_xp037"]
|
||||
@@ -91,31 +92,43 @@ animations = [{
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[node name="HammerheadPredator" type="CharacterBody2D" unique_id=678504815 groups=["predator"]]
|
||||
collision_layer = 4
|
||||
collision_mask = 3
|
||||
motion_mode = 1
|
||||
[node name="HammerheadPredator" type="Node" unique_id=1312337720 groups=["predator"]]
|
||||
script = ExtResource("1_xp037")
|
||||
maxHealth = 50
|
||||
metadata/_custom_type_script = "uid://dgfimmq53whll"
|
||||
|
||||
[node name="WrappingManager" type="Node" parent="." unique_id=826586678 node_paths=PackedStringArray("sprite", "shape")]
|
||||
script = ExtResource("9_shhro")
|
||||
sprite = NodePath("../AnimatedSprite2D")
|
||||
shape = NodePath("../CollisionPolygon2D")
|
||||
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
|
||||
[node name="Collision" type="CharacterBody2D" parent="." unique_id=76553184]
|
||||
scale = Vector2(0.8, 0.8)
|
||||
collision_layer = 4
|
||||
collision_mask = 3
|
||||
script = ExtResource("2_7qt2q")
|
||||
|
||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." unique_id=1596156928]
|
||||
[node name="Sprite" type="AnimatedSprite2D" parent="Collision" unique_id=410999609]
|
||||
rotation = -1.5707964
|
||||
sprite_frames = SubResource("SpriteFrames_shhro")
|
||||
animation = &"Healthy"
|
||||
|
||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Collision" unique_id=1596156928]
|
||||
light_mask = 4
|
||||
visibility_layer = 4
|
||||
position = Vector2(0.111679085, 1.1167793)
|
||||
rotation = -1.5707964
|
||||
polygon = PackedVector2Array(-22.184862, -27.994831, 23.481365, -27.21198, 13.82622, 25.891317, -6.005971, 25.891317)
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=410999609]
|
||||
rotation = 4.712389
|
||||
sprite_frames = SubResource("SpriteFrames_shhro")
|
||||
animation = &"Hunting"
|
||||
[node name="Sight" type="Area2D" parent="Collision" unique_id=1608385873]
|
||||
collision_layer = 0
|
||||
collision_mask = 7
|
||||
|
||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Collision/Sight" unique_id=1707240701]
|
||||
light_mask = 4
|
||||
visibility_layer = 4
|
||||
position = Vector2(-1.0900421, 1.6350927)
|
||||
rotation = -1.5707964
|
||||
polygon = PackedVector2Array(-27.769547, -29.426758, 31.88504, -29.184647, 12.700996, 28.7294, 56.058624, 148.93633, 22.979004, 163.77974, -19.854843, 161.65926, -53.782654, 143.84715, -8.333115, 30.157196)
|
||||
|
||||
[node name="WrappingManager" type="Node" parent="." unique_id=826586678]
|
||||
script = ExtResource("9_shhro")
|
||||
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
|
||||
|
||||
[node name="StateMachine" type="Node" parent="." unique_id=1857729810 node_paths=PackedStringArray("initial_state")]
|
||||
script = ExtResource("3_xp037")
|
||||
@@ -137,22 +150,11 @@ one_shot = true
|
||||
[node name="Hunting" type="Node" parent="StateMachine" unique_id=1569866955]
|
||||
script = ExtResource("8_7qt2q")
|
||||
|
||||
[node name="Sight" type="Area2D" parent="." unique_id=1608385873]
|
||||
collision_layer = 0
|
||||
collision_mask = 7
|
||||
|
||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Sight" unique_id=1707240701]
|
||||
light_mask = 4
|
||||
visibility_layer = 4
|
||||
position = Vector2(-1.0900421, 1.6350927)
|
||||
rotation = -1.5707964
|
||||
polygon = PackedVector2Array(-27.769547, -29.426758, 31.88504, -29.184647, 12.700996, 28.7294, 56.058624, 148.93633, 22.979004, 163.77974, -19.854843, 161.65926, -53.782654, 143.84715, -8.333115, 30.157196)
|
||||
|
||||
[node name="AttackCooldownTimer" type="Timer" parent="." unique_id=435253442]
|
||||
wait_time = 0.5
|
||||
one_shot = true
|
||||
|
||||
[connection signal="body_entered" from="Collision/Sight" to="." method="_on_sight_body_entered"]
|
||||
[connection signal="timeout" from="StateMachine/Idle/Timer" to="StateMachine/Idle" method="_on_timer_timeout"]
|
||||
[connection signal="timeout" from="StateMachine/RandomMovement/Timer" to="StateMachine/RandomMovement" method="_on_timer_timeout"]
|
||||
[connection signal="body_entered" from="Sight" to="." method="_on_sight_body_entered"]
|
||||
[connection signal="timeout" from="AttackCooldownTimer" to="." method="_on_attack_cooldown_timer_timeout"]
|
||||
|
||||
Reference in New Issue
Block a user