SebastianLawe

Untitled

Apr 27th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.52 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using GUISimplification;
  4. using Inventory;
  5. using IOUtlility;
  6. using System.Collections.Generic;
  7. using Assets.Scripts;
  8. using System.Diagnostics;
  9.  
  10. public class MainMenu : MonoBehaviour {
  11.     World world;
  12.     int y = 10;
  13.     int x = 10;
  14.     public Texture logo;
  15.     public GUIStyle multiplayerStyle;
  16.     public GUIStyle legalStyle;
  17.     public GUIStyle instructionsStyle;
  18.     bool gotCredentials;
  19.     GameJoltAPIManager manager;
  20.     PlayerController player;
  21.     GamePadScript gamePad;
  22.     public int MaxSpeed;
  23.     public bool customizationMenu = false;
  24.     public bool multiplayerMenu = false;
  25.     bool loadBall = false;
  26.     int currentBall = 0;
  27.     int score = 0;
  28.     List<CustomBall> balls;
  29.     GUICoordinates guiCoordinates;
  30.     private bool instructions;
  31.     private bool credits;
  32.     private bool alreadyInitialized = false;
  33.     CameraFollow camera;
  34.     public Stopwatch initiationTimer = Stopwatch.StartNew();
  35.     #region Instructions
  36.     private string instructionsText = string.Format(
  37. @"The controls for Smashy Ball have been designed to be intuitive from the start.
  38. Hold up to slowly hover, and press left and right to move. {0}", Application.platform == RuntimePlatform.Android ? "On android these actions are performed on different portions of the screen." : "");
  39.     #endregion Instructions
  40.     #region Legal
  41.     private string legal = @"
  42.  
  43. Smashy Ball is the sole property of Sebastian Lawe. Sebane Studios is
  44. an alias, and has yet to be registered as a business or company.
  45. The name and logo for Sebane Studios are the sole property of Sebastian Lawe.
  46.  
  47. Music soundtrack created by FoxHunt.";
  48.     #endregion Legal
  49.     #region Multiplayer
  50.     private string _multiplayer =
  51. @"
  52. Welcome to Multiplayer!
  53. Play Smashy Ball with another friend in your living room!
  54.  
  55. Instructions:
  56. One player will play the game using a Wii Remote or Wii U Pro controller.
  57. The other player will play with the gamepad, and control what spawns next in the game.
  58. After 10 deaths, both players will swap controllers. Whoever survives the longest wins!
  59. ";
  60.     #endregion Multiplayer
  61.     // Use this for initialization
  62.     void Start() {
  63.         camera = Camera.main.GetComponent<CameraFollow>();
  64.         world = FindObjectOfType<World>();
  65.         manager = FindObjectOfType<GameJoltAPIManager>();
  66.         player = GetComponent<PlayerController>();
  67.         gamePad = GameObject.FindObjectOfType<GamePadScript>();
  68.         balls = CustomBall.GetBalls();
  69.         if (!world.oldOffsetAlreadySet) {
  70.             world.oldOffset = camera.Offset;
  71.             world.oldOffsetAlreadySet = true;
  72.         }
  73. #if !UNITY_WEBPLAYER
  74.         string[] userNameAndPass = IOAccess.OpenCredentials("credentials.sbf");
  75.         score = IOAccess.OpenScore("score.sbf");
  76.         manager.userName = userNameAndPass[0];
  77.         manager.userToken = userNameAndPass[1];
  78.         manager.Verify();
  79. #endif
  80.         while (balls[currentBall].Name != world.BallName) {
  81.             currentBall++;
  82.         }
  83.     }
  84.  
  85.     // Update is called once per frame
  86.     void FixedUpdate() {
  87. #if !UNITY_WEBPLAYER
  88.         if (!gotCredentials) {
  89.             //if (GJAPI.User != null) {
  90.             //  IOAccess.SaveCredentials("credentials.sbf", GJAPI.User.Name, GJAPI.User.Token);
  91.             //  gotCredentials = true;
  92.             //}
  93.         }
  94. #endif
  95.         if (customizationMenu) {
  96.             camera.Offset = Vector3.Lerp(camera.Offset, new Vector3(0.05f, 0.007f, -0.75f), 0.2f);
  97.         } else {
  98.             camera.Offset = Vector3.Lerp(camera.Offset, world.oldOffset, 0.2f);
  99.             if (initiationTimer.ElapsedMilliseconds >= 5000) {
  100.                 if (transform.position.y < world.CurrentYPos) {
  101.                     transform.rigidbody.AddForce(0, 20, 0);
  102.                 } else {
  103.                     if (transform.rigidbody.velocity.x < MaxSpeed) {
  104.                         transform.rigidbody.AddForce(10, 0, 0);
  105.                         if (player != null) {
  106.                             player.enabled = false;
  107.                         }
  108.                     }
  109.                 }
  110.             } else {
  111.                 transform.rigidbody.velocity = new Vector3();
  112.             }
  113.         }
  114.     }
  115.  
  116.     void OnCollisionStay(Collision collision) {
  117.  
  118.     }
  119.  
  120.     void OnGetFromWeb(string name, string token) {
  121.         manager.name = name;
  122.         manager.userToken = token;
  123.  
  124.     }
  125.     void OnGUI() {
  126. #if UNITY_WEBPLAYER
  127.         if (manager.Verified) {
  128.             IOAccess.OpenScoreOnline();
  129.             score = IOAccess.OnlineScore;
  130.         }
  131. #endif
  132.         GUI.skin = world.Skin;
  133.         if (!customizationMenu && !credits && !instructions && !multiplayerMenu) {
  134.             guiCoordinates = new GUICoordinates(new RelativeRect(40, 35, 20, 10));
  135.             if (!world.FreeVersion) {
  136.                 //if (GJAPI.User == null) {
  137.                 //  if (GUI.Button(guiCoordinates.AssignCoordinates(), "Login")) {
  138.                 //    GJAPIHelper.Users.ShowLogin();
  139.                 //    GJAPIHelper.Users.ShowGreetingNotification();
  140.                 //    GJAPIHelper.Users.GetFromWeb(OnGetFromWeb);
  141.                 //  }
  142.                 //}
  143.             }
  144.             GUI.DrawTexture(RelativeRect.GetRelative(new Rect(0, 5, 100, 40)), logo);
  145.             if (GUI.Button(guiCoordinates.AssignCoordinates(), "Play")) {
  146.                 player.enabled = true;
  147.                 player.score = 0;
  148.                 player.Die();
  149.                 player.score = 0;
  150.                 world.ZenMode = false;
  151.                 world._multiplayer = false;
  152.                 world.MainMenu = false;
  153.                 world.Reset();
  154.                 GetComponent<MainMenu>().enabled = false;
  155.             }
  156. #if UNITY_WIIU
  157.             if (GUI.Button(guiCoordinates.AssignCoordinates(), "Play Multiplayer")) {
  158.                 multiplayerMenu = true;
  159.             }
  160. #endif
  161.             if (!world.FreeVersion) {
  162. #if UNITY_EDITOR
  163.                 if (GUI.Button(guiCoordinates.AssignCoordinates(), "Zen")) {
  164.                     player.enabled = true;
  165.                     player.Die();
  166.                     player.score = 0;
  167.                     world.ZenMode = true;
  168.                     GetComponent<MainMenu>().enabled = false;
  169.                     //Application.LoadLevel(Application.loadedLevel + 1);
  170.                     world.MainMenu = false;
  171.                     world.Reset();
  172.                 }
  173. #endif
  174.             }
  175.             if (GUI.Button(guiCoordinates.AssignCoordinates(), "Instructions")) {
  176.                 instructions = true;
  177.             }
  178.             //if (GUI.Button(guiCoordinates.AssignCoordinates(), "Leaderboards")) {
  179.             //  //GJAPIHelper.Scores.ShowLeaderboards();
  180.             //}
  181.             string gamePadText = "Touchpad On";
  182.             if (gamePad.OverridePlatformRestriction) {
  183.                 gamePadText = "Touchpad On";
  184.             } else {
  185.                 gamePadText = "Touchpad Off";
  186.             }
  187.             if (Application.isEditor) {
  188.                 if (GUI.Button(guiCoordinates.AssignCoordinates(), gamePadText)) {
  189.                     gamePad.OverridePlatformRestriction = !gamePad.OverridePlatformRestriction;
  190.                 }
  191.             }
  192.         } else if (customizationMenu) {
  193.             /*string data = ""
  194.             GJAPI.Data.GetCallback(data);
  195.             GJAPI.Data.Get("score");
  196.             if (score < int.Parse(data)) {
  197.                 score = int.Parse(data);
  198.             }*/
  199.             if (GUI.Button(RelativeRect.GetRelative(80, 40, 20, 10), "Next")) {
  200. #if !UNITY_WEBPLAYER
  201.                 score = IOAccess.OpenScore("score.sbf");
  202. #endif
  203.                 if (currentBall + 1 < balls.Count) {
  204.                     currentBall++;
  205.                 } else {
  206.                     currentBall = 0;
  207.                 }
  208.                 loadBall = true;
  209.             }
  210.             if (GUI.Button(RelativeRect.GetRelative(0, 40, 20, 10), "Previous")) {
  211. #if !UNITY_WEBPLAYER
  212.                 score = IOAccess.OpenScore("score.sbf");
  213. #endif
  214.                 if (currentBall - 1 > -1) {
  215.                     currentBall--;
  216.                 } else {
  217.                     currentBall = balls.Count - 1;
  218.                 }
  219.                 loadBall = true;
  220.             }
  221.             CustomBall ball = balls[currentBall];
  222.             if (ball.Free == world.FreeVersion || ball.Free) {
  223.                 if (score >= ball.Cost) {
  224.                     GUI.Label(RelativeRect.GetRelative(0, 0, 100, 100), Spacer.SpaceCapitals(ball.Name));
  225.                     if (loadBall) {
  226.                         loadBall = false;
  227.                         GameObject newObject = Instantiate(Resources.Load(ball.Name), transform.position, player.transform.rotation) as GameObject;
  228.                         world.BallName = ball.Name;
  229.                         Vector3 pos = transform.GetComponent<PlayerController>().startPosition;
  230.                         if (newObject != null) {
  231.                             newObject.rigidbody.velocity = player.rigidbody.velocity;
  232.                             newObject.GetComponent<PlayerController>().enabled = false;
  233.                             newObject.GetComponent<MainMenu>().customizationMenu = true;
  234.                         }
  235.                         DestroyObject(transform.gameObject);
  236.                         world.BallName = ball.Name;
  237. #if !UNITY_WEBPLAYER
  238.                         IOAccess.SaveBallType("ballType.sbf", ball.Name);
  239. #endif
  240.                     }
  241.                 } else {
  242.                     GUI.Label(RelativeRect.GetRelative(0, 0, 100, 100), ball.Cost + "m to unlock.");
  243.                     if (loadBall) {
  244.                         loadBall = false;
  245.                         GameObject newObject = Instantiate(Resources.Load(ball.Name), transform.position, Quaternion.identity) as GameObject;
  246.                         world.BallName = ball.Name;
  247.                         Vector3 pos = transform.GetComponent<PlayerController>().startPosition;
  248.                         if (newObject != null) {
  249.                             newObject.GetComponent<PlayerController>().enabled = false;
  250.                             newObject.GetComponent<MainMenu>().customizationMenu = true;
  251.                         }
  252.                         DestroyObject(transform.gameObject);
  253.                     }
  254.                 }
  255.             } else {
  256.                 if (GUI.Button(guiCoordinates.AssignCoordinates(), "Not in this version.")) {
  257.  
  258.                 }
  259.             }
  260.         } else if (credits) {
  261.             if (!customizationMenu && !instructions && !multiplayerMenu) {
  262.                 GUI.Window(0, RelativeRect.GetRelative(0, 0, 100, 100), delegate(int windowID) {
  263.                     if (GUI.Button(RelativeRect.GetRelative(80, 84, 20, 10), "Back")) {
  264.                         credits = false;
  265.                     }
  266.                 }, "", legalStyle);
  267.             }
  268.         }
  269.         if (instructions) {
  270.             if (!customizationMenu && !credits && !multiplayerMenu) {
  271.                 GUI.Window(0, RelativeRect.GetRelative(0, 0, 100, 100), delegate(int windowID) {
  272.                     if (GUI.Button(RelativeRect.GetRelative(80, 84, 20, 10), "Back")) {
  273.                         instructions = false;
  274.                     }
  275.                 }, "", instructionsStyle);
  276.             }
  277.         }
  278.         if (multiplayerMenu && !customizationMenu && !instructions) {
  279.             GUI.Window(0, RelativeRect.GetRelative(0, 0, 100, 100), delegate(int windowID) {
  280.                 if (GUI.Button(RelativeRect.GetRelative(0, 84, 20, 10), "Back")) {
  281.                     multiplayerMenu = false;
  282.                 }
  283.  
  284.                 if (GUI.Button(RelativeRect.GetRelative(80, 84, 20, 10), "Play")) {
  285.                     player.enabled = true;
  286.                     multiplayerMenu = false;
  287.                     player.score = 0;
  288.                     player.Die();
  289.                     player.score = 0;
  290.                     world.ZenMode = false;
  291.                     world._multiplayer = true;
  292.                     world.MainMenu = false;
  293.                     world.Reset();
  294.                     GetComponent<MainMenu>().enabled = false;
  295.                 }
  296.             }, "", multiplayerStyle);
  297.         }
  298.         if (!credits && !instructions && !multiplayerMenu) {
  299.             if (!customizationMenu && !instructions) {
  300.                 if (GUI.Button(RelativeRect.GetRelative(0, 90, 20, 10), "Credits")) {
  301.                     credits = true;
  302.                 }
  303.             }
  304.             if (!world.FreeVersion && IOAccess.OpenScore("score.sbf") > 0) {
  305.                 if (GUI.Button(RelativeRect.GetRelative(80, 90, 20, 10), "Customize")) {
  306. #if !UNITY_WEBPLAYER
  307.                     score = IOAccess.OpenScore("score.sbf");
  308. #endif
  309.                     if (score >= balls[currentBall].Cost) {
  310.                         if (customizationMenu) {
  311.                             customizationMenu = !customizationMenu;
  312.                             GameObject newObject = Instantiate(Resources.Load(balls[currentBall].Name), transform.position, Quaternion.identity) as GameObject;
  313. #if !UNITY_WEBPLAYER
  314.                             world.BallName = IOAccess.OpenBallType("ballType.sbf");
  315. #endif
  316.                             Vector3 pos = transform.GetComponent<PlayerController>().startPosition;
  317.                             if (newObject != null) {
  318.                                 newObject.GetComponent<PlayerController>().startPosition = new Vector3(pos.x, pos.y, pos.z);
  319.                                 newObject.GetComponent<MainMenu>().customizationMenu = this.customizationMenu;
  320.                             }
  321.                             DestroyObject(transform.gameObject);
  322.                         }
  323.                         customizationMenu = !customizationMenu;
  324.                     }
  325.                 }
  326.             }
  327.         }
  328. #if UNITY_STANDALONE
  329.         if (!customizationMenu) {
  330.             if (GUI.Button(guiCoordinates.AssignCoordinates(), "Quit")) {
  331.                 Application.Quit();
  332.             }
  333.         }
  334. #endif
  335.     }
  336.     void Update() {
  337.         //float inputY = Input.GetAxis("Vertical");
  338.         //float inputX = Input.GetAxis("Horizontal");
  339.         //Vector3 playerPos = gameObject.transform.position;
  340.         //if (gameObject.transform.position.x + 1 > x && inputX > 0f) {
  341.         //  gameObject.transform.position = new Vector3(playerPos.x + inputX, playerPos.y, playerPos.z);
  342.         //}
  343.         //if (gameObject.transform.position.y + 1 > x && inputX > 0f) {
  344.         //  gameObject.transform.position = new Vector3(playerPos.x, playerPos.y + inputY, playerPos.z);
  345.         //}
  346.     }
  347. }
Advertisement
Add Comment
Please, Sign In to add comment