working on enemies

This commit is contained in:
2025-08-20 05:06:00 +02:00
parent f6a4db7b4d
commit fb1c3f8290
619 changed files with 46709 additions and 668 deletions

View File

@@ -0,0 +1,68 @@
using System.Collections.Generic;
using RebootKit.Engine.Extensions;
using RebootKit.Engine.Main;
using RebootKit.Engine.Simulation;
using Unity.Collections;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace RebootReality.jelycho.Enemies {
public class WavesManagerActor : Actor {
[SerializeField] AssetReferenceGameObject[] m_ZombiesPrefabs;
[SerializeField] Transform[] m_SpawnPoints;
[SerializeField] float m_SpawnRate = 32;
[SerializeField] int m_MaxZombies = 1000;
int m_Stage;
int m_ZombiesToSpawn;
float m_SpawnTimer;
readonly List<ZombieActor> m_AliveZombies = new List<ZombieActor>(128);
//
// @MARK: Waves Manager
//
public void StartWave(int stage) {
m_Stage = stage;
m_ZombiesToSpawn = stage * 10;
m_SpawnTimer = 1.0f;
}
void SpawnZombieAtRandomPosition() {
Transform spawnPoint = m_SpawnPoints.Random();
ZombieActor zombieActor = (ZombieActor) RR.SpawnActor(m_ZombiesPrefabs.Random(), spawnPoint.position, spawnPoint.rotation);
zombieActor.died.AddListener(() => {
m_AliveZombies.RemoveSwapBack(zombieActor);
});
m_AliveZombies.Add(zombieActor);
}
//
// @MARK: IActor
//
protected override IActorData CreateActorData() {
return new NoActorData();
}
public override void OnServerTick(float deltaTime) {
base.OnServerTick(deltaTime);
if (m_ZombiesToSpawn <= 0) {
return;
}
if (m_AliveZombies.Count >= m_MaxZombies) {
return;
}
m_SpawnTimer -= deltaTime;
if (m_SpawnTimer <= 0.0f) {
SpawnZombieAtRandomPosition();
m_ZombiesToSpawn -= 1;
m_SpawnTimer = 1.0f / m_SpawnRate;
}
}
}
}