Adds NPCFactory that populates the level

main
Ervan Lefevre 2 years ago
parent 90500c2ee1
commit 478b5b9c60
  1. 4
      nodes/npc/npc.tscn
  2. 20
      nodes/npc_factory/npc_factory.gd
  3. 9
      nodes/npc_factory/npc_factory.tscn
  4. 31
      scenes/poc.tscn

@ -5,8 +5,8 @@
[ext_resource type="Script" path="res://scripts/ia/fsm.gd" id="3_vhp64"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_f223n"]
radius = 4.0
height = 14.0
radius = 1.0
height = 4.0
[node name="npc" type="CharacterBody2D"]
script = ExtResource("1_38jh5")

@ -0,0 +1,20 @@
extends Node2D
class_name NpcFactory
@export var NPC_SCENE: PackedScene
@export var SPAWN_DELAY: float = 0.5
var current_spawn_duration = 0
func _ready():
if !NPC_SCENE:
push_error("npc scene is null")
func _physics_process(delta):
current_spawn_duration += delta
if current_spawn_duration > SPAWN_DELAY:
current_spawn_duration = 0
var npc = NPC_SCENE.instantiate()
add_child(npc)

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://b2hu7kxvxvgc1"]
[ext_resource type="Script" path="res://nodes/npc_factory/npc_factory.gd" id="1_p5cuf"]
[ext_resource type="PackedScene" uid="uid://dvx48q5ecyxjs" path="res://nodes/npc/npc.tscn" id="2_exj6u"]
[node name="npc_factory" type="Node2D"]
script = ExtResource("1_p5cuf")
NPC_SCENE = ExtResource("2_exj6u")
SPAWN_DELAY = 2.0

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save