PageRenderTime 25ms CodeModel.GetById 2ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Scripts/Tutorial.js

http://acid-and-base.googlecode.com/
JavaScript | 527 lines | 472 code | 44 blank | 11 comment | 110 complexity | 6675225e2ed74adcc8bd28694544e655 MD5 | raw file
  1var inRange : boolean = false;
  2var inRangeB : boolean = false;
  3var inRangeC : boolean = false;
  4var showGUI : boolean = false;
  5var resetdialog : boolean = true;
  6
  7var part : int;
  8var tutorialtext : String;
  9var speakChar : String;
 10
 11private var count : int = 0;
 12private var wi : int;
 13private var he : int;
 14private var i : int;
 15private static var lineLength = 90;
 16private var bred;
 17private var acid;
 18private var base;
 19private var mcont : MasterController_edit;
 20var weedkiller : boolean = false;
 21var shovel : boolean = false;
 22var moveshow : boolean = false;
 23
 24private var enter : String = "Press Space to Continue";
 25
 26function Start ()
 27{
 28        mcont = GameObject.Find("Master Controller Light").GetComponent("MasterController_edit");
 29        bred = GameObject.Find("Big Red");
 30        acid = GameObject.Find("Acid");
 31        base = GameObject.Find("Base");
 32        switch(part)
 33        {
 34                case 0:
 35						speakChar = "System";
 36                        tutorialtext = "Press W A S D to Move.";
 37                break;
 38                
 39                case 1:
 40						speakChar = "System";
 41                        tutorialtext = "Press E to Interact.";
 42                break;
 43                
 44                case 2:
 45						speakChar = "Acid";
 46                        tutorialtext = "Oh... hi there. I'm Acid!";
 47                break;
 48                
 49                case 3:
 50						speakChar = "Base";
 51                        tutorialtext = "Oh thank you for freeing me! I'm Base. I'd be happy to help you.";
 52                break;
 53                
 54                case 4:
 55						speakChar = "System";
 56                        tutorialtext = "Acid and Base need to be neutral enough to climb.";
 57                break;
 58                
 59                case 5:
 60						speakChar = "Sad Ant";
 61						tutorialtext = "Man, I wish I could bring that steak \n back to my queen but it's blocked!";
 62                break;
 63                
 64                default:
 65                break;
 66        }
 67		
 68		tempStart();
 69}
 70
 71function Update ()
 72{
 73        switch(part)
 74        {
 75                case 0:
 76                        if(!showGUI && count == 0)
 77                        {
 78							count = 1;
 79							bred.GetComponent("ModifiedController").enabled = false;
 80							bred.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
 81                        }
 82						else if(count == 1 && !showGUI && moveshow)
 83                        {
 84                             showGUI = true;
 85                         }
 86                        else if(showGUI)
 87                        {
 88							if(Input.GetKeyDown(KeyCode.Space))
 89							{
 90									showGUI = false;
 91									bred.GetComponent("ModifiedController").enabled = true;
 92									Destroy(this);
 93							}
 94                        }
 95                break;
 96                
 97                case 1:
 98                        if(showGUI)
 99                        {
100                                if(Input.GetKeyDown(KeyCode.Space))
101                                {
102                                        showGUI = false;
103                                        bred.GetComponent("ModifiedController").enabled = true;
104                                        Destroy(this);
105                                }
106                        }
107                        else if(inRange)
108                        {
109                                showGUI = true;
110                                bred.GetComponent("ModifiedController").enabled = false;
111                                bred.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
112                        }
113                break;
114                
115                case 2:
116                        if(inRange && count == 0)
117                        {
118                                showGUI = true;
119                                bred.GetComponent("ModifiedController").enabled = false;
120                                count = 1;
121                                bred.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
122                        }
123                        else if(count == 1)
124                        {
125                                if(Input.GetKeyDown(KeyCode.Space))
126                                {
127                                        count = 2;
128										speakChar = "Acid";
129                                        tutorialtext = "What? You're stuck in a dream?";
130                                }
131                        }
132                        else if(count == 2)
133                        {
134                                if(Input.GetKeyDown(KeyCode.Space))
135                                {
136                                        count = 3;
137										speakChar = "Acid";
138                                        tutorialtext = "Okay, I'll help you, but you have to let me free my friend Base first. He got caught in a rat cage!";
139                                }
140                        }
141                        else if(count == 3)
142                        {
143                                if(Input.GetKeyDown(KeyCode.Space))
144                                {
145                                        count = 4;
146										speakChar = "Acid";
147                                        tutorialtext = "I can melt it if I become stronger. Help me find an item that will lower my pH.";
148                                }
149                        }
150                                                else if(count == 4)
151                                                {
152                                                        if(Input.GetKeyDown(KeyCode.Space))
153                                {
154                                        count = 5;
155										speakChar = "System";
156                                        tutorialtext = "Press Q to switch control between characters.";
157                                }
158                                                }
159                                                else if(count == 5)
160                                                {
161                                                        if(Input.GetKeyDown(KeyCode.Space))
162                                {
163                                        count = 6;
164										speakChar = "System";
165                                        tutorialtext = "Press F while touching a character to toggle follow.\nThe character will stop following you if you press E or Q.";
166                                }
167                                                }
168                        else if(count == 6)
169                        {
170                                if(Input.GetKeyDown(KeyCode.Space))
171                                {print("give me the controls back");
172                                        showGUI = false;
173                                        bred.GetComponent("ModifiedController").enabled = true;
174                                        mcont.gotAcid = true;
175                                        Destroy(this);
176                                }
177                        }
178                break;
179                
180                case 3:
181                        if(count == 4)
182                        {
183                                if(Input.GetKeyDown(KeyCode.Space))
184                                {
185                                        showGUI = false;
186                                        bred.GetComponent("ModifiedController").enabled = true;
187                                        acid.GetComponent("ModifiedController").enabled = true;
188                                        mcont.both = true;
189                                        Destroy(this);
190                                }
191                        }
192                                                else if(count == 3)
193                        {
194                                if(Input.GetKeyDown(KeyCode.Space))
195                                {
196                                        count = 4;
197										speakChar = "System";
198                                        tutorialtext = "Press ESC key to go to the pause menu.";
199                                }
200                        }
201                                                else if(count == 2)
202                        {
203                                if(Input.GetKeyDown(KeyCode.Space))
204                                {
205                                        count = 3;
206                                                                                /*var scale : controlInstruction = GameObject.Find("Master Controller Light").GetComponent("controlInstruction");
207                                                                                scale.canShowScale = true;*/
208                                                                                //scale.showScale = true;
209										speakChar = "System";
210                                        tutorialtext = "The top right bar on the pause screen represents the pH levels of Acid and Base.";
211                                }
212                        }
213                        else if(count == 1)
214                        {
215                                if(Input.GetKeyDown(KeyCode.Space))
216                                {
217                                        count = 2;
218										speakChar = "Base";
219                                        tutorialtext = "Let's get out of here first.\nI can't climb the dandelion though because I'm too basic.";
220                                }
221                        }
222                        else if(inRangeB || inRange && count == 0)
223                        {
224                                showGUI = true;
225                                bred.GetComponent("ModifiedController").enabled = false;
226                                bred.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
227                                acid.GetComponent("ModifiedController").enabled = false;
228                                acid.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
229                                mcont.gotAcid = false;
230                                count = 1;
231                        }
232                break;
233                
234                case 4:
235                        if(showGUI)
236                        {
237                                if(Input.GetKeyDown(KeyCode.Space))
238                                {
239                                        showGUI = false;
240                                        bred.GetComponent("ModifiedController").enabled = true;
241                                        acid.GetComponent("ModifiedController").enabled = true;
242                                        base.GetComponent("ModifiedController").enabled = true;
243                                        mcont.both = true;
244                                        Destroy(this);
245                                }
246                        }
247                        else if(inRangeC)
248                        {
249                                showGUI = true;
250                                bred.GetComponent("ModifiedController").enabled = false;
251                                bred.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
252                                acid.GetComponent("ModifiedController").enabled = false;
253                                acid.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
254                                base.GetComponent("ModifiedController").enabled = false;
255                                base.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
256                                mcont.both = false;
257                        }
258                break;
259                
260                case 5:
261                                if(showGUI && !weedkiller)
262                        {
263                                if(Input.GetKeyDown(KeyCode.Space))
264                                {
265                                        showGUI = false;
266                                        resetdialog = false;
267                                        bred.GetComponent("ModifiedController").enabled = true;
268                                        acid.GetComponent("ModifiedController").enabled = true;
269                                        base.GetComponent("ModifiedController").enabled = true;
270                                        mcont.both = true;
271                                        //Destroy(this);
272                                }
273                        }
274                        if(showGUI && weedkiller && count == 0)
275                        {
276                                if(Input.GetKeyDown(KeyCode.Space))
277                                {
278                                        count = 1;
279                                        resetdialog = false;
280										speakChar = "Base";
281                                        tutorialtext = "I bet I can use the steak to become soapy!";
282                                }
283
284                        }
285                        else if(count == 1)
286                        {
287                                if(Input.GetKeyDown(KeyCode.Space))
288                                {
289                                        showGUI = false;
290                                        bred.GetComponent("ModifiedController").enabled = true;
291                                        acid.GetComponent("ModifiedController").enabled = true;
292                                        base.GetComponent("ModifiedController").enabled = true;
293                                        mcont.both = true;
294                                        count = 0;
295										speakChar = "Sad Ant";
296										tutorialtext = "Man, I wish I could bring that steak back to my queen but it's blocked!";
297                                        //Destroy(this);
298                                }
299                        }
300                        else if(inRangeC && resetdialog)
301                        {
302                                showGUI = true;
303                                bred.GetComponent("ModifiedController").enabled = false;
304                                bred.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
305                                acid.GetComponent("ModifiedController").enabled = false;
306                                acid.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
307                                base.GetComponent("ModifiedController").enabled = false;
308                                base.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
309                                mcont.both = false;
310                        }
311                                                if(shovel)
312                                                {
313                                                        part = 6;
314                                                }
315                break;
316                
317                                case 6:
318                                                if(showGUI && count == 0)
319                        {
320                                                        if(Input.GetKeyDown(KeyCode.Space))
321                                                        {
322                                                                count = 1;
323																speakChar = "Base";
324                                                                tutorialtext = "I bet I can use the steak to become soapy!";
325                                                        }
326                        }
327                                                else if(count == 1)
328                                                {
329                                                         if(Input.GetKeyDown(KeyCode.Space))
330                                {
331                                        showGUI = false;
332                                        bred.GetComponent("ModifiedController").enabled = true;
333                                        acid.GetComponent("ModifiedController").enabled = true;
334                                        base.GetComponent("ModifiedController").enabled = true;
335                                        mcont.both = true;
336                                        Destroy(this);
337                                }
338                                                }
339                                                else if(inRangeC)
340                                                {
341                                                        showGUI = true;
342                                                        bred.GetComponent("ModifiedController").enabled = false;
343                                                        bred.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
344                                                        acid.GetComponent("ModifiedController").enabled = false;
345                                                        acid.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
346                                                        base.GetComponent("ModifiedController").enabled = false;
347                                                        base.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
348                                                        mcont.both = false;
349														speakChar = "Happy Ant";
350                                                        tutorialtext = "I wanna take you for a ride!";
351                                                        GameObject.Find("Ant").GetComponent("AntRide").enabled = true;
352}
353                                break;
354                                
355                default:
356                                if(showGUI)
357                        {
358                                if(Input.GetKeyDown(KeyCode.Space))
359                                {
360                                        showGUI = false;
361                                        bred.GetComponent("ModifiedController").enabled = true;
362                                        acid.GetComponent("ModifiedController").enabled = true;
363                                        base.GetComponent("ModifiedController").enabled = true;
364                                        mcont.both = true;
365                                        Destroy(this);
366                                }
367                        }
368                        else if(inRangeC)
369                        {
370                                showGUI = true;
371                                bred.GetComponent("ModifiedController").enabled = false;
372                                bred.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
373                                acid.GetComponent("ModifiedController").enabled = false;
374                                acid.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
375                                base.GetComponent("ModifiedController").enabled = false;
376                                base.GetComponent(CharacterMotor).inputMoveDirection = Vector3(0,0,0);
377                                mcont.both = false;
378                        }
379                break;
380        }
381		tempUpdate();
382}
383
384function OnTriggerEnter (col : Collider)
385{
386        var prop : Properties = col.GetComponent("Properties");
387        if(col.GetComponent(CharacterController) == null)
388                return;
389        inRangeC = true;
390        if(prop != null)
391        {
392                if(prop.abType == AcidOrBase.Acid)
393                        inRangeB = true;
394                return;
395        }
396        inRange = true;
397}
398
399function OnTriggerExit (col : Collider)
400{
401        var prop : Properties = col.GetComponent("Properties");
402        if(col.GetComponent(CharacterController) == null)
403                return;
404        inRangeC = false;
405        resetdialog = true;
406        if(prop != null)
407        {
408                if(prop.abType == AcidOrBase.Acid)
409                        inRangeB = false;
410                return;
411        }
412        inRange = false;
413}
414
415function OnGUI()
416{
417        if (showGUI)
418        {
419                //GUI.Label (Rect (Screen.width/2 - wi/2, Screen.height/2 - he/2, wi, he), tutorialtext, "box");
420                //GUI.Label (Rect (Screen.width/2 - (10*enter.length/2), Screen.height/2 + he/2 + 10, (10*enter.length), 20), enter, "box");
421				displayTextGUI(speakChar, tutorialtext);
422        }
423		tempOnGUI();
424}
425
426
427
428// below here are temporarily here for tomorrow's demo
429
430private var guiHeight = 0;			// gui window height.
431private var guiPadding = 10;		// gui padding
432var bgGoesHere : Texture2D;
433var putFontHere : Font;
434var acidFullImage : Texture2D;
435var baseFullImage : Texture2D;
436var redFullImage : Texture2D;
437
438var bgStyle : GUIStyle;					// textbox GUI style
439var idStyle : GUIStyle;					// text GUI style
440var txtStyle : GUIStyle;				// text GUI style (2)
441var emptyStyle : GUIStyle;			// empty style for images
442
443private var dispChar;
444private var dispMessage;
445
446private var wTop;
447private var wLeft;
448private var wLength;
449private var wWidth;
450
451private var gapForName;
452private var fNameSize;
453private var fTextSize;
454
455var displayGUI = false;
456
457function tempStart()
458{
459	// here goes the style!!
460	bgStyle.name = "box";
461	bgStyle.normal.background = bgGoesHere;
462
463	idStyle.name = "text_name";
464	idStyle.wordWrap = true;
465	idStyle.font = putFontHere;
466	idStyle.padding.left = 10;
467	idStyle.padding.top = 10;
468	idStyle.padding.right = 10;
469	idStyle.padding.bottom = 10;
470	idStyle.fontSize = 30;
471	idStyle.normal.textColor = Color(1,1,1,1);
472
473	txtStyle.name = "text_conversation";
474	txtStyle.wordWrap = true;
475	txtStyle.font = putFontHere;
476	txtStyle.padding.left = 10;
477	txtStyle.padding.top = 10;
478	txtStyle.padding.right = 10;
479	txtStyle.padding.bottom = 10;
480	txtStyle.fontSize = 20;
481	txtStyle.normal.textColor = Color(1,1,1,1);
482	
483	dispChar = "NULL";
484	dispMessage = "NULL String is NULL";
485}
486
487function tempUpdate()
488{
489	// height of the GUI will always be 1/3 of the screen...
490	guiHeight = Screen.height/3;
491	
492	wLeft = guiPadding;
493	wTop = Screen.height-guiHeight;
494	wLength = Screen.width-(2*guiPadding);
495	wWidth = guiHeight-guiPadding;
496	
497	fNameSize = guiHeight/5;
498	idStyle.fontSize = fNameSize;
499	
500	fTextSize = guiHeight/8;
501	txtStyle.fontSize = fTextSize;
502	
503	gapForName = fNameSize;
504}
505
506function tempOnGUI()
507{
508	if (displayGUI)
509	{
510		//GUI.Box(Rect(0,0,Screen.width,Screen.height),acidFullImage,emptyStyle);
511		GUI.Box(Rect(wLeft,wTop,wLength,wWidth),"",bgStyle);
512		GUI.Box(Rect(wLeft,wTop,wLength,wWidth),dispChar,idStyle);
513		GUI.Box(Rect(wLeft,wTop+gapForName,wLength,wWidth),dispMessage,txtStyle);
514	}
515}
516
517function displayTextGUI(chara : String, message : String)
518{
519	displayGUI = true;
520	dispChar = chara;
521	dispMessage = message;
522}
523
524function removeGUI()
525{
526	displayGUI = false;
527}