ft (very very wip): prey impl

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

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)