ft (wip): hammerhead predator

This commit is contained in:
Djairo Hougee 2026-02-02 01:41:01 +01:00
parent b21bf52938
commit 5751f25732
22 changed files with 245 additions and 45 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ch5rddsumyyhm"
path="res://.godot/imported/predator-healthy.png-4df87d98e435e1fb3d3b0c12615f1c9b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://molecular/assets/predator/predator-healthy.png"
dest_files=["res://.godot/imported/predator-healthy.png-4df87d98e435e1fb3d3b0c12615f1c9b.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

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://dxluckxdkpv4f"]
[gd_scene format=3 uid="uid://dxluckxdkpv4f"]
[ext_resource type="Script" uid="uid://di7eglnrnqm6i" path="res://molecular/molecular_player.gd" id="1_0ix7k"]
[ext_resource type="Texture2D" uid="uid://boknmstvkc0a2" path="res://molecular/assets/player-sprite-placeholder-attacking-crop.png" id="2_5hxmy"]
@ -30,33 +30,33 @@ radius = 378.18
radius = 191.95984
height = 1295.8773
[node name="player" type="CharacterBody2D"]
collision_mask = 2
[node name="player" type="CharacterBody2D" unique_id=2032508208]
collision_mask = 6
script = ExtResource("1_0ix7k")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1745800698]
visibility_layer = 2
scale = Vector2(0.5, 0.5)
sprite_frames = SubResource("SpriteFrames_onrkg")
[node name="AttackArea" type="Area2D" parent="."]
[node name="AttackArea" type="Area2D" parent="." unique_id=187975387]
position = Vector2(0, 56)
rotation = -1.5732701
collision_mask = 2
collision_mask = 6
[node name="CollisionShape2D" type="CollisionShape2D" parent="AttackArea"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="AttackArea" unique_id=1968501358]
position = Vector2(41.029465, 288.86832)
shape = SubResource("CircleShape2D_5hxmy")
debug_color = Color(0.80813414, 0.3957308, 0.3356335, 0.41960785)
[node name="CollisionShape2D" type="CollisionShape2D" parent="." groups=["player"]]
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=2137063701 groups=["player"]]
rotation = -1.5732701
shape = SubResource("CapsuleShape2D_4flbx")
[node name="AttackTimer" type="Timer" parent="."]
[node name="AttackTimer" type="Timer" parent="." unique_id=2057433652]
one_shot = true
[node name="AttackCooldownTimer" type="Timer" parent="."]
[node name="AttackCooldownTimer" type="Timer" parent="." unique_id=1056439284]
one_shot = true
[connection signal="body_entered" from="AttackArea" to="." method="_on_attack_hit"]

File diff suppressed because one or more lines are too long

View 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})

View File

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

View File

@ -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"]

View 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}")

View File

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

View File

@ -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})

View File

@ -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)

View File

@ -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()

View File

@ -25,12 +25,13 @@ GameManager="*res://game_manager.gd"
[editor_plugins]
enabled=PackedStringArray("res://addons/godot_vim/plugin.cfg")
enabled=PackedStringArray("res://addons/godot-neovim/plugin.cfg")
[global_group]
player="All scenes that constitute players should be added here."
prey="any passive killable entities belong in this group"
predator=""
[input]
@ -64,6 +65,9 @@ try_attack={
2d_render/layer_1="Player"
2d_render/layer_2="Prey"
2d_physics/layer_1="Player"
2d_physics/layer_2="Prey"
2d_physics/layer_3="Predator"
[rendering]

View File

@ -22,15 +22,6 @@ func take_damage(dmg: int) -> void:
if self.health < 0:
self.die()
# I think the move per npc is to model concrete behaviours in functions.
# How the npc acts can be determined elsewhere, these functions just implement the behvaiour
func flee(direction: Vector3) -> void:
push_error("Function flee() not implemented.")
# Im envisioning we feed on "sustenance (to be classed)" only; when something dies it should spawn some sustenance
func feed(source ) -> void:
push_error("Function feed() not implemented.")
func die() -> void:
died.emit()
queue_free()