more enemy stuff
This commit is contained in:
parent
3b60583c76
commit
d8c49317a3
235 changed files with 27781 additions and 3909 deletions
8
Assets/Scripts/Entities/Enemy.meta
Normal file
8
Assets/Scripts/Entities/Enemy.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 76492d48e9b8650b3a777d1a78255403
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/Entities/Enemy/BossRange.cs
Normal file
14
Assets/Scripts/Entities/Enemy/BossRange.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Entities/Enemy/BossRange.cs.meta
Normal file
2
Assets/Scripts/Entities/Enemy/BossRange.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4b504e72f3e510d93bbb892b7ce53bbe
|
||||
|
|
@ -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)
|
||||
36
Assets/Scripts/Entities/Enemy/EnemyFireBullet.cs
Normal file
36
Assets/Scripts/Entities/Enemy/EnemyFireBullet.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Entities/Enemy/EnemyFireBullet.cs.meta
Normal file
2
Assets/Scripts/Entities/Enemy/EnemyFireBullet.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0c76701d260732d13a1beca8945ac458
|
||||
61
Assets/Scripts/Entities/Enemy/EnemySpawner.cs
Normal file
61
Assets/Scripts/Entities/Enemy/EnemySpawner.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue