mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-11-14 04:57:19 +01:00
1a37b2bee0
Used `var variable := 0.0` as discussed in the Godot issue, instead of `var variable: = 0.0`. Mostly these are minor/cosmetic changes, but I've also reorganized the folder structure (naming of folders) to reflect our guidelines, plus made some minor changes to the demo codes. Still work in progress.
72 lines
1.8 KiB
GDScript
72 lines
1.8 KiB
GDScript
extends Node2D
|
|
# Access helper class for children to access window boundaries.
|
|
|
|
|
|
enum Mode { FLEE, SEEK }
|
|
|
|
export(Mode) var behavior_mode := Mode.SEEK setget set_behavior_mode
|
|
export(float, 0, 2000, 40) var max_linear_speed := 200.0 setget set_max_linear_speed
|
|
export(float, 0, 500, 0.5) var max_linear_accel := 10.0 setget set_max_linear_accel
|
|
|
|
var camera_boundaries: Rect2
|
|
|
|
onready var player: KinematicBody2D = $Player
|
|
onready var spawner: Node2D = $Spawner
|
|
|
|
|
|
func _ready() -> void:
|
|
camera_boundaries = Rect2(
|
|
Vector2.ZERO,
|
|
Vector2(
|
|
ProjectSettings["display/window/size/width"],
|
|
ProjectSettings["display/window/size/height"]
|
|
)
|
|
)
|
|
|
|
var rng := RandomNumberGenerator.new()
|
|
rng.randomize()
|
|
|
|
for i in range(spawner.entity_count):
|
|
var new_pos := Vector2(
|
|
rng.randf_range(-camera_boundaries.size.x/2, camera_boundaries.size.x/2),
|
|
rng.randf_range(-camera_boundaries.size.y/2, camera_boundaries.size.y/2)
|
|
)
|
|
var entity: KinematicBody2D = spawner.Entity.instance()
|
|
entity.global_position = new_pos
|
|
entity.player_agent = player.agent
|
|
entity.start_speed = max_linear_speed
|
|
entity.start_accel = max_linear_accel
|
|
spawner.add_child(entity)
|
|
|
|
|
|
func set_behavior_mode(mode: int) -> void:
|
|
if not is_inside_tree():
|
|
return
|
|
|
|
behavior_mode = mode
|
|
match mode:
|
|
Mode.SEEK:
|
|
for child in spawner.get_children():
|
|
child.use_seek = true
|
|
Mode.FLEE:
|
|
for child in spawner.get_children():
|
|
child.use_seek = false
|
|
|
|
|
|
func set_max_linear_speed(value: float) -> void:
|
|
if not is_inside_tree():
|
|
return
|
|
|
|
max_linear_speed = value
|
|
for child in spawner.get_children():
|
|
child.agent.max_linear_speed = value
|
|
|
|
|
|
func set_max_linear_accel(value: float) -> void:
|
|
if not is_inside_tree():
|
|
return
|
|
|
|
max_linear_accel = value
|
|
for child in spawner.get_children():
|
|
child.agent.max_linear_acceleration = value
|