-
Notifications
You must be signed in to change notification settings - Fork 1
/
Menu.cs
287 lines (241 loc) · 9.66 KB
/
Menu.cs
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour {
string mode = "main"; //How-to, credits.
int bomChanging;
public Texture soundOn;
public Texture soundOff;
public GUIStyle guiButton;
public GUIStyle guiBox;
public GUIStyle guiSmallButton;
public GUIStyle guiChangeBomb;
public GUIStyle guiSettings;
public Font font;
string newGame = "NEW GAME";
string howTo = "HOW TO";
string customize = "CUSTOMIZE";
string credits = "CREDITS";
string quit = "QUIT";
string back = "BACK";
#region GUI Positions
// The Y-coordinates and heights based on the screen being divided by 5.
// Each button is 1/5 of the screen, and is placed accordingly.
// the '-50' is used to modify the placement so it looks more aligned.
// New game button
int newGamePosX = Screen.width / 4;
int newGamePosY = Screen.height / 5 - 50;
int newGameWidth = Screen.width / 4 * 2;
int newGameHeight = Screen.height / 5;
Rect rectNewGame;
//How-to button ** Coordinates are also used for the customize-button **
int howToPosX = Screen.width / 4;
int howToPosY = Screen.height / 5 * 2 - 50;
int howToWidth = Screen.width / 4 * 2;
int howToHeight = Screen.height / 5;
Rect rectHowTo;
//Credits button ** Coordinates are also used for the Back-Button **
int creditsPosX = Screen.width / 4;
int creditsPosY = Screen.height / 5 * 3 - 50;
int creditsWidth = Screen.width / 4 * 2;
int creditsHeight = Screen.height / 5;
Rect rectCredits;
//Quit
int quitPosX = Screen.width / 4;
int quitPosY = Screen.height / 5 * 4 - 50;
int quitWidth = Screen.width / 4 * 2;
int quitHeight = Screen.height / 5;
Rect rectQuit;
// Settings
float settingsPosX = 10; // 10 for a little spacing;
float settingsPosY = Screen.height - 100 - 10; // minus 100 for the image. Minus 10 for a little spacing
float settingsWidth = Screen.width / 8; // Results in 100px at a width-800.
float settingsHeight = Screen.height / 4.8f; // Results in 100px at a height-480.
Rect rectSettings;
//Text Box - used for HowTo, Credits and Customize
int textBoxPosX = Screen.width / 4;
int textBoxPosY = Screen.height / 5 - 50;
int textBoxWidth = Screen.width / 4 * 2;
int textBoxHeight = Screen.height / 5 * 3;
Rect rectTextBox;
#region Customize bombs
//Customize bomb buttons
float customBombPosX1 = Screen.width / 4;
float customBombWidth1 = Screen.width / 4 * 2 / 3;
float customBombWidth2 = Screen.width / 4 * 2 / 3;
float customBombWidth3 = Screen.width / 4 * 2 / 3;
float customBombHeight = Screen.height / 5;
float customBombPosY = Screen.height / 5 * 2 - 50;
Rect[] rectCustomBomb = new Rect[3];
#endregion
#endregion
void Start()
{
rectNewGame = new Rect(newGamePosX, newGamePosY, newGameWidth, newGameHeight);
rectHowTo = new Rect(howToPosX, howToPosY, howToWidth, howToHeight);
rectCredits = new Rect(creditsPosX, creditsPosY, creditsWidth, creditsHeight);
rectQuit = new Rect(quitPosX, quitPosY, quitWidth, quitHeight);
rectTextBox = new Rect(textBoxPosX, textBoxPosY, textBoxWidth, textBoxHeight);
rectSettings = new Rect(settingsPosX, settingsPosY, settingsWidth, settingsHeight);
rectCustomBomb[0] = new Rect(customBombPosX1, customBombPosY, customBombWidth1, customBombHeight);
rectCustomBomb[1] = new Rect(customBombPosX1 + customBombWidth1, customBombPosY, customBombWidth2, customBombHeight);
rectCustomBomb[2] = new Rect((customBombPosX1 + customBombWidth1)+customBombWidth2, customBombPosY, customBombWidth3, customBombHeight);
if (!PlayerPrefs.HasKey("sound"))
{
PlayerPrefs.SetString("sound", "on");
}
//Bombs
if ( !PlayerPrefs.HasKey("BombType0") && !PlayerPrefs.HasKey("BombType1") && !PlayerPrefs.HasKey("BombType2"))
{
PlayerPrefs.SetString("BombType0", "SimpleBomb");
PlayerPrefs.SetString("BombType1", "SimpleBomb");
PlayerPrefs.SetString("BombType2", "SimpleBomb");
}
//settings for GUIStyles
guiBox.font = font;
guiButton.font = font;
guiChangeBomb.font = font;
guiSettings.font = font;
guiSmallButton.font = font;
}
void OnGUI()
{
switch (mode)
{
case "main":
MainMenu();
break;
case "howto":
HowTo();
break;
case "credits":
Credits();
break;
case "customize":
Customize();
break;
case "changebomb":
ChangeBomb(bomChanging);
break;
case "settings":
Settings();
break;
}
}
void MainMenu()
{
if (GUI.Button(rectNewGame, newGame, guiButton))
{
Application.LoadLevel(1);
}
if (GUI.Button(rectHowTo, howTo,guiButton))
{
mode = "howto";
}
if (GUI.Button(rectCredits, credits, guiButton))
{
mode = "credits";
}
if (GUI.Button(rectQuit, quit, guiButton))
{
Application.Quit();
}
if(GUI.Button(rectSettings, "", guiSettings))
{
mode = "settings";
}
}
void HowTo()
{
//GUI.Box(rectTextBox, "HOW TO PLAY!\nEach level you get 3 bombs.\nPlace them where you want.\nHit the Explode-button to begin when all bombs are placed.");
GUITextBox("\nHOW TO PLAY!\nEach level you get 3 bombs.\nPlace them where you want.\nHit the Detonate-button to begin,\n when all bombs are placed.\n\nPress the customize-button beow to change,\n what bombs you are placing.");
if(GUI.Button(rectCredits, customize, guiButton))
{
mode = "customize";
}
if (GUI.Button(rectQuit, back, guiButton))
{
mode = "main";
}
}
void Customize()
{
string[] bombtype = new string[3];
bombtype[0] = PlayerPrefs.GetString("BombType0");
bombtype[1] = PlayerPrefs.GetString("BombType1");
bombtype[2] = PlayerPrefs.GetString("BombType2");
GUITextBox("\nCustomize your gameplay.\nSelect one of the bombs to change the loadout.");
for (int i = 0; i < rectCustomBomb.Length; i++)
{
if (GUI.Button(rectCustomBomb[i], "Bomb " + i + "\n"+bombtype[i], guiSmallButton))
{
bomChanging = i;
mode = "changebomb";
}
}
if (GUI.Button(rectCredits, back, guiButton))
{
mode = "main";
}
}
void Credits()
{
//GUI.Box(rectTextBox, "Credits!\nDeveloped by Mikkel Thygesen.\nGraphics made by Mikkel Thygesen\nThanks to the Unity team!");
GUITextBox("\nCREDITS\nDeveloped by Mikkel Thygesen.\nGraphics made by Mikkel Thygesen\nThanks to the Unity team!\n- Copyright Mikkel Thygesen 2011 -");
if (GUI.Button(rectCredits, back, guiButton))
{
mode = "main";
}
}
void ChangeBomb(int i)
{
//GUI.Box(rectTextBox, "Change the bomb for bomb "+i);
GUITextBox("\nChange the bomb-loadout for bomb " + (i+1));
if (GUI.Button(rectHowTo, "SIMPLE BOMB\nThe simple bomb explode without any fancy tricks.\nShort name: SimpleBomb.", guiChangeBomb))
{
string[] value = { "BombType", i.ToString() };
PlayerPrefs.SetString(string.Join("", value, 0, 2), "SimpleBomb");
mode = "customize";
}
if (GUI.Button(rectCredits, "TIME BOMB\nThis lazy waits a few moments before it explode.\nShort name: TimeBomb.", guiChangeBomb))
{
string[] value = { "BombType", i.ToString() };
PlayerPrefs.SetString(string.Join("", value, 0, 2), "TimeBomb");
mode = "customize";
}
if (GUI.Button(rectQuit, "IMPLOSION BOMB\nThis highly advanced bomb pulls objects instead of throwing them away.\nShort name: ImpBomb.", guiChangeBomb))
{
string[] value = { "BombType", i.ToString() };
PlayerPrefs.SetString(string.Join("", value, 0, 2), "ImpBomb");
mode = "customize";
}
if (GUI.Button(new Rect(rectQuit.xMin,rectQuit.yMax,rectQuit.width,rectQuit.height), "COLLISION BOM\nThis bomb explodes when an object hits it.\nShort name: CollBomb", guiChangeBomb))
{
string[] value = { "BombType", i.ToString() };
PlayerPrefs.SetString(string.Join("", value, 0, 2), "CollBomb");
mode = "customize";
}
}
void GUITextBox(string text)
{
GUI.Box(rectTextBox, text, guiBox);
}
void Settings()
{
GUITextBox("\nSETTINGS\nClick the below icons to toggle sound, --");
if (PlayerPrefs.GetString("sound") == "on")
{
if (GUI.Button(rectCustomBomb[0], soundOn, GUIStyle.none))
{
PlayerPrefs.SetString("sound", "off");
}
}
else if (GUI.Button(rectCustomBomb[0], soundOff, GUIStyle.none))
{
PlayerPrefs.SetString("sound", "on");
}
if (GUI.Button(rectCredits, back, guiButton))
{
mode = "main";
}
}
}