enum State {Initialise,Sequence,Play,Pause,Win,Lose,GameOver,LevelComplete};
var rootObject : GameObject;
var animationRoot : GameObject;
var corona : GameObject;
var outerRing : GameObject;
var innerRing : GameObject;
////////////////////////
// Buttons info:
// 0 - Blue
// 1 - Green
// 2 - Red
// 3 - Yellow
////////////////////////
var outerButtons : GameObject[];
var innerButtons : GameObject[];
// GUI
var guiColour : Color;
var guiSkin : GUISkin;
var gameOverTexture : Texture2D;
var levelCompleteTexture : Texture2D;
var heartIcon : Texture2D;
// sounds
var pingSound : AudioClip;
var buzzerSound : AudioClip;
var klaxonSound : AudioClip;
// level stats
var currentLevel : int = 1;
var difficultyLevel : int = 1;
var score : int = 0;
var pointsPerHit : int = 1;
var TimeBonus : int = 10;
var maxTime : float = 20;
var lives : int = 3;
// disc rotation
var outerSpinSpeed : float = 2;
var innerSpinSpeed : float = 0;
var maxSpinSpeed : float = 60;
// button timings
var flashTime : float = 1.5;
var minFlashTime : float = 0.2;
// counters, arrays, etc
var timeCounter : float = 60;
var gameState : State = State.Sequence;
private var buttonSequence : Array = new Array();
private var sequenceIndex : int = 0;
function Start(){
//buttonSequence = new Array();
yield WaitForSeconds(4); // wait for animtaion
rootObject.transform.position = Vector3.zero;
NewGame();
}
function Update () {
if(gameState == State.Play){
UpdateTime();
UpdateTouchInput();
}
UpdateCorona();
}
function OnGUI(){
GUI.skin = guiSkin;
GUI.color = guiColour;
if(gameState == State.Initialise){
}else if(gameState == State.GameOver){
GUI.DrawTexture(Rect(0,Screen.height/2-(Screen.width*0.1),Screen.width,Screen.width*0.2),gameOverTexture);
GUI.Label(Rect(0,50,Screen.width,40),"SCORE: "+score,"Centered");
if(GUI.Button(Rect(Screen.width/2-190,Screen.height/2+(Screen.width/11)+20,180,40),"","Restart")){
Application.LoadLevel(Application.loadedLevel);
}
if(GUI.Button(Rect(Screen.width/2+10,Screen.height/2+(Screen.width/11)+20,180,40),"","Menu")){
// go to menu
Application.LoadLevel("TTT_MainMenu");
}
}else if(gameState == State.LevelComplete){
GUI.Label(Rect(Screen.width*0.04,15,Screen.width,40),"LEVEL - "+currentLevel.ToString());
GUI.Label(Rect(Screen.width*0.04,27,Screen.width,40),"SCORE - "+score.ToString());
GUI.DrawTexture(Rect(0,Screen.height/2-(Screen.width*0.05),Screen.width,Screen.width*0.1),levelCompleteTexture);
GUI.Label(Rect(0,Screen.height-100,Screen.width,40),"Level Bonus: "+(currentLevel*difficultyLevel*20),"Centered");
for(i=0;i<lives;i++){
GUI.DrawTexture(Rect(Screen.width-32*i-42,Screen.height-35,32,30),heartIcon);
}
}else if(gameState == State.Win){
GUI.Label(Rect(Screen.width*0.04,15,Screen.width,40),"LEVEL - "+currentLevel.ToString());
GUI.Label(Rect(Screen.width*0.04,27,Screen.width,40),"SCORE - "+score.ToString());
GUI.Label(Rect(0,Screen.height/2-6,Screen.width,40),Mathf.Ceil(timeCounter).ToString(),"Centered");
GUI.Label(Rect(0,Screen.height-100,Screen.width,40),"Time Bonus: "+(Mathf.Ceil(timeCounter)*difficultyLevel),"Centered");
for(i=0;i<lives;i++){
GUI.DrawTexture(Rect(Screen.width-32*i-42,Screen.height-35,32,30),heartIcon);
}
}else if(gameState == State.Pause){
// Pause Buttons
if(Screen.width<500){
if(GUI.Button(Rect(Screen.width*.85,Screen.height*.05625,48,43),"","Pause")){
gameState = State.Play;
}
}else{
if(GUI.Button(Rect(846,34,97,84),"","Pause")){
gameState = State.Play;
}
}
if(GUI.Button(Rect(Screen.width/2-90,Screen.height/2-40,180,40),"","Continue")){
gameState = State.Play;
}
if(GUI.Button(Rect(Screen.width/2-90,Screen.height/2+5,180,40),"","Restart")){
Application.LoadLevel(Application.loadedLevel);
}
if(GUI.Button(Rect(Screen.width/2-90,Screen.height/2+50,180,40),"","Menu")){
// load menu
Application.LoadLevel("TTT_MainMenu");
}
GUI.Label(Rect(Screen.width*0.04,15,Screen.width,40),"LEVEL - "+currentLevel.ToString());
GUI.Label(Rect(Screen.width*0.04,27,Screen.width,40),"SCORE - "+score.ToString());
for(i=0;i<lives;i++){
GUI.DrawTexture(Rect(Screen.width-32*i-42,Screen.height-35,32,30),heartIcon);
}
}else if(gameState == State.Play){
// Pause Buttons
if(Screen.width<500){
if(GUI.Button(Rect(Screen.width*.85,Screen.height*.05625,48,43),"","Pause")){
gameState = State.Pause;
}
}else{
if(GUI.Button(Rect(846,34,97,84),"","Pause")){
gameState = State.Pause;
}
}
GUI.Label(Rect(Screen.width*0.04,15,Screen.width,40),"LEVEL - "+currentLevel.ToString());
GUI.Label(Rect(Screen.width*0.04,27,Screen.width,40),"SCORE - "+score.ToString());
GUI.Label(Rect(0,Screen.height/2-6,Screen.width,40),Mathf.Ceil(timeCounter).ToString(),"Centered");
for(i=0;i<lives;i++){
GUI.DrawTexture(Rect(Screen.width-32*i-42,Screen.height-35,32,30),heartIcon);
}
}else{
GUI.Label(Rect(Screen.width*0.04,15,Screen.width,40),"LEVEL - "+currentLevel.ToString());
GUI.Label(Rect(Screen.width*0.04,27,Screen.width,40),"SCORE - "+score.ToString());
GUI.Label(Rect(0,Screen.height/2-6,Screen.width,40),Mathf.Ceil(timeCounter).ToString(),"Centered");
for(i=0;i<lives;i++){
GUI.DrawTexture(Rect(Screen.width-32*i-42,Screen.height-35,32,30),heartIcon);
}
}
}
function UpdateTime(){
timeCounter -= Time.deltaTime;
if(timeCounter <= 0){
LoseLife();
}
}
function UpdateTouchInput(){
// spin the disc
if(currentLevel >= 1){
outerRing.transform.Rotate(Vector3.forward*outerSpinSpeed*Time.deltaTime);
}
if(currentLevel >= 20){
innerRing.transform.Rotate(-Vector3.forward*innerSpinSpeed*Time.deltaTime);
}
if(Application.isEditor){
// stuff
}else{
if(Input.touchCount == 1 Input.GetTouch(0).phase == TouchPhase.Began){
// Construct a ray from the current mouse coordinates
ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
if (Physics.Raycast (ray,hit)) {
for(i=0;i<4;i++){
if(hit.collider.gameObject == outerButtons[i]){
TouchButton(outerButtons[i]);
outerButtons[i].renderer.material.color = Color.white;
if(!PlayerPrefs.HasKey("Mute")){
audio.pitch = 1-i*0.1;
audio.Play();
}
}else if(hit.collider.gameObject == innerButtons[i]){
TouchButton(innerButtons[i]);
innerButtons[i].renderer.material.color = Color.white;
if(!PlayerPrefs.HasKey("Mute")){
audio.pitch = 1-i*0.1;
audio.Play();
}
}
}
}
}
if(Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(0).phase == TouchPhase.Canceled || Input.touchCount < 1){
// make all materials grey
for(i=0;i<4;i++){
innerButtons[i].renderer.material.color = Color.grey;
outerButtons[i].renderer.material.color = Color.grey;
}
}
}
}
function TouchButton(go : GameObject){
if(go == buttonSequence[sequenceIndex]){
sequenceIndex++;
score += sequenceIndex;
if(buttonSequence.length == sequenceIndex){
Win();
}
}else{
LoseLife();
}
}
function Win(){
//stuff
}
function LoseLife(){
// stuff
}
function NewGame(){
flashTime *= 0.9;
flashTime = Mathf.Clamp(flashTime,0.2,1);
if(buttonSequence.length >= difficultyLevel*5){
gameState = State.LevelComplete;
score += currentLevel*difficultyLevel*20; // level bonus
animationRoot.animation.Play("fly out and in");
yield WaitForSeconds(4.5); // display the level complete screen for 3.5 seconds
rootObject.transform.position = Vector3.zero;
currentLevel++;
// Clear the array
buttonSequence.Clear();
sequenceLength = 0;
//lives = 3;
flashTime = 1-currentLevel*0.01;
outerSpinSpeed += 6;
outerSpinSpeed = Mathf.Clamp(outerSpinSpeed,0,maxSpinSpeed);
if(currentLevel>5){
innerSpinSpeed += 6;
innerSpinSpeed = Mathf.Clamp(innerSpinSpeed,0,maxSpinSpeed);
}
}
timeCounter = maxTime-difficultyLevel*5;
UpdateSequence();
}
function LoseRepeat(){
// stuff
}
function UpdateSequence(){
gameState = State.Sequence;
// set up the audio
audio.clip = pingSound;
// make all materials grey
for(i=0;i<4;i++){
innerButtons[i].renderer.material.color = Color.grey;
outerButtons[i].renderer.material.color = Color.grey;
}
// Step 1: Select a random button
var buttonIndex = Random.Range(0,4);
var buttonGO : GameObject;
if(currentLevel < 5){ // inner ring only activates beyond level 20
buttonGO = outerButtons[buttonIndex];
}else{
if(Random.value>0.5){ // outer ring
buttonGO = outerButtons[buttonIndex];
}else{ // inner ring
buttonGO = innerButtons[buttonIndex];
}
}
// Step 2: Record the button
buttonSequence.Push(buttonGO);
// Step 3: Flash the whole sequence button on for a second
for(i=0;i<buttonSequence.length;i++){
buttonSequence[i].renderer.material.color = Color.white;
// pitch change audio
for(j=0;j<4;j++){
if(buttonSequence[i] == outerButtons[j]){
if(!PlayerPrefs.HasKey("Mute")){
audio.pitch = 1-j*0.1;
audio.Play();
break;
}
}else if(buttonSequence[i] == innerButtons[j]){
if(!PlayerPrefs.HasKey("Mute")){
audio.pitch = 1-j*0.1;
audio.Play();
break;
}
}
}
yield WaitForSeconds(flashTime);
buttonSequence[i].renderer.material.color = Color.grey;
audio.Stop();
yield WaitForSeconds(flashTime/2);
}
gameState = State.Play;
}
function UpdateCorona(){
// stuff
}
function PlayFlyOut(){
// stuff
}
function GameOver(){
// stuff
}