ft (wip): hammerhead predator
This commit is contained in:
38
evolve-die-repeat/molecular/predator/hammerhead_predator.gd
Normal file
38
evolve-die-repeat/molecular/predator/hammerhead_predator.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
extends AbstractPredator2D
|
||||
|
||||
# TODO: attacking logic + behaviour
|
||||
# TODO: movement is buged (seems to not move/teleport somewhat
|
||||
# TODO: mirroring (thought, extracct that to general function/resource?
|
||||
|
||||
@onready var sprite = $AnimatedSprite2D
|
||||
@onready var fsm = $StateMachine
|
||||
|
||||
@export var speed = 0.8
|
||||
var desired_rotation: float = self.rotation
|
||||
|
||||
func _ready() -> void:
|
||||
health = maxHealth
|
||||
sprite.play("Healthy")
|
||||
|
||||
|
||||
# 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
|
||||
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)
|
||||
|
||||
|
||||
func _on_sight_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("prey") or (health < maxHealth and body.is_in_group("player")):
|
||||
fsm.transition_to_next_state(fsm.States.HUNTING, {"target": body})
|
||||
@@ -0,0 +1 @@
|
||||
uid://d07cjelbqbiug
|
||||
@@ -0,0 +1,85 @@
|
||||
[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="Texture2D" uid="uid://ch5rddsumyyhm" path="res://molecular/assets/predator/predator-healthy.png" id="2_34kwa"]
|
||||
[ext_resource type="Script" uid="uid://cygrmt03sx0k1" path="res://molecular/predator/state_machine.gd" id="3_xp037"]
|
||||
[ext_resource type="Script" uid="uid://xbiqj7ubmj7d" path="res://molecular/prey/state_idle.gd" id="4_8a23j"]
|
||||
[ext_resource type="Script" uid="uid://ubcu8fdfxxj1" path="res://molecular/prey/state_random_movement.gd" id="5_6rsu5"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_8a23j"]
|
||||
atlas = ExtResource("2_34kwa")
|
||||
region = Rect2(0, 0, 64, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_6rsu5"]
|
||||
atlas = ExtResource("2_34kwa")
|
||||
region = Rect2(64, 0, 64, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0ts4d"]
|
||||
atlas = ExtResource("2_34kwa")
|
||||
region = Rect2(128, 0, 64, 64)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_shhro"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 3.0,
|
||||
"texture": SubResource("AtlasTexture_8a23j")
|
||||
}, {
|
||||
"duration": 2.0,
|
||||
"texture": SubResource("AtlasTexture_6rsu5")
|
||||
}, {
|
||||
"duration": 4.0,
|
||||
"texture": SubResource("AtlasTexture_0ts4d")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"Healthy",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[node name="HammerheadPredator" type="CharacterBody2D" unique_id=678504815 groups=["predator"]]
|
||||
scale = Vector2(0.3, 0.3)
|
||||
collision_layer = 4
|
||||
collision_mask = 3
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_xp037")
|
||||
maxHealth = 50
|
||||
metadata/_custom_type_script = "uid://dgfimmq53whll"
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=410999609]
|
||||
sprite_frames = SubResource("SpriteFrames_shhro")
|
||||
animation = &"Healthy"
|
||||
|
||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." unique_id=1596156928]
|
||||
light_mask = 4
|
||||
visibility_layer = 4
|
||||
position = Vector2(0.11167908, 1.1167793)
|
||||
polygon = PackedVector2Array(-22.184862, -27.994831, 23.481365, -27.21198, 13.82622, 25.891317, -6.005971, 25.891317)
|
||||
|
||||
[node name="StateMachine" type="Node" parent="." unique_id=1857729810 node_paths=PackedStringArray("initial_state")]
|
||||
script = ExtResource("3_xp037")
|
||||
initial_state = NodePath("Idle")
|
||||
metadata/_custom_type_script = "uid://ck7k8ht54snsy"
|
||||
|
||||
[node name="Idle" type="Node" parent="StateMachine" unique_id=265876039]
|
||||
script = ExtResource("4_8a23j")
|
||||
metadata/_custom_type_script = "uid://co2xp7gauamql"
|
||||
|
||||
[node name="Timer" type="Timer" parent="StateMachine/Idle" unique_id=1870665609]
|
||||
one_shot = true
|
||||
|
||||
[node name="RandomMovement" type="Node" parent="StateMachine" unique_id=105315122]
|
||||
script = ExtResource("5_6rsu5")
|
||||
metadata/_custom_type_script = "uid://co2xp7gauamql"
|
||||
|
||||
[node name="Timer" type="Timer" parent="StateMachine/RandomMovement" unique_id=447822526]
|
||||
one_shot = true
|
||||
|
||||
[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
|
||||
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)
|
||||
|
||||
[connection signal="body_entered" from="Sight" to="." method="_on_sight_body_entered"]
|
||||
18
evolve-die-repeat/molecular/predator/state_machine.gd
Normal file
18
evolve-die-repeat/molecular/predator/state_machine.gd
Normal file
@@ -0,0 +1,18 @@
|
||||
extends StateMachine
|
||||
|
||||
enum States {IDLE, RANDOMMOVEMENT, FEEDING, FLEEING, HUNTING}
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
super()
|
||||
await owner.ready
|
||||
|
||||
|
||||
func transition_to_next_state(target: int, data: Dictionary = {}) -> void:
|
||||
match target:
|
||||
States.IDLE: _transition_to_next_state("Idle", data)
|
||||
States.RANDOMMOVEMENT: _transition_to_next_state("RandomMovement", data)
|
||||
States.FEEDING: _transition_to_next_state("Feeding", data)
|
||||
States.FLEEING: _transition_to_next_state("Fleeing", data)
|
||||
States.HUNTING: _transition_to_next_state("Hunting", data)
|
||||
_: push_error("Trying to transition to unknown state {target}")
|
||||
@@ -0,0 +1 @@
|
||||
uid://cygrmt03sx0k1
|
||||
Reference in New Issue
Block a user