Exemple #1
0
        //Updates the AI
        public void Update(Player p, Vector2 screenSize)
        {
            int frameChecker = 0;
            Vector2 vecD = new Vector2((p.BoundingRect.Center.X - BoundingRect.X), (p.BoundingRect.Center.Y - BoundingRect.Y));
            vecD.Normalize();
            rotation = (float)(Math.Atan2(vecD.Y, vecD.X) + Math.PI / 2);

            //If the ai is not spawning
            if (!isSpawning)
            {
                //Updates the ai based on their ai type
                switch (type)
                {
                    #region Square
                    case Type.Square:

                        //Update for a square
                        frameChecker = 2;

                        //Determines velocity
                        velocity.Normalize();
                        velocity += vecD;
                        velocity.Normalize();
                        velocity *= Speed;

                        boundingRect.X += (int)velocity.X;
                        boundingRect.Y += (int)velocity.Y;

                        break;
                    #endregion

                    #region Circle
                    case Type.Circle:

                        //Update for a circle
                        frameChecker = 4;

                        //Creates centripetal motion
                        velocity.Normalize();

                        Vector2 centripalVector = new Vector2(-velocity.Y, velocity.X) / 10;
                        velocity += centripalVector;
                        velocity.Normalize();
                        velocity *= speed;

                        //Adds the centripetal motion with the direction vector
                        boundingRect.X += (int)(velocity.X);
                        boundingRect.Y += (int)(velocity.Y);

                        break;
                    #endregion

                    #region Octagon
                    case Type.Octagon:

                        //Update for an octagon
                        frameChecker = 5;

                        if (velocity.X == 0 && velocity.Y == 0)
                        {
                            velocity = vecD * speed;
                        }

                        //Bounces the ai if they hit the side of the screen
                        if (BoundingRect.X + LENGTH > screenSize.X)
                        {
                            velocity = new Vector2(-velocity.X, velocity.Y);
                        }
                        else if (BoundingRect.X - LENGTH < 0)
                        {
                            velocity = new Vector2(-velocity.X, velocity.Y);
                        }
                        else if (BoundingRect.Y + LENGTH > screenSize.Y)
                        {
                            velocity = new Vector2(velocity.X, -velocity.Y);
                        }
                        else if (BoundingRect.Y - LENGTH < 100)
                        {
                            velocity = new Vector2(velocity.X, -velocity.Y);
                            boundingRect.Y += 2;
                        }

                        rotation = (float)(Math.Atan2(velocity.Y, velocity.X) + Math.PI / 2);

                        boundingRect.X += (int)velocity.X;
                        boundingRect.Y += (int)velocity.Y;

                        break;
                    #endregion

                    #region Triangle
                    case Type.Triangle:

                        frameChecker = 1;

                        //Determines velocity
                        velocity.Normalize();
                        velocity += vecD;
                        velocity.Normalize();
                        velocity *= Speed;

                        boundingRect.X += (int)velocity.X;
                        boundingRect.Y += (int)velocity.Y;

                        break;
                    #endregion
                }
            }
            //Else continue spawning
            else
            {
                switch (type)
                {
                    case Type.Square:
                        frameChecker = 10;
                        break;

                    case Type.Circle:
                        frameChecker = 10;
                        break;

                    case Type.Triangle:
                        frameChecker = 10;
                        break;

                    case Type.Octagon:
                        frameChecker = 5;
                        break;
                }

                if (count == spawnTime)
                {
                    FinishSpawning();
                }
            }

            Animate(frameChecker);
        }
Exemple #2
0
        protected override void LoadContent()
        {
            //Spritebatch and fonts
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>("Font");
            fontSmall = Content.Load<SpriteFont>("SmallFont");

            #region Media Loading

            //Backgrounds
            imgBackgroundOne = Content.Load<Texture2D>("Backgrounds/Space3");
            imgBackgroundTwo = Content.Load<Texture2D>("Backgrounds/background1");
            imgQuadrant = Content.Load<Texture2D>("Backgrounds/Quadrant");
            imgSpecialBar = Content.Load<Texture2D>("Backgrounds/Special Bar");
            imgSpecialMeter = Content.Load<Texture2D>("Backgrounds/Special Meter");
            imgMenuBar = Content.Load<Texture2D>("Backgrounds/Menu Bar");

            //Player Images
            imgPlayer = Content.Load<Texture2D>("Entities/Player");;
            imgECircle = Content.Load<Texture2D>("Entities/Enemy Blue Circle");
            imgESquare = Content.Load<Texture2D>("Entities/Enemy Pink Square");
            imgETriangle = Content.Load<Texture2D>("Entities/Enemy Arrow2");
            imgEOctagon = Content.Load<Texture2D>("Entities/Enemy Green Emerald2");
            test = Content.Load<Texture2D>("Entities/Collision Circle");

            //Effects
            imgParticle = Content.Load<Texture2D>("Effects/Particle");
            imgPBullet = Content.Load<Texture2D>("Effects/Bullet");
            imgBomb = Content.Load<Texture2D>("Effects/Bombs");
            imgPlayerLife = Content.Load<Texture2D>("Effects/Player Life");
            seLaser = Content.Load<SoundEffect>("Effects/Laser");
            sePop = Content.Load<SoundEffect>("Effects/Pop");
            imgSpawnAnim = Content.Load<Texture2D>("Effects/Spawn Animations");

            //Songs
            sngHeaven = Content.Load<Microsoft.Xna.Framework.Media.Song>("Songs/EnV - Heaven");

            //Particle Colors
            particleColors[0, 0] = new Color(136, 5, 168); // purple
            particleColors[0, 1] = new Color(189, 99, 212);
            particleColors[0, 2] = new Color(88, 2, 109);
            particleColors[1, 0] = new Color(8, 108, 162); //blue 
            particleColors[1, 1] = new Color(60, 157, 208);
            particleColors[1, 2] = new Color(3, 69, 105);
            particleColors[2, 0] = new Color(93, 255, 0); //green
            particleColors[2, 1] = new Color(163, 240, 108);
            particleColors[2, 2] = new Color(61, 146, 0);
            particleColors[3, 0] = new Color(255, 199, 0); // yellow 
            particleColors[3, 1] = new Color(255, 213, 64);
            particleColors[3, 2] = new Color(255, 224, 115);
            particleColors[4, 0] = new Color(255, 13, 0); //red
            particleColors[4, 1] = new Color(255, 122, 115);
            particleColors[4, 2] = new Color(166, 8, 0);

            #endregion

            player = new Player(new Rectangle(Convert.ToInt32(optimalWidth * scale.X / 2 - imgPlayer.Width * scale.X / 2), Convert.ToInt32(optimalHeight * scale.Y / 2 - imgPlayer.Height * scale.Y / 2), (int)(imgPlayer.Width * scale.X), 
                (int)(imgPlayer.Height * scale.Y)), imgPlayer, 3, 4);

            MediaPlayer.Volume = 0.6f;
        }
Exemple #3
0
            //Updates the ai in the swarm and returns the id
            public void Update(Player p, Vector2 screenDimensions)
            {
                int index = -1;
                int frameC = SetVelocityAndReturnFrameCheck(p, screenDimensions);
                float rotation = (float)(Math.Atan2(groupVelocity.Y, groupVelocity.X) + Math.PI / 2);
                Vector2 direcV = new Vector2((p.BoundingRect.Center.X - center.X), (p.BoundingRect.Center.Y - center.Y));
                direcV.Normalize();
                grid.MovePoints(groupVelocity);
                

                //Loops through every ai and 
                foreach (AI a in ai)
                {
                    index++;
                    switch (a.Type)
                    {
                        case Type.Square:
                            
                            a.Update(groupVelocity + ReturnSwarmGridVector(index, direcV), rotation, frameC);
                            break;

                        case Type.Circle:

                            a.Update(groupVelocity + ReturnSwarmGridVector(index, direcV), rotation, frameC);
                            break;

                        case Type.Triangle:

                            a.Update(groupVelocity + ReturnSwarmGridVector(index, direcV), rotation, frameC);
                            break;

                        case Type.Octagon:

                            a.Update(groupVelocity + ReturnSwarmGridVector(index, direcV), rotation, frameC);
                            break;
                    }
                }
            }
Exemple #4
0
            //Determines the velocity of a swarm of ai and returns the frame checker
            private int SetVelocityAndReturnFrameCheck(Player p, Vector2 screenSize)
            {
                center.X = 0;
                center.Y = 0;

                //Calculates Center
                for (int i = 0; i < ai.Count; i++)
                {
                    center.X += ai[i].BoundingRect.X;
                    center.Y += ai[i].BoundingRect.Y;
                }
                center.X /= ai.Count;
                center.Y /= ai.Count;

                //Holds a temporary velocity used to calculate the ai velocities
                Vector2 tempV;

                //Determines how the velocity should be calculated and applies it
                switch (ai[0].Type)
                {
                    //Velocity for a swarm of squares, animation updates every 3 frames
                    case Type.Square:

                        tempV = new Vector2((p.BoundingRect.Center.X - center.X), (p.BoundingRect.Center.Y - center.Y));
                        tempV.Normalize();
                        groupVelocity += tempV;
                        groupVelocity.Normalize();
                        groupVelocity *= ai[0].Speed;
                        return 2;

                    //Velocity for a swarm of circles, animation updates every 5 frames
                    case Type.Circle:

                        tempV = new Vector2(-groupVelocity.Y, groupVelocity.X) / 10;
                        groupVelocity += tempV;
                        groupVelocity.Normalize();
                        groupVelocity *= ai[0].Speed;
                        return 4;

                    //Velocity for a swarm of triangles, animation updates every 3 frames
                    case Type.Triangle:

                        tempV = new Vector2((p.BoundingRect.Center.X - center.X), (p.BoundingRect.Center.Y - center.Y));
                        tempV.Normalize();
                        groupVelocity += tempV;
                        groupVelocity.Normalize();
                        groupVelocity *= ai[0].Speed;
                        return 2;  
                    
                    //The type was not found
                    default:
                        return -1;
                }
            }
Exemple #5
0
        //Updates all the ai within the manager
        public void Update(Player p, Vector2 screenSize)
        {
            //Updates individual ai
            foreach (AI a in loneAi)
            {
                a.Update(p, screenSize);          
            }

            //Updates swarms
            for(int i = 0; i < swarms.Count; i++)
            {
                //If there are more than two ai in the swarm, preform the update
                if (swarms[i].AI.Count >= 2)
                {
                    swarms[i].Update(p, screenSize);
                }
                //Otherwise disband the swarm
                else
                {
                    if (swarms[i].AI.Count == 1)
                    {
                        AddLoneAI(swarms[i].AI[0]);
                    }
                    swarms.RemoveAt(i);
                    i--;
                }
            }
        }