コード例 #1
0
ファイル: GameManager.cs プロジェクト: mgitlin/rowball
    void EndRound(PlayerManager.PlayerInfo[] winners)
    {
        roundOver = true;
        if (scorePerRound)
        {
            winners[0].Score(baseScorePoints);                      //Score target is undefined, entire team scores
        }
        round++;
        warmupOn = false;

        //Check score to end game
        if (scoreMode != ScoreMode.KILL)
        {
            for (int i = 0; i < (teams == 0?PlayerManager.ActivePlayers().Length:teams); ++i)
            {
                if (PlayerManager.TeamScore(i) >= scoreToWin)
                {
                    //EndGame();
                    if (!endSequenceInitiated)
                    {
                        InterfaceManager.ShowStatsScreen();
                    }
                    endSequenceInitiated = true;
                    break;
                }
            }
        }

        Restart(restartTime);
    }
コード例 #2
0
 //Get player spawn point
 public static Vector2 SpawnPoint(int i)
 {
     if (PlayerManager.ActivePlayers().Length != instance.spawnPoints.Length)
     {
         instance.GenerateSpawnPoints();
     }
     return(instance.spawnPoints[i]);
 }
コード例 #3
0
    //Generate spawn points for players
    void GenerateSpawnPoints()
    {
        if (generateSpawnPoints)
        {
            int count = PlayerManager.ActivePlayers().Length;
            spawnPoints = new Vector2[count];
            //Get optimum side length
            int yLength = (int)Mathf.Round(Mathf.Sqrt(count));
            int xLength = (int)Mathf.Ceil(count / (float)yLength);

            for (int i = 0; i < count; ++i)
            {
                spawnPoints[i]  = new Vector2((i % xLength) * spawnPointOffset, (i / xLength) * spawnPointOffset);               //Grid
                spawnPoints[i] -= new Vector2((xLength - 1) * spawnPointOffset * 0.5f, (yLength - 1) * spawnPointOffset * 0.5f); //Center
                //Last-line offset
                if ((i / xLength) % 2 == yLength - 1 && count % xLength != 0)
                {
                    spawnPoints[i] += new Vector2(spawnPointOffset * 0.5f, 0);
                }
            }
        }
    }
コード例 #4
0
ファイル: GameManager.cs プロジェクト: mgitlin/rowball
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape) || GamepadInput.GamePad.GetButtonDown(GamepadInput.GamePad.Button.Start, GamepadInput.GamePad.Index.Any))
        {
            if (!isPaused)            //if (roundState != RoundState.PAUSED) {
            {
                Pause();
            }
            else
            {
                UnPause();
            }
        }
        if (roundState != RoundState.PAUSED)
        {
            if (roundState != RoundState.PLAYING && (!warmupOn || round != -1))
            {
                roundState = RoundState.PLAYING;
            }

            freezeTimer -= Time.deltaTime;             //Goes negative for fading

            //Set mode-specific variables
            switch (mode)
            {
            case (GameMode.CORE):
                restartTime = 2.5f;
                teams       = 2;
                minPlayers  = 2;
                maxPlayers  = 4;
                //scoreToWin = 60;
                scoreMode     = ScoreMode.GOAL;
                scorePerRound = false;                 //Technically true, but the hook is for the goal shot
                useRespawns   = true;
                respawnTime   = 4;
                break;

            case (GameMode.FFA):
                restartTime = 10;
                teams       = 0;
                minPlayers  = 2;
                maxPlayers  = 4;
                //scoreToWin=20;
                scoreMode     = ScoreMode.KILL;
                scorePerRound = false;
                useRespawns   = true;
                respawnTime   = 3;
                break;

            case (GameMode.DUEL):
                restartTime = 1.5f;
                teams       = 0;
                minPlayers  = 2;
                maxPlayers  = 2;
                //scoreToWin = 10;
                scoreMode     = ScoreMode.LMS;
                scorePerRound = true;
                useRespawns   = false;
                respawnTime   = 0;
                break;
            }
            //Winners
            switch (scoreMode)
            {
            //case(ScoreMode.GOAL):
            //	winners = PlayerManager.lastScoredGoal;
            //	break;

            case (ScoreMode.LMS):
                winners = PlayerManager.lastAlive;
                break;

            case (ScoreMode.KILL):
                //Round never ends
                break;
            }
            //End round
            if (scoreMode == ScoreMode.KILL)
            {
                for (int i = 0; i < (teams == 0 ? PlayerManager.ActivePlayers().Length : teams); ++i)
                {
                    if (PlayerManager.TeamScore(i) >= scoreToWin)
                    {
                        winners = PlayerManager.TeamPlayers(i);
                        //EndGame();
                        if (!endSequenceInitiated)
                        {
                            InterfaceManager.ShowStatsScreen();
                        }
                        endSequenceInitiated = true;
                        break;
                    }
                }
            }
            else if (winners != null && !roundOver)
            {
                EndRound(winners);
            }

            //Hard reset (debug)
            if (Input.GetKeyDown(KeyCode.Space))
            {
                //Restart ();
            }

            if (PlayerManager.gameReady && roundState == RoundState.SETUP)
            {
                roundState = RoundState.RESPAWN;
            }

            //Editor
            if (mode != lastMode)
            {
                PlayerManager.Refresh();
                lastMode = mode;
            }
            maxPlayers = Mathf.Max(minPlayers, maxPlayers);
            scoreToWin = Mathf.Max(1, scoreToWin);
        }
    }
コード例 #5
0
ファイル: InterfaceManager.cs プロジェクト: mgitlin/rowball
    public void Update()
    {
        //Regenerate text objects if cache is stale
        PlayerManager.PlayerInfo[] players = PlayerManager.ActivePlayers();
        if (PlayerManager.HasChanged(ref playerCache))
        {
            //Clear
            foreach (TextOverlay t in texts)
            {
                if (t != null && t.gui != null)
                {
                    if (!Application.isEditor || Application.isPlaying)
                    {
                        Destroy(t.gui.gameObject);
                    }
                    else
                    {
                        DestroyImmediate(t.gui.gameObject);
                    }
                }
            }

            //Populate and parent
            if (players.Length > 0)
            {
                texts = new TextOverlay[players.Length];
                for (int i = 0; i < texts.Length; ++i)
                {
                    if (players[i] != null)
                    {
                        texts[i] = new TextOverlay(4.6f, 2f);
                        //Instantiate for each ship
                        texts[i].gui = Instantiate(shipTextPrefab, Vector3.zero, Quaternion.identity) as Text;
                        texts[i].gui.gameObject.name = "Text Overlay (Player " + (players[i].order + 1) + ")";
                        //Container
                        texts[i].gui.transform.SetParent(shipTextContainer, false);
                    }
                }
            }
        }

        for (int i = 0; i < texts.Length; ++i)
        {
            if (texts[i] != null)
            {
                TextOverlay t = texts[i];

                //Update position, scale, color, and text
                Vector2 screenPos = players[i].position - Vector2.up * (players[i].player.ship.size + offset) + Vector2.right * xOffset;
                screenPos.y -= 10.0f;
                screenPos    = viewCamera.WorldToScreenPoint(screenPos);
                t.gui.transform.position = screenPos;

                //Scale (uses zoom range constants)
                float scale = Mathf.Lerp(size.x, size.y, 1 - ((CameraController.zoom - 32) / (256 - 32)));
                t.gui.GetComponent <RectTransform>().localScale = new Vector3(scale, scale, 1);

                t.color = PlayerManager.TeamColor(players[i]);

                /*
                 * if(players[i].totaled){ //Totaled
                 *      //Reset
                 *      if(t.deathMessage==""){
                 *              t.deathMessage=deathMessages[Random.Range(0,deathMessages.Length)];
                 *              //Set blink start time so that the blink doesn't cut out early
                 *              if((Time.time+blinkTime)%(blinkRate*2)>blinkRate)t.blinkStartTime=Time.time-blinkRate;
                 *              else t.blinkStartTime=Time.time;
                 *      }
                 *      t.text=t.deathMessage;
                 *      bool blink = Time.time-t.blinkStartTime<blinkTime?Time.time%(blinkRate*2)>blinkRate:false;
                 *      t.alpha=blink?1:0;
                 * }
                 */
                if (PlayerManager.Winner(players[i]))         //Winner
                {
                    t.text = GameManager.instance.scoreMode == GameManager.ScoreMode.GOAL?"SCORE!":"VICTORY";
                    bool blink = Time.time % (blinkRate * 2) > blinkRate;
                    t.alpha = blink?1:0;
                }
                else                     //Normal behavior, displays controls
                {
                    t.deathMessage = ""; //Reset death message for respawn

                    if (GameManager.instance.roundState == GameManager.RoundState.SETUP &&
                        GameManager.instance.round == -1)
                    {
                        if (!players[i].ready)
                        {
                            t.text =
                                "Player " + players[i].player.control.controller;
                            //players[i].player.control.leftOars+" | "+
                            //players[i].player.control.cannon+" | "+
                            //players[i].player.control.rightOars;//+
                            //"\nReady up";
                            //t.text+=
                            //Time.time%(readyUpRate*4)>readyUpRate*3?"...":
                            //Time.time%(readyUpRate*4)>readyUpRate*2?"..":
                            //Time.time%(readyUpRate*4)>readyUpRate*1?".":
                            //"";
                        }
                        else
                        {
                            t.text = "READY";
                        }
                        finishedSetup = false;
                    }
                    else
                    {
                        if (!finishedSetup)
                        {
                            finishedSetup = true;
                            //GameManager.instance.roundState = GameManager.RoundState.PLAYING;
                            startTime = Time.time;
                        }
                        t.text = "";
                    }
                }
            }
        }

        if (GameManager.instance.roundState == GameManager.RoundState.SETUP &&
            GameManager.instance.round == -1)
        {
            //statusLoader.enabled = true;
            gameStatus.text = "Warmup \n" + PlayerManager.playersReady + "/" + PlayerManager.ActivePlayers().Length + " Players Ready";
            //if (statusLoader.fillAmount == 0) {
            //    statusLoader.fillClockwise = true;
            //    flip = 1;
            //} else if (statusLoader.fillAmount == 1) {
            //    statusLoader.fillClockwise = false;
            //    flip = -1;
            //}
            //statusLoader.fillAmount += flip * (Time.deltaTime);
            finishedSetup = false;
        }
        else
        {
            if (!finishedSetup)
            {
                finishedSetup = true;
                statusBg.gameObject.SetActive(false);
                startTime = Time.time;
            }
            if (finishedSetup && GameManager.instance.freezeTimer > -goTime)
            {
                statusBg.gameObject.SetActive(false);
                // Handle status text
                if (GameManager.instance.roundState == GameManager.RoundState.PLAYING)
                {
                    if (statusUpdated == false)
                    {
                        lastTime = Time.time;
                        statusLoader.fillAmount    = 0;
                        statusLoader.fillClockwise = true;
                        for (int i = 0; i < texts.Length; ++i)
                        {
                            if (texts[i] != null)
                            {
                                texts[i].text = "";
                            }
                        }

                        SetStatus(true);
                        statusUpdated = true;
                        gameObjective.gameObject.SetActive(false);
                    }
                }
                if (GameManager.instance.freezeTimer > 0)
                {
                    gameStatus.text = "Waiting...";
                    readyImg.gameObject.SetActive(true);
                }
                else
                {
                    readyImg.gameObject.SetActive(false);
                    gameStatus.text = "GO!";
                    SetAlpha(statusLoader, 0);
                    goImg.gameObject.SetActive(true);
                }

                // Keep the loading circle moving
                statusLoader.fillAmount = (Time.time - lastTime) / GameManager.instance.freezeTime;
            }
            if (Time.time - startTime > visibleTime && (GameManager.instance.roundState == GameManager.RoundState.PLAYING || GameManager.instance.roundState == GameManager.RoundState.STARTING_PLAY))
            {
                SetAlpha(gameStatus, 0);
                goImg.gameObject.SetActive(false);
            }
            if (GameManager.instance.roundState == GameManager.RoundState.RESTARTING)
            {
                SetAlpha(gameStatus);
                SetAlpha(statusLoader);
            }
        }
        for (int i = 0; i < scores.Length; i++)
        {
            if (PlayerManager.TeamScore(i) >= GameManager.instance.scoreToWin * closeToWinPercent)
            {
                scores[i].fontSize = scoreTextPrefab.fontSize + (int)(4 * ((1 + Mathf.Sin(Time.time * 15) / 2)));
            }
        }
    }
コード例 #6
0
ファイル: CameraBounds.cs プロジェクト: mgitlin/rowball
    void Update()
    {
        //Temporary, will function in GameManager later
        if (GameController.game != null)
        {
            trackWinner = GameManager.instance.scoreMode == GameManager.ScoreMode.KILL;
        }

        //Edge bound
        if (edgeCollider == null)
        {
            edgeCollider = GetComponent <EdgeCollider2D>();
        }

        float xOffset = boundedCam.orthographicSize * boundedCam.aspect;       //X offset depends on aspect ratio
        float yOffset = boundedCam.orthographicSize;

        corners[0] = new Vector2(-xOffset, yOffset); corners[1] = new Vector2(xOffset, yOffset);
        corners[2] = new Vector2(xOffset, -yOffset); corners[3] = new Vector2(-xOffset, -yOffset);
        corners[4] = corners[0];

        edgeCollider.points = corners;

        if (GameController.game != null)
        {
            foreach (PlayerManager.PlayerInfo p in PlayerManager.ActivePlayers())
            {
                p.player.ship.boundsOffset = new Vector2(xOffset, yOffset);
            }

            //Effector ring--generated manually for now (prototype)
            if (GameManager.instance.winners == null || GameManager.instance.winners.Length > 1 || !trackWinner)
            {
                if (effectors.Length == 0 || effectors [0] == null)
                {
                    BuildRing();
                }
                foreach (AreaEffector2D e in effectors)
                {
                    e.forceMagnitude = force;
                }
                Vector2[] vertices = new Vector2[4];

                //Corners
                vertices [0] = new Vector2(-xOffset - depth, yOffset + depth);
                vertices [1] = new Vector2(-xOffset, yOffset + depth);
                vertices [2] = new Vector2(-xOffset, yOffset);
                vertices [3] = new Vector2(-xOffset - depth, yOffset);
                effectors [0].GetComponent <PolygonCollider2D> ().SetPath(0, vertices);
                effectors [0].forceAngle = -45;

                vertices [0] = new Vector2(xOffset, yOffset + depth);
                vertices [1] = new Vector2(xOffset + depth, yOffset + depth);
                vertices [2] = new Vector2(xOffset + depth, yOffset);
                vertices [3] = new Vector2(xOffset, yOffset);
                effectors [1].GetComponent <PolygonCollider2D> ().SetPath(0, vertices);
                effectors [1].forceAngle = -135;

                vertices [0] = new Vector2(xOffset, -yOffset);
                vertices [1] = new Vector2(xOffset + depth, -yOffset);
                vertices [2] = new Vector2(xOffset + depth, -yOffset - depth);
                vertices [3] = new Vector2(xOffset, -yOffset - depth);
                effectors [2].GetComponent <PolygonCollider2D> ().SetPath(0, vertices);
                effectors [2].forceAngle = -225;

                vertices [0] = new Vector2(-xOffset - depth, -yOffset);
                vertices [1] = new Vector2(-xOffset, -yOffset);
                vertices [2] = new Vector2(-xOffset, -yOffset - depth);
                vertices [3] = new Vector2(-xOffset - depth, -yOffset - depth);
                effectors [3].GetComponent <PolygonCollider2D> ().SetPath(0, vertices);
                effectors [3].forceAngle = -315;

                //Edges
                vertices [0] = new Vector2(-xOffset, yOffset + depth);
                vertices [1] = new Vector2(xOffset, yOffset + depth);
                vertices [2] = new Vector2(xOffset, yOffset);
                vertices [3] = new Vector2(-xOffset, yOffset);
                effectors [4].GetComponent <PolygonCollider2D> ().SetPath(0, vertices);
                effectors [4].forceAngle = -90;

                vertices [0] = new Vector2(xOffset, yOffset);
                vertices [1] = new Vector2(xOffset + depth, yOffset);
                vertices [2] = new Vector2(xOffset + depth, -yOffset);
                vertices [3] = new Vector2(xOffset, -yOffset);
                effectors [5].GetComponent <PolygonCollider2D> ().SetPath(0, vertices);
                effectors [5].forceAngle = -180;

                vertices [0] = new Vector2(-xOffset, -yOffset);
                vertices [1] = new Vector2(xOffset, -yOffset);
                vertices [2] = new Vector2(xOffset, -yOffset - depth);
                vertices [3] = new Vector2(-xOffset, -yOffset - depth);
                effectors [6].GetComponent <PolygonCollider2D> ().SetPath(0, vertices);
                effectors [6].forceAngle = -270;

                vertices [0] = new Vector2(-xOffset - depth, yOffset);
                vertices [1] = new Vector2(-xOffset, yOffset);
                vertices [2] = new Vector2(-xOffset, -yOffset);
                vertices [3] = new Vector2(-xOffset - depth, -yOffset);
                effectors [7].GetComponent <PolygonCollider2D> ().SetPath(0, vertices);
                effectors [7].forceAngle = 0;
            }
            else                 //Disable all bounds for winner
            {
                if (!Application.isEditor || Application.isPlaying)
                {
                    edgeCollider.enabled = false;
                }
                Clear();
            }
        }
    }
コード例 #7
0
ファイル: CameraController.cs プロジェクト: mgitlin/rowball
    void Update()
    {
        //Track multiple winners for anything but duels
        if (GameController.game != null)
        {
            trackMultiple = GameManager.instance.scoreMode != GameManager.ScoreMode.LMS;
        }
        if (!Application.isEditor || Application.isPlaying)
        {
            if (!trackMultiple)
            {
                totaledFactor = 1;
            }
        }

        //Zoom
        if (attachedCamera == null)
        {
            attachedCamera = GetComponent <Camera>();
        }
        attachedCamera.orthographicSize = _zoom;

        if ((!Application.isEditor || Application.isPlaying) && GameController.game != null)
        {
            Vector2 averagePosition            = Vector2.zero;
            PlayerManager.PlayerInfo[] winners = GameController.game.winners;
            PlayerManager.PlayerInfo[] players = PlayerManager.ActivePlayers();

            //Normal gameplay (position calculation)
            if (winners == null || !trackMultiple)
            {
                //Get weight
                float totalWeight = 0;
                foreach (PlayerManager.PlayerInfo p in players)
                {
                    totalWeight += (p.totaled?totaledFactor:1);
                }
                //Get average position
                foreach (PlayerManager.PlayerInfo p in players)
                {
                    float totaledWeight = (p.totaled?totaledFactor:1) / totalWeight;
                    averagePosition += p.position * totaledWeight;
                }
            }
            //Zoom on winners
            else
            {
                Vector2 goalPos = Vector2.zero;
                //if(GameManager.instance.scoreMode==GameManager.ScoreMode.GOAL){
                //	Vector3 pos = WorldManager.GetGoal(PlayerManager.lastScoredGoal[0].player.team).transform.position;
                //	goalPos=new Vector2(pos.x,pos.y);
                //}

                Vector2 firstTarget = new Vector2(transform.position.x, transform.position.y);
                firstTarget = (GameManager.instance.scoreMode == GameManager.ScoreMode.GOAL)?
                              goalPos:
                              PlayerManager.lastTotaled != null?PlayerManager.lastTotaled.position:firstTarget;

                Vector2 winnersPosition = Vector2.zero;
                foreach (PlayerManager.PlayerInfo p in winners)
                {
                    if (p != null)
                    {
                        winnersPosition += p.position;
                    }
                }
                winnersPosition /= winners.Length;

                if (endTime == 0)
                {
                    endTime = Time.time;
                }
                averagePosition = Time.time - endTime < targetSwapTime?firstTarget:winnersPosition;

                if (winners.Length < 2)
                {
                    _zoom = Mathf.Lerp(_zoom, winnerZoom, Time.deltaTime * zoomDamping);
                }
                damping = winnerDamping;
            }
            //Constrain
            if (winners == null || !trackMultiple)
            {
                averagePosition = new Vector2(
                    Mathf.Clamp(averagePosition.x, -WorldManager.bounds.x * 0.5f, WorldManager.bounds.x * 0.5f),
                    Mathf.Clamp(averagePosition.y, -WorldManager.bounds.y * 0.5f, WorldManager.bounds.y * 0.5f)
                    );
            }

            //Lerp
            Vector2 lerpedPosition = Vector2.Lerp(transform.position, averagePosition, Time.deltaTime * damping);
            transform.position = new Vector3(lerpedPosition.x, lerpedPosition.y, transform.position.z);
        }
    }