Example #1
0
    public MatchStatsScreen(MatchStartData matchData, FrontEndConstants consts, ScreenUI owner)
        : base(matchData, consts, owner)
    {
        LevelManager manager = WorldConstants.MatchController.GetComponent <LevelManager>();

        players        = WorldConstants.ColTracker.Actors;
        statsToDisplay = Stats.GetStats(manager.MatchRules, players);
    }
    public LobbyMenuScreen(MatchStartData matchStartData, FrontEndConstants consts, ScreenUI owner)
        : base(matchStartData, consts, owner)
    {
        for (int i = 0; i < Owner.ControlsTextures.Length; ++i)
        {
            controlContents[i] = new GUIContent(Owner.ControlsTextures[i]);
        }

        playerDatas[0] = new PlayerData(0);
        playerDatas[1] = new PlayerData(1);
        playerDatas[2] = null;
        playerDatas[3] = null;
    }
 public GenerateLevelMenuScreen(MatchStartData matchStartData, FrontEndConstants consts, ScreenUI owner)
     : base(matchStartData, consts, owner)
 {
     MatchData.GenerateLevelAndSpawns();
     regenerate = true;
 }
Example #4
0
 public MenuScreen(MatchStartData matchStartData, FrontEndConstants consts, ScreenUI owner)
 {
     MatchData = matchStartData;
     Consts    = consts;
     Owner     = owner;
 }
Example #5
0
 public MainMenuScreen(MatchStartData matchData, FrontEndConstants consts, ScreenUI owner)
     : base(matchData, consts, owner)
 {
 }
Example #6
0
    /// <summary>
    /// Generates all game objects (players, objectives/collectibles, etc).
    /// </summary>
    /// <param name="isPreview">If true, only creates objects useful for a preview of the world.</param>
    public void Generate(MatchStartData matchData, bool isPreview)
    {
        Generator    level  = matchData.GeneratedLevel;
        SpawnCreator spawns = matchData.Spawns;
        Dictionary <Color, List <byte> > playersOnTeams       = matchData.PlayersOnTeams;
        Dictionary <byte, byte>          localPlayersControls = matchData.PlayerControlSchemes;

        List <Camera> playerCameras = new List <Camera>();

        PrefabCreator prefCreator  = WorldConstants.Creator;
        LevelManager  levelManager = WorldConstants.MatchController.GetComponent <LevelManager>();

        #region Create players

        //Get the number of players on this machine.
        int localPlayers = 0;
        foreach (List <byte> bs in playersOnTeams.Values)
        {
            foreach (byte id in bs)
            {
                if (id <= 4)
                {
                    localPlayers++;
                }
            }
        }

        //Make sure there are a valid number of players in-game and on this machine.
        if (playersOnTeams.Keys.Count < 1 || playersOnTeams.Keys.Count > 8 ||
            localPlayersControls.Count < 1 || localPlayersControls.Count > 4)
        {
            throw new System.ArgumentOutOfRangeException();
        }

        //Spawn teams.
        int             spawnIndex = 0;
        List <Location> spawnAreas;
        Dictionary <Color, List <Location> > spawnsByTeam = new Dictionary <Color, List <Location> >();
        GameObject p;
        Location   spawnLoc;
        foreach (KeyValuePair <Color, List <byte> > team in playersOnTeams)
        {
            spawnAreas = spawns.TeamSpawns[spawnIndex++];
            spawnsByTeam.Add(team.Key, spawnAreas);

            int count = 0;
            foreach (byte id in team.Value)
            {
                spawnLoc = spawnAreas[count];
                bool cantSpawn = false;
                while (level.Map[spawnLoc.X, spawnLoc.Y])
                {
                    if (count >= spawnAreas.Count - 1)
                    {
                        cantSpawn = true;
                        break;
                    }
                    spawnLoc = spawnAreas[++count];
                }

                if (cantSpawn)
                {
                    throw new UnityException();
                }
                else if (!isPreview)
                {
                    p = prefCreator.CreatePlayer(ToWorldPos(spawnAreas[count++], matchData), id, localPlayersControls[id], team.Key);
                    playerCameras.Add(prefCreator.CreatePlayerCamera(p, localPlayers).camera);
                }
            }
        }

        #endregion

        #region Set up view data

        prefCreator.CreateMinimapCamera(new Location(Mathf.RoundToInt(WorldConstants.Size.x), Mathf.RoundToInt(WorldConstants.Size.y)), localPlayers);

        //Calculate the bounds covering all areas a camera could ever see.

        int       numbCams           = playerCameras.Count;
        Vector2[] viewExtentsInWorld = new Vector2[numbCams];
        Camera    ca;

        for (int i = 0; i < numbCams; ++i)
        {
            ca = playerCameras[i].camera;

            viewExtentsInWorld[i]  = ca.ViewportToWorldPoint(new Vector3(1.0f, 1.0f, 0.0f)) - ca.ViewportToWorldPoint(Vector3.zero);
            viewExtentsInWorld[i] *= 0.5f;
        }

        //Get the largest view sizes.
        Vector2 maxViewExtentsInWorld;
        float   maxX = System.Single.MinValue,
                maxY = System.Single.MinValue;
        for (int i = 0; i < viewExtentsInWorld.Length; ++i)
        {
            if (viewExtentsInWorld[i].x > maxX)
            {
                maxX = viewExtentsInWorld[i].x;
            }
            if (viewExtentsInWorld[i].y > maxY)
            {
                maxY = viewExtentsInWorld[i].y;
            }
        }
        maxViewExtentsInWorld = new Vector2(maxX, maxY);
        //Give the view rect a bit of leeway.
        maxViewExtentsInWorld += Vector2.one;

        //Get a boundary representing all the areas a player could ever view.
        WorldConstants.MaxViewBounds = new RecBounds(WorldConstants.LevelBounds.center,
                                                     WorldConstants.LevelBounds.size);
        WorldConstants.MaxViewBounds.size += maxViewExtentsInWorld * 2.0f;

        #endregion

        #region Create parallax objects

        if (!isPreview)
        {
            float starsChance    = WorldConstants.StarsChance;
            float specialsChance = WorldConstants.SpecialsChance;

            if (level.GenSettings.WrapX && level.GenSettings.WrapY)
            {
                starsChance /= 8;
            }
            else if (level.GenSettings.WrapX || level.GenSettings.WrapY)
            {
                starsChance /= 3;
            }

            starsChance /= localPlayers;

            for (int i = 0; i < level.Map.GetLength(0); ++i)
            {
                for (int j = 0; j < level.Map.GetLength(1); ++j)
                {
                    if (!level.Map[i, j])
                    {
                        if (Random.value <= starsChance)
                        {
                            prefCreator.CreateStars(new Vector2(i, j));
                        }
                        else if (Random.value <= specialsChance)
                        {
                            prefCreator.CreateSpecial(new Vector2(i, j));
                        }
                    }
                }
            }
        }

        #endregion

        #region Create flags/teams

        if (isPreview || levelManager.MatchRules.CTF != null)
        {
            foreach (Color c in playersOnTeams.Keys)
            {
                //Get a spot that has a floor underneath it.

                bool foundFloor = false;

                foreach (Location l in spawnsByTeam[c])
                {
                    //If a spot was found, put the flag there.
                    //Using "above" instead of "below" is intentional --
                    //   much of this framework was tested in XNA, which uses a flipped Y axis.
                    if (level.FillData.GetMapAt(l.Above) && !level.FillData.GetMapAt(l))
                    {
                        if (isPreview)
                        {
                            prefCreator.CreateMinimapIcon(ToWorldPos(l, matchData), Animations.MM_Team, c, prefCreator.MinimapIconScaling.Team, prefCreator.MinimapIconZPoses.Team);
                        }
                        else
                        {
                            prefCreator.CreateFlagAndFlagBase(ToWorldPos(l, matchData), c);
                        }
                        foundFloor = true;
                        break;
                    }
                }

                //If no spawn location has a floor under it, just put the flag in the air.
                if (!foundFloor)
                {
                    foreach (Location l in spawnsByTeam[c])
                    {
                        //If a spot is empty, put the flag there.
                        if (!level.FillData.GetMapAt(l))
                        {
                            if (isPreview)
                            {
                                prefCreator.CreateMinimapIcon(ToWorldPos(l, matchData), Animations.MM_Team, c, prefCreator.MinimapIconScaling.Team, prefCreator.MinimapIconZPoses.Team);
                            }
                            else
                            {
                                prefCreator.CreateFlagAndFlagBase(ToWorldPos(l, matchData), c);
                            }
                            break;
                        }
                    }
                }
            }
        }

        #endregion

        #region Create a waypoint

        //Get areas inside a wall.
        List <int> toRemove = new List <int>();
        Location   tempL;
        for (int i = 0; i < spawns.OtherSpawnsCreated[Spawns.Waypoint].Count; ++i)
        {
            tempL = spawns.OtherSpawnsCreated[Spawns.Waypoint][i];
            if (level.Map[tempL.X, tempL.Y])
            {
                Debug.Log("Found a spawn spot inside a wall!");
                toRemove.Add(i);
            }
        }

        //Remove areas that were inside the wall.
        //Start from the end so there's no issue with indices changing after an object is deleted.
        for (int i = toRemove.Count - 1; i >= 0; --i)
        {
            spawns.OtherSpawnsCreated[Spawns.Waypoint].RemoveAt(toRemove[i]);
        }

        //Generate a waypoint.
        if (!isPreview && levelManager.MatchRules.WaypointFight != null)
        {
            List <Location> waypointSpawns = spawns.OtherSpawnsCreated[Spawns.Waypoint];
            Location        l = waypointSpawns[Random.Range(0, waypointSpawns.Count - 1)];
            prefCreator.CreateWaypoint(ToWorldPos(l, matchData));
        }

        #endregion

        #region Create powerup spawns

        if (!isPreview)
        {
            PowerupSpawnLocations = spawns.OtherSpawnsCreated[Spawns.Powerup].ToList().ConvertAll <Vector2>(l => ToWorldPos(l, matchData));
        }

        #endregion
    }
Example #7
0
 public static Vector2 ToWorldPos(Location levelMapPos, MatchStartData matchData)
 {
     return(new Vector2(new Interval(0.0f, matchData.GeneratedLevel.Map.GetLength(0), true, 3).Wrap(levelMapPos.X),
                        new Interval(0.0f, matchData.GeneratedLevel.Map.GetLength(1), true, 3).Wrap(levelMapPos.Y)));
 }
 public CreditsScreen(ScreenUI owner, MatchStartData msd, FrontEndConstants consts) : base(msd, consts, owner)
 {
 }
    public CreateMatchMenuScreen(MatchStartData matchStartData, FrontEndConstants consts, ScreenUI owner)
        : base(matchStartData, consts, owner)
    {
        //Initialize data.

        //Debug.Log("Reading matches:");
        XmlDocument matchDoc = new XmlDocument();

        matchDoc.LoadXml(Owner.MatchesFile.text);
        //matchDoc.LoadXml(Owner.MatchesFile.text.Substring(1, Owner.MatchesFile.text.Length - 1));
        matchSettings = new MatchSettingsReadWrite(matchDoc);
        //Debug.Log("Read matches");

        //Debug.Log("Reading levels:");
        XmlDocument levelsDoc = new XmlDocument();

        levelsDoc.LoadXml(Owner.LevelsFile.text);
        //levelsDoc.LoadXml(Owner.LevelsFile.text.Substring(1, Owner.LevelsFile.text.Length - 1));
        levelGeneration = new LevelGenerationReadWrite(levelsDoc);
        //Debug.Log("Read levels");

        selectedMatch         = "Unreadable";
        selectedLevelGen      = "Unreadable";
        selectedMatchIndex    = 0;
        selectedLevelGenIndex = 0;

        //Read matches.

        if (matchSettings.ErrorMessage == "")
        {
            matches   = new GUIContent[matchSettings.Matches.Count()];
            matchSets = new Rules[matches.Length];
            int count = 0;
            foreach (string rulesN in matchSettings.Matches)
            {
                matchSets[count] = matchSettings.ReadMatch(rulesN);

                if (matchSettings.ErrorMessage != "")
                {
                    matches   = null;
                    matchSets = null;
                    break;
                }

                matches[count] = new GUIContent(rulesN, matchSets[count].Description);
                count         += 1;
            }

            selectedMatchIndex      = Search(Convert(matches, m => m.text), "Brawl", (s1, s2) => s1 == s2);
            selectedMatch           = matches[selectedMatchIndex].text;
            MatchData.MatchSettings = matchSets[selectedMatchIndex];
        }
        else
        {
            matches   = null;
            matchSets = null;
        }

        //Read levels.

        if (levelGeneration.ErrorMessage == "")
        {
            levels    = new GUIContent[levelGeneration.Levels.Count()];
            levelGens = new Generator[levels.Length];
            int count = 0;
            foreach (string levelN in levelGeneration.Levels)
            {
                levelGens[count] = levelGeneration.ReadGenerator(levelN);

                if (levelGeneration.ErrorMessage != "")
                {
                    levels    = null;
                    levelGens = null;
                    break;
                }

                levels[count] = new GUIContent(levelN, levelGens[count].Description);
                count        += 1;
            }

            selectedLevelGenIndex    = Search(Convert(levels, l => l.text), "Corridor", (s1, s2) => s1 == s2);
            selectedLevelGen         = levels[selectedLevelGenIndex].text;
            MatchData.GeneratedLevel = levelGens[selectedLevelGenIndex];
            MatchData.GenerateLevelAndSpawns();
        }
        else
        {
            levels    = null;
            levelGens = null;
        }
    }
 public MatchScreen(MatchStartData matchData, FrontEndConstants consts, ScreenUI owner)
     : base(matchData, consts, owner)
 {
     manager = WorldConstants.Creator.CreateMatchController().GetComponent <LevelManager>();
 }
 public MatchEndScreen(MatchStartData matchData, FrontEndConstants consts, ScreenUI owner)
     : base(matchData, consts, owner)
 {
     elapsed = 0.0f;
     WorldConstants.MatchController.GetComponent <InputManager>().DisableInput = true;
 }