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,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

@ -0,0 +1,126 @@
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;
public bool detectedPlayer = false;
[Header("Direction")]
public float acceleration;
public Transform[] possibleDirections;
public float forwardPercent;
public float strafePercent;
private float xSign = -1f;
private float ySign = 1f;
[System.Serializable]
public class UpgradeDrop
{
public AbilityUpgrade droppedUpgrade;
public float chance;
}
[Header("Drops")]
public List<UpgradeDrop> possibleDrops = new();
[SerializeField] private UpgradePickup pickupObject;
[Header("Abilities")]
[SerializeField] private Ability[] allAbilities;
private void Start()
{
if (Random.Range(0f, 2f) > 1f)
{
xSign = -xSign;
ySign = -ySign;
}
}
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)
{
detectedPlayer = true;
}
if (stalled || !closestTarget || !detectedPlayer)
{
rb.VelocityTowards(Vector2.zero.ScaleToMagnitude(speed), acceleration);
}
else
{
Vector2 directionToTarget = (closestTarget.transform.position - transform.position).normalized;
Vector2 directionToMove = directionToTarget;
float currentHighestScore = float.NegativeInfinity;
Vector2 strafeDirection = new Vector3(directionToTarget.y * ySign, directionToTarget.x * xSign);
foreach (Transform direction in possibleDirections)
{
Vector3 directionToPoint = (direction.position - transform.position).normalized;
float forwardScore = Vector3.Dot(directionToPoint, directionToTarget);
float strafeScore = Vector3.Dot(directionToPoint, strafeDirection);
float finalScore = (forwardScore * forwardPercent) + (strafeScore * strafePercent);
//Debug.Log($"Forward: {forwardScore} Strafe: {strafeScore} Final: {finalScore}");
if (finalScore > currentHighestScore)
{
//Debug.Log($"{finalScore} is higher than current score: {currentHighestScore}");
currentHighestScore = finalScore;
directionToMove = directionToPoint;
}
}
rb.VelocityTowards(directionToMove.ScaleToMagnitude(speed), acceleration);
FlipSprite(directionToMove);
}
}
protected override void OnKillEffects()
{
Destroy(gameObject);
foreach (UpgradeDrop drop in possibleDrops)
{
DropUpgrade(drop);
}
}
protected virtual void DropUpgrade(UpgradeDrop drop)
{
float random = Random.Range(0, 100);
{
if (random < drop.chance) //just so it matches up with the number. 80 chance means 80 percent? idk but less than 80 lol
{
UpgradePickup newPickup = Instantiate(pickupObject, transform.position, Quaternion.identity);
newPickup.upgradeDropped = drop.droppedUpgrade;
}
}
}
}

View file

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

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

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