Skip to content

Commit

Permalink
added explosion and working on game over screen
Browse files Browse the repository at this point in the history
  • Loading branch information
maxilevi committed Nov 10, 2017
1 parent 9e935ea commit 9b0b1d9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
14 changes: 5 additions & 9 deletions Assets/Explode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
public class Explode : MonoBehaviour
{

void Update(){
if(Input.GetMouseButtonDown(0))
StartCoroutine(SplitMesh());
void Start(){
SplitMesh();
}

IEnumerator SplitMesh ()
void SplitMesh ()
{
MeshFilter MF = GetComponent<MeshFilter>();
MeshRenderer MR = GetComponent<MeshRenderer>();
Expand Down Expand Up @@ -47,16 +46,13 @@ IEnumerator SplitMesh ()
GO.AddComponent<MeshRenderer>().material = MR.materials[submesh];
GO.AddComponent<MeshFilter>().mesh = mesh;
GO.AddComponent<BoxCollider>();
GO.AddComponent<Rigidbody>().AddExplosionForce(100, transform.position, 30);
GO.AddComponent<Rigidbody>().AddExplosionForce(20, transform.position, 30);

Destroy(GO, 5 + Random.Range(0.0f, 5.0f));
}
}
MR.enabled = false;

Time.timeScale = 0.2f;
yield return new WaitForSeconds(0.8f);
Time.timeScale = 1.0f;
Destroy(gameObject);
Destroy(this.gameObject);
}
}
13 changes: 12 additions & 1 deletion Assets/Movement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ public class Movement : MonoBehaviour {
public Color TrailColor;
public Vector3 LeftPosition, RightPosition;
public Material TrailMaterial;
private bool _lock;

public void Lock(){
_lock = true;
}

public void Unlock(){
_lock = false;
}


// Update is called once per frame
void Update () {
if (_lock)
return;

transform.parent.position += transform.forward * Time.deltaTime * 4 * Speed;
transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler(Vector3.zero), Time.deltaTime * 1.5f);

Expand Down
24 changes: 14 additions & 10 deletions Assets/ShipCollision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@

public class ShipCollision : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

public TimeControl Control;
public GameObject Model;
public Movement Controls;
private bool _lock = false;

public void Reset(){
_lock = false;
}

void OnCollisionEnter(Collision col){
//Instantiate ();
//Destroy (this);
if (_lock)
return;

Controls.Lock ();
Control.Lose ();
Model.AddComponent<Explode> ();
_lock = true;
}
}
13 changes: 13 additions & 0 deletions Assets/TimeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ public class TimeControl : MonoBehaviour {
public Camera View;
public Text Score;
private float _score;
public bool Lost = false;
public RectTransform GameOver;
private Vector2 _targetGameOver;

public void Lose(){
Lost = true;
Time.timeScale = .25f;
_targetGameOver = Vector2.one * .5f;
}

void Update(){
GameOver.localScale = Lerp(GameOver.localScale, _targetGameOver, Time.deltaTime * 4f * (1/Time.timeScale));

if (Lost)
return;

if(Input.GetKey(KeyCode.Space) && EnergyLeft > 0 && !WasPressed){
EnergyLeft -= Time.deltaTime * EnergyUsage * (1/Time.timeScale);
Expand Down

0 comments on commit 9b0b1d9

Please sign in to comment.