-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGameController.cs
More file actions
executable file
·185 lines (142 loc) · 4.12 KB
/
Copy pathGameController.cs
File metadata and controls
executable file
·185 lines (142 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameController : MonoBehaviour {
public static float CurrentDistance = 0.0f;
public static int CurrentFoxCount = 0;
public static float BestDistance = 0.0f;
public static int BestFoxCount = 0;
public static float TotalDistance = 0.0f;
public static int TotalFoxCount = 0;
public static int Level = 0;
public static bool GamePaused = false;
public static bool IsTapFlyTutorialFinished = false;
public static bool IsTapFoxTutorialFinished = false;
public Animator restartButton;
public Animator homeButton;
public Animator gameoverPanel;
public Text distanceText;
public Text foxCountText;
public Text levelText;
public Toggle[] chickenIcons;
public Toggle[] foxIcons;
private int passedawayFriends = 0;
private int escapeFox = 0;
private bool gameOvered = false;
public delegate void GameDelegate();
public event GameDelegate GameOverEvent;
PlayerController playerController;
int touchCount = 0;
DomobAD domAD;
void Awake(){
TotalDistance = PlayerPrefs.GetFloat ("TotalDistance",0.0f);
TotalFoxCount = PlayerPrefs.GetInt ("TotalFoxCount",0);
Level = (int)(TotalDistance / 1000);
playerController = GameObject.Find("ChickenPlayer").GetComponent<PlayerController>();
playerController.OnTouchEvent += OnLeftScreenTouched;
playerController.OnTapFoxEvent += OnFoxTaped;
domAD = GameObject.Find("DomobAD").GetComponent<DomobAD>();
}
// Use this for initialization
void Start () {
BestDistance = PlayerPrefs.GetFloat ("BestDistance",0.0f);
BestFoxCount = PlayerPrefs.GetInt ("BestFoxCount",0);
GamePaused = false;
gameOvered = false;
passedawayFriends = 0;
}
void OnLeftScreenTouched(){
touchCount ++;
if(touchCount >= 6){
playerController.OnTouchEvent -= OnLeftScreenTouched;
IsTapFlyTutorialFinished = true;
}
}
void OnFoxTaped(){
playerController.OnTapFoxEvent -= OnFoxTaped;
IsTapFoxTutorialFinished = true;
}
// Update is called once per frame
void Update () {
}
void OnFriendPassedAway(){
passedawayFriends ++;
switch(passedawayFriends){
case 1:
chickenIcons[2].isOn = false;
break;
case 2:
chickenIcons[1].isOn = false;
break;
case 3:
chickenIcons[0].isOn = false;
OnGameOver();
break;
}
Debug.Log ("Friends:" + passedawayFriends);
}
void OnFoxEscape(){
escapeFox ++;
switch(escapeFox){
case 1:
foxIcons[0].isOn = true;
break;
case 2:
foxIcons[1].isOn = true;
break;
case 3:
foxIcons[2].isOn = true;
OnGameOver();
break;
}
}
void OnGameOver(){
GamePaused = true;
gameOvered = true;
PlayerPrefs.SetFloat ("TotalDistance",TotalDistance + CurrentDistance);
PlayerPrefs.SetInt ("TotalFoxCount",TotalFoxCount + CurrentFoxCount);
Level = (int)((TotalDistance + CurrentDistance) / 1000);
levelText.text = "Level:" + Level;
if (CurrentDistance > BestDistance) {
BestDistance = CurrentDistance;
PlayerPrefs.SetFloat ("BestDistance", BestDistance);
distanceText.text = "" + BestDistance + "m Best!";
} else {
distanceText.text = "" + CurrentDistance + "m VS " + BestDistance + "m";
}
if (CurrentFoxCount > BestFoxCount) {
BestFoxCount = CurrentFoxCount;
PlayerPrefs.SetInt ("BestFoxCount", BestFoxCount);
foxCountText.text = "" + BestFoxCount + " Best!";
} else {
foxCountText.text = "" + CurrentFoxCount + " VS " + BestFoxCount;
}
gameoverPanel.enabled = true;
gameoverPanel.SetBool ("isHidden",false);
if(GameOverEvent != null){
GameOverEvent();
}
if (domAD) {
//domAD.ShowInterstitial ();
}
}
public void OnPauseButtonClicked(){
if(gameOvered){return;}
GamePaused = !GamePaused;
restartButton.enabled = true;
homeButton.enabled = true;
restartButton.SetBool ("isHidden",!restartButton.GetBool("isHidden"));
homeButton.SetBool ("isHidden",!homeButton.GetBool("isHidden"));
}
public void OnRestartButtonClicked(){
CurrentDistance = 0.0f;
CurrentFoxCount = 0;
GamePaused = false;
IsTapFlyTutorialFinished = false;
IsTapFoxTutorialFinished = false;
Application.LoadLevel ("Game");
}
public void OnHomeButtonClicked(){
Application.LoadLevel ("Menu");
}
}