Esempio n. 1
0
    void LocalLogic(Collider2D c)
    {
        PlayerController pc = this.transform.root.GetComponent <PlayerController>();
        StickyBomb       sb = c.gameObject.GetComponent <StickyBomb>();

        Debug.Log("Sticky : " + sb.ownerID + ", Owner: " + pc.playerID);

        if (sb.hitGround)
        {
            PopText.Create("Get Bomb!", Color.black, 60, sb.transform.position + Vector3.up);
            Vector3 scale = new Vector3(c.gameObject.transform.localScale.x, c.gameObject.transform.localScale.y, c.gameObject.transform.localScale.z);
            pc.LOCAL_PickupBombGround(sb);
        }
        else
        {
            if (!pc.playerID.Equals(sb.ownerID) && !sb.isStuck)
            {
                Debug.Log("Sucess!");
                Vector3 scale = new Vector3(c.gameObject.transform.localScale.x, c.gameObject.transform.localScale.y, c.gameObject.transform.localScale.z);
                pc.LOCAL_GetStuck(sb.transform.position, scale, sb);
            }

            //for switching owners
            else if (sb.isStuck && !sb.GetComponent <LocalStickyBomb>().justTransfered&&
                     !pc.playerID.Equals(sb.stuckID))
            {
                Debug.Log("Sucess!");
                Vector3 scale = new Vector3(c.gameObject.transform.localScale.x, c.gameObject.transform.localScale.y, c.gameObject.transform.localScale.z);
                //this transform, scale, stickyID
                pc.LOCAL_SwitchOwners(sb.transform.position, scale, sb);
                sb.GetComponent <LocalStickyBomb>().TransferBomb();
            }
        }
    }
Esempio n. 2
0
    void GetStuck(Vector3 stuckPos, Vector3 scale, int stickyID)
    {
        Debug.Log("Got stuck");
        isStuck       = true;
        stuckPosition = stuckPos;

        StickyBomb[] stickys   = GameObject.FindObjectsOfType <StickyBomb> ();
        StickyBomb   theSticky = null;

        foreach (var s in stickys)
        {
            if (s.GetComponent <PhotonView>().viewID == stickyID)
            {
                theSticky = s;
                break;
            }
        }

        if (theSticky != null)
        {
            AudioSource.PlayClipAtPoint(getStuck, GameObject.FindObjectOfType <GameCamera>().transform.position);
            currentStuck = theSticky.GetComponent <StickyBomb>();
            theSticky.transform.SetParent(this.transform);
            theSticky.transform.localScale = scale * 9;
            theSticky.transform.position   = stuckPos;
            theSticky.GetComponent <Rigidbody2D>().isKinematic = true;
            theSticky.isStuck = true;
            theSticky.GetComponent <StickyBomb>().stuckID = playerID;
            PopText.Create("STUCK!", Color.white, 120, this.transform.position + Vector3.up * .5f);
            Debug.Log("Current stuck: " + currentStuck.name);
        }
    }
 void HitGround()
 {
     GetComponent <StickyBomb> ().hitGround = true;
     PopText.Create("Hit Ground!", Color.white, 60, transform.position + Vector3.up * .5f);
     GetComponent <Rigidbody2D> ().velocity = Vector2.zero;
     GetComponent <Rigidbody2D> ().velocity = Vector2.zero;
 }
Esempio n. 4
0
    public void LOCAL_SwitchOwners(Vector3 stuckPos, Vector3 scale, StickyBomb theSticky)
    {
        isStuck       = true;
        stuckPosition = stuckPos;

        if (theSticky != null)
        {
            currentStuck = theSticky.GetComponent <StickyBomb>();
            theSticky.transform.SetParent(this.transform);
            theSticky.transform.position = stuckPos;
            theSticky.GetComponent <Rigidbody2D>().isKinematic = true;
            theSticky.isStuck = true;
            //the person that ran into you is now the potential killer
            theSticky.GetComponent <StickyBomb>().ownerID = theSticky.GetComponent <StickyBomb>().stuckID;
            theSticky.GetComponent <StickyBomb>().stuckID = playerID;
            theSticky.GetComponent <LocalStickyBomb>().TransferBomb();
            PopText.Create("STUCK!", Color.white, 120, this.transform.position + Vector3.up * .5f);
            //get the new owner and tell him he isnt stuck anymore
            AudioSource.PlayClipAtPoint(transferBomb, GameObject.FindObjectOfType <GameCamera>().transform.position);
            PlayerController   newOwner = null;
            PlayerController[] players  = GameObject.FindObjectsOfType <PlayerController>();

            foreach (var p in players)
            {
                if (p.playerID == theSticky.ownerID)
                {
                    newOwner = p;
                }
            }

            newOwner.isStuck      = false;
            newOwner.currentStuck = null;
        }
        GameObject.Find("Main Camera").GetComponent <GameCamera> ().BombStuck();
    }
Esempio n. 5
0
    public void LOCAL_GetStuck(Vector3 stuckPos, Vector3 scale, StickyBomb theSticky)
    {
        isStuck       = true;
        stuckPosition = stuckPos;

        if (theSticky != null)
        {
            if (!isPaused)
            {
                theSticky.GetComponent <LocalStickyBomb> ().gamePaused = false;
                AudioSource.PlayClipAtPoint(getStuck, GameObject.FindObjectOfType <GameCamera> ().transform.position);
                currentStuck = theSticky.GetComponent <StickyBomb> ();
                theSticky.transform.SetParent(this.transform);
                theSticky.transform.localScale = scale * 9;
                theSticky.transform.position   = stuckPos;
                theSticky.GetComponent <Rigidbody2D> ().isKinematic = true;
                theSticky.isStuck = true;
                theSticky.GetComponent <LocalStickyBomb> ().TransferBomb();
                theSticky.GetComponent <StickyBomb> ().stuckID = playerID;
                PopText.Create("STUCK!", Color.white, 120, this.transform.position + Vector3.up * .5f);
                Debug.Log("Current stuck: " + currentStuck.name);
            }
            else
            {
                theSticky.GetComponent <LocalStickyBomb> ().gamePaused = true;
            }
        }
    }
    void BigBoyHit(int killed, int killer)
    {
        PlayerController stuckPlayer   = null;
        PlayerController gotKillPlayer = null;

        PlayerController[] players = GameObject.FindObjectsOfType <PlayerController>();

        foreach (var p in players)
        {
            if (p.playerID == sb.stuckID)
            {
                stuckPlayer = p;
            }
        }
        foreach (var p in players)
        {
            if (p.playerID == sb.ownerID)
            {
                gotKillPlayer = p;
            }
        }

        stuckPlayer.isStuck = false;
        stuckPlayer.GetComponent <BigBoy> ().alreadyHit = true;

        PopText.Create("P" + killed.ToString() + " was hit by P" + killer.ToString(), Color.white, 250,
                       new Vector3(0, 4, 1));

        this.gameObject.active = false;
    }
Esempio n. 7
0
    public void StartLocalGame()
    {
        GlobalProperties.IS_NETWORKED = false;
        if (GlobalProperties.LEVEL.Equals(""))
        {
            PopText.Create("Choose a level!", Color.red, 120, playLocalButton.transform.position);
        }
        else
        {
            switch (GlobalProperties.LEVEL)
            {
            case "Cottage":
                Application.LoadLevel("The Cottage");
                break;

            case  "Mines":
                Application.LoadLevel("The Mines");
                break;

            case  "Galaxy":
                Application.LoadLevel("The Galaxy");
                break;

            case  "Ruins":
                Application.LoadLevel("The Ruins");
                break;

            case  "Warehouse":
                Application.LoadLevel("The Warehouse");
                break;
            }
        }

        AudioSource.PlayClipAtPoint(GetComponent <NetworkingObjectMenu>().click, GameObject.FindGameObjectWithTag("MainCamera").transform.position);
    }
Esempio n. 8
0
    public void PlayerFellLocal(PlayerController player)
    {
        int numPlayersIncludingYou = GameObject.FindObjectsOfType <PlayerController> ().Length;

        //AudioSource.PlayClipAtPoint(countdownSound, GameObject.FindObjectOfType<GameCamera>().transform.position);

        if (numPlayersIncludingYou == 1)
        {
            //dont worry, we already won
            PopText.Create("P" + player.playerID.ToString() + " killed himself out of happiness.", Color.white, 250,
                           new Vector3(0, 4, 1));
        }
        else if (numPlayersIncludingYou == 2)
        {
            player.myStats.Deaths++;
            player.gameObject.active = false;
            PlayerController winner = GameObject.FindObjectsOfType <PlayerController> ()[0];
            winner.myStats.RoundsWon++;
            //you just made someone else win
            PopText.Create("ROUND OVER - P" + winner.playerID.ToString() + " WINS!", Color.white, 250,
                           new Vector3(0, 4, 1));
            GameObject.FindObjectOfType <GameCamera>().RoundOver();
        }
        else
        {
            player.myStats.Deaths++;
            //you died, tragic, but the show must go on.
            PopText.Create("P" + player.playerID.ToString() + " killed himself.", Color.white, 250,
                           new Vector3(0, 4, 1));
        }
    }
Esempio n. 9
0
    public override void OnJoinedLobby()
    {
        //turn off old options
        connect_online.gameObject.active = false;
        quit.gameObject.active           = false;
        about.gameObject.active          = false;
        //turn on new options
        join.gameObject.active   = true;
        create.gameObject.active = true;

        AudioSource.PlayClipAtPoint(click, this.transform.position);
        PopText.Create("Connected to game server.", Color.black, 150, this.transform.position);
    }
Esempio n. 10
0
    public void ClickCreate()
    {
        string level = levelChoose.captionText.text;

        Debug.Log("LEVEL: " + level);
        GlobalProperties.LEVEL = level;
        RoomOptions ro = new RoomOptions();

        ro.MaxPlayers = byte.Parse(maxPlayers.text);
        AudioSource.PlayClipAtPoint(click, this.transform.position);
        PhotonNetwork.JoinOrCreateRoom(roomName.text, ro, TypedLobby.Default);
        PopText.Create("Creating and joining room \"" + roomName.text + "\"...", Color.white, 200, this.transform.position);
    }
    void DisplayKill(int killed, int killer)
    {
        PlayerController stuckPlayer   = null;
        PlayerController gotKillPlayer = null;

        PlayerController[] players = GameObject.FindObjectsOfType <PlayerController>();

        foreach (var p in players)
        {
            if (p.playerID == sb.stuckID)
            {
                stuckPlayer = p;
            }
        }
        foreach (var p in players)
        {
            if (p.playerID == sb.ownerID)
            {
                gotKillPlayer = p;
            }
        }

        //there isnt always a killed player - if there is, lets kill him but if not move on
        if (killed != -1)
        {
            stuckPlayer.isStuck           = false;
            stuckPlayer.gameObject.active = false;

            gotKillPlayer.myStats.Kills++;
            stuckPlayer.myStats.Deaths++;

            players = GameObject.FindObjectsOfType <PlayerController>();
            if (players.Length == 1)
            {
                PopText.Create("ROUND OVER - P" + killer.ToString() + " WINS!", Color.white, 250,
                               new Vector3(0, 4, 1));
                gotKillPlayer.myStats.RoundsWon++;
                GameObject.FindObjectOfType <GameCamera>().RoundOver();
            }
            else
            {
                PopText.Create("P" + killed.ToString() + " was killed by P" + killer.ToString(), Color.white, 250,
                               new Vector3(0, 4, 1));
            }
        }

        this.gameObject.active = false;
    }
Esempio n. 12
0
    void LocalLogic()
    {
        Xbox360Controller xc = GetComponent <PlayerController> ().GetXBox();

        if (trySteal)
        {
            if (target.GetComponent <PlayerController> ().hasStickyBomb)
            {
                target.GetComponent <PlayerController> ().hasStickyBomb = false;
                this.GetComponent <PlayerController> ().hasStickyBomb   = true;
                target.GetComponent <PlayerController> ().bombStatus.GetComponent <SpriteRenderer>().sprite = target.GetComponent <PlayerController> ().noBombSprite;
                this.GetComponent <PlayerController> ().bombStatus.GetComponent <SpriteRenderer>().sprite   = this.GetComponent <PlayerController> ().hasBombSprite;
                abilityAvailable = false;
                PopText.Create("SNATCHED!", Color.white, 60, transform.position + Vector3.up * .5f);
            }
        }
    }
Esempio n. 13
0
    void NetworkedLogic(Collider2D c)
    {
        PlayerController pc = this.transform.root.GetComponent <PlayerController>();
        StickyBomb       sb = c.gameObject.GetComponent <StickyBomb>();

        Debug.Log("Sticky : " + sb.ownerID + ", Owner: " + pc.playerID);

        if (sb.hitGround)
        {
            PopText.Create("Get Bomb!", Color.black, 60, sb.transform.position + Vector3.up);
            Vector3 scale = new Vector3(c.gameObject.transform.localScale.x, c.gameObject.transform.localScale.y, c.gameObject.transform.localScale.z);
            //this transform, scale, stickyID
            pc.GetComponent <PhotonView> ().RPC("PickupBombGround", PhotonTargets.All, sb.transform.position, scale, sb.GetComponent <PhotonView>().viewID);
        }
        else
        {
            if (!pc.playerID.Equals(sb.ownerID) && !sb.isStuck)
            {
                Debug.Log("Sucess!");
                Vector3 scale = new Vector3(c.gameObject.transform.localScale.x, c.gameObject.transform.localScale.y, c.gameObject.transform.localScale.z);
                //this transform, scale, stickyID
                pc.GetComponent <PhotonView> ().RPC("GetStuck", PhotonTargets.All, sb.transform.position, scale, sb.GetComponent <PhotonView>().viewID);
            }

            //for switching owners
            else if (sb.isStuck && !sb.GetComponent <NetworkStickyBomb>().justTransfered&&
                     !pc.playerID.Equals(sb.stuckID))
            {
                Debug.Log("Sucess!");
                Vector3 scale = new Vector3(c.gameObject.transform.localScale.x, c.gameObject.transform.localScale.y, c.gameObject.transform.localScale.z);
                //this transform, scale, stickyID
                pc.GetComponent <PhotonView> ().RPC("SwitchOwners", PhotonTargets.All, sb.transform.position, sb.GetComponent <PhotonView>().viewID);

                //call first on master client so transfer doesnt occur multiple times
                sb.GetComponent <NetworkStickyBomb>().TransferBomb();
            }
        }
    }
    void DisplayKillGround(int threwTheBomb, int op1, int op2, int op3, int op4)
    {
        PlayerController gotKillPlayer = null;

        PlayerController[]      players     = GameObject.FindObjectsOfType <PlayerController> ();
        List <PlayerController> deadPlayers = new List <PlayerController> ();

        foreach (var p in players)
        {
            if (p.playerID == sb.ownerID)
            {
                gotKillPlayer = p;
            }
            if (p.playerID == op1)
            {
                deadPlayers.Add(p);
            }
            else if (p.playerID == op2)
            {
                deadPlayers.Add(p);
            }
            else if (p.playerID == op3)
            {
                deadPlayers.Add(p);
            }
            else if (p.playerID == op4)
            {
                deadPlayers.Add(p);
            }
        }

        foreach (PlayerController dp in deadPlayers)
        {
            dp.isStuck           = false;
            dp.gameObject.active = false;
            if (dp != gotKillPlayer)
            {
                gotKillPlayer.myStats.Kills++;
            }
            dp.myStats.Deaths++;
        }

        players = GameObject.FindObjectsOfType <PlayerController>();
        if (players.Length == 1 && PhotonNetwork.playerList.Length != 1)
        {
            PopText.Create("ROUND OVER - P" + gotKillPlayer.playerID.ToString() + " WINS!", Color.white, 250,
                           new Vector3(0, 4, 1));
            gotKillPlayer.myStats.RoundsWon++;
            GameObject.FindObjectOfType <GameCamera>().RoundOver();
        }
        else if (deadPlayers.Count == 1)
        {
            if (deadPlayers[0].playerID == gotKillPlayer.playerID)
            {
                PopText.Create("P" + deadPlayers[0].playerID.ToString() + " killed himself.", Color.white, 250,
                               new Vector3(0, 4, 1));

                if (players.Length == 0)
                {
                    //PopText.Create ("ROUND OVER - Tie!", Color.white, 250,
                    //new Vector3(0, 4, 1));
                    GameObject.FindObjectOfType <GameCamera>().RoundOver();
                }
            }
            else
            {
                PopText.Create("P" + deadPlayers[0].playerID.ToString() + " was killed by P" + gotKillPlayer.playerID.ToString(), Color.white, 250,
                               new Vector3(0, 4, 1));
            }
        }
        else if (players.Length == 0)
        {
            PopText.Create("ROUND OVER - Tie!", Color.white, 250,
                           new Vector3(0, 4, 1));
            GameObject.FindObjectOfType <GameCamera>().RoundOver();
        }
        else if (deadPlayers.Count > 1)
        {
            PopText.Create("P" + gotKillPlayer.playerID.ToString() + " got a " + deadPlayers.Count.ToString() + " player multikill!", Color.white, 250,
                           new Vector3(0, 4, 1));
        }

        this.gameObject.active = false;
    }
 void LOCAL_DisplayCountdown(int num)
 {
     PopText.Create(num.ToString(), Color.white, 60, transform.position + Vector3.up * .5f);
     AudioSource.PlayClipAtPoint(countdownSound, GameObject.FindObjectOfType <GameCamera>().transform.position);
 }
 void DisplayCountdown(int num)
 {
     PopText.Create(num.ToString(), Color.white, 60, transform.position + Vector3.up * .5f);
 }
Esempio n. 17
0
 public void ClickJoin()
 {
     AudioSource.PlayClipAtPoint(click, this.transform.position);
     PhotonNetwork.JoinRoom(roomName.text);
     PopText.Create("Joining room \"" + roomName.text + "\"...", Color.white, 200, this.transform.position);
 }
    void FixedUpdate()
    {
        if (!gamePaused)
        {
            PlayerController[] players = GameObject.FindObjectsOfType <PlayerController> ();
            for (int i = 0; i < players.Length; i++)
            {
                if (players [i].isPaused)
                {
                    gamePaused = true;
                }
            }
            if (sb == null)
            {
                sb = GetComponent <StickyBomb> ();
            }

            if (sb.isStuck)
            {
                PopText.Create("o", Color.cyan, 30, this.transform.position);
                countdownTimer--;

                if (countdownTimer % 60 == 0)
                {
                    LOCAL_DisplayCountdown(countdownTimer / 60);
                }

                if (countdownTimer == 0)
                {
                    bool lastBomb = true;

                    StickyBomb[] allStickys = GameObject.FindObjectsOfType <StickyBomb> ();
                    if (allStickys.Length > 1)
                    {
                        lastBomb = false;
                    }
                    if (PlayerController.SomeoneHasSticky())
                    {
                        lastBomb = false;
                    }

                    Blowup();
                    GameObject.Destroy(this.gameObject);

                    PlayerController stuckPlayer   = null;
                    PlayerController gotKillPlayer = null;

                    foreach (var p in players)
                    {
                        if (p.playerID == sb.stuckID)
                        {
                            stuckPlayer = p;
                        }
                        if (p.playerID == sb.ownerID)
                        {
                            gotKillPlayer = p;
                        }
                    }

                    if (stuckPlayer.GetComponent <BigBoy> () != null &&
                        !stuckPlayer.GetComponent <BigBoy> ().alreadyHit)
                    {
                        //take away a life but dont kill him
                        BigBoyHit(stuckPlayer.playerID, gotKillPlayer.playerID);
                    }
                    else
                    {
                        if (stuckPlayer != null && gotKillPlayer != null)
                        {
                            DisplayKill(stuckPlayer.playerID, gotKillPlayer.playerID);
                        }
                    }

                    //check to see if we should spawn a crate
                    players = GameObject.FindObjectsOfType <PlayerController> ();
                    if (players.Length == 1)
                    {
                        //dont spawn crate
                        Debug.Log("DIDNT SPAWN CRATE BECAUSE ONLY ONE PLAYER!");
                    }
                    else if (lastBomb)
                    {
                        //spawn crate
                        GameObject crate = (GameObject)GameObject.Instantiate(localCratePrefab,
                                                                              GameObject.FindObjectOfType <GameCamera> ().GetRandomSpawnPoint(), Quaternion.identity);
                    }

                    GameObject.FindObjectOfType <GameCamera> ().UpdateStatsLocal();
                }

                if (justTransfered)
                {
                    justTransferedTimer--;

                    if (justTransferedTimer == 0)
                    {
                        justTransfered = false;
                    }
                }
            }
            else if (sb.hitGround)
            {
                groundedTimer--;

                if (groundedTimer % 60 == 0)
                {
                    LOCAL_DisplayCountdown(groundedTimer / 60);
                }

                if (groundedTimer <= 180 && groundedTimer % 30 == 0)
                {
                    Bursting(bursting);
                    bursting = !bursting;
                }

                if (groundedTimer == 0)
                {
                    bool lastBomb = true;

                    StickyBomb[] allStickys = GameObject.FindObjectsOfType <StickyBomb> ();
                    if (allStickys.Length > 1)
                    {
                        lastBomb = false;
                    }
                    if (PlayerController.SomeoneHasSticky())
                    {
                        lastBomb = false;
                    }

                    Blowup();

                    PlayerController stuckPlayer   = null;
                    PlayerController gotKillPlayer = null;

                    foreach (var p in players)
                    {
                        if (p.playerID == sb.stuckID)
                        {
                            stuckPlayer = p;
                        }
                        if (p.playerID == sb.ownerID)
                        {
                            gotKillPlayer = p;
                        }
                    }

                    int[] hits = new int[] { -1, -1, -1, -1 };
                    int[] pID  = new int[] { -1, -1, -1, -1 };
                    for (int i = 0; i < players.Length; ++i)
                    {
                        PlayerController p = players [i];
                        //pID[i] = p.playerID;
                        if (Vector3.Distance(this.transform.position, p.transform.position) < 1.8f)
                        {
                            hits [i] = p.playerID;
                        }
                    }

                    if (gotKillPlayer != null)
                    {
                        DisplayKillGround(gotKillPlayer.playerID,
                                          hits [0], hits [1], hits [2], hits [3]);
                    }

                    //check to see if we should spawn a crate
                    players = GameObject.FindObjectsOfType <PlayerController> ();
                    if (players.Length == 1)
                    {
                        //dont spawn crate, round is over
                    }
                    else if (lastBomb)                    //only spawn a crate if all the bombs are gone (there might be a scientist on the map)
                    {
                        GameObject crate = (GameObject)GameObject.Instantiate(localCratePrefab,
                                                                              GameObject.FindObjectOfType <GameCamera> ().GetRandomSpawnPoint(), Quaternion.identity);
                    }
                }
            }
            else if (!sb.hitGround)
            {
                PopText.Create("o", Color.cyan, 30, this.transform.position);
            }
        }

        else
        {
            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
            for (int i = 0; i < players.Length; i++)
            {
                if (players [i].GetComponent <PlayerController> ().isPaused)
                {
                    gamePaused = false;
                }
            }
        }
    }