ft (Wip): FSM behaviour prey

This commit is contained in:
Djairo Hougee 2026-01-23 10:48:14 +01:00
parent 0b9b1e75d4
commit c11afd9ddd
24 changed files with 154 additions and 54 deletions

View File

@ -0,0 +1,8 @@
@tool
extends GodotVimPlugin
func _enter_tree():
pass
func _exit_tree():
pass

View File

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

View File

@ -0,0 +1,12 @@
[configuration]
entry_symbol = "gdext_rust_init"
compatibility_minimum = "4.5"
reloadable = true
[libraries]
linux.debug.x86_64 = "res://addons/godot_vim/bin/libgodot_vim.so"
linux.release.x86_64 = "res://addons/godot_vim/bin/libgodot_vim.so"
windows.debug.x86_64 = "res://addons/godot_vim/bin/godot_vim.dll"
windows.release.x86_64 = "res://addons/godot_vim/bin/godot_vim.dll"
macos.debug.universal = "res://addons/godot_vim/bin/libgodot_vim.dylib"
macos.release.universal = "res://addons/godot_vim/bin/libgodot_vim.dylib"

View File

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

View File

@ -0,0 +1,6 @@
[plugin]
name="GodotVim"
description="Vim emulation for Godot's script editor"
author="hmdfrds"
version="0.1.4"
script="godot_vim.gd"

View File

@ -2,6 +2,7 @@ extends Node
var screen_size = Vector2(1920.0, 1080.0) # Default screen size (this is a float for some reason)
var viewport_size
@onready var extent: Rect2 = get_viewport().get_visible_rect()
func _ready() -> void:
viewport_size = get_viewport().get_visible_rect().size

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

View File

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

@ -20,8 +20,6 @@ func _ready() -> void:
attack_timer.wait_time = attack_duration
attack_cooldown_timer.wait_time = attack_cooldown_duration
func _process(delta):
velocity = Vector2.ZERO
if Input.is_action_pressed("move_right"):

View File

@ -14,7 +14,7 @@ tile_data = PackedInt32Array(0, 65536, 2, 65536, 65536, 3, 1, 131072, 2, 65537,
tile_data = PackedInt32Array(0, 196608, 2, 65536, 196608, 3, 1, 262144, 2, 65537, 262144, 3)
[sub_resource type="TileMapPattern" id="TileMapPattern_mys4o"]
tile_data = PackedInt32Array(0, 196608, 0, 65536, 196608, 1, 1, 262144, 0, 65537, 262144, 1)
tile_data = PackedInt32Array(0, 196608, 0, 65536, 196608, 1)
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_b1jr0"]
resource_name = "Background tileset"
@ -76,6 +76,7 @@ tile_map_data = PackedByteArray("AAAAAAAAAAAAAAIAAAAAAAEAAAAAAAIAAAAAAAIAAAAAAAI
tile_set = SubResource("TileSet_mys4o")
[node name="ParallaxNear" type="Parallax2D" parent="Background"]
z_index = 5
scroll_scale = Vector2(0.9, 0.9)
repeat_times = 7

View File

@ -11,8 +11,7 @@ var mirrorSprite3: Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
health = maxHealth
sprite.animation = "Healthy"
sprite.play()
sprite.play("Healthy")
mirrorSprite1 = sprite.duplicate()
mirrorSprite2 = sprite.duplicate()

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://c3iw2v3x6ngrb"]
[gd_scene load_steps=12 format=3 uid="uid://c3iw2v3x6ngrb"]
[ext_resource type="PackedScene" uid="uid://bvsdg1v3ksixy" path="res://shared/npc/prey2D.tscn" id="1_qvulj"]
[ext_resource type="Script" uid="uid://bgossk6xo31gi" path="res://molecular/nucleotide_prey.gd" id="2_0227s"]
@ -8,11 +8,13 @@
[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://c7o7sp02u0wkv" path="res://molecular/nucleotide_prey_state.gd" id="9_guu3v"]
[ext_resource type="Script" uid="uid://ubcu8fdfxxj1" path="res://molecular/nucleotide_prey_foraging.gd" id="10_rgguv"]
[sub_resource type="SpriteFrames" id="SpriteFrames_66x8p"]
animations = [{
"frames": [{
"duration": 20.0,
"duration": 1.0,
"texture": ExtResource("2_lkj7f")
}, {
"duration": 20.0,
@ -23,7 +25,7 @@ animations = [{
"speed": 1.0
}, {
"frames": [{
"duration": 20.0,
"duration": 1.0,
"texture": ExtResource("4_ee1gb")
}, {
"duration": 20.0,
@ -34,7 +36,7 @@ animations = [{
"speed": 1.0
}, {
"frames": [{
"duration": 20.0,
"duration": 1.0,
"texture": ExtResource("6_0f87h")
}, {
"duration": 20.0,
@ -54,4 +56,17 @@ maxHealth = 20
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"]
scale = Vector2(0.1, 0.1)
sprite_frames = SubResource("SpriteFrames_66x8p")
animation = &"Dying"
animation = &"Injured"
[node name="State" type="Node" parent="." index="2"]
script = ExtResource("9_guu3v")
metadata/_custom_type_script = "uid://co2xp7gauamql"
[node name="Foraging" type="Node" parent="State" index="0"]
script = ExtResource("10_rgguv")
metadata/_custom_type_script = "uid://c7o7sp02u0wkv"
[node name="Timer" type="Timer" parent="State/Foraging" index="0"]
one_shot = true
[connection signal="timeout" from="State/Foraging/Timer" to="State/Foraging" method="_on_timer_timeout"]

View File

@ -0,0 +1,17 @@
extends NucleotidePreyState
@onready var timer = $Timer
var dir: float = 0.0
func enter(previous_state_path: String, data := {}) -> void:
timer.start(randi() % 5)
dir = randi() % 360
func physics_update(_delta: float) -> void:
# TODO: move in direction of dir
pass
func _on_timer_timeout() -> void:
dir = randi() % 360
timer.start(randi() % 5)

View File

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

View File

@ -0,0 +1,6 @@
class_name NucleotidePreyState extends State
enum State {IDLE, FORAGING, FEEDING, FLEEING}
func _ready() -> void:
await owner.ready

View File

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

View File

@ -1,10 +1,11 @@
extends SpawnManager2D
@export var cam: Camera2D
#@export var cam: Camera2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
spawnRange = cam.get_viewport_rect()
spawnRange = GameManager.extent
#spawnRange = cam.get_viewport_rect()
_spawn_minimum()

View File

@ -19,6 +19,10 @@ config/icon="res://icon.svg"
GameManager="*res://game_manager.gd"
[editor_plugins]
enabled=PackedStringArray("res://addons/godot_vim/plugin.cfg")
[global_group]
player="All scenes that constitute players should be added here."

View File

@ -1,6 +1,10 @@
extends NPC2D
class_name AbstractPrey2D
enum States {IDLE, FORAGING, FLEEING}
var state = States.IDLE
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.

View File

@ -1,11 +1,10 @@
extends Node
class_name SpawnManager2D
#var scene = preload("res://molecular/nucleotide_prey.tscn")
@export var scene: PackedScene
@export var minCount = 1
@export var maxCount = 2
@export var spawnRange: Rect2
@export var spawnRange: Rect2 = Rect2(0, 0, 0, 0)
var _currentCount = 0

View File

@ -0,0 +1,24 @@
class_name State extends Node
# Emits on state completion
signal finished(next_state_path: String, data: Dictionary)
# Called by StateMachine on unhandled input
func handle_input(_event: InputEvent) -> void:
pass
# Main update loop
func update(_delta: float) -> void:
pass
# Physics update loop
func physics_update(_delta: float) -> void:
pass
# Called by StateMachine on state change. Data contains arbitrary data to initialize state.
func enter(previous_state_path: String, data := {}) -> void:
pass
# Called by StateMachine before state change. Should be used for cleanup.
func exit() -> void:
pass

View File

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

View File

@ -0,0 +1,39 @@
class_name StateMachine extends Node
@export var initial_state: State = null
# use first child as 'active' state
@onready var state: State = (func get_initial_state() -> State:
return initial_state if initial_state != null else get_child(0)
).call()
# Connect states on ready, then wait.
func _ready() -> void:
for node: State in find_children("*", "State"):
node.finished.connect(_transition_to_next_state)
await owner.ready
state.enter("")
# pass unhandled input to state.
func _unhandled_input(event: InputEvent) -> void:
state.handle_input(event)
# Pass process tick to state.
func _process(delta: float) -> void:
state.update(delta)
# Pass physics tick to state.
func _physics_process(delta: float) -> void:
state.physics_update(delta)
# Transition to next state
func _transition_to_next_state(target_path: String, data: Dictionary = {}) -> void:
if not has_node(target_path):
printerr(owner.name + ": Trying to transition to state " + target_path + ", which does not exist.")
return
var previous_state_path := state.name
state.exit()
state = get_node(target_path)
state.enter(previous_state_path, data)

View File

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