-
-
Save alxcancado/aea1062c877e2bc7ad58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class Game : MonoBehaviour | |
{ | |
public static Game instance; | |
public Player player; | |
public int score = 0; | |
public bool isPlaying = true; | |
public TextMesh scoreHud; | |
public TextMesh scoreText; | |
public Renderer screenWin; | |
public Renderer screenLose; | |
public GameObject enemyGroup; | |
public GameObject titleScreen; | |
public enum Direction | |
{ | |
North, | |
South, | |
East, | |
West | |
} | |
void Awake() | |
{ | |
Direction dir = (Direction.North | Direction.South); | |
if (dir == Direction.North) | |
Debug.Log("north"); | |
if (dir == Direction.South) | |
Debug.Log("south"); | |
instance = this; | |
screenWin.enabled = false; | |
screenLose.enabled = false; | |
scoreText.renderer.enabled = false; | |
score = 0; | |
UpdateScore(0); | |
} | |
public void UpdateScore(int newScore) | |
{ | |
score += newScore; | |
scoreHud.text = "Score: " + score.ToString("000000"); | |
scoreText.text = "Score: " + score.ToString("000000"); | |
} | |
public void WinGame() | |
{ | |
if (isPlaying == false) | |
return; | |
Gui.Log("Congratulations!"); | |
foreach (EnemySide enemy in FindObjectsOfType( typeof(EnemySide) ) ) | |
enemy.SendMessage("Death", SendMessageOptions.DontRequireReceiver); | |
isPlaying = false; | |
Sound.Play(Sound.FX.JingleWin); | |
StartCoroutine("FadeIn", screenWin); | |
} | |
public void LoseGame() | |
{ | |
Gui.Log("Oh noes!"); | |
foreach (EnemySide enemy in FindObjectsOfType( typeof(EnemySide) ) ) | |
enemy.SendMessage("Death", SendMessageOptions.DontRequireReceiver); | |
Destroy(enemyGroup); | |
isPlaying = false; | |
Sound.Play(Sound.FX.JingleLose); | |
StartCoroutine("FadeIn", screenLose); | |
} | |
IEnumerator FadeIn(Renderer rend) | |
{ | |
float f = 0.0f; | |
rend.enabled = true; | |
rend.material.color = Color.clear; | |
scoreText.renderer.material.color = Color.clear; | |
scoreText.renderer.enabled = true; | |
while (f < 1.0f) | |
{ | |
yield return null; | |
f += Time.deltaTime; | |
rend.material.color = new Color(1,1,1, Mathfx.Hermite (0, 1, f) ); | |
scoreText.renderer.material.color = new Color(1,1,1, Mathfx.Hermite (0, 1, f) ); | |
} | |
rend.material.color = Color.white; | |
} | |
// Use this for initialization | |
void Start () | |
{ | |
Debug.Log("rot = " + transform.rotation.ToString() ); | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
if (Input.GetKeyDown(KeyCode.T)) | |
FadeInOut.FadeOutAll(); | |
if (Input.GetKeyDown(KeyCode.Y)) | |
FadeInOut.FadeInAll(); | |
if (Input.GetKeyDown(KeyCode.F)) | |
Gui.instance.gameObject.BroadcastMessage("Fade", SendMessageOptions.DontRequireReceiver); | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ | |
Time.timeScale = 1.0f; | |
Destroy(titleScreen); | |
} | |
if (Input.GetKeyDown(KeyCode.R)) | |
Application.LoadLevel(Application.loadedLevel); | |
if (Input.GetKeyDown(KeyCode.H) ) | |
WinGame(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment