void OnGUI() { GUI.skin = skin; GUI.Box(new Rect(10, 10, 180, 90), ""); bool avoidObstacles = true; // Default if (gameMaster != null) { avoidObstacles = gameMaster.FlyDemoObstacleAvoidance; } if (GUI.Button(new Rect(20, 20, 160, 30), "Avoid obstacles: " + (avoidObstacles? "On" : "Off"))) { if (gameMaster != null) { gameMaster.FlyDemoObstacleAvoidance = !gameMaster.FlyDemoObstacleAvoidance; } UpdateFlies(); } if (GUI.Button(new Rect(20, 60, 160, 30), "Restart demo")) { UnPause(); Application.LoadLevel(Application.loadedLevel); } // Draw the pause menu if (isPaused) { int menuWidth = 300; int menuHeight = 220; // Center the menu on the screen. GUI.BeginGroup(new Rect(Screen.width / 2 - menuWidth / 2, Screen.height / 2 - menuHeight / 2, menuWidth, menuHeight)); GUI.Box(new Rect(0, 0, menuWidth, menuHeight), ""); GUI.Label(new Rect(79, 30, 100, 30), "Game Paused", pauseText); // Draw the button which will take the player back to the main menu. // And handle the situation in which it is pressed. if (GUI.Button(new Rect(100, 70, 100, 30), "Main Menu")) { UnPause(); AStarTargeter.ClearGrids(); Application.LoadLevel("Menu"); } if (GUI.Button(new Rect(100, 110, 100, 30), "Resume")) { UnPause(); } if (GUI.Button(new Rect(100, 150, 100, 30), "Exit Game")) { AppHelper.Quit(); } GUI.EndGroup(); } }
void OnGUI() { GUI.skin = skin; GUI.Box(new Rect(10, 10, 100, 140), ""); int health = PlayerInfo.GetMainFrogHealth(); for (int i = 0; i < health; i++) { GUI.DrawTexture(new Rect(20 + (heartSize + heartSeparation) * i, 20, heartSize, heartSize), heartTex, ScaleMode.ScaleToFit, true, 0.0f); } // This could probably be made better by using GUI groups. GUI.DrawTexture(new Rect(20, 45, heartSize, heartSize), waterTex, ScaleMode.ScaleToFit, true, 0.0f); GUI.DrawTexture(new Rect(20, 70, heartSize, heartSize), Fly, ScaleMode.ScaleToFit, true, 0.0f); GUI.DrawTexture(new Rect(20, 95, heartSize, heartSize), eggTex, ScaleMode.ScaleToFit, true, 0.0f); GUI.DrawTexture(new Rect(20, 120, heartSize, heartSize), snakeTex, ScaleMode.ScaleToFit, true, 0.0f); GUI.DrawTexture(new Rect(50 - 2, 45 + 3, PlayerInfo.GetMainFrogWaterLevel() / 2.0f, 14), waterMeterTex, ScaleMode.StretchToFill, true, 0.0f); GUI.Label(new Rect(40, 70, 120, 20), ": " + PlayerInfo.GetMainFrogScore() + "/" + PlayerInfo.GetRequiredFlies()); GUI.Label(new Rect(40, 95, 120, 20), ": " + PlayerInfo.GetEggsDestroyed()); GUI.Label(new Rect(40, 120, 120, 20), ": " + PlayerInfo.GetSnakesDrowned()); // Draw the pause menu if (isPaused) { int menuWidth = 300; int menuHeight = 220; // Center the menu on the screen. GUI.BeginGroup(new Rect(Screen.width / 2 - menuWidth / 2, Screen.height / 2 - menuHeight / 2, menuWidth, menuHeight)); GUI.Box(new Rect(0, 0, menuWidth, menuHeight), ""); GUI.Label(new Rect(79, 30, 100, 30), "Game Paused", pauseText); // Draw the button which will take the player back to the main menu. // And handle the situation in which it is pressed. if (GUI.Button(new Rect(100, 70, 100, 30), "Main Menu")) { UnPause(); AStarTargeter.ClearGrids(); Application.LoadLevel("Menu"); } if (GUI.Button(new Rect(100, 110, 100, 30), "Resume")) { UnPause(); } if (GUI.Button(new Rect(100, 150, 100, 30), "Exit Game")) { AppHelper.Quit(); } GUI.EndGroup(); } }
public void OnTriggerStay2D(Collider2D other) { // Try to ensure we don't get stuck ramming against an obstacle if (LayerMask.LayerToName(other.gameObject.layer) == "Obstacles") { AStarTargeter ast = GetComponent <AStarTargeter>(); if (ast != null) { ast.ForceRecalculate(); } } }
public bool SprayWater(bool frogIsBot = false, Vector2?target = null) { if (BubbleEnabled && !PlayerInfo.isPaused && (frogIsBot || Input.GetMouseButtonDown(0)) && playerInfo.waterLevel > PlayerInfo.BUBBLE_COST) { if (!frogIsBot) { target = (Vector2?)(Camera.main.ScreenToWorldPoint(Input.mousePosition)); } Vector2 shotDirection = (Vector2)target - (Vector2)(transform.position); float angle = Mathf.Atan2(shotDirection.y, shotDirection.x) * Mathf.Rad2Deg; if (transform.parent.GetComponent <Animator>().GetBool("Sitting")) { transform.parent.GetComponent <Animator>().SetBool("Sitting", false); } if (movement != null) { movement.OverrideRotation(angle); } MouseTargeter mouseTargeter = transform.parent.GetComponent <MouseTargeter>(); if (mouseTargeter != null) { mouseTargeter.StopTargeting(); } AStarTargeter aStarTargeter = transform.parent.GetComponent <AStarTargeter>(); if (aStarTargeter != null) { aStarTargeter.StopTargeting(); } shotDirection.Normalize(); Instantiate(waterProjectilePrefab, new Vector3(transform.position.x + shotDirection.x * BubbleLaunchDistance, transform.position.y + shotDirection.y * BubbleLaunchDistance, transform.position.z), Quaternion.Euler(0.0f, 0.0f, angle - rotationOffset)); playerInfo.ReduceWaterAfterBubble(); return(true); } else { return(false); } }
void OnGUI() { GUI.skin = skin; GUI.Box(new Rect(10, 10, 100, 120), ""); //int health = PlayerInfo.GetMainFrogHealth(); // This could probably be made better by using GUI groups. GUI.DrawTexture(new Rect(20, 20, heartSize, heartSize), flyTex, ScaleMode.ScaleToFit, true, 0.0f); GUI.DrawTexture(new Rect(20, 45, heartSize, heartSize), eggTex, ScaleMode.ScaleToFit, true, 0.0f); GUI.DrawTexture(new Rect(20, 70, heartSize, heartSize), snakeTex, ScaleMode.ScaleToFit, true, 0.0f); GUI.DrawTexture(new Rect(20, 95, heartSize, heartSize), scoreTex, ScaleMode.ScaleToFit, true, 0.0f); GUI.Label(new Rect(40, 20, 120, 20), ": " + FlyPlayerInfo.NumFlies); GUI.Label(new Rect(40, 45, 120, 20), ": " + FlyPlayerInfo.SelectedFliesResource1); GUI.Label(new Rect(40, 70, 120, 20), ": " + FlyPlayerInfo.SelectedFliesResource2); GUI.Label(new Rect(40, 95, 120, 20), ": " + FlyPlayerInfo.PlayerScore); // Draw the pause menu if (isPaused) { int menuWidth = 300; int menuHeight = 220; // Center the menu on the screen. GUI.BeginGroup(new Rect(Screen.width / 2 - menuWidth / 2, Screen.height / 2 - menuHeight / 2, menuWidth, menuHeight)); GUI.Box(new Rect(0, 0, menuWidth, menuHeight), ""); GUI.Label(new Rect(79, 30, 100, 30), "Game Paused", pauseText); // Draw the button which will take the player back to the main menu. // And handle the situation in which it is pressed. if (GUI.Button(new Rect(100, 70, 100, 30), "Main Menu")) { UnPause(); AStarTargeter.ClearGrids(); FlyPlayerInfo.SetNewGame(); Application.LoadLevel("MenuA2"); } if (GUI.Button(new Rect(100, 110, 100, 30), "Resume")) { UnPause(); } if (GUI.Button(new Rect(100, 150, 100, 30), "Exit Game")) { AppHelper.Quit(); } GUI.EndGroup(); } }
void OnGUI() { GUI.skin = skin; GUI.Box(new Rect(10, 10, 80, 70), ""); GUI.Label(new Rect(20, 20, 120, 20), "Epoch: " + geneticAlgo.CurrentEpoch); GUI.Label(new Rect(20, 45, 120, 20), "Batch: " + geneticAlgo.CurrentBatch); // Draw the pause menu if (isPaused) { int menuWidth = 300; int menuHeight = 220; // Center the menu on the screen. GUI.BeginGroup(new Rect(Screen.width / 2 - menuWidth / 2, Screen.height / 2 - menuHeight / 2, menuWidth, menuHeight)); GUI.Box(new Rect(0, 0, menuWidth, menuHeight), ""); GUI.Label(new Rect(79, 30, 100, 30), "Game Paused", pauseText); // Draw the button which will take the player back to the main menu. // And handle the situation in which it is pressed. if (GUI.Button(new Rect(100, 70, 100, 30), "Main Menu")) { UnPause(); AStarTargeter.ClearGrids(); Application.LoadLevel("Menu"); } if (GUI.Button(new Rect(100, 110, 100, 30), "Resume")) { UnPause(); } if (GUI.Button(new Rect(100, 150, 100, 30), "Exit Game")) { AppHelper.Quit(); } GUI.EndGroup(); } }
void Awake() { targeter = GetComponent <AStarTargeter>(); SoundSource = gameObject.AddComponent <AudioSource>(); SoundSource.loop = false; // So we can access from static functions... Ugly but it works _InvulnerableTimeWhenHit = InvulnerableTimeWhenHit; _HurtSound = HurtSound; _EatSound = EatSound; _SplashSound = SplashSound; // Set animators & sprite renderers animator = GetComponent <Animator>(); spriteRenderer = GetComponent <SpriteRenderer>(); Animator[] animators = GetComponentsInChildren <Animator>(); foreach (Animator a in animators) { if (a.gameObject.tag == "Tongue") { tongueAnimator = a; } } SpriteRenderer[] renderers = GetComponentsInChildren <SpriteRenderer>(); foreach (SpriteRenderer sr in renderers) { if (sr.gameObject.tag == "Tongue") { tongueSpriteRenderer = sr; } } // Difficulty settings int difficulty = 1; GameObject optionsGameObj = GameObject.Find("GameOptions"); // We won't be able to find the options GameObject if we haven't gone via the main menu if (optionsGameObj != null) { GameOptions options = optionsGameObj.GetComponent <GameOptions>(); difficulty = options.difficulty; } switch (difficulty) { case 0: // Easy requiredFlies = 10; break; case 1: default: // Normal requiredFlies = 15; break; case 2: // Hard requiredFlies = 20; break; case 3: // Insane requiredFlies = 20; break; } }
void Awake() { homeTargeter = GetComponent <GameObjectTargeter>(); huntTargeter = GetComponent <HuntTargeter>(); aStarTargeter = GetComponent <AStarTargeter>(); wanderer = GetComponent <Wander>(); seek = GetComponent <Seek>(); movement = GetComponent <Movement>(); animator = GetComponent <Animator>(); originalScale = transform.localScale; parentingTimer = 0f; timeSinceWentHome = GoHomeTimeout; // Ensure that the snake has someone to target and a home. if (Home == null || Player == null) { // Place in predator hierarchy. transform.parent = GameObject.Find("Predators").transform; // Set the player for the predator to chase and this predators home base. var predStateMac = GetComponent <PredatorStateMachine>(); predStateMac.Player = GameObject.FindGameObjectWithTag("Player"); if (Random.Range(0, 2) == 0) { predStateMac.Home = GameObject.Find("SnakeHomeLeft"); } else { predStateMac.Home = GameObject.Find("SnakeHomeRight"); } } huntTargeter.Target = Player; homeTargeter.Target = Home; currentState = State.HeadingHome; // So we don't play the chasing sound immediately! SoundSource = gameObject.AddComponent <AudioSource>(); SoundSource.loop = false; // Difficulty settings int difficulty = 1; GameObject optionsGameObj = GameObject.Find("GameOptions"); // We won't be able to find the options GameObject if we haven't gone via the main menu if (optionsGameObj != null) { GameOptions options = optionsGameObj.GetComponent <GameOptions>(); difficulty = options.difficulty; } switch (difficulty) { case 0: // Easy BubbleTime = 6.0f; normalSpeed = 1.5f; chaseSpeed = 1.9f; LeashLength = 8.0f; break; case 1: default: // Normal BubbleTime = 3.0f; normalSpeed = 2.0f; chaseSpeed = 3.0f; LeashLength = 8.0f; break; case 2: // Hard BubbleTime = 2.0f; normalSpeed = 2.0f; chaseSpeed = 3.5f; LeashLength = 12.0f; break; case 3: // Insane BubbleTime = 1.5f; normalSpeed = 3.0f; chaseSpeed = 4.0f; LeashLength = 9999.0f; break; } if (difficulty == 0) { huntTargeter.dumbAttack = true; } MaxSnakes = 5 + difficulty; ParentAge = 40.0f - 10.0f * (float)(difficulty); // For the class demonstration if (DemoMode) { // Make the snakes chase over the whole map in the demo LeashLength = 9999.0f; // Default, 1 = true int smart = 1; if (PlayerPrefs.HasKey("SmartDemoSnakes")) { smart = PlayerPrefs.GetInt("SmartDemoSnakes"); } if (smart == 1) { huntTargeter.dumbAttack = false; } else { huntTargeter.dumbAttack = true; } } }
void Awake() { targeter = GetComponent <AStarTargeter>(); SoundSource = GetComponent <AudioSource>(); if (SoundSource == null) { SoundSource = gameObject.AddComponent <AudioSource>(); SoundSource.loop = false; } // So we can access from static functions... Ugly but it works _HurtSound = HurtSound; _EatSound = EatSound; _SplashSound = SplashSound; // Set animators & sprite renderers animator = GetComponent <Animator>(); spriteRenderer = GetComponent <SpriteRenderer>(); Animator[] animators = GetComponentsInChildren <Animator>(); foreach (Animator a in animators) { if (a.gameObject.tag == "Tongue") { tongueAnimator = a; } } SpriteRenderer[] renderers = GetComponentsInChildren <SpriteRenderer>(); foreach (SpriteRenderer sr in renderers) { if (sr.gameObject.tag == "Tongue") { tongueSpriteRenderer = sr; } } // Difficulty settings if (!TrainingMode) { int difficulty = 1; GameObject gameMasterGameObj = GameObject.Find("GameMaster"); if (gameMasterGameObj != null) { GameMaster gameMaster = gameMasterGameObj.GetComponent <GameMaster>(); difficulty = gameMaster.difficulty; } switch (difficulty) { case 0: // Easy requiredFlies = 10; break; case 1: default: // Normal requiredFlies = 15; break; case 2: // Hard requiredFlies = 20; break; case 3: // Insane requiredFlies = 20; break; } } else { requiredFlies = 99999; } }