コード例 #1
0
        private void DebugColorEdit()
        {
            KeyControl keyPlayer = new KeyControl(Keys.NumPad4);
            KeyControl keyTeam1  = new KeyControl(Keys.NumPad2);
            KeyControl keyTeam2  = new KeyControl(Keys.NumPad3);
            KeyControl keyShift1 = new KeyControl(Keys.LeftControl);
            KeyControl keyShift2 = new KeyControl(Keys.RightControl);

            if (keyPlayer.KeyPressed())
            {
                ColorMaskedSprite playerMaskedSprite = Owner.FindComponent <ColorMaskedSprite>();
                if (PlayerIndex == PlayerIndex.One) // hack to avoid several Color incrementations
                {
                    if (keyShift1.KeyDown() || keyShift2.KeyDown())
                    {
                        Colors.Previous();
                    }
                    else
                    {
                        Colors.Next();
                    }
                }

                playerMaskedSprite.Color1 = Colors.Current();
            }
            else if (keyTeam1.KeyPressed() && m_team.TeamID == TeamId.TeamOne ||
                     (keyTeam2.KeyPressed() && m_team.TeamID == TeamId.TeamTwo))
            {
                ColorMaskedSprite playerMaskedSprite = Owner.FindComponent <ColorMaskedSprite>();

                if (keyShift1.KeyDown() || keyShift2.KeyDown())
                {
                    Colors.Current();
                }
                else
                {
                    Colors.Current();
                }

                m_team.ColorScheme.Color1 = Colors.Current();

                playerMaskedSprite.Color3 = Colors.Current();
            }
        }
コード例 #2
0
ファイル: NavigationManager.cs プロジェクト: GDxU/GoalRush
        public override void Update()
        {
            if (m_navigationGrid == null)
            {
                return;
            }

            if (Game.GameManager.Ball != null)
            {
                m_ballSource.Position = Game.GameManager.Ball.Position;
            }

            //Random rand = new Random();
            //int nAABB = 128;
            //AABB[] aabbs = new AABB[nAABB];
            //for (int i = 0; i < nAABB; i++)
            //{
            //    aabbs[i] = new AABB(rand.NextVector2(), rand.NextFloat(), rand.NextFloat());
            //}

            //int t = 0;
            //int n = 1000000;
            //for (int i = 0; i < n; i++)
            //{
            //    if (AABB.TestOverlapFast(ref aabbs[(i) % nAABB], ref aabbs[(i + 1) % nAABB])) t++;
            //    if (AABB.TestOverlap(ref aabbs[(i) % nAABB], ref aabbs[(i + 1) % nAABB])) t++;
            //}

            //Engine.Log.Debug("T", t);

            m_shootLeftPlayerCosts[0].Position  = Game.Arena.LeftGoal.Team.Players[0].Position;
            m_shootLeftPlayerCosts[1].Position  = Game.Arena.LeftGoal.Team.Players[1].Position;
            m_shootRightPlayerCosts[0].Position = Game.Arena.RightGoal.Team.Players[0].Position;
            m_shootRightPlayerCosts[1].Position = Game.Arena.RightGoal.Team.Players[1].Position;

            if (m_debugIndexPlusCtrl.KeyPressed())
            {
                m_mapDebugIndex++;
            }

            if (m_debugIndexMinusCtrl.KeyPressed())
            {
                m_mapDebugIndex--;
            }

            int nMap = m_potentialMaps.Keys.Count;

            m_mapDebugIndex = (m_mapDebugIndex + nMap) % nMap;

            int iMap = 0; //Use an incrementing index to spread the updates across frames

            Parallel.ForEach(m_potentialMaps.Values, map =>
            {
                if (map.UpdateFrequency == PotentialMapUpdateFrequency.Slow)
                {
                    if ((Engine.FrameCount + iMap++) % (3 * Parameters.MapUpdateMultiplier) == 0)
                    {
                        map.Update();
                    }
                }
                else if (map.UpdateFrequency == PotentialMapUpdateFrequency.Normal)
                {
                    if ((Engine.FrameCount + iMap++) % (2 * Parameters.MapUpdateMultiplier) == 0)
                    {
                        map.Update();
                    }
                }
                else if (map.UpdateFrequency == PotentialMapUpdateFrequency.Fast)
                {
                    if ((Engine.FrameCount + iMap++) % (1 * Parameters.MapUpdateMultiplier) == 0)
                    {
                        map.Update();
                    }
                }
            });

            if (Parameters.Debug && Engine.Debug.Flags.RenderDebug && m_potentialMaps.Count != 0)
            {
                var keyValue = m_potentialMaps.ElementAt(m_mapDebugIndex);
                var map      = keyValue.Value;
                Engine.Log.Debug("Potential Map", keyValue.Key);
                map.Debug();
            }

            int arraySize = m_navigationGrid.Data.Length;
            int nUpdate   = Parameters.GridUpdateCount;

            for (int i = m_updateIndex; i < m_updateIndex + nUpdate; i++)
            {
                int idx  = i % arraySize;
                var cell = m_navigationGrid.Data[idx];

                //Update connectivity
                for (int iNeighbour = 0; iNeighbour < cell.Neighbours.Length; iNeighbour++)
                {
                    var nextCell = cell.Neighbours[iNeighbour];
                    if (nextCell == null)
                    {
                        continue;
                    }

                    cell.CanNavigateToNeighbour[iNeighbour] = RayCastVisibility(cell.Position, nextCell.Position);
                }
                //Shooting parameters
                float maxShootDistancePenalty = Engine.Debug.EditSingle("MaxShootDistancePenalty", 0.5f);
                float minShootDistance        = Engine.Debug.EditSingle("MinShootDistance", 200.0f);
                float maxShootDistance        = Engine.Debug.EditSingle("MaxShootDistance", 600.0f);
                float bestShootDistance       = Engine.Debug.EditSingle("BestShootDistance", 450.0f);

                //Raycast to left goal
                cell.CanShootLeft      = RayCastVisibility(cell.Position, Game.Arena.LeftGoal.Position);
                cell.CanShootLeftValue = 0.0f;
                if (cell.CanShootLeft)
                {
                    bool intercept1 = TestInterception(Game.GameManager.Teams[0], cell.Position, Game.Arena.LeftGoal.Position);
                    bool intercept2 = TestInterception(Game.GameManager.Teams[1], cell.Position, Game.Arena.LeftGoal.Position);

                    if (intercept1 && intercept2)
                    {
                        float distToGoal = Vector2.Distance(Game.Arena.LeftGoal.Position, cell.Position);
                        var   distCoef   = 0.0f;
                        if (distToGoal < bestShootDistance)
                        {
                            distCoef = LBE.MathHelper.LinearStep(minShootDistance, bestShootDistance, distToGoal);
                        }
                        else
                        {
                            distCoef = 1 - LBE.MathHelper.LinearStep(bestShootDistance, maxShootDistance, distToGoal);
                        }
                        float shootValue = LBE.MathHelper.Lerp(maxShootDistancePenalty, 1.0f, distCoef);

                        cell.CanShootLeftValue = shootValue;
                    }
                }

                //Raycast to right goal
                cell.CanShootRight      = RayCastVisibility(cell.Position, Game.Arena.RightGoal.Position);
                cell.CanShootRightValue = 0.0f;
                if (cell.CanShootRight)
                {
                    bool intercept1 = TestInterception(Game.GameManager.Teams[0], cell.Position, Game.Arena.RightGoal.Position);
                    bool intercept2 = TestInterception(Game.GameManager.Teams[1], cell.Position, Game.Arena.RightGoal.Position);

                    if (intercept1 && intercept2)
                    {
                        float distToGoal = Vector2.Distance(Game.Arena.RightGoal.Position, cell.Position);
                        var   distCoef   = 0.0f;
                        if (distToGoal < bestShootDistance)
                        {
                            distCoef = LBE.MathHelper.LinearStep(minShootDistance, bestShootDistance, distToGoal);
                        }
                        else
                        {
                            distCoef = 1 - LBE.MathHelper.LinearStep(bestShootDistance, maxShootDistance, distToGoal);
                        }
                        float shootValue = LBE.MathHelper.Lerp(maxShootDistancePenalty, 1.0f, distCoef);

                        cell.CanShootRightValue = shootValue;
                    }
                }

                for (int iPlayer = 0; iPlayer < 4; iPlayer++)
                {
                    cell.CanSeePlayer[iPlayer] = RayCastVisibility(cell.Position, Game.GameManager.Players[iPlayer].Position);
                }
            }
            m_updateIndex = (m_updateIndex + nUpdate) % arraySize;

            DebugGrid();
        }
コード例 #3
0
        private void DebugColorEdit()
        {
            KeyControl keyArenaWall   = new KeyControl(Keys.NumPad0);
            KeyControl keyArenaGround = new KeyControl(Keys.NumPad1);
            KeyControl keyTeam1       = new KeyControl(Keys.NumPad2);
            KeyControl keyTeam2       = new KeyControl(Keys.NumPad3);
            KeyControl keyShift1      = new KeyControl(Keys.LeftControl);
            KeyControl keyShift2      = new KeyControl(Keys.RightControl);

            if (keyArenaWall.KeyPressed())
            {
                ColorMaskedSprite arenaMaskedSprite = Owner.FindComponent <ColorMaskedSprite>();

                if (keyShift1.KeyDown() || keyShift2.KeyDown())
                {
                    arenaMaskedSprite.Color1 = Colors.Previous();
                }
                else
                {
                    arenaMaskedSprite.Color1 = Colors.Next();
                }
            }
            else if (keyArenaGround.KeyPressed())
            {
                ColorMaskedSprite arenaMaskedSprite = Owner.FindComponent <ColorMaskedSprite>();

                if (keyShift1.KeyDown() || keyShift2.KeyDown())
                {
                    arenaMaskedSprite.Color4 = Colors.Previous();
                }
                else
                {
                    arenaMaskedSprite.Color4 = Colors.Next();
                }
            }
            else
            {
                bool keyTeamPressed = false;
                Team team           = null;

                if (keyTeam1.KeyPressed())
                {
                    keyTeamPressed = true;
                    team           = Game.GameManager.Teams[0];
                }
                else if (keyTeam2.KeyPressed())
                {
                    keyTeamPressed = true;
                    team           = Game.GameManager.Teams[1];
                }

                if (keyTeamPressed)
                {
                    if (keyShift1.KeyDown() || keyShift2.KeyDown())
                    {
                        Colors.Previous();
                    }
                    else
                    {
                        Colors.Next();
                    }

                    team.ColorScheme.Color1 = Colors.Current();

                    ColorMaskedSprite arenaMaskedSprite = Owner.FindComponent <ColorMaskedSprite>();
                    if (m_leftGoal.Team.TeamID == team.TeamID)
                    {
                        arenaMaskedSprite.Color2 = Colors.Current();
                    }
                    else
                    {
                        arenaMaskedSprite.Color3 = Colors.Current();
                    }
                }
            }
        }
コード例 #4
0
        public override void StartFrame()
        {
            m_optionMgr.Update();

            if (!m_gameManager.Paused)
            {
                m_screenShake.Update();
                m_screenFocus.Update();
            }

            if (!m_startInfo.Release && m_resetCtrl.KeyPressed())
            {
                Reset();
            }

            m_AIGameData.IdleTimeMS += Engine.GameTime.ElapsedMS;

            for (int i = 0; i < 4; i++)
            {
                foreach (var button in Enum.GetValues(typeof(Buttons)))
                {
                    if (Engine.Input.GamePadState((PlayerIndex)i).IsButtonDown((Buttons)button))
                    {
                        ResetAiTimerOrQuit();
                    }
                }
            }

            if (Engine.Input.KeyboardState().IsKeyDown(Keys.Enter))
            {
                ResetAiTimerOrQuit();
            }
            if (Engine.Input.KeyboardState().IsKeyDown(Keys.Escape))
            {
                ResetAiTimerOrQuit();
            }

            var iaCtrl = new KeyControl(Keys.End);

            if (iaCtrl.KeyPressed())
            {
                if (m_AIGameData.IsIdleAIRunning == false)
                {
                    StartAIDemo();
                }
                else
                {
                    QuitAIDemo();
                }
            }

            float timeDemoS = 60;

            if (m_AIGameData.IdleTimeMS > timeDemoS * 1000 && m_AIGameData.IsIdleAIRunning == false)
            {
                if (Game.MenuManager.CurrentMenu != null && Game.MenuManager.CurrentMenu.Script.GetType() == typeof(AltMainMenuScript))
                {
                    StartAIDemo();
                }
                else
                {
                    if (m_gameManager.IsAIGame())
                    {
                        Reset();
                    }
                }
            }
        }