Implemented the functionality for monster rooms.
This commit is contained in:
parent
6a309804ad
commit
aa49815fb9
16 changed files with 1182 additions and 71 deletions
53
PuzzleGameProject/Assets/Scripts/Rooms/Monster Room.cs
Normal file
53
PuzzleGameProject/Assets/Scripts/Rooms/Monster Room.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
|
||||
public class MonsterRoom : Room
|
||||
{
|
||||
[SerializeField] private List<int> locks = new();
|
||||
[SerializeField] private GameObject numberTextObject;
|
||||
[SerializeField] private int _health; // Number of times the room needs to be unlocked before becoming explored.
|
||||
|
||||
protected override void InitializeRoom() {
|
||||
base.InitializeRoom();
|
||||
|
||||
// Create the lock numbers on the room.
|
||||
numberTextObject.GetComponent<TextMeshProUGUI>().text = locks[0].ToString();
|
||||
GameObject lockToDuplicate = numberTextObject;
|
||||
for (int i = 1; i < locks.Count; i++)
|
||||
{
|
||||
lockToDuplicate = DuplicateToTheLeft(lockToDuplicate, ((RectTransform)lockToDuplicate.transform).rect.width);
|
||||
lockToDuplicate.GetComponent<TextMeshProUGUI>().text = locks[i].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryUnlock(DicePair pair) {
|
||||
foreach (int lockNumber in locks)
|
||||
{
|
||||
if (pair.Sum() == lockNumber)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void SetRoomExplored() {
|
||||
_health -= 1;
|
||||
if (_health == 0)
|
||||
{
|
||||
_isExplored = true;
|
||||
UnhighlightRoomAsOption();
|
||||
gameObject.GetComponent<SpriteRenderer>().color =
|
||||
ColorHelper.AddColorTint(gameObject.GetComponent<SpriteRenderer>().color, Color.grey, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject DuplicateToTheLeft(GameObject original, float offset) {
|
||||
GameObject clone = Instantiate(original, original.transform.parent);
|
||||
clone.transform.localPosition -= new Vector3(offset, 0, 0);
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue