Made game able to be reloaded
This commit is contained in:
@@ -8,13 +8,15 @@ namespace InterfaceOff.WorldScene
|
||||
{
|
||||
private static PlayerController Instance;
|
||||
private PlayerFrameInfo[] Frames;
|
||||
|
||||
|
||||
[SerializeField] private WindowSpawner ActiveWindowSpawner;
|
||||
[SerializeField] private LineRenderer BulletTracerRenderer;
|
||||
[SerializeField] private Transform BulletTracerStart;
|
||||
[SerializeField] private Transform BulletTracerEnd;
|
||||
[field: SerializeField] public int FrameIndex { get; private set; }
|
||||
[SerializeField] private int[] DeathIndices;
|
||||
|
||||
private bool PlayerAlive = true;
|
||||
private float LerpValue;
|
||||
|
||||
private void Awake()
|
||||
@@ -26,34 +28,41 @@ namespace InterfaceOff.WorldScene
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
/* Iterates the frame index */
|
||||
FrameIndex = (FrameIndex + 1) % (Frames.Length - 2);
|
||||
|
||||
if (DeathIndices.Contains(FrameIndex))
|
||||
if (PlayerAlive)
|
||||
{
|
||||
Debug.Log("Possible player death");
|
||||
/* Iterates the frame index */
|
||||
FrameIndex = (FrameIndex + 1) % (Frames.Length - 2);
|
||||
|
||||
if (DeathIndices.Contains(FrameIndex) && ActiveWindowSpawner.SpawnedWindowCount > 20)
|
||||
{
|
||||
ActiveWindowSpawner.StartEndSequence();
|
||||
PlayerAlive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
/* Updates the position according to the lerp */
|
||||
LerpValue = (LerpValue + Time.deltaTime * 20f) % 1f;
|
||||
|
||||
PlayerFrameInfo frameA = Frames[FrameIndex + 0];
|
||||
PlayerFrameInfo frameB = Frames[FrameIndex + 1];
|
||||
|
||||
transform.position = Vector3.Lerp(frameA.Position, frameB.Position, LerpValue);
|
||||
|
||||
Vector2 rotation = Vector2.Lerp(frameA.Rotation, frameB.Rotation, LerpValue);
|
||||
transform.rotation = Quaternion.Euler(rotation.x, rotation.y, 0);
|
||||
|
||||
/* Updates the gun state */
|
||||
BulletTracerRenderer.positionCount = 2;
|
||||
BulletTracerRenderer.SetPosition(index: 0, BulletTracerStart.position);
|
||||
BulletTracerRenderer.SetPosition(index: 1, BulletTracerEnd.position);
|
||||
if (PlayerAlive)
|
||||
{
|
||||
/* Updates the position according to the lerp */
|
||||
LerpValue = (LerpValue + Time.deltaTime * 20f) % 1f;
|
||||
|
||||
BulletTracerRenderer.enabled = Frames[FrameIndex].ShootGun;
|
||||
PlayerFrameInfo frameA = Frames[FrameIndex + 0];
|
||||
PlayerFrameInfo frameB = Frames[FrameIndex + 1];
|
||||
|
||||
transform.position = Vector3.Lerp(frameA.Position, frameB.Position, LerpValue);
|
||||
|
||||
Vector2 rotation = Vector2.Lerp(frameA.Rotation, frameB.Rotation, LerpValue);
|
||||
transform.rotation = Quaternion.Euler(rotation.x, rotation.y, 0);
|
||||
|
||||
/* Updates the gun state */
|
||||
BulletTracerRenderer.positionCount = 2;
|
||||
BulletTracerRenderer.SetPosition(index: 0, BulletTracerStart.position);
|
||||
BulletTracerRenderer.SetPosition(index: 1, BulletTracerEnd.position);
|
||||
|
||||
BulletTracerRenderer.enabled = Frames[FrameIndex].ShootGun;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace InterfaceOff
|
||||
/* Default close button closes the window */
|
||||
public virtual void OnWindowCloseButtonClicked() => DestroyWindow();
|
||||
|
||||
protected void DestroyWindow()
|
||||
public void DestroyWindow()
|
||||
{
|
||||
Creator.AlertOfDespawnedWindow();
|
||||
Destroy(gameObject);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Ext.B83.Unity.Attributes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace InterfaceOff
|
||||
@@ -17,7 +18,7 @@ namespace InterfaceOff
|
||||
{
|
||||
[field: SerializeField] private GameObject SampleChild { get; set; }
|
||||
[field: SerializeField] private Canvas GameCanvas { get; set; }
|
||||
|
||||
[field: SerializeField] private GameObject DeathInfo { get; set; }
|
||||
[field: SerializeField] private SpawnableWindowType[] WindowTypes { get; set; }
|
||||
private int TotalSpawnWeight { get; set; }
|
||||
|
||||
@@ -92,6 +93,7 @@ namespace InterfaceOff
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
/* Spawns new windows whilst active */
|
||||
if (AutoSpawn)
|
||||
{
|
||||
const int TICKS_PER_SECOND = 20;
|
||||
@@ -106,17 +108,30 @@ namespace InterfaceOff
|
||||
SpawnNewRandomWindow();
|
||||
}
|
||||
}
|
||||
|
||||
/* Else checks if it should reload the scene */
|
||||
else if (Input.GetKey(KeyCode.Space))
|
||||
{
|
||||
int sceneIndex = SceneManager.GetActiveScene().buildIndex;
|
||||
SceneManager.LoadScene(sceneIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
public void StartEndSequence()
|
||||
{
|
||||
if (!AutoSpawn)
|
||||
/* Destroys all children and stops them from spawning */
|
||||
AutoSpawn = false;
|
||||
foreach (Transform child in GameCanvas.transform)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
WindowBase window = child.GetComponent<WindowBase>();
|
||||
if (DebugUtils.IsNotNull(window))
|
||||
{
|
||||
SpawnNewRandomWindow();
|
||||
window.DestroyWindow();
|
||||
}
|
||||
}
|
||||
|
||||
/* Makes the death text visible to the player */
|
||||
DeathInfo.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user