monster spawner and moving to the camera direction
This commit is contained in:
parent
8c29b8bffd
commit
b20f3b5124
821 changed files with 1611 additions and 1409 deletions
68
scripts/monster_spawnpoint.gd
Normal file
68
scripts/monster_spawnpoint.gd
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
class_name MonsterSpawnpoint
|
||||
extends Node3D
|
||||
|
||||
# a spawnpoint that can spawn monsters around the center point
|
||||
# with a given distance
|
||||
# monsters are only spawned, if the player is not looking
|
||||
|
||||
@onready var spawn_timer: Timer = Timer.new()
|
||||
|
||||
# list that holds all spawnable monsters
|
||||
@export var spawnable_monsters: Array[MonsterStats]
|
||||
|
||||
# the maximum amount of spawned monsters
|
||||
# no monsters will spawn, when this number is reached
|
||||
@export var max_monsters: int = 5
|
||||
|
||||
# the maximum distance a monster can spawn around the spawnpoint
|
||||
@export var max_distance_spawn: float = 10.0
|
||||
|
||||
# the maximum lifetime a monster can be in the world
|
||||
# a monster is then deleted if the following conditions are met:
|
||||
# the monster has exceeded its maximum lifetime and it is not on screen
|
||||
# TODO: figure out how to check for the exceeded lifetime and delete
|
||||
@export var max_lifetime: float = 60.0 # seconds
|
||||
|
||||
@export var spawn_cooldown: float = 3.0 # seconds
|
||||
|
||||
# a spawnpoint should keep track of spawned entities
|
||||
#var active_monsters: Array[Monster] = []
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
spawn_timer.wait_time = spawn_cooldown
|
||||
spawn_timer.autostart = true
|
||||
spawn_timer.timeout.connect(spawn)
|
||||
add_child(spawn_timer)
|
||||
spawn_timer.start()
|
||||
|
||||
func spawn() -> void:
|
||||
if $VisibleOnScreenNotifier3D.is_on_screen():
|
||||
print("Spawnpoint is visible on screen. Not spawning a monster.")
|
||||
return
|
||||
|
||||
# TODO: Add a check to not spawn enemies X units near the player
|
||||
|
||||
# get a random position near the spawn point
|
||||
var spawn_point_x = randf_range(-max_distance_spawn, max_distance_spawn)
|
||||
var spawn_point_z = randf_range(-max_distance_spawn, max_distance_spawn)
|
||||
|
||||
# instantiate a monster .tscn scene
|
||||
var monster_to_spawn = spawnable_monsters[0]
|
||||
|
||||
# TODO: Replace this with actual instantiation of a walking monster
|
||||
var mesh_instance = MeshInstance3D.new()
|
||||
mesh_instance.mesh = BoxMesh.new()
|
||||
# calculate the position of the monster and add the offset of the spawnpoint itself
|
||||
var monster_position = Vector3(spawn_point_x, 0.2, spawn_point_z)
|
||||
mesh_instance.position = monster_position + position
|
||||
|
||||
var debug_level_node = get_node("/root/Main/CurrentLevel/DebugLevel")
|
||||
debug_level_node.add_child(mesh_instance)
|
||||
print("spawning mob")
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
var time = Time.get_ticks_msec()
|
||||
$Diamond.rotation.y = sin(time / 800.0) * 2
|
||||
$Diamond.position.y = 1.5 + sin(time / 800.0) * 0.3
|
||||
Loading…
Add table
Add a link
Reference in a new issue