Esempio n. 1
0
    //Called by the Game.cs script when the game starts.
    public void SetStartValues()
    {
        //Sets the tank's stats based on the Game.cs start values.
        health          = game.tankStartHealth;
        maxHealth       = game.tankStartHealth;
        damage          = game.tankStartDamage;
        rocketDamage    = damage + 2;
        moveSpeed       = game.tankStartMoveSpeed;
        turnSpeed       = game.tankStartTurnSpeed;
        projectileSpeed = game.tankStartProjectileSpeed;
        reloadSpeed     = game.tankStartReloadSpeed;
        //Debug.Log("colours" + OpenGame.GetColorPlayer1() + "   " + OpenGame.GetColorPlayer2());
        if (MenuUI.getFlag() != 3)
        {
            game.player1Tank.GetComponent <SpriteRenderer>().color = OpenGame.GetColorPlayer1();
            game.player2Tank.GetComponent <SpriteRenderer>().color = OpenGame.GetColorPlayer2();
        }
        else
        {
            game.player1Tank.GetComponent <SpriteRenderer>().color = game.player1Color;
            game.player2Tank.GetComponent <SpriteRenderer>().color = game.player2Color;
        }

        game.playerMultiplayer.GetComponent <SpriteRenderer>().color = game.playerMultiplayerColor;
    }
Esempio n. 2
0
    void Start()
    {
        // player icon only in coop
        if (MenuUI.getFlag() == 3)
        {
            player1Im.GetComponent <Image>().sprite = OpenGame.GetPlayer1Sprite();    //set image sprite to the sprite player 1 has chosen
            player2Im.GetComponent <Image>().sprite = OpenGame.GetPlayer2Sprite();    //set image sprite to the sprite player 2 has chosen
        }

        // Create a temporary reference to the current scene.
        Scene currentScene = SceneManager.GetActiveScene();

        // Retrieve the name of this scene.
        string sceneName = currentScene.name;

        if (sceneName == "GameArena1" || sceneName == "vsPC")            //scenes with different arena maps
        //Load The Map
        {
            mapToLoad = PlayerPrefs.GetString("MapToLoad");
            TextAsset map = Resources.Load <TextAsset>("Maps/" + mapToLoad) as TextAsset;
            //Debug.Log(mapToLoad + "\n");
            //Debug.Log("    " + map.text + "   ");
            LoadMap(map.text);
        }
        else
        {
            //Load The Map
            mapToLoad = "Arena";
            TextAsset map = Resources.Load <TextAsset>("Maps/" + mapToLoad) as TextAsset;
            //Debug.Log(mapToLoad + "\n");
            //Debug.Log("    " + map.text + "   ");
            LoadStandardMap(map.text);
        }

        if (MenuUI.getFlag() != 1)
        {
            //Tank Bools
            player1Tank.canMove  = true;
            player1Tank.canShoot = true;

            player2Tank.canMove  = true;
            player2Tank.canShoot = true;

            //Tank Start Values
            player1Tank.SetStartValues();
            player2Tank.SetStartValues();

            ui.SetupHealthBars();
            if (MenuUI.getFlag() == 3)
            {
                //Tank Color
                player1Tank.GetComponent <SpriteRenderer>().color = OpenGame.GetColorPlayer1();   //player1Color;
                player2Tank.GetComponent <SpriteRenderer>().color = OpenGame.GetColorPlayer2();   //player2Color;
                //set players colors to the colors user has chosen
                player1Color = OpenGame.GetColorPlayer1();
                player2Color = OpenGame.GetColorPlayer2();

                if (OpenGame.colorChangePlayer1 == "green")             //green tank player 1
                //Debug.Log("green");
                {
                    player1Tank.damage++;                               //extra damage
                    player1Tank.reloadSpeed *= 2;                       //slower reload
                }
                else if (OpenGame.colorChangePlayer1 == "blue")         //blue tank player 1
                //Debug.Log("blue");
                {
                    player1Tank.moveSpeed   *= 2;                       //more move speed
                    player1Tank.turnSpeed   *= 2;                       //more turn speed
                    player1Tank.reloadSpeed *= 2;                       //slower reload
                }
                if (OpenGame.colorChangePlayer2 == "green")             //green tank player 2
                //Debug.Log("green ppplayer2");
                {
                    player2Tank.damage++;                               //extra damage
                    player2Tank.reloadSpeed *= 2;                       //more time to reload
                }
                else if (OpenGame.colorChangePlayer2 == "blue")         //blue tank player 2
                //Debug.Log("blue ppplayer2");
                {
                    player2Tank.moveSpeed   *= 2;                       //moves faster
                    player2Tank.turnSpeed   *= 2;                       //more speed at turns
                    player2Tank.reloadSpeed *= 2;                       //slower reload
                }
            }
            else
            {
                //Tank Color
                player1Tank.GetComponent <SpriteRenderer>().color = player1Color;
                player2Tank.GetComponent <SpriteRenderer>().color = player2Color;
            }
            //spawn points campaign
            if (MenuUI.getFlag() == 2)
            {
                player1Tank.transform.position = new Vector3(-48, -22, 0);
                player2Tank.transform.position = new Vector3(-3, 21, 0);
            }
            else
            {
                //set tank spawn position
                player1Tank.transform.position = spawnPoints[0].transform.position;
                player2Tank.transform.position = spawnPoints[1].transform.position;
            }
        }
        //else we are in multiplayer
        else
        {
            //spawnPlayer();
            //playerMultiplayer.gameObject.SetActive(true);
            ui.SetupHealthBars();
            //deactivate the usual coop - singleplayer tanks
            myObjectTank1.SetActive(false);
            myObjectTank2.SetActive(false);
        }
    }
Esempio n. 3
0
    void OnCollisionEnter2D(Collision2D col)
    {
        //Is the object we hit a tank and we are in singleplayer or campaign?
        if (col.gameObject.tag == "Tank" && (MenuUI.getFlag() == 2 || MenuUI.getFlag() == 4))
        {
            Tank tank = col.gameObject.GetComponent <Tank>();    //Get the tank's Tank.cs component.

            //play powerup sound effect
            FindObjectOfType <AudioManager>().Play("powerUp");

            //health increased according to the health our tank already had
            damage = 3 - tank.health;
            if (tank.health == 3)
            {
                if (tank.GetComponent <SpriteRenderer>().color == game.player1Tank.GetComponent <SpriteRenderer>().color)
                {
                    fillPlayer1.color = Color.green;
                }
                else
                {
                    fillPlayer2.color = Color.green;
                }

                //if health is full get one extra bar
                damage++;
            }

            //tank cannot take more HP
            if (tank.health > 3)
            {
                damage = 0;
            }

            //Call the damage function on that tank to take health
            tank.Damage(-damage);
        }
        //if we hit a tank and we are in co-op
        if (col.gameObject.tag == "Tank" && MenuUI.getFlag() != 1)                //Is the object we hit a tank?

        {
            Tank tank = col.gameObject.GetComponent <Tank>();    //Get the tank's Tank.cs component.

            //play powerup sound effect
            FindObjectOfType <AudioManager>().Play("powerUp");

            //health increased according to the health our tank already had
            damage = 3 - tank.health;
            if (tank.health == 3)
            {
                if (tank.GetComponent <SpriteRenderer>().color == OpenGame.GetColorPlayer1())
                {
                    fillPlayer1.color = Color.green;
                }
                else
                {
                    fillPlayer2.color = Color.green;
                }

                //if health is full get one extra bar
                damage++;
            }

            //tank cannot take more HP
            if (tank.health > 3)
            {
                damage = 0;
            }

            //Call the damage function on that tank to take health
            tank.Damage(-damage);
        }

        //play the hit effect every time the ball collides with objects
        GameObject hitEffect1 = Instantiate(hitParticleEffect, transform.position, Quaternion.identity) as GameObject;

        Destroy(hitEffect1, 1.0f);
        if (!(col.gameObject.tag == "Projectile" || col.gameObject.tag == "ProjectileRocket"))
        {
            Destroy(gameObject);
        }
    }