more enemy stuff

This commit is contained in:
myondev 2026-02-26 07:48:50 -08:00
parent 3b60583c76
commit d8c49317a3
235 changed files with 27781 additions and 3909 deletions

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 76492d48e9b8650b3a777d1a78255403
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,14 @@
using System;
using UnityEngine;
public class BossRange : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag(tag))
{
EnemySpawner.instance.StartBoss();
gameObject.SetActive(false);
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4b504e72f3e510d93bbb892b7ce53bbe

View file

@ -1,9 +1,17 @@
using System;
using Core.Extensions;
using UnityEngine;
using System.Collections.Generic;
using Random = UnityEngine.Random;
public class Enemy : Entity
{
[System.Serializable]
public class Ability
{
public EnemyAbility ability;
public float currentCooldown;
}
[Header("Targetting")]
public Entity closestTarget;
public float engagementRange;
@ -24,9 +32,11 @@ public class Enemy : Entity
}
[Header("Drops")]
public List<UpgradeDrop> possibleDrops = new();
[SerializeField] private UpgradePickup pickupObject;
private void Start()
[Header("Abilities")]
[SerializeField] private Ability[] allAbilities;
private void Start()
{
if (Random.Range(0f, 2f) > 1f)
{
@ -35,6 +45,30 @@ public class Enemy : Entity
}
}
private void Update()
{
if (detectedPlayer)
{
Ability foundAbility = null;
foreach (Ability availableAbility in allAbilities)
{
if (foundAbility == null && availableAbility.currentCooldown <= 0)
{
foundAbility = availableAbility;
}
else if (availableAbility.currentCooldown > 0)
{
availableAbility.currentCooldown -= Time.deltaTime;
}
}
if (foundAbility != null)
{
foundAbility.ability.UseAbility(closestTarget, this);
foundAbility.currentCooldown = foundAbility.ability.cooldown;
}
}
}
protected override void FixedUpdate()
{
if (!detectedPlayer && Vector3.Distance(transform.position, closestTarget.transform.position) < engagementRange)

View file

@ -0,0 +1,36 @@
using UnityEngine;
[CreateAssetMenu(fileName = "New Enemy Projectile Ability", menuName = "EnemyAbilities/FireBullet")]
public class EnemyFireBullet : EnemyAbility
{
public enum FireMode {Angled, Offset};
[Header("Projectile")]
public FireMode fireMode = FireMode.Offset;
public Vector2 offset;
public float angle;
public int projectileCount;
public int pierceAmount;
public float projectileSpeed;
public float bulletLifetime;
public float accuracy;
public Projectile projectile;
public override void UseAbility(Entity target, Enemy owner)
{
for (int i = 0; i < projectileCount; i++)
{
Projectile newProjectile = Instantiate(projectile, owner.transform.position, Quaternion.identity);
newProjectile.RotateToTarget(target.transform.position);
if (fireMode == FireMode.Offset && projectileCount > 1)
{
newProjectile.transform.position += new Vector3(Random.Range(-offset.x, offset.x), Random.Range(-offset.y, offset.y));
}
newProjectile.pierceAmount = pierceAmount;
newProjectile.damage = power;
newProjectile.speed = projectileSpeed;
newProjectile.lifetime = bulletLifetime;
newProjectile.transform.Rotate(0, 0, Random.Range(-accuracy, accuracy));
newProjectile.tag = owner.tag;
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0c76701d260732d13a1beca8945ac458

View file

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
public class EnemySpawner : MonoBehaviour
{
#region Statication
public static EnemySpawner instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
instance = this;
}
#endregion
[Header("Enemies")]
public bool canSpawn = true;
public Enemy[] enemiesToSpawn;
public List<Transform> spawnPoints;
public float spawnRate;
[SerializeField] private float currentSpawnTime;
[Header("Boss")]
public Enemy bossEnemy;
public Transform bossSpawnPoint;
[Header("Cache")]
[SerializeField] private Transform enemyFolder;
[SerializeField] private Marisa player;
private void Update()
{
if (canSpawn)
{
currentSpawnTime -= Time.deltaTime;
if (currentSpawnTime < 0)
{
currentSpawnTime = spawnRate;
SpawnEnemy(enemiesToSpawn[Random.Range(0, enemiesToSpawn.Length)], spawnPoints[Random.Range(0, spawnPoints.Count)].position);
}
}
}
public void SpawnEnemy(Enemy enemy, Vector3 location)
{
Enemy newEnemy = Instantiate(enemy, location, Quaternion.identity);
newEnemy.transform.SetParent(enemyFolder);
newEnemy.closestTarget = player; //idk if there's actually gonna be any other target lol
}
public void StartBoss()
{
SpawnEnemy(bossEnemy, bossSpawnPoint.position);
canSpawn = false;
}
}

View file

@ -1,31 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
public class EnemySpawner : MonoBehaviour
{
[SerializeField] private Marisa player;
public Enemy[] enemiesToSpawn;
public List<Transform> spawnPoints;
public float spawnRate;
[SerializeField] private float currentSpawnTime;
[SerializeField] private Transform enemyFolder;
private void Update()
{
currentSpawnTime -= Time.deltaTime;
if (currentSpawnTime < 0)
{
currentSpawnTime = spawnRate;
SpawnEnemy(enemiesToSpawn[Random.Range(0, enemiesToSpawn.Length)], spawnPoints[Random.Range(0, spawnPoints.Count)].position);
}
}
public void SpawnEnemy(Enemy enemy, Vector3 location)
{
Enemy newEnemy = Instantiate(enemy, location, Quaternion.identity);
newEnemy.transform.SetParent(enemyFolder);
newEnemy.closestTarget = player; //idk if there's actually gonna be any other target lol
}
}