GUI and pathfinding expansions and resting places.
This commit is contained in:
parent
26ee79c57d
commit
27964084ff
6 changed files with 70 additions and 16 deletions
6
scenes/maps/elements/rest.tscn
Normal file
6
scenes/maps/elements/rest.tscn
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://bn60ywtwfn7bq"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/maps/rest.gd" id="1_m76x3"]
|
||||||
|
|
||||||
|
[node name="Rest" type="Node3D"]
|
||||||
|
script = ExtResource("1_m76x3")
|
|
@ -1,6 +1,7 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://cbyee7drds7qu"]
|
[gd_scene load_steps=9 format=3 uid="uid://cbyee7drds7qu"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/maps/map.gd" id="1_4npcs"]
|
[ext_resource type="Script" path="res://scripts/maps/map.gd" id="1_4npcs"]
|
||||||
|
[ext_resource type="Script" path="res://scripts/maps/rest.gd" id="2_yv1d0"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bsghm187n6ykx" path="res://scenes/objects/closet.tscn" id="2_yvpvm"]
|
[ext_resource type="PackedScene" uid="uid://bsghm187n6ykx" path="res://scenes/objects/closet.tscn" id="2_yvpvm"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cvnjpnvchvakj" path="res://scenes/entities/npc.tscn" id="3_x3gyc"]
|
[ext_resource type="PackedScene" uid="uid://cvnjpnvchvakj" path="res://scenes/entities/npc.tscn" id="3_x3gyc"]
|
||||||
|
|
||||||
|
@ -30,6 +31,20 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 16, 4, 0)
|
||||||
[node name="2" type="Node3D" parent="PlayerSpawn"]
|
[node name="2" type="Node3D" parent="PlayerSpawn"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3, 15)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3, 15)
|
||||||
|
|
||||||
|
[node name="NPCRestPlaces" type="Node3D" parent="."]
|
||||||
|
|
||||||
|
[node name="0" type="Node3D" parent="NPCRestPlaces"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 2, -28)
|
||||||
|
script = ExtResource("2_yv1d0")
|
||||||
|
|
||||||
|
[node name="1" type="Node3D" parent="NPCRestPlaces"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 13, 2, -32)
|
||||||
|
script = ExtResource("2_yv1d0")
|
||||||
|
|
||||||
|
[node name="2" type="Node3D" parent="NPCRestPlaces"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 12, 2, -48)
|
||||||
|
script = ExtResource("2_yv1d0")
|
||||||
|
|
||||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||||
transform = Transform3D(-0.899519, 0.375, 0.224144, -0.224144, -0.836516, 0.5, 0.375, 0.399519, 0.836516, 0, 0, 0)
|
transform = Transform3D(-0.899519, 0.375, 0.224144, -0.224144, -0.836516, 0.5, 0.375, 0.399519, 0.836516, 0, 0, 0)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,18 @@
|
||||||
|
## SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
## Copyright (c) 2024 interstellardevelopment.org
|
||||||
|
|
||||||
extends CharacterBody3D
|
extends CharacterBody3D
|
||||||
|
|
||||||
var movement_speed: float = 3.0
|
var movement_speed: float = 3.0
|
||||||
var angry_meter: int = 5
|
var angry_meter: int = 5
|
||||||
var target: CharacterBody3D
|
var target: Node3D
|
||||||
|
|
||||||
|
# Legend:
|
||||||
|
# 0 - get an objective
|
||||||
|
# 1 - wait
|
||||||
|
# 2 - chase a player
|
||||||
|
var phase: int = 0
|
||||||
|
|
||||||
@onready var timer: Timer = $Timer
|
@onready var timer: Timer = $Timer
|
||||||
|
|
||||||
var skip: bool = false
|
var skip: bool = false
|
||||||
|
@ -13,34 +23,46 @@ func _ready() -> void:
|
||||||
if Networking.isManager:
|
if Networking.isManager:
|
||||||
if timer.timeout.connect(_timer_done):
|
if timer.timeout.connect(_timer_done):
|
||||||
pass
|
pass
|
||||||
first_frame.call_deferred()
|
find_rest()
|
||||||
|
|
||||||
func _timer_done() -> void:
|
func _timer_done() -> void:
|
||||||
if angry_meter > 0:
|
if angry_meter > 0:
|
||||||
angry_meter -= 1
|
angry_meter -= 1
|
||||||
else:
|
else:
|
||||||
timer.stop()
|
timer.stop()
|
||||||
first_frame()
|
phase = 2
|
||||||
|
find_player(99999999999999)
|
||||||
|
|
||||||
func first_frame() -> void:
|
# determines the closest resting place and navigates to it.
|
||||||
await get_tree().physics_frame
|
func find_rest() -> void:
|
||||||
timer.start()
|
var lowest_distance: float = 99999999999999
|
||||||
actor_setup(999999999)
|
for child: Node in get_tree().root.get_node("/root/"+Game.mapname+"/NPCRestPlaces").get_children():
|
||||||
|
if child is Rest and position.distance_to((child as Rest).position) < lowest_distance and !(child as Rest).occupied:
|
||||||
|
target = child
|
||||||
|
|
||||||
# determines the closest player and navigate.
|
navigation_agent.set_target_position(target.position)
|
||||||
func actor_setup(lowest_distance: float) -> void:
|
|
||||||
|
# determines the closest player and navigates to them.
|
||||||
|
func find_player(lowest_distance: float) -> void:
|
||||||
for child: Node in get_tree().root.get_node("/root/"+Game.mapname+"/").get_children():
|
for child: Node in get_tree().root.get_node("/root/"+Game.mapname+"/").get_children():
|
||||||
if child is Node3D:
|
if child is Player and position.distance_to((child as Player).position) < lowest_distance:
|
||||||
if child.has_method("playerstub") and position.distance_to((child as Node3D).position) < lowest_distance:
|
target = child
|
||||||
target = child
|
|
||||||
|
|
||||||
navigation_agent.set_target_position(target.position)
|
navigation_agent.set_target_position(target.position)
|
||||||
|
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
if Networking.isManager and angry_meter == 0:
|
if Networking.isManager and phase != 1:
|
||||||
actor_setup(position.distance_to(target.position))
|
if phase == 2:
|
||||||
|
find_player(position.distance_to(target.position))
|
||||||
|
elif phase == 0 and target is Player:
|
||||||
|
find_rest()
|
||||||
|
|
||||||
if navigation_agent.is_navigation_finished():
|
if navigation_agent.is_navigation_finished():
|
||||||
|
if phase == 0:
|
||||||
|
if target is Rest:
|
||||||
|
(target as Rest).occupied = false
|
||||||
|
phase = 1
|
||||||
|
timer.start()
|
||||||
return
|
return
|
||||||
|
|
||||||
var current_agent_position: Vector3 = global_position
|
var current_agent_position: Vector3 = global_position
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
## SPDX-License-Identifier: GPL-3.0-or-later
|
## SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
## Copyright (c) 2024 interstellardevelopment.org
|
## Copyright (c) 2024 interstellardevelopment.org
|
||||||
|
|
||||||
|
class_name Player
|
||||||
extends CharacterBody3D
|
extends CharacterBody3D
|
||||||
|
|
||||||
|
|
||||||
|
|
7
scripts/maps/rest.gd
Normal file
7
scripts/maps/rest.gd
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
## SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
## Copyright (c) 2024 interstellardevelopment.org
|
||||||
|
|
||||||
|
class_name Rest
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
var occupied: bool = false
|
|
@ -1,3 +1,6 @@
|
||||||
|
## SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
## Copyright (c) 2024 interstellardevelopment.org
|
||||||
|
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
|
Loading…
Reference in a new issue