Skip to content
Merged

Boss2 #112

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,367 changes: 8,367 additions & 0 deletions Assets/Prefabs/Rooms/RoomBossPrefab.prefab

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Assets/Prefabs/Rooms/RoomBossPrefab.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Prefabs/enemies/Boss.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Assets/Prefabs/enemies/Boss/DoorClosing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using UnityEngine;

public class DoorClosing : MonoBehaviour
{
public PhaseTransition pt;
[SerializeField]
private GameObject doorL;
[SerializeField]
private GameObject doorU;
private bool playerInside = false;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
playerInside = true;
doorL.SetActive(true);
doorU.SetActive(true);
pt.StartBattle();
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Player") && (doorL.activeSelf || doorU.activeSelf))
{
playerInside = false;
doorL.SetActive(false);
doorU.SetActive(false);
}
}
private void Update()
{
if (!playerInside && (doorL.activeSelf || doorU.activeSelf))
{
doorL.SetActive(false);
doorU.SetActive(false);
}
}
}
2 changes: 2 additions & 0 deletions Assets/Prefabs/enemies/Boss/DoorClosing.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Prefabs/enemies/Boss/Logic.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions Assets/Prefabs/enemies/Boss/Logic/HealthAndPhases.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using UnityEngine;

[RequireComponent (typeof(PhaseTransition))]
public class HealthAndPhases : MonoBehaviour
{
[SerializeField]
private float health1;
[SerializeField]
private float health2;
public GameObject phase1Object;
public GameObject phase2Object;
[SerializeField]
private Enemy healthScript;
[SerializeField, Range(1, 2)]
private int phase;
[SerializeField]
private float currentHealth;
public PhaseTransition phaseTransition;

private void Awake()
{
if (phase1Object != null && phase1Object.GetComponent<Enemy>())
{
phase1Object.SetActive(true);
phase1Object.GetComponent<Enemy>().maxHp = health1;
}
else
{
Debug.Log("No phase 1 Boss object or Enemy on it");
Application.Quit();
}
//if (phase2Object != null && phase2Object.GetComponent<Enemy>())
//{
// phase2Object.GetComponent<Enemy>().maxHp = health2;
// phase2Object.SetActive(false);
//}
//else
//{
// Debug.Log("No phase 2 Boss object or Enemy on it");
// Application.Quit();
//}
if (phaseTransition == null)
{
phaseTransition = GetComponent<PhaseTransition>();
}
phase = 1;
}
private void Update()
{
if (phase == 1)
{
health1 = phase1Object.GetComponent<Enemy>().GetHp;
}
//else
//{
// health2 = phase2Object.GetComponent<Enemy>().GetHp;
//}
if (phase1Object == null || health1 == 0)
{
phase = 2;
//phaseTransition.ChangePhase();
if (phase1Object != null)
{
phase1Object.SetActive(false);
}
Debug.LogErrorFormat("You won!");
//phase2Object.SetActive(true);
}
//if (phase2Object == null || health2 == 0)
//{
// if (phase2Object != null)
// {
// phase2Object.SetActive(false);
// }
// Debug.Log("Player won!");
//}
}
}
2 changes: 2 additions & 0 deletions Assets/Prefabs/enemies/Boss/Logic/HealthAndPhases.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Assets/Prefabs/enemies/Boss/Logic/PhaseTransition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using UnityEngine;

public class PhaseTransition : MonoBehaviour
{
public Phases phases;
public Collider2D col1;
public Collider2D col2;

public void StartBattle() {
phases.isPhaseInProcess = true;
phases.StartPhaseOne();
}
public void ChangePhase()
{
phases.isPhaseInProcess = false;
phases.StartPhaseTwo();
}
}
2 changes: 2 additions & 0 deletions Assets/Prefabs/enemies/Boss/Logic/PhaseTransition.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions Assets/Prefabs/enemies/Boss/Logic/Phases.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Random = UnityEngine.Random;

public class Phases : MonoBehaviour
{
public List<AttackInfo> attackPrefAndWarn;
public float attackTimeout;
public List<GameObject> enemyPrefabs;

public float enemyTimeout;
public List<AttackInfo> attackPrefAndWarn2;
public float attackTimeout2;
public List<GameObject> enemyPrefabs2;

int lastAttackIndex = -1;
public Coroutine curPhaseCoroutine;
public bool isPhaseInProcess;

//void Start() {
// StartPhaseOne();
//}

public void StartPhaseOne() {
curPhaseCoroutine = StartCoroutine(PhaseCoroutine());
}
public void StartPhaseTwo()
{
curPhaseCoroutine = StartCoroutine(WaitForEndOfThePhase());
}

IEnumerator PhaseCoroutine() {
while (isPhaseInProcess) {
AttackInfo attack = attackPrefAndWarn.Where((at, i) => i != lastAttackIndex).OrderBy(at => Random.value).First();
lastAttackIndex = attackPrefAndWarn.IndexOf(attack);
StartCoroutine(PerformAttack(attack));
yield return new WaitForSeconds(attackTimeout + attack.attackTime + attack.timeBeforeAttack);
}
curPhaseCoroutine = null;
}

IEnumerator PerformAttack(AttackInfo attack) {
GameObject warn = Instantiate(attack.warnPrefab, transform, false);
yield return new WaitForSeconds(attack.timeBeforeAttack);
Destroy(warn);
GameObject curAttack = Instantiate(attack.attackPrefab, transform, false);
yield return new WaitForSeconds(attack.attackTime);
Destroy(curAttack);
}
IEnumerator WaitForEndOfThePhase()
{
while (isPhaseInProcess || curPhaseCoroutine != null)
{
yield return new WaitForEndOfFrame();
}
curPhaseCoroutine = StartCoroutine(PhaseTwoCoroutine());
isPhaseInProcess = true;
}
IEnumerator PhaseTwoCoroutine()
{
while (isPhaseInProcess)
{
AttackInfo attack = attackPrefAndWarn2.Where((at, i) => i != lastAttackIndex).OrderBy(at => Random.value).First();
lastAttackIndex = attackPrefAndWarn2.IndexOf(attack);
StartCoroutine(PerformAttack(attack));
yield return new WaitForSeconds(attack.attackTime + attack.timeBeforeAttack);
yield return new WaitForSeconds(attackTimeout2);
}
curPhaseCoroutine = null;
}
IEnumerator TimeoutAfterAttack(float time)
{
transform.position = new Vector3(0, 0, 0);
yield return new WaitForSeconds(time);
}
}

[Serializable]
public struct AttackInfo {
public GameObject attackPrefab;
public GameObject warnPrefab;
public float timeBeforeAttack;
public float attackTime;
}
2 changes: 2 additions & 0 deletions Assets/Prefabs/enemies/Boss/Logic/Phases.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions Assets/Prefabs/enemies/Boss/Logic/SpawnAttack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnAttack : MonoBehaviour
{
[SerializeField]
private List<GameObject> enemyPrefabs;
[SerializeField]
private int amountToSpawn;
private int spawned;
[SerializeField]
private float delay;
public Phases phases;
public Coroutine coroutine;
void Start()
{
if (phases == null)
{
phases = FindFirstObjectByType<Phases>();
}
enemyPrefabs = phases.enemyPrefabs;
coroutine = StartCoroutine(SpawnEnemiesForBoss());
}
IEnumerator SpawnEnemiesForBoss()
{
while (spawned < amountToSpawn)
{
yield return new WaitForSeconds(delay);
SpawnEnemy();
}
}
void SpawnEnemy()
{
GameObject pref = enemyPrefabs[Random.Range(0, (enemyPrefabs.Count - 1))];
GameObject enemy = Instantiate(pref, transform.position, pref.transform.rotation);
spawned++;
}
}
2 changes: 2 additions & 0 deletions Assets/Prefabs/enemies/Boss/Logic/SpawnAttack.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Prefabs/enemies/Boss/PentagramW&A.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading