ft (wip): hammerhead predator
This commit is contained in:
@@ -34,7 +34,7 @@ func _ready() -> void:
|
||||
# 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: # FIXME: causes the mirror sprites to flip out
|
||||
if self.rotation != self.desired_rotation:
|
||||
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
|
||||
|
||||
# Boundary mirroring
|
||||
@@ -43,8 +43,8 @@ func _process(delta: float) -> void:
|
||||
func _physics_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func move(motion: Vector3) -> void:
|
||||
move_and_collide(Vector2(motion.x, motion.y).normalized() * self.speed) # Moves along the given vector
|
||||
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
|
||||
@@ -72,7 +72,7 @@ func become_injured() -> void:
|
||||
mirrorSprite3.play("Injured")
|
||||
|
||||
func _on_sight_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("predators") or body.is_in_group("player"):
|
||||
if body.is_in_group("predator") or (health < maxHealth and body.is_in_group("player")):
|
||||
fsm.transition_to_next_state(fsm.States.FLEEING, {"threat": body})
|
||||
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
[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"]
|
||||
[ext_resource type="Texture2D" uid="uid://bqll8ge4cr2uf" path="res://molecular/assets/prey/prey-injured-frame1.png" id="7_w7inl"]
|
||||
[ext_resource type="Script" uid="uid://0vwv2nt16gpv" path="res://molecular/prey/nucleotide_prey_state_machine.gd" id="9_xxtgy"]
|
||||
[ext_resource type="Script" uid="uid://ubcu8fdfxxj1" path="res://molecular/prey/nucleotide_prey_random_movement.gd" id="10_rgguv"]
|
||||
[ext_resource type="Script" uid="uid://xbiqj7ubmj7d" path="res://molecular/prey/nucleotide_prey_idle.gd" id="12_ubfhk"]
|
||||
[ext_resource type="Script" uid="uid://dlw7inlh6asvu" path="res://molecular/prey/nucleotide_prey_fleeing.gd" id="12_xxtgy"]
|
||||
[ext_resource type="Script" uid="uid://0vwv2nt16gpv" path="res://molecular/prey/state_machine.gd" id="9_xxtgy"]
|
||||
[ext_resource type="Script" uid="uid://ubcu8fdfxxj1" path="res://molecular/prey/state_random_movement.gd" id="10_rgguv"]
|
||||
[ext_resource type="Script" uid="uid://xbiqj7ubmj7d" path="res://molecular/prey/state_idle.gd" id="12_ubfhk"]
|
||||
[ext_resource type="Script" uid="uid://dlw7inlh6asvu" path="res://molecular/prey/state_fleeing.gd" id="12_xxtgy"]
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_66x8p"]
|
||||
animations = [{
|
||||
@@ -51,6 +51,7 @@ 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
|
||||
@@ -63,6 +64,8 @@ sprite_frames = SubResource("SpriteFrames_66x8p")
|
||||
animation = &"Healthy"
|
||||
|
||||
[node name="CollisionPolygon2D" parent="." index="1"]
|
||||
light_mask = 2
|
||||
visibility_layer = 2
|
||||
position = Vector2(6.929083, 3.0664783)
|
||||
rotation = 0.474154
|
||||
|
||||
@@ -86,8 +89,12 @@ script = ExtResource("12_ubfhk")
|
||||
one_shot = true
|
||||
|
||||
[node name="Sight" type="Area2D" parent="." index="3" 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
|
||||
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)
|
||||
|
||||
|
||||
@@ -2,18 +2,25 @@ extends State
|
||||
|
||||
@onready var timer = $Timer
|
||||
var dir = Vector3(1, 1, 0)
|
||||
var threshold = 1
|
||||
var max = 30
|
||||
|
||||
func enter(previous_state_path: String, data := {}) -> void:
|
||||
timer.start((float)(randi() % 5)/5)
|
||||
|
||||
func physics_update(_delta: float) -> void:
|
||||
owner.move(_delta * Vector3(randfn(0, 1), randfn(0, 1), 0))
|
||||
if threshold == max:
|
||||
owner.move(_delta * Vector3(randfn(0, 1), randfn(0, 1), 0), 4)
|
||||
threshold = 1
|
||||
else:
|
||||
threshold += 1
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
if (randi() % 4 != 0):
|
||||
finished.emit(owner.fsm.States.RANDOMMOVEMENT, {})
|
||||
else:
|
||||
finished.emit(owner.fsm.States.IDLE, {})
|
||||
finished.emit(owner.fsm.States.RANDOMMOVEMENT, {})
|
||||
# finished.emit(owner.fsm.States.IDLE, {})
|
||||
|
||||
func exit() -> void:
|
||||
timer.stop()
|
||||
Reference in New Issue
Block a user