Revert "Merge branch 'leveldesign_r'"

This reverts commit 998a52fe3c.
This commit is contained in:
Jan Groß
2018-09-08 17:44:36 +02:00
parent 998a52fe3c
commit c64220a353
209 changed files with 274 additions and 59813 deletions

View File

@@ -0,0 +1,135 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LurchRespawn : MonoBehaviour {
//Spawnpoints
[SerializeField]
private List<GameObject> respawnPoints = new List<GameObject>();
private GameObject lastRespawnPoint;
private int lastRespawnPointIndex;
//Refs
[SerializeField]
private Transform lowerBounds;
//ExtRefs
[SerializeField]
private GameObject lurch;
private LurchMovement compLurchMovement;
//States
private bool offGround = false;
private Vector3 lastGroundPos;
//Settings
[Header("Settings")]
[SerializeField]
[Tooltip("Update the spawnpoint every n frames")]
private int UpdateFrequenzy = 15;
[SerializeField]
private float maxFallDist = 100;
public float maxDistanceToPoint = 10.0f;
[SerializeField]
private KeyCode respawnKey = KeyCode.R;
void Start () {
if (respawnPoints.Count == 0)
{
this.enabled = false;
throw new System.Exception("No respawn points assigned");
}
compLurchMovement = gameObject.GetComponent<LurchMovement>();
lastGroundPos = lurch.transform.position;
lastRespawnPoint = respawnPoints[0];
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(respawnKey))
{
RespawnLurch("Player respawned");
}
if(!offGround)
{
if(!compLurchMovement.LurchOnGround())
{
offGround = true;
lastGroundPos = lurch.transform.position;
}
} else
{
if (compLurchMovement.LurchOnGround())
{
offGround = false;
float fallDist = Vector3.Distance(lurch.transform.position, lastGroundPos);
if (fallDist > maxFallDist)
{
//We fell too far
RespawnLurch("Lurch fell too far");
}
lastGroundPos = lurch.transform.position;
}
}
if(Time.frameCount % UpdateFrequenzy == 0)
{
UpdateRespawnPoint();
}
if (Time.frameCount % UpdateFrequenzy * 2 == 0)
{
CheckBounds();
}
}
private void CheckBounds()
{
if(transform.position.y < lowerBounds.position.y)
{
RespawnLurch("Lurch went out of bounds");
}
}
private void UpdateRespawnPoint()
{
float nextPointDist;
float lastPointDist = Vector3.Distance(transform.position, lastRespawnPoint.transform.position);
for (int i = lastRespawnPointIndex; i < respawnPoints.Count; i++)
{
nextPointDist = Vector3.Distance(transform.position, respawnPoints[i].transform.position);
if (nextPointDist < lastPointDist && nextPointDist < maxDistanceToPoint)
{
lastRespawnPoint = respawnPoints[i];
lastRespawnPointIndex = i;
}
}
}
public void RespawnLurch(string message = "Lurch respawned")
{
Debug.LogWarning("Lurch respawned: " + message);
compLurchMovement.DontStick();
lurch.transform.position = lastRespawnPoint.transform.position;
}
private void OnDrawGizmos()
{
for(int i = 0; i < respawnPoints.Count; i++)
{
if(respawnPoints[i] == lastRespawnPoint)
{
Gizmos.DrawIcon(respawnPoints[i].transform.position, "RespawnActive.png");
} else if (i < lastRespawnPointIndex)
{
Gizmos.DrawIcon(respawnPoints[i].transform.position, "RespawnInactive.png");
} else
Gizmos.DrawIcon(respawnPoints[i].transform.position, "Respawn.png");
}
}
}