/Scripts/Tutorial.js

http://acid-and-base.googlecode.com/ · JavaScript · 527 lines · 472 code · 44 blank · 11 comment · 110 complexity · 6675225e2ed74adcc8bd28694544e655 MD5 · raw file

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