Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using GUISimplification;
- using Inventory;
- using IOUtlility;
- using System.Collections.Generic;
- using Assets.Scripts;
- using System.Diagnostics;
- public class MainMenu : MonoBehaviour {
- World world;
- int y = 10;
- int x = 10;
- public Texture logo;
- public GUIStyle multiplayerStyle;
- public GUIStyle legalStyle;
- public GUIStyle instructionsStyle;
- bool gotCredentials;
- GameJoltAPIManager manager;
- PlayerController player;
- GamePadScript gamePad;
- public int MaxSpeed;
- public bool customizationMenu = false;
- public bool multiplayerMenu = false;
- bool loadBall = false;
- int currentBall = 0;
- int score = 0;
- List<CustomBall> balls;
- GUICoordinates guiCoordinates;
- private bool instructions;
- private bool credits;
- private bool alreadyInitialized = false;
- CameraFollow camera;
- public Stopwatch initiationTimer = Stopwatch.StartNew();
- #region Instructions
- private string instructionsText = string.Format(
- @"The controls for Smashy Ball have been designed to be intuitive from the start.
- 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." : "");
- #endregion Instructions
- #region Legal
- private string legal = @"
- Smashy Ball is the sole property of Sebastian Lawe. Sebane Studios is
- an alias, and has yet to be registered as a business or company.
- The name and logo for Sebane Studios are the sole property of Sebastian Lawe.
- Music soundtrack created by FoxHunt.";
- #endregion Legal
- #region Multiplayer
- private string _multiplayer =
- @"
- Welcome to Multiplayer!
- Play Smashy Ball with another friend in your living room!
- Instructions:
- One player will play the game using a Wii Remote or Wii U Pro controller.
- The other player will play with the gamepad, and control what spawns next in the game.
- After 10 deaths, both players will swap controllers. Whoever survives the longest wins!
- ";
- #endregion Multiplayer
- // Use this for initialization
- void Start() {
- camera = Camera.main.GetComponent<CameraFollow>();
- world = FindObjectOfType<World>();
- manager = FindObjectOfType<GameJoltAPIManager>();
- player = GetComponent<PlayerController>();
- gamePad = GameObject.FindObjectOfType<GamePadScript>();
- balls = CustomBall.GetBalls();
- if (!world.oldOffsetAlreadySet) {
- world.oldOffset = camera.Offset;
- world.oldOffsetAlreadySet = true;
- }
- #if !UNITY_WEBPLAYER
- string[] userNameAndPass = IOAccess.OpenCredentials("credentials.sbf");
- score = IOAccess.OpenScore("score.sbf");
- manager.userName = userNameAndPass[0];
- manager.userToken = userNameAndPass[1];
- manager.Verify();
- #endif
- while (balls[currentBall].Name != world.BallName) {
- currentBall++;
- }
- }
- // Update is called once per frame
- void FixedUpdate() {
- #if !UNITY_WEBPLAYER
- if (!gotCredentials) {
- //if (GJAPI.User != null) {
- // IOAccess.SaveCredentials("credentials.sbf", GJAPI.User.Name, GJAPI.User.Token);
- // gotCredentials = true;
- //}
- }
- #endif
- if (customizationMenu) {
- camera.Offset = Vector3.Lerp(camera.Offset, new Vector3(0.05f, 0.007f, -0.75f), 0.2f);
- } else {
- camera.Offset = Vector3.Lerp(camera.Offset, world.oldOffset, 0.2f);
- if (initiationTimer.ElapsedMilliseconds >= 5000) {
- if (transform.position.y < world.CurrentYPos) {
- transform.rigidbody.AddForce(0, 20, 0);
- } else {
- if (transform.rigidbody.velocity.x < MaxSpeed) {
- transform.rigidbody.AddForce(10, 0, 0);
- if (player != null) {
- player.enabled = false;
- }
- }
- }
- } else {
- transform.rigidbody.velocity = new Vector3();
- }
- }
- }
- void OnCollisionStay(Collision collision) {
- }
- void OnGetFromWeb(string name, string token) {
- manager.name = name;
- manager.userToken = token;
- }
- void OnGUI() {
- #if UNITY_WEBPLAYER
- if (manager.Verified) {
- IOAccess.OpenScoreOnline();
- score = IOAccess.OnlineScore;
- }
- #endif
- GUI.skin = world.Skin;
- if (!customizationMenu && !credits && !instructions && !multiplayerMenu) {
- guiCoordinates = new GUICoordinates(new RelativeRect(40, 35, 20, 10));
- if (!world.FreeVersion) {
- //if (GJAPI.User == null) {
- // if (GUI.Button(guiCoordinates.AssignCoordinates(), "Login")) {
- // GJAPIHelper.Users.ShowLogin();
- // GJAPIHelper.Users.ShowGreetingNotification();
- // GJAPIHelper.Users.GetFromWeb(OnGetFromWeb);
- // }
- //}
- }
- GUI.DrawTexture(RelativeRect.GetRelative(new Rect(0, 5, 100, 40)), logo);
- if (GUI.Button(guiCoordinates.AssignCoordinates(), "Play")) {
- player.enabled = true;
- player.score = 0;
- player.Die();
- player.score = 0;
- world.ZenMode = false;
- world._multiplayer = false;
- world.MainMenu = false;
- world.Reset();
- GetComponent<MainMenu>().enabled = false;
- }
- #if UNITY_WIIU
- if (GUI.Button(guiCoordinates.AssignCoordinates(), "Play Multiplayer")) {
- multiplayerMenu = true;
- }
- #endif
- if (!world.FreeVersion) {
- #if UNITY_EDITOR
- if (GUI.Button(guiCoordinates.AssignCoordinates(), "Zen")) {
- player.enabled = true;
- player.Die();
- player.score = 0;
- world.ZenMode = true;
- GetComponent<MainMenu>().enabled = false;
- //Application.LoadLevel(Application.loadedLevel + 1);
- world.MainMenu = false;
- world.Reset();
- }
- #endif
- }
- if (GUI.Button(guiCoordinates.AssignCoordinates(), "Instructions")) {
- instructions = true;
- }
- //if (GUI.Button(guiCoordinates.AssignCoordinates(), "Leaderboards")) {
- // //GJAPIHelper.Scores.ShowLeaderboards();
- //}
- string gamePadText = "Touchpad On";
- if (gamePad.OverridePlatformRestriction) {
- gamePadText = "Touchpad On";
- } else {
- gamePadText = "Touchpad Off";
- }
- if (Application.isEditor) {
- if (GUI.Button(guiCoordinates.AssignCoordinates(), gamePadText)) {
- gamePad.OverridePlatformRestriction = !gamePad.OverridePlatformRestriction;
- }
- }
- } else if (customizationMenu) {
- /*string data = ""
- GJAPI.Data.GetCallback(data);
- GJAPI.Data.Get("score");
- if (score < int.Parse(data)) {
- score = int.Parse(data);
- }*/
- if (GUI.Button(RelativeRect.GetRelative(80, 40, 20, 10), "Next")) {
- #if !UNITY_WEBPLAYER
- score = IOAccess.OpenScore("score.sbf");
- #endif
- if (currentBall + 1 < balls.Count) {
- currentBall++;
- } else {
- currentBall = 0;
- }
- loadBall = true;
- }
- if (GUI.Button(RelativeRect.GetRelative(0, 40, 20, 10), "Previous")) {
- #if !UNITY_WEBPLAYER
- score = IOAccess.OpenScore("score.sbf");
- #endif
- if (currentBall - 1 > -1) {
- currentBall--;
- } else {
- currentBall = balls.Count - 1;
- }
- loadBall = true;
- }
- CustomBall ball = balls[currentBall];
- if (ball.Free == world.FreeVersion || ball.Free) {
- if (score >= ball.Cost) {
- GUI.Label(RelativeRect.GetRelative(0, 0, 100, 100), Spacer.SpaceCapitals(ball.Name));
- if (loadBall) {
- loadBall = false;
- GameObject newObject = Instantiate(Resources.Load(ball.Name), transform.position, player.transform.rotation) as GameObject;
- world.BallName = ball.Name;
- Vector3 pos = transform.GetComponent<PlayerController>().startPosition;
- if (newObject != null) {
- newObject.rigidbody.velocity = player.rigidbody.velocity;
- newObject.GetComponent<PlayerController>().enabled = false;
- newObject.GetComponent<MainMenu>().customizationMenu = true;
- }
- DestroyObject(transform.gameObject);
- world.BallName = ball.Name;
- #if !UNITY_WEBPLAYER
- IOAccess.SaveBallType("ballType.sbf", ball.Name);
- #endif
- }
- } else {
- GUI.Label(RelativeRect.GetRelative(0, 0, 100, 100), ball.Cost + "m to unlock.");
- if (loadBall) {
- loadBall = false;
- GameObject newObject = Instantiate(Resources.Load(ball.Name), transform.position, Quaternion.identity) as GameObject;
- world.BallName = ball.Name;
- Vector3 pos = transform.GetComponent<PlayerController>().startPosition;
- if (newObject != null) {
- newObject.GetComponent<PlayerController>().enabled = false;
- newObject.GetComponent<MainMenu>().customizationMenu = true;
- }
- DestroyObject(transform.gameObject);
- }
- }
- } else {
- if (GUI.Button(guiCoordinates.AssignCoordinates(), "Not in this version.")) {
- }
- }
- } else if (credits) {
- if (!customizationMenu && !instructions && !multiplayerMenu) {
- GUI.Window(0, RelativeRect.GetRelative(0, 0, 100, 100), delegate(int windowID) {
- if (GUI.Button(RelativeRect.GetRelative(80, 84, 20, 10), "Back")) {
- credits = false;
- }
- }, "", legalStyle);
- }
- }
- if (instructions) {
- if (!customizationMenu && !credits && !multiplayerMenu) {
- GUI.Window(0, RelativeRect.GetRelative(0, 0, 100, 100), delegate(int windowID) {
- if (GUI.Button(RelativeRect.GetRelative(80, 84, 20, 10), "Back")) {
- instructions = false;
- }
- }, "", instructionsStyle);
- }
- }
- if (multiplayerMenu && !customizationMenu && !instructions) {
- GUI.Window(0, RelativeRect.GetRelative(0, 0, 100, 100), delegate(int windowID) {
- if (GUI.Button(RelativeRect.GetRelative(0, 84, 20, 10), "Back")) {
- multiplayerMenu = false;
- }
- if (GUI.Button(RelativeRect.GetRelative(80, 84, 20, 10), "Play")) {
- player.enabled = true;
- multiplayerMenu = false;
- player.score = 0;
- player.Die();
- player.score = 0;
- world.ZenMode = false;
- world._multiplayer = true;
- world.MainMenu = false;
- world.Reset();
- GetComponent<MainMenu>().enabled = false;
- }
- }, "", multiplayerStyle);
- }
- if (!credits && !instructions && !multiplayerMenu) {
- if (!customizationMenu && !instructions) {
- if (GUI.Button(RelativeRect.GetRelative(0, 90, 20, 10), "Credits")) {
- credits = true;
- }
- }
- if (!world.FreeVersion && IOAccess.OpenScore("score.sbf") > 0) {
- if (GUI.Button(RelativeRect.GetRelative(80, 90, 20, 10), "Customize")) {
- #if !UNITY_WEBPLAYER
- score = IOAccess.OpenScore("score.sbf");
- #endif
- if (score >= balls[currentBall].Cost) {
- if (customizationMenu) {
- customizationMenu = !customizationMenu;
- GameObject newObject = Instantiate(Resources.Load(balls[currentBall].Name), transform.position, Quaternion.identity) as GameObject;
- #if !UNITY_WEBPLAYER
- world.BallName = IOAccess.OpenBallType("ballType.sbf");
- #endif
- Vector3 pos = transform.GetComponent<PlayerController>().startPosition;
- if (newObject != null) {
- newObject.GetComponent<PlayerController>().startPosition = new Vector3(pos.x, pos.y, pos.z);
- newObject.GetComponent<MainMenu>().customizationMenu = this.customizationMenu;
- }
- DestroyObject(transform.gameObject);
- }
- customizationMenu = !customizationMenu;
- }
- }
- }
- }
- #if UNITY_STANDALONE
- if (!customizationMenu) {
- if (GUI.Button(guiCoordinates.AssignCoordinates(), "Quit")) {
- Application.Quit();
- }
- }
- #endif
- }
- void Update() {
- //float inputY = Input.GetAxis("Vertical");
- //float inputX = Input.GetAxis("Horizontal");
- //Vector3 playerPos = gameObject.transform.position;
- //if (gameObject.transform.position.x + 1 > x && inputX > 0f) {
- // gameObject.transform.position = new Vector3(playerPos.x + inputX, playerPos.y, playerPos.z);
- //}
- //if (gameObject.transform.position.y + 1 > x && inputX > 0f) {
- // gameObject.transform.position = new Vector3(playerPos.x, playerPos.y + inputY, playerPos.z);
- //}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment