Beispiel #1
0
    public void StartPressed()
    {
        // if character unlocked!
        if (characterList[index].GetComponent <player_selection_script>().unlocked)
        {
            int player_amount = PlayerPrefsHandler.GetPersistentVar <int>(Statics.ai_amount, 0);

            string s = "";

            // reset score for amount of players
            for (int i = 0; i < player_amount; i++)
            {
                // reset score
                PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(i), ref i, 0, true);
            }

            PlayerPrefsHandler.SetPersistentVar <string>(Statics.player_name(1), ref s, "Ai_play", false);

            // reset score
            int j = 0;
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(1), ref j, 0, false);
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(0), ref j, 0, true);


            SaveCharacterSelection();
            SceneManager.LoadScene(nextScene);
        }
        else
        {
            warning.text = "Can't choose this player!";
        }
    }
Beispiel #2
0
 public void NameUpdated()
 {
     // save Name
     if (name_text.text == null || name_text.text == "")
     {
         PlayerPrefsHandler.SetPersistentVar <string>(Statics.player_name(0), ref player_name, "Player" + Random.Range(1, 100), true);
     }
     else
     {
         PlayerPrefsHandler.SetPersistentVar <string>(Statics.player_name(0), ref player_name, name_text.text, true);
     }
 }
Beispiel #3
0
    public void toggle()
    {
        if (AudioListener.volume == 0)
        {
            soundOn = true;
            PlayerPrefsHandler.SetPersistentVar <bool>(Statics.sound, ref soundOn, soundOn, true);

            AudioListener.volume = 1;
        }
        else
        {
            soundOn = false;
            PlayerPrefsHandler.SetPersistentVar <bool>(Statics.sound, ref soundOn, soundOn, true);
            AudioListener.volume = 0;
        }
    }
Beispiel #4
0
    public void done()
    {
        int    r = 0;
        string s = "";

        // save
        PlayerPrefsHandler.SetPersistentVar <int>(Statics.ai_amount, ref r, Int32.Parse(ai_amount_dropdown.options[ai_amount_dropdown.value].text), false);
        PlayerPrefsHandler.SetPersistentVar <int>(Statics.enemy_amount, ref r, Int32.Parse(enemies_dropdown.options[enemies_dropdown.value].text), false);
        PlayerPrefsHandler.SetPersistentVar <string>(Statics.player_character(1), ref s, ai_char_dropdown.options[ai_char_dropdown.value].text, false);
        PlayerPrefsHandler.SetPersistentVar <string>(Statics.game_mode, ref s, game_mode_dropdown.options[game_mode_dropdown.value].text, false);
        PlayerPrefsHandler.SetPersistentVar <string>(Statics.ai_difficulty(1), ref s, diff_dropdown.options[diff_dropdown.value].text, false);
        PlayerPrefsHandler.SetPersistentVar <string>(Statics.ai_difficulty(0), ref s, diff_dropdown.options[diff_dropdown.value].text, true);

        //disable
        canvas.enabled = false;
    }
Beispiel #5
0
 public void yes_pressed()
 {
     if (restart)
     {
         int i = 0;
         PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(0), ref i, 0, true);
         PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(1), ref i, 0, true);
         Time.timeScale = 1;
         SceneManager.LoadScene(2);
     }
     else
     {
         Time.timeScale = 1;
         SceneManager.LoadScene(0);
     }
 }
Beispiel #6
0
 public void continue_pressed()
 {
     if (!gameOver)
     {
         inGameMenu.enabled = false;
         Time.timeScale     = 1;
     }
     else
     {
         if (matchover)
         {
             int i = 0;
             PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(0), ref i, 0, true);
             PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(1), ref i, 0, true);
             Time.timeScale = 1;
             SceneManager.LoadScene(0);
         }
         else
         {
             Time.timeScale = 1;
             SceneManager.LoadScene(2);
         }
     }
 }
Beispiel #7
0
    void Start()
    {
        Time.timeScale = 0;
        string s = "";

        PlayerPrefsHandler.SetPersistentVar <string>(Statics.player_controller(0), ref s, Player_Controll.Player.ToString(), true);
        PlayerPrefsHandler.SetPersistentVar <string>(Statics.player_controller(1), ref s, Player_Controll.Ai.ToString(), true);

        int player_amount = PlayerPrefsHandler.GetPersistentVar <int>(Statics.player_amount, 2);

        // Game Mode (only have one)
        //  string game_mode = PlayerPrefsHandler.GetPersistentVar<string>(Statics.game_mode, "1vs1");

        // Create entire gameworld
        for (int i = 0; i < player_amount; i++)
        {
            // create map
            Transform map = Instantiate(Resources.Load <GameObject>(map_prefab_path), new Vector3((Statics.map_x + Statics.map_space) * i, 0, 0), transform.rotation).GetComponent <Transform>();
            map_reference    = map.GetComponent <Map_script>();
            map_reference.id = i;


            // spawn and instantiate Player
            string player_prefab_path = "Players(ingame)/" + PlayerPrefsHandler.GetPersistentVar <string>(Statics.player_character(i), "Mage");
            player = Resources.Load <GameObject>(player_prefab_path);
            Player p = Instantiate(player, map.transform.position + transform.up * 2, transform.rotation).GetComponent <Player>();

            // set player parent
            p.transform.SetParent(map);

            // set player name
            p.Name = PlayerPrefsHandler.GetPersistentVar <string>(Statics.player_name(i), "Player1");


            // set controller
            string controller = PlayerPrefsHandler.GetPersistentVar <string>(Statics.player_controller(i), "Ai");
            if (controller == "Ai")
            {
                p.setController(Player_Controll.Ai);
                p.controller.setDifficulty(PlayerPrefsHandler.GetPersistentVar <string>(Statics.ai_difficulty(i), "Easy"));
            }
            else
            {
                p.setController(Player_Controll.Player);
                p.controller.setDifficulty(PlayerPrefsHandler.GetPersistentVar <string>(Statics.ai_difficulty(i), "Easy"));
            }
            diff_value.text = p.controller.difficulty.ToString();

            // get enemyparent and init player
            foreach (Transform t in map.GetComponentsInChildren <Transform>())
            {
                if (t.tag == "EnemyParent")
                {
                    p.InitiatePlayer(this, t);
                    break;
                }
            }

            // init camera
            camera_controller = map.GetComponentInChildren <Camera_Controller>();
            camera_controller.setTarget(p);

            // init game
            game_controller           = map.GetComponentInChildren <Game_Controller>();
            game_controller.MAX_ENEMY = PlayerPrefsHandler.GetPersistentVar <int>(Statics.enemy_amount, 50);
            enemy_limit.text          = game_controller.MAX_ENEMY.ToString();
            game_controller.initiate(p);

            // add to list
            Game_List.Add(game_controller);
        }

        global_camera = FindObjectOfType <global_camera_controller>();
        global_camera.initiate();

        // init menu
        inGameMenu.enabled    = false;
        extraQuestion.enabled = false;

        // get score
        int p1 = PlayerPrefsHandler.GetPersistentVar <int>(Statics.player_score(0), 0);
        int p2 = PlayerPrefsHandler.GetPersistentVar <int>(Statics.player_score(1), 0);

        scoreboard.text = p1 + " : " + p2;
    }
Beispiel #8
0
    public void GameOver(Player player)
    {
        /*
         * Below is fast written code to have a game for show...
         */

        Time.timeScale = 0;
        gameOver       = true;
        Text text = inGameMenu.GetComponentInChildren <Text>();

        text.text          = "Game Over!";
        inGameMenu.enabled = true;

        foreach (Game_Controller game in Game_List)
        {
            game.gameOver = true;
        }

        // check who lost and set text
        string s = "";

        if (player.health <= 0)
        {
            s = player.Name + " died!";
        }
        else
        {
            s = player.Name + " didn't kill fast enough!";
        }

        // add score
        int i  = 0;
        int p1 = PlayerPrefsHandler.GetPersistentVar <int>(Statics.player_score(0), 0);
        int p2 = PlayerPrefsHandler.GetPersistentVar <int>(Statics.player_score(1), 0);

        if (player.map_reference.id == 0)
        {
            p2++;
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(1), ref i, p2, true);
        }
        else
        {
            p1++;
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(0), ref i, p1, true);
        }

        if (p1 >= match_limit)
        {
            gameOver_text.text = "Winner is " + PlayerPrefsHandler.GetPersistentVar <string>(Statics.player_name(0), s) + "\n" + " Score: " + p1 + " : " + p2;
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(0), ref i, 0, true);
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(1), ref i, 0, true);
            matchover = true;

            // add player won game and total wins
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.character_wins(player.character), ref i, PlayerPrefsHandler.GetPersistentVar <int>(Statics.character_wins(player.character), 0) + 1, true);
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.total_wins, ref i, PlayerPrefsHandler.GetPersistentVar <int>(Statics.total_wins, 0) + 1, true);
        }
        else if (p2 >= match_limit)
        {
            gameOver_text.text = "Winner is " + PlayerPrefsHandler.GetPersistentVar <string>(Statics.player_name(1), s) + "\n" + " Score: " + p1 + " : " + p2;
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(0), ref i, 0, true);
            PlayerPrefsHandler.SetPersistentVar <int>(Statics.player_score(1), ref i, 0, true);
            matchover = true;
        }
        else
        {
            scoreboard.text    = p1 + " : " + p2;
            gameOver_text.text = s + "\n" + " Score: " + p1 + " : " + p2;
        }
    }
Beispiel #9
0
 private void SaveCharacterSelection()
 {
     PlayerPrefsHandler.SetPersistentVar <string>(Statics.player_character(0), ref character_name, current_character.ToString(), true);
 }