public void StartWorld(bool isPreview)
    {
        WorldConstants.MirrorContainer = new GameObject("Mirror Objects");
        WorldConstants.WallContainer   = new GameObject("Walls");

        //Get some references.
        CreateLevel     levG = WorldConstants.MatchWrapper.GetComponent <CreateLevel>();
        GenerateObjects objG = WorldConstants.MatchWrapper.GetComponent <GenerateObjects>();

        //Take ownership of the game rules.
        if (!isPreview)
        {
            MatchRules       = MatchData.MatchSettings;
            MatchRules.Owner = this;
            MatchStarted     = true;
        }
        CountdownToGameEnd = new System.TimeSpan(MatchRules.MatchLength.Ticks);

        //Create the level and objects.
        levG.SetGenerationData(MatchData.GeneratedLevel, MatchData.Spawns);
        WorldConstants.LevelOffset = Vector2.zero;
        levG.Generate(Vector2.zero, isPreview);
        objG.Generate(MatchData, isPreview);

        //Start crowd cheering.
        if (!isPreview)
        {
            WorldConstants.CrowdCheering.StartCheering();
            WorldConstants.CrowdCheering.CreateCrowdCheer(CrowdCheers.Events.GameStart);
        }
    }
Beispiel #2
0
 /// <summary>
 /// Verifica se o objeto está próximo de outros objetos do cenario.
 /// Se estiver muito proximo, sua posição está inválida.
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public bool PositionIsValid(GenerateObjects obj)
 {
     foreach (GenerateObjects structure in structures)
     {
         if (Mathf.Abs(obj.GetObjectYPosition() - structure.GetObjectYPosition()) < 3)
         {
             return(false);
         }
         iterations++;
     }
     return(true);
 }
Beispiel #3
0
    public void CreateMap()
    {
        int structuresNumber = NumberOfStructures();

        structures = new List <GenerateObjects>();

        float[] lastYPosition = new float[2];
        lastYPosition[0] = lastYPosition[1] = -1;

        for (int i = 0; i < structuresNumber; i++)
        {
            GenerateObjects obj = new GenerateObjects();
            obj.GenerateXAxis();
            int side = obj.GetSide();
            obj.GenerateYAxis(lastYPosition[side]);
            lastYPosition[side] = obj.GetObjectYPosition();

            structures.Add(obj);
            structuresPool.SpawnFromPool("House1", obj.GetObjectVector(), obj.GetObjectRotation());
        }
    }
    public override void Update()
    {
        //Initialize/find the waypoint object.
        if (waypoint == null)
        {
            waypoint = GameObject.FindGameObjectWithTag("Waypoint");
        }

        //If there is no waypoint, find a new one.
        if (waypoint == null)
        {
            elapsed += Time.deltaTime;
            if (elapsed >= NewWaypointDelay)
            {
                //Get the next spawn location.
                GenerateObjects objG      = Owner.Owner.ObjGenerator;
                List <Location> waySpawns = spawns.OtherSpawnsCreated[Spawns.Waypoint];
                CurrentWaypointIndex += 1;
                CurrentWaypointIndex %= waySpawns.Count;

                //Spawn a waypoint.
                Location spawn = spawns.OtherSpawnsCreated[Spawns.Waypoint][CurrentWaypointIndex];
                waypoint = Owner.Owner.Creator.CreateWaypoint(GenerateObjects.ToWorldPos(spawn, WorldConstants.MatchData));
                WorldConstants.Creator.CreateFloatingTextsForPlayers(st => WorldConstants.ActorConsts.WaypointSpawnedMessages.Allies,
                                                                     st => true,
                                                                     WorldConstants.Creator.CreateWaypointFloatingText);
                WorldConstants.CrowdCheering.CreateCrowdCheer(CrowdCheers.Events.WaypointSpawned);

                elapsed = 0.0f;
            }
        }
        //Otherwise, reset the timer to spawn a new one.
        else
        {
            elapsed = 0.0f;
        }
    }
    void Update()
    {
        if (!MatchStarted || GameOver)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            GetComponent <InputManager>().DisableInput = true;
            confirmGameEnd = true;
        }

        #region Update player/team scores

        TeamScores.Clear();
        PlayerScores.Clear();

        //Go through and re-add each player/team.
        foreach (StateMachine st in WorldConstants.ColTracker.Actors)
        {
            PlayerScores.Add(st, MatchRules.GetScore(st.OwnerStats));

            if (!TeamScores.ContainsKey(st.ActorData.Team))
            {
                TeamScores.Add(st.ActorData.Team, 0.0f);
            }

            TeamScores[st.ActorData.Team] += PlayerScores[st];
        }

        //Get the teams in order by score.
        List <KeyValuePair <Color, float> > descendingTeams = TeamScores.ToList();
        descendingTeams = DescendingBubbleSort(descendingTeams);
        Color bestTeam     = descendingTeams[0].Key;
        float largestScore = descendingTeams[0].Value;

        #endregion

        #region Check for team won/near winning

        //Warn players of the match nearly ending if applicable.
        if (!warnedPlayersYet)
        {
            //If any of the teams are near winning, say so.
            if (largestScore > (WorldConstants.ScoreWarningThreshold * MatchRules.ScoreGoal))
            {
                WorldConstants.Creator.CreateFloatingTextsForPlayers(WorldConstants.Creator.ThreeMessages(ActorConsts.AlmostWonMessages, bestTeam, null),
                                                                     st => st.ActorData.Team == bestTeam,
                                                                     WorldConstants.Creator.CreateMatchFloatingText);
                warnedPlayersYet = true;
            }
            //If time is almost out, say so.
            if (CountdownToGameEnd.TotalSeconds <= 60.0)
            {
                WorldConstants.Creator.CreateFloatingTextsForPlayers(WorldConstants.Creator.ThreeMessages(ActorConsts.OneMinuteLeftMessages, bestTeam, null),
                                                                     st => st.ActorData.Team == bestTeam,
                                                                     WorldConstants.Creator.CreateMatchFloatingText);
                warnedPlayersYet = true;
            }
        }

        //See if a team won.
        if (largestScore >= MatchRules.ScoreGoal)
        {
            GameOver = true;
            Creator.CreateFloatingTextsForPlayers(Creator.ThreeMessages(ActorConsts.GameOverMessages, bestTeam, null),
                                                  st => st.ActorData.Team == bestTeam,
                                                  Creator.CreateMatchFloatingText);
            WorldConstants.CrowdCheering.CreateCrowdCheer(CrowdCheers.Events.GameWin);
            return;
        }
        //See if time ran out.
        CountdownToGameEnd -= System.TimeSpan.FromSeconds(Time.deltaTime);
        if (CountdownToGameEnd.TotalSeconds <= 0.0)
        {
            GameOver = true;
            Creator.CreateFloatingTextsForPlayers(Creator.ThreeMessages(ActorConsts.GameOverMessages, bestTeam, null),
                                                  st => st.ActorData.Team == bestTeam,
                                                  Creator.CreateMatchFloatingText);
            WorldConstants.CrowdCheering.CreateCrowdCheer(CrowdCheers.Events.GameWin);
            return;
        }

        #endregion

        #region Debug drawing

        StateMachine.DrawBounds(WorldConstants.LevelBounds, Color.red);
        StateMachine.DrawBounds(WorldConstants.MaxViewBounds, Color.yellow);

        if (ObjGenerator == null)
        {
            ObjGenerator = WorldConstants.MatchWrapper.GetComponent <GenerateObjects>();
        }

        #endregion

        #region Powerup timer

        //If it's time, refresh the collection of powerups.
        if (elapsed >= getObjectsInterval)
        {
            GetObjects();
            elapsed = 0.0f;
        }
        elapsed += Time.deltaTime;

        MatchRules.Update();

        //Update the timer to getting a powerup.
        if (Powerups.Count == 0 || !MatchRules.WaitForPowerupCollection)
        {
            CountdownToPowerup -= System.TimeSpan.FromSeconds(Time.deltaTime);
            if (CountdownToPowerup <= System.TimeSpan.Zero)
            {
                //Make the powerup.
                Vector2 spawnP = ObjGenerator.PowerupSpawnLocations[Random.Range(0, ObjGenerator.PowerupSpawnLocations.Count)];
                Creator.CreatePowerup(spawnP);

                //Reset the timer.
                CountdownToPowerup = MatchRules.PowerupSpawnInterval;
            }
        }
        TimeToPowerup = CountdownToPowerup.ToString();

        #endregion
    }