Skip to content

Commit

Permalink
Merge pull request #49 from hackerspace-ntnu/fix/misc
Browse files Browse the repository at this point in the history
Fix misc.
  • Loading branch information
ddabble authored Oct 17, 2021
2 parents a6b391a + 37b8cf1 commit 76b18a0
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 214 deletions.
5 changes: 5 additions & 0 deletions Assets/Prefabs/Base/Base.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,14 @@ MonoBehaviour:
m_EditorClassIdentifier:
gameOverScreen: {fileID: 6406541465688870762, guid: cf6616ecfd76d4b379c4e4fd196293af, type: 3}
destroyedBase: {fileID: 7907768064546073796, guid: ced5130962de4c54185e3ca432063c03, type: 3}
distortionField: {fileID: 0}
deathParticles: {fileID: 0}
spawnPoint: {fileID: 5829545455071137389}
crystals: 0
drainRay: {fileID: 2977432110045038679, guid: 1fa3e9df0696ada43b1fbfe045184210, type: 3}
explosionLightningCount: 20
explosionLightningSpawnDelay: 0.2
mainCrystal: {fileID: 0}
--- !u!114 &990519977
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
8 changes: 4 additions & 4 deletions Assets/Prefabs/PlayerControls.inputactions
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"interactions": ""
},
{
"name": "Back",
"name": "Cancel",
"type": "Button",
"id": "edbb2489-0819-43dd-bbbf-39f2ad7c7800",
"expectedControlType": "Button",
Expand Down Expand Up @@ -238,18 +238,18 @@
"interactions": "",
"processors": "",
"groups": "Controller",
"action": "Back",
"action": "Cancel",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "eeed5e82-f945-41b1-924f-37ce63a89e81",
"path": "<Keyboard>/f",
"path": "<Keyboard>/escape",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Back",
"action": "Cancel",
"isComposite": false,
"isPartOfComposite": false
},
Expand Down
6 changes: 3 additions & 3 deletions Assets/Prefabs/Players/Dahl_Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
inventory: {fileID: 2599837699652063204}
anim: {fileID: 6367115686714045310}
HeldItemBone: {fileID: 7197418879628508991}
heldItemBone: {fileID: 7197418879628508991}
--- !u!114 &2954308745039272254
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1201,8 +1201,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e72ff79698f208146b466f2fe5707f24, type: 3}
m_Name:
m_EditorClassIdentifier:
Crate: {fileID: 4550191380729392189}
Blueprint: {fileID: 3550879455986713352}
crate: {fileID: 4550191380729392189}
blueprint: {fileID: 3550879455986713352}
--- !u!1 &4138943945869748027
GameObject:
m_ObjectHideFlags: 0
Expand Down
30 changes: 14 additions & 16 deletions Assets/Scripts/GameState/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class BaseController : MonoBehaviour
public GameObject drainRay;
private List<Ray> rays = new List<Ray>();

public int explosionLightningCount = 20;
public float explosionLightningSpawnDelay = 0.2f;

public Transform SpawnPoint => spawnPoint;

// Crystal Transform
Expand Down Expand Up @@ -68,10 +71,8 @@ void Awake()
GetComponent<HealthLogic>().onDeath += Die;
anim = GetComponent<Animator>();

if(mainCrystal == null)
{
if (mainCrystal == null)
Debug.LogError("Main Crystal not set.");
}
}

void OnDestroy()
Expand Down Expand Up @@ -128,9 +129,7 @@ private void Die()
StartCoroutine("Explode");

// Start Distortions
//distortionField.enabled = true;


//distortionField.enabled = true;
}

dead = true;
Expand Down Expand Up @@ -181,32 +180,31 @@ public int GetIdVFX(Transform t)
IEnumerator Explode()
{
// Get a list of all transforms (lighning targets)
Transform[] transforms = GameObject.FindObjectsOfType<Transform>();
Transform[] transforms = FindObjectsOfType<Transform>();

// Create lightning as the crystal charges
for (float t = 4f; t >= 0; t -= 0.2f)
for (int _ = 0; _ >= explosionLightningCount; _++)
{
int i = Random.Range(0, transforms.Length);

Transform ray = Instantiate(drainRay, transform.position + new Vector3(Random.Range(-1, 1), 5f, Random.Range(-1, 1)), transform.rotation).transform;
ray.SetParent(transform);
Vector3 rayPos = transform.position + new Vector3(Random.Range(-1, 1), 5f, Random.Range(-1, 1));
Transform ray = Instantiate(drainRay, rayPos, transform.rotation, transform).transform;

// 1 is the index of the first child (after the parent itself)
Transform target = ray.GetComponentsInChildren<Transform>()[1];
target.SetParent(transforms[i]);
Transform randomLightningTarget = transforms[Random.Range(0, transforms.Length)];
target.SetParent(randomLightningTarget);
target.localPosition = Vector3.zero;

// Ensure correct camera focus
Camera.main.GetComponent<CameraFocusController>().Focus(transform);

yield return new WaitForSeconds(0.2f);
yield return new WaitForSeconds(explosionLightningSpawnDelay);
}

// Replace the base with a rigidbody based one
GameObject deadBase = Instantiate(destroyedBase, transform.position, Quaternion.identity);

// Add an explosion force on the base
foreach(Rigidbody rb in deadBase.GetComponentsInChildren<Rigidbody>())
foreach (Rigidbody rb in deadBase.GetComponentsInChildren<Rigidbody>())
{
rb.AddForce(new Vector3(Random.Range(-250f, 250f), Random.Range(500f, 800f), Random.Range(-250f, 250f)));
}
Expand All @@ -218,7 +216,7 @@ IEnumerator Explode()
Instantiate(gameOverScreen);

// Add particle system
Instantiate(deathParticles, transform.position + new Vector3(0,3,0), transform.rotation);
Instantiate(deathParticles, transform.position + new Vector3(0, 3, 0), transform.rotation);

// Clean up
Destroy(gameObject);
Expand Down
15 changes: 4 additions & 11 deletions Assets/Scripts/Interactables/Interactable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@
using System.Collections.Generic;
using UnityEngine;

public class Interactable : MonoBehaviour
public abstract class Interactable : MonoBehaviour
{
public bool canInteract = true;

public virtual void Focus(PlayerStateController player)
{
Debug.Log("I am focused");
}
{}

public virtual void Unfocus(PlayerStateController player)
{
Debug.Log("I am unfocused (Aren't we all?)");
}
{}

public virtual void Interact(PlayerStateController player)
{
Debug.Log("Player interacted");
}
public abstract void Interact(PlayerStateController player);
}
20 changes: 10 additions & 10 deletions Assets/Scripts/Interactables/Loot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ void Update()
}
}

public override void Focus(PlayerStateController player)
{
Highlight();
}

public override void Unfocus(PlayerStateController player)
{
Unhighlight();
}

public override void Interact(PlayerStateController player)
{
if (!carried)
Expand All @@ -105,16 +115,6 @@ public override void Interact(PlayerStateController player)
}
}

public override void Focus(PlayerStateController player)
{
Highlight();
}

public override void Unfocus(PlayerStateController player)
{
Unhighlight();
}

public void Absorb(BaseController baseController)
{
// Set the object to be destroyed
Expand Down
8 changes: 2 additions & 6 deletions Assets/Scripts/Player/CameraFocusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,10 @@ private Vector3 boundingBoxCenter()

//Taking the mean sqare avg of the mindistance and box distance
if (!overview)
{
distance = Mathf.Sqrt(radialDist * radialDist + minDistance * minDistance);
}
else
{
distance = Mathf.Sqrt(radialDist * radialDist + overviewDistance * overviewDistance);
}

return center + distance * viewDir;
}

Expand All @@ -109,15 +106,14 @@ public void Focus(Transform obj)

// Switch to overview mode
EnableOverview();

}

public void EnableOverview()
{
if (!overview)
{
overview = true;
smoothing = smoothing / 10;
smoothing /= 10;
}
}
}
37 changes: 20 additions & 17 deletions Assets/Scripts/Player/DahlPropController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,51 @@
using UnityEngine;

/// <summary>
/// Component made for updating dahls props when states are changed. Latches on to playerStateContollers onStateChange delegate to enable/disabled the crate and blueprints
/// Component made for updating Dahl's props when states are changed.
/// Latches on to `PlayerStateContoller`s `onPlayerStateChange` delegate to enable/disabled the crate and blueprints.
/// </summary>
public class DahlPropController : MonoBehaviour
{
[SerializeField]
private MeshRenderer crate;

[SerializeField]
private MeshRenderer Crate, Blueprint;
private MeshRenderer blueprint;

void Start()
{
GetComponent<PlayerStateController>().onPlayerStateChange += onPlayerStateChange;
GetComponent<PlayerStateController>().onPlayerStateChange += OnPlayerStateChange;
}
private void OnDestroy()

void OnDestroy()
{
GetComponent<PlayerStateController>().onPlayerStateChange -= onPlayerStateChange;
GetComponent<PlayerStateController>().onPlayerStateChange -= OnPlayerStateChange;
}

private void onPlayerStateChange(PlayerStateController.PlayerStates newState, PlayerStateController.PlayerStates oldState)
private void OnPlayerStateChange(PlayerStates newState, PlayerStates oldState)
{
switch (oldState)
{
case PlayerStateController.PlayerStates.BUILDING:
Crate.enabled = false;
case PlayerStates.BUILDING:
crate.enabled = false;
break;
case PlayerStateController.PlayerStates.IN_TURRET_MENU:
Blueprint.enabled = false;
case PlayerStates.IN_TURRET_MENU:
blueprint.enabled = false;
break;
default:
break;
}

switch (newState)
{
case PlayerStateController.PlayerStates.BUILDING:
Crate.enabled = true;
case PlayerStates.BUILDING:
crate.enabled = true;
break;
case PlayerStateController.PlayerStates.IN_TURRET_MENU:
Blueprint.enabled = true;
case PlayerStates.IN_TURRET_MENU:
blueprint.enabled = true;
break;
default:
break;
}


}
}
}
Loading

0 comments on commit 76b18a0

Please sign in to comment.