🐛 Allows to delete factories & force process entities

main
Ervan Lefevre 2 years ago
parent 1c498ef822
commit 2f387a1a7b
  1. 10
      nodes/npc_factory/npc_factory.tscn
  2. 24
      scripts/gameplay/rising_level.gd

@ -1,9 +1,17 @@
[gd_scene load_steps=3 format=3 uid="uid://b2hu7kxvxvgc1"]
[gd_scene load_steps=4 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"]
[sub_resource type="CircleShape2D" id="CircleShape2D_nl4mj"]
[node name="npc_factory" type="Node2D"]
script = ExtResource("1_p5cuf")
NPC_SCENE = ExtResource("2_exj6u")
SPAWN_DELAY = 2.0
[node name="factory_death" type="Area2D" parent="." groups=["factory_death"]]
monitoring = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="factory_death"]
shape = SubResource("CircleShape2D_nl4mj")

@ -2,23 +2,39 @@ extends Area2D
class_name RisingLevel
@export var RISING_SPEED = 30
const FORCE_CHECK_FREQUENCY = 5
var duration = 0
func _ready():
body_entered.connect(_body_entered)
area_entered.connect(_area_entered)
body_exited.connect(_body_exited)
func _physics_process(delta):
$shape.position.y -= RISING_SPEED * delta
self.position = self.position
duration += delta
if duration > FORCE_CHECK_FREQUENCY:
duration = 0
for body in get_overlapping_bodies():
process_body(body, true)
func _body_entered(body):
process_body(body, false)
func _area_entered(body):
if body.is_in_group("factory_death"):
body.get_parent().queue_free()
func _body_exited(body):
if body.is_in_group("player"):
body.unswim()
func process_body(body, force= false):
if force == false && body.is_in_group("player"):
body.swim()
if body.is_in_group("npc"):
body.die(RISING_SPEED)
func _body_exited(body):
if body.is_in_group("player"):
body.unswim()

Loading…
Cancel
Save