Пример #1
0
        /// <summary>
        /// Handler to interpret and execute commands entered in the console
        /// </summary>
        /// <param name="Sender"></param>
        /// <param name="CommandEvent"></param>
        private void ConsoleCommandHandler(object Sender, string CommandEvent)
        {
            if (RegEx.LooseTest(CommandEvent, @"^\s*(quit|exit|close)\s*$") == true)
            {
                Exit();
            }
            else if (RegEx.LooseTest(CommandEvent, @"^add\s*([0-9]+)\s*([^ ]+)$") == true)
            {
                string       strPart;
                bool         bParse;
                UInt32       nCtr, nNumParticles;
                TextureFiles eTexture;
                Particle2D   NewParticle;

                strPart       = RegEx.GetRegExGroup(CommandEvent, @"^add\s*([0-9]+)\s*([^ ]+)$", 1);
                nNumParticles = UInt32.Parse(strPart);

                strPart = RegEx.GetRegExGroup(CommandEvent, @"^add\s*([0-9]+)\s*([^ ]+)$", 2);
                bParse  = Enum.TryParse <TextureFiles>(strPart, true, out eTexture);
                if (bParse == false)
                {
                    cDevConsole.AddText(String.Format("No texture named '{0}' could be found", strPart));
                    return;
                }

                //Randomly generate the number of particles requested
                for (nCtr = 0; nCtr < nNumParticles; nCtr++)
                {
                    NewParticle = new Particle2D(GraphicsDevice);
                    //Particle images should be grayscale, allowing this tint value to color them
                    NewParticle.Tint  = new Color(cRand.Next(0, 255), cRand.Next(0, 255), cRand.Next(0, 255));
                    NewParticle.Image = cTextureDict[eTexture];

                    //Set the dimensions of the image on screen
                    NewParticle.Height = cTextureDict[eTexture].Height / 2;
                    NewParticle.Width  = cTextureDict[eTexture].Width / 2;
                    //Set the position of the image
                    NewParticle.TopLeft.X = (GraphicsDevice.Viewport.Width / 2) - (NewParticle.Width / 2);
                    NewParticle.TopLeft.Y = (GraphicsDevice.Viewport.Height / 2) - (NewParticle.Height / 2);
                    NewParticle.Rotation  = (float)((cRand.Next(0, 360) * (2 * Math.PI)) / 360);

                    //Set the total movement the particle will travel
                    NewParticle.TotalDistance.X = cRand.Next(GraphicsDevice.Viewport.Width / -2, GraphicsDevice.Viewport.Width / 2);
                    NewParticle.TotalDistance.Y = cRand.Next(GraphicsDevice.Viewport.Height / -2, GraphicsDevice.Viewport.Height / 2);
                    NewParticle.TotalRotate     = (float)(cRand.Next(-5, 5) * 2 * Math.PI);

                    //Set how long the particle will live in milliseconds
                    NewParticle.TimeToLive = cRand.Next(1000, 10000);
                    NewParticle.AlphaFade  = true;

                    cSparkles.AddParticle(NewParticle);
                }
            }
            else
            {
                cDevConsole.AddText("Unrecognized command: " + CommandEvent);
            }
        }
Пример #2
0
        public override bool Update(GameTime CurrTime)
        {
            Vector2 vNewPos;
            int     nCtr, nBestTargetID = -1;
            float   nBestTargetDist = 0, nCurrDist;
            List <PhysicalObject> aTargetList = cObjMgr[cnTargetGroupID];
            bool bRetVal = true;

            base.Update(CurrTime);

            if (ctCreated == -1)               //Just created, mark the time
            {
                ctCreated = CurrTime.TotalGameTime.TotalMilliseconds;
            }

            switch (ceProjType)
            {
            case eProjectileType_t.Tracking:
                //Find a target to track
                for (nCtr = 0; nCtr < aTargetList.Count; nCtr++)
                {
                    nCurrDist = MGMath.SquaredDistanceBetweenPoints(CenterPoint, aTargetList[nCtr].CenterPoint);

                    if (nBestTargetID == -1)                       //No target picked
                    {
                        nBestTargetID   = nCtr;
                        nBestTargetDist = nCurrDist;
                    }
                    else if (nCurrDist < nBestTargetDist)
                    {
                        nBestTargetID   = nCtr;
                        nBestTargetDist = nCurrDist;
                    }
                }

                if (nBestTargetID != -1)                   //Found a valid target, steer toward it
                {
                    nCurrDist = AITools.SteerTowardTarget(CenterPoint, aTargetList[nBestTargetID].CenterPoint, ObjectRotation, cnMaxTurn);

                    //Set the new movement direction, but don't change the speed
                    SetMovement(nCurrDist, cnMaxSpeed);
                }

                if (CurrTime.TotalGameTime.TotalMilliseconds - ctCreated > ctTimeToLive)
                {
                    //Lived its full life, time to pop
                    bRetVal = false;
                }

                break;

            case eProjectileType_t.Straight:
            default:
                //No logic, just flies straight
                if (cGraphDev.Viewport.Width < CenterPoint.X + Width)                   //remove it when off screen
                {
                    bRetVal = false;
                }

                if (cGraphDev.Viewport.Height < CenterPoint.Y + Height)                  //remove it when off screen
                {
                    bRetVal = false;
                }

                if (CenterPoint.X < -1 * Width)
                {
                    bRetVal = false;
                }

                if (CenterPoint.Y < -1 * Height)
                {
                    bRetVal = false;
                }

                break;
            }

            //Look for collisions with all possible targets
            foreach (PhysicalObject CurrObj in aTargetList)
            {
                if (CurrObj.TestCollision(this) == true)
                {
                    //Hit a target! (tell it that it was hit)
                    CurrObj.ReportCollision(CurrTime, this);
                    bRetVal = false;
                    break;
                }
            }

            //Apply the current speed
            vNewPos     = CenterPoint;
            vNewPos.X  += Speed.X;
            vNewPos.Y  += Speed.Y;
            CenterPoint = vNewPos;

            if ((ParticleHandler != null) && (bRetVal == false))
            {
                //Missile is expiring, throw some particles
                for (nCtr = 0; nCtr < 10; nCtr++)
                {
                    ParticleHandler.AddParticle(new DustParticle(CenterPoint, Rand, cGraphDev, cImgAtlas, "spaceEffects_008.png"));
                }
            }

            //Return True to keep this alive, false to have it removed
            return(bRetVal);
        }
Пример #3
0
        private void CommandSentEventHandler(object Sender, string Command)
        {
            if (Tools.RegEx.QuickTest(Command, "^(quit|exit)$") == true)
            {
                Exit();
            }
            else if (Tools.RegEx.QuickTest(Command, "^ship *stop$") == true)
            {
                cPlayerShip.cSpeedX = 0;
                cPlayerShip.cSpeedY = 0;
                cDevConsole.AddText("Ship speed set to 0");
            }
            else if (Tools.RegEx.QuickTest(Command, "^ship *center$") == true)
            {
                cPlayerShip.Top  = (cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Height) / 2 - (cPlayerShip.Height / 2);
                cPlayerShip.Left = (cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Width) / 2 - (cPlayerShip.Width / 2);
                cDevConsole.AddText("Ship position set to [X=" + cPlayerShip.Left + ", Y=" + cPlayerShip.Width + "]");
            }
            else if (Tools.RegEx.QuickTest(Command, "^ship *state$") == true)
            {
                cDevConsole.AddText("Ship Position [X=" + cPlayerShip.Top + ", Y=" + cPlayerShip.Left + "]");
                cDevConsole.AddText("     Speed X=" + cPlayerShip.cSpeedX + " Y=" + cPlayerShip.cSpeedY);
                cDevConsole.AddText("     Size Width=" + cPlayerShip.Width + " Height=" + cPlayerShip.Height);
            }
            else if (Tools.RegEx.QuickTest(Command, "^fire *spread$") == true)
            {
                cDevConsole.AddText("Firing Spread");
                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation - 0.628f, 10, Color.White);
                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation - 0.314f, 10, Color.White);
                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation, 10, Color.White);
                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation + 0.314f, 10, Color.White);
                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], cPlayerShip.Top + (cPlayerShip.Height / 2) - 10, cPlayerShip.Left + (cPlayerShip.Height / 2) - 10, 20, 20, cPlayerShip.cRotation + 0.628f, 10, Color.White);
            }
            else if (Tools.RegEx.QuickTest(Command, "^fire *multi-?(ple|shot)$") == true)
            {
                cDevConsole.AddText("Firing Multi-Shot");
                Vector2 BulletOrigin, BulletOffset;
                BulletOrigin = MGMath.CalculateXYMagnitude(-1 * cPlayerShip.cRotation, cPlayerShip.Width / 4);
                BulletOffset = MGMath.CalculateXYMagnitude(-1 * cPlayerShip.cRotation + 1.570796f, cPlayerShip.Width / 5);

                //Adjust it so that it's relative to the top left screen corner
                BulletOrigin.Y += cPlayerShip.Top + (cPlayerShip.Height / 2);
                BulletOrigin.X += cPlayerShip.Left + (cPlayerShip.Height / 2);

                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y + (BulletOffset.Y * 2) - 10, BulletOrigin.X + (BulletOffset.X * 2) - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White);
                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y + BulletOffset.Y - 10, BulletOrigin.X + BulletOffset.X - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White);
                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y - 10, BulletOrigin.X - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White);
                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y - BulletOffset.Y - 10, BulletOrigin.X - BulletOffset.X - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White);
                cPlayerBullets.AddParticle(cTextureDict[Textures.Bullet], BulletOrigin.Y - (BulletOffset.Y * 2) - 10, BulletOrigin.X - (BulletOffset.X * 2) - 10, 20, 20, cPlayerShip.cRotation, 15, Color.White);
            }
            else if (Tools.RegEx.QuickTest(Command, "^new *asteroid$") == true)
            {
                cDevConsole.AddText("Spawning Asteroid");
                cAsteroids.AddParticle(cTextureDict[Textures.Asteroid], cPlayerShip.Top + (cPlayerShip.Height / 2) - 50, cPlayerShip.Left + (cPlayerShip.Height / 2) - 50, 100, 100, cPlayerShip.cRotation - 0.628f, 2, Color.White);
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*ast(eroid)?\s*count\s*?$") == true)
            {
                cDevConsole.AddText("Current Asteroid Count: " + cAsteroids.ParticleList.Count);
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*ast(eroid)?\s*clear$") == true)
            {
                cDevConsole.AddText("Destroying all asteroids");
                cAsteroids.ParticleList.Clear();
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*mouse\s*turn\s*=\s*(on|true|enable|1)\s*$") == true)
            {
                cDevConsole.AddText("Using mouse position to rotate ship");
                cPlayerShip.MouseRotate = true;
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*mouse\s*turn\s*=\s*(off|false|disable|0)\s*$") == true)
            {
                cDevConsole.AddText("Using arrow keys to rotate ship");
                cPlayerShip.MouseRotate = false;
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*(spawn|new)\s*hunter\s*$") == true)
            {
                cDevConsole.AddText("Spawning new hunter UFO");
                Vector2 StartPos = new Vector2(-50, -50);
                CreateNewHunter(100, StartPos);
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*(sparkles|particles)\s*$") == true)
            {
                Particle2D NewSparkle;
                Vector2    Speed;

                cDevConsole.AddText("Particle burst on player ship");

                for (int Ctr = 0; Ctr < 25; Ctr++)
                {
                    NewSparkle = new Particle2D(cGraphDevMgr.GraphicsDevice);

                    NewSparkle.AlphaFade  = true;
                    NewSparkle.TimeToLive = 100 + (cRandom.NextDouble() * 1000);
                    NewSparkle.Height     = 10;
                    NewSparkle.Width      = 10;
                    NewSparkle.TopLeft.X  = cPlayerShip.Left + (cPlayerShip.Width / 2);
                    NewSparkle.TopLeft.Y  = cPlayerShip.Top + (cPlayerShip.Height / 2);
                    NewSparkle.Image      = cTextureDict[Textures.Bullet];

                    NewSparkle.Rotation = (float)(cRandom.NextDouble() * 6.2f);
                    Speed             = MGMath.CalculateXYMagnitude(NewSparkle.Rotation, (float)(cRandom.NextDouble() * 5));
                    NewSparkle.SpeedX = Speed.X;
                    NewSparkle.SpeedY = Speed.Y;

                    NewSparkle.Tint = Color.White;

                    cSparkles.AddParticle(NewSparkle);
                }
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*(headlight|flashlight|dark)\s*=\s*(1|true|enable)\s*$") == true)
            {
                cDevConsole.AddText("Headlight mode enabled.");
                cHeadlightMode = true;
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*(headlight|flashlight|dark)\s*=\s*(0|false|disable)\s*$") == true)
            {
                cDevConsole.AddText("Headlight mode disabled.");
                cHeadlightMode = false;
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*stats\s*=\s*(1|true|enable|on)\s*$") == true)
            {
                cDevConsole.AddText("Stats enabled.");
                cShowStats = true;
            }
            else if (Tools.RegEx.QuickTest(Command, @"^\s*stats\s*=\s*(0|false|disable|off)\s*$") == true)
            {
                cDevConsole.AddText("Stats disabled.");
                cShowStats = false;
            }
            else
            {
                cDevConsole.AddText("Unrecognized command: " + Command);
            }
        }