ft (very very wip): prey impl

This commit is contained in:
Djairo Hougee 2025-12-19 20:07:53 +01:00
parent 551482e209
commit a5055a523f
19 changed files with 226 additions and 55 deletions

View File

@ -0,0 +1,15 @@
extends NPC
class_name AbstractPredator
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func attack(target) -> void:
push_error("Function attack() not implemented.")

View File

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

View File

@ -0,0 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://b7wqd5owafn6g"]
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://npc.tscn" id="1_eoj71"]
[ext_resource type="Script" uid="uid://dgfimmq53whll" path="res://abstract_predator.gd" id="2_hv0s6"]
[node name="AbstractPredator" instance=ExtResource("1_eoj71")]
script = ExtResource("2_hv0s6")

View File

@ -1,5 +1,5 @@
extends RigidBody2D
extends NPC
class_name AbstractPrey
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@ -10,6 +10,3 @@ func _ready() -> void:
func _process(delta: float) -> void:
pass
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free();

View File

@ -0,0 +1 @@
uid://76jxpubyd8wp

View File

@ -0,0 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://bvsdg1v3ksixy"]
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://npc.tscn" id="1_2m1le"]
[ext_resource type="Script" uid="uid://76jxpubyd8wp" path="res://abstract_prey.gd" id="2_dny00"]
[node name="AbstractPrey" instance=ExtResource("1_2m1le")]
script = ExtResource("2_dny00")

View File

@ -1,7 +1,8 @@
extends Area2D
extends CharacterBody2D
@export var speed = 400
var screen_size
var str = 1
func _ready():
screen_size = get_viewport_rect().size

View File

@ -18,14 +18,16 @@ animations = [{
radius = 191.95984
height = 1295.8773
[node name="player" type="Area2D"]
[node name="player" type="CharacterBody2D"]
collision_mask = 2
script = ExtResource("1_0ix7k")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
visibility_layer = 2
scale = Vector2(0.5, 0.5)
sprite_frames = SubResource("SpriteFrames_onrkg")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="." groups=["player"]]
position = Vector2(0, 56)
rotation = -1.5732701
shape = SubResource("CapsuleShape2D_4flbx")

View File

@ -1,17 +1,10 @@
[gd_scene load_steps=8 format=3 uid="uid://b55w56d4twno1"]
[gd_scene load_steps=6 format=3 uid="uid://b55w56d4twno1"]
[ext_resource type="Texture2D" uid="uid://dnlrq8gxiix6" path="res://molecular/assets/bg-far-placeholder.jpg" id="1_cthuy"]
[ext_resource type="Texture2D" uid="uid://bfjf6dxvbq5cj" path="res://dirt-specs.png" id="2_a5cls"]
[ext_resource type="PackedScene" uid="uid://dxluckxdkpv4f" path="res://molecular/molecular_player.tscn" id="3_b1jr0"]
[ext_resource type="Script" uid="uid://ceut2lrvkns75" path="res://debug_label.gd" id="4_mys4o"]
[ext_resource type="Script" uid="uid://2pmjtnrg5471" path="res://molecular/preyManager.gd" id="5_ojt85"]
[ext_resource type="PackedScene" uid="uid://cum0iux1pv7bu" path="res://molecular/prey.tscn" id="6_a5cls"]
[sub_resource type="Curve2D" id="Curve2D_4kroc"]
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 5, 78, 0, 0, 0, 0, 234, 81, 0, 0, 0, 0, 234, 209, 0, 0, 0, 0, 5, 209, 0, 0, 0, 0, 5, 77)
}
point_count = 5
[node name="MolecularStag" type="Node2D"]
@ -40,7 +33,7 @@ position = Vector2(596, 359.5)
scale = Vector2(3.725, 2.4159663)
texture = ExtResource("2_a5cls")
[node name="player" parent="." instance=ExtResource("3_b1jr0")]
[node name="player" parent="." groups=["player"] instance=ExtResource("3_b1jr0")]
position = Vector2(120, 144)
scale = Vector2(0.01, 0.01)
@ -66,11 +59,3 @@ script = ExtResource("4_mys4o")
[node name="Prey" type="Node" parent="."]
script = ExtResource("5_ojt85")
preyScene = ExtResource("6_a5cls")
[node name="PreyPath" type="Path2D" parent="Prey"]
curve = SubResource("Curve2D_4kroc")
[node name="PreySpawnLocation" type="PathFollow2D" parent="Prey/PreyPath"]
position = Vector2(5, 78)
rotation = 0.013099688

View File

@ -0,0 +1,37 @@
extends AbstractPrey
@onready var sprite = get_node("AnimatedSprite2D")
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
self.move(Vector3(randfn(0, 1), randfn(0, 1), 0))
return
func move(destination: Vector3) -> void:
self.position += Vector2(destination.x, destination.y) # stub
func _on_rigid_body_2d_body_entered(body: Node) -> void:
# TODO: collision with other entities
# check if colision with player
print("we collidin")
if body.is_in_group("player"):
handle_collision_player(body)
else:
self.die()
# Function to handle collision logic
func handle_collision_player(player):
print("Collision!")
self.health -= player.str
if sprite:
if self.health <= 0:
self.die()
else:
sprite.play("injured")

View File

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

View File

@ -0,0 +1,63 @@
[gd_scene load_steps=10 format=3 uid="uid://c3iw2v3x6ngrb"]
[ext_resource type="PackedScene" uid="uid://bvsdg1v3ksixy" path="res://abstract_prey.tscn" id="1_qvulj"]
[ext_resource type="Script" uid="uid://bgossk6xo31gi" path="res://molecular/nucleotide_prey.gd" id="2_0227s"]
[ext_resource type="Texture2D" uid="uid://bhcb5g7g7um8" path="res://molecular/assets/prey/prey-dying-frame0.png" id="2_lkj7f"]
[ext_resource type="Texture2D" uid="uid://bxn11avw7dykl" path="res://molecular/assets/prey/prey-dying-frame1.png" id="3_svqyr"]
[ext_resource type="Texture2D" uid="uid://ctkehsavw6ghx" path="res://molecular/assets/prey/prey-healthy-frame0.png" id="4_ee1gb"]
[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"]
[sub_resource type="SpriteFrames" id="SpriteFrames_66x8p"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("2_lkj7f")
}, {
"duration": 1.0,
"texture": ExtResource("3_svqyr")
}],
"loop": true,
"name": &"Dying",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("4_ee1gb")
}, {
"duration": 1.0,
"texture": ExtResource("5_ae5nf")
}],
"loop": true,
"name": &"Healthy",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("6_0f87h")
}, {
"duration": 1.0,
"texture": ExtResource("7_w7inl")
}],
"loop": true,
"name": &"Injured",
"speed": 5.0
}]
[node name="NucleotidePrey" instance=ExtResource("1_qvulj")]
script = ExtResource("2_0227s")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"]
scale = Vector2(0.1, 0.1)
sprite_frames = SubResource("SpriteFrames_66x8p")
animation = &"Healthy"
[node name="RigidBody2D" type="RigidBody2D" parent="." index="1"]
collision_layer = 2
collision_mask = 3
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="RigidBody2D" index="0"]
polygon = PackedVector2Array(-16.442108, -21.739502, 14.039459, -23.432922, 29.280273, 3.097351, 12.346039, 27.369736, -17.571075, 29.62761, -32.247375, 1.968399)
[connection signal="body_entered" from="RigidBody2D" to="." method="_on_rigid_body_2d_body_entered"]

View File

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

View File

@ -1,6 +1,5 @@
[gd_scene load_steps=9 format=3 uid="uid://cum0iux1pv7bu"]
[ext_resource type="Script" uid="uid://d1b3twb5c47c0" path="res://molecular/prey.gd" id="1_wojl0"]
[ext_resource type="Texture2D" uid="uid://bhcb5g7g7um8" path="res://molecular/assets/prey/prey-dying-frame0.png" id="2_5mr0w"]
[ext_resource type="Texture2D" uid="uid://bxn11avw7dykl" path="res://molecular/assets/prey/prey-dying-frame1.png" id="3_eomdj"]
[ext_resource type="Texture2D" uid="uid://ctkehsavw6ghx" path="res://molecular/assets/prey/prey-healthy-frame0.png" id="4_t6vdg"]
@ -8,6 +7,24 @@
[ext_resource type="Texture2D" uid="uid://btnyajci8ptb2" path="res://molecular/assets/prey/prey-injured-frame0.png" id="6_o44iv"]
[ext_resource type="Texture2D" uid="uid://bqll8ge4cr2uf" path="res://molecular/assets/prey/prey-injured-frame1.png" id="7_wx0y7"]
[sub_resource type="GDScript" id="GDScript_56kmc"]
script/source = "extends RigidBody2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free();
"
[sub_resource type="SpriteFrames" id="SpriteFrames_43b72"]
animations = [{
"frames": [{
@ -46,7 +63,7 @@ animations = [{
[node name="Prey" type="RigidBody2D"]
gravity_scale = 0.379
script = ExtResource("1_wojl0")
script = SubResource("GDScript_56kmc")
metadata/_edit_group_ = true
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]

View File

@ -1,39 +1,27 @@
extends Node
@export var preyScene: PackedScene
var preyScene = preload("res://molecular/nucleotide_prey.tscn")
#var predatorScene = preload("res://Predator.tscn")
var score
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
for i in range(0, 100, 10):
spawn_creature(preyScene, Vector2(i, i))
spawn_random()
spawn_random()
spawn_random()
spawn_random()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func spawn_random() -> void:
spawn_creature(preyScene, Vector2(randfn(100, 100), randfn(100, 100)))
func _on_prey_timer_timeout() -> void:
# Create a new instance of the Mob scene.
var prey = preyScene.instantiate()
# Choose a random location on Path2D.
var preySpawnLocation = $PreyPath/PreySpawnLocation
preySpawnLocation.progress_ratio = randf()
# Set the mob's position to the random location.
prey.position = preySpawnLocation.position
# Set the mob's direction perpendicular to the path direction.
var direction = preySpawnLocation.rotation + PI / 2
# Add some randomness to the direction.
direction += randf_range(-PI / 4, PI / 4)
prey.rotation = direction
# Choose the velocity for the mob.
var velocity = Vector2(randf_range(50.0, 100.0), 0.0)
prey.linear_velocity = velocity.rotated(direction)
# Spawn the mob by adding it to the Main scene.
add_child(prey)
func spawn_creature(scene, position: Vector2) -> void:
var instance = scene.instantiate()
instance.position = position
add_child(instance)

34
evolve-die-repeat/npc.gd Normal file
View File

@ -0,0 +1,34 @@
extends Node2D
class_name NPC
@export var maxHealth: int = 0
var health: int = maxHealth
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
spawn()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func spawn() -> void:
pass
# 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:
queue_free()
# TODO: should associate this class with a loot table (or equivalent), and can then implement logic for dying in parent class here.
func move(destination: Vector3) -> void:
push_error("Function move() not implemented.")

View File

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

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://biup0eej85fq2"]
[ext_resource type="Script" uid="uid://biu3sctw15ga" path="res://npc.gd" id="1_ideak"]
[node name="NPC" type="Node2D"]
script = ExtResource("1_ideak")

View File

@ -15,6 +15,10 @@ run/main_scene="uid://drgv154ei1vrl"
config/features=PackedStringArray("4.5", "Forward Plus")
config/icon="res://icon.svg"
[global_group]
player="All scenes that constitute players should be added here."
[input]
move_right={
@ -37,3 +41,8 @@ move_down={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
]
}
[layer_names]
2d_render/layer_1="Player"
2d_render/layer_2="Prey"