update
This commit is contained in:
34
portal/gate.gd
Normal file
34
portal/gate.gd
Normal file
@@ -0,0 +1,34 @@
|
||||
extends StaticBody3D
|
||||
|
||||
@export var target_scene: String = "res://dungeon/dungeon.tscn"
|
||||
@export var is_exit: bool = false
|
||||
|
||||
var active := false
|
||||
|
||||
func _ready() -> void:
|
||||
if not is_exit:
|
||||
if GameState.dungeon_cleared:
|
||||
queue_free()
|
||||
return
|
||||
get_tree().create_timer(0.5).timeout.connect(_check_overlapping)
|
||||
else:
|
||||
get_tree().create_timer(1.0).timeout.connect(func() -> void: active = true)
|
||||
|
||||
func _check_overlapping() -> void:
|
||||
active = true
|
||||
for body in $GateArea.get_overlapping_bodies():
|
||||
_on_gate_area_body_entered(body)
|
||||
|
||||
func _on_gate_area_body_entered(body: Node3D) -> void:
|
||||
if not active:
|
||||
return
|
||||
if body is CharacterBody3D and body.name == "Player":
|
||||
GameState.save_player(body)
|
||||
if is_exit:
|
||||
GameState.returning_from_dungeon = true
|
||||
else:
|
||||
GameState.portal_position = global_position
|
||||
call_deferred("_change_scene")
|
||||
|
||||
func _change_scene() -> void:
|
||||
get_tree().change_scene_to_file(target_scene)
|
||||
1
portal/gate.gd.uid
Normal file
1
portal/gate.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ctci5mc3cd2ck
|
||||
36
portal/gate.tscn
Normal file
36
portal/gate.tscn
Normal file
@@ -0,0 +1,36 @@
|
||||
[gd_scene format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://portal/gate.gd" id="1"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_1"]
|
||||
albedo_color = Color(0.1, 0.9, 0.3, 1)
|
||||
emission_enabled = true
|
||||
emission = Color(0.1, 0.9, 0.3, 1)
|
||||
emission_energy_multiplier = 0.5
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_1"]
|
||||
top_radius = 1.0
|
||||
bottom_radius = 1.0
|
||||
height = 2.0
|
||||
material = SubResource("StandardMaterial3D_1")
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_1"]
|
||||
radius = 3.0
|
||||
|
||||
[node name="Gate" type="StaticBody3D"]
|
||||
script = ExtResource("1")
|
||||
collision_layer = 0
|
||||
collision_mask = 0
|
||||
|
||||
[node name="Mesh" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("CylinderMesh_1")
|
||||
|
||||
[node name="GateArea" type="Area3D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 1
|
||||
monitoring = true
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="GateArea"]
|
||||
shape = SubResource("SphereShape3D_1")
|
||||
|
||||
[connection signal="body_entered" from="GateArea" to="." method="_on_gate_area_body_entered"]
|
||||
33
portal/portal.gd
Normal file
33
portal/portal.gd
Normal file
@@ -0,0 +1,33 @@
|
||||
extends StaticBody3D
|
||||
|
||||
@export var stats: BaseStats
|
||||
|
||||
const GATE_SCENE: PackedScene = preload("res://portal/gate.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("portals")
|
||||
Stats.register(self, stats)
|
||||
EventBus.entity_died.connect(_on_entity_died)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
Stats.deregister(self)
|
||||
|
||||
func _on_entity_died(entity: Node) -> void:
|
||||
if entity != self:
|
||||
return
|
||||
if not is_inside_tree():
|
||||
return
|
||||
var pos: Vector3 = global_position
|
||||
var gate: Node3D = GATE_SCENE.instantiate()
|
||||
gate.global_position = pos
|
||||
get_parent().add_child(gate)
|
||||
var enemies := get_tree().get_nodes_in_group("enemies")
|
||||
for enemy in enemies:
|
||||
if is_instance_valid(enemy):
|
||||
enemy.queue_free()
|
||||
EventBus.portal_defeated.emit(self)
|
||||
queue_free()
|
||||
|
||||
func _on_detection_area_body_entered(body: Node3D) -> void:
|
||||
if body is CharacterBody3D and body.name == "Player":
|
||||
EventBus.enemy_engaged.emit(self, body)
|
||||
1
portal/portal.gd.uid
Normal file
1
portal/portal.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://byjxj4mq84gki
|
||||
84
portal/portal.tscn
Normal file
84
portal/portal.tscn
Normal file
@@ -0,0 +1,84 @@
|
||||
[gd_scene format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://portal/portal.gd" id="1"]
|
||||
[ext_resource type="Script" path="res://components/healthbar.gd" id="3"]
|
||||
[ext_resource type="Resource" path="res://resources/stats/portal_stats.tres" id="6"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_1"]
|
||||
radius = 10.0
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_1"]
|
||||
radius = 1.0
|
||||
height = 2.0
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_2"]
|
||||
radius = 1.0
|
||||
height = 2.0
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_1"]
|
||||
albedo_color = Color(0.5, 0.1, 0.8, 1)
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_1"]
|
||||
top_radius = 1.0
|
||||
bottom_radius = 1.0
|
||||
height = 2.0
|
||||
material = SubResource("StandardMaterial3D_1")
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_health_bg"]
|
||||
bg_color = Color(0.3, 0.1, 0.1, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_health_fill"]
|
||||
bg_color = Color(0.2, 0.8, 0.2, 1)
|
||||
|
||||
[node name="Portal" type="StaticBody3D"]
|
||||
script = ExtResource("1")
|
||||
stats = ExtResource("6")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CylinderShape3D_1")
|
||||
|
||||
[node name="Mesh" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("CylinderMesh_1")
|
||||
|
||||
[node name="HitArea" type="Area3D" parent="."]
|
||||
collision_layer = 4
|
||||
collision_mask = 0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="HitArea"]
|
||||
shape = SubResource("CylinderShape3D_2")
|
||||
|
||||
[node name="DetectionArea" type="Area3D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 1
|
||||
monitoring = true
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="DetectionArea"]
|
||||
shape = SubResource("SphereShape3D_1")
|
||||
|
||||
[node name="Healthbar" type="Sprite3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.5, 0)
|
||||
billboard = 1
|
||||
pixel_size = 0.01
|
||||
script = ExtResource("3")
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="Healthbar"]
|
||||
transparent_bg = true
|
||||
size = Vector2i(104, 15)
|
||||
|
||||
[node name="Border" type="ColorRect" parent="Healthbar/SubViewport"]
|
||||
offset_right = 104.0
|
||||
offset_bottom = 15.0
|
||||
color = Color(1, 0.9, 0.2, 1)
|
||||
|
||||
[node name="HealthBar" type="ProgressBar" parent="Healthbar/SubViewport"]
|
||||
offset_left = 2.0
|
||||
offset_top = 2.0
|
||||
offset_right = 102.0
|
||||
offset_bottom = 13.0
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_health_bg")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_health_fill")
|
||||
max_value = 500.0
|
||||
value = 500.0
|
||||
show_percentage = false
|
||||
|
||||
[connection signal="body_entered" from="DetectionArea" to="." method="_on_detection_area_body_entered"]
|
||||
Reference in New Issue
Block a user