ft (wip): molecular stage prey
This commit is contained in:
39
evolve-die-repeat/molecular/preyManager.gd
Normal file
39
evolve-die-repeat/molecular/preyManager.gd
Normal file
@@ -0,0 +1,39 @@
|
||||
extends Node
|
||||
|
||||
@export var preyScene: PackedScene
|
||||
var score
|
||||
|
||||
# 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_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)
|
||||
Reference in New Issue
Block a user