Exemplo n.º 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            food1.Location = new Vector2(100, 400);
            food2.Location = new Vector2(100, 100);
            food3.Location = new Vector2(400, 400);
            food4.Location = new Vector2(400, 100);


            Texture2D ghostHit = Content.Load <Texture2D>("GhostHit");

            //Mouse Particles
            ParticleManager.Instance().ParticleSystems.Add("mouse",
                                                           new ParticleSystem(10, 200,
                                                                              ghostHit,
                                                                              1, 2,        //Speed
                                                                              1, 3,        //Accel
                                                                              1, 10,       //Rot
                                                                              5.5f, 10.0f, //Life
                                                                              0.2f, 0.7f,  //Scale
                                                                              10));
        }
Exemplo n.º 2
0
        protected override void LoadContent()
        {
            this.ghost    = this.content.Load <Texture2D>(strGhostTexture);
            this.ghostHit = content.Load <Texture2D>("GhostHit");

            this.spriteTexture = ghost;
            this.Direction     = new Vector2(0, 1);
            this.Location      = StartLoc;
            this.Speed         = 50.0f;

            base.LoadContent();

            this.Orgin = new Vector2(this.spriteTexture.Width / 2, this.spriteTexture.Height / 2);

            ParticleManager.Instance().ParticleSystems.Add("ghost" + ghostNum,
                                                           new ParticleSystem(
                                                               1,          //Min
                                                               3,          //Max
                                                               this.ghost,
                                                               1, 1,       //Speed
                                                               1, 1,       //Accel
                                                               1, 1,       //Rot
                                                               2.5f, 4.0f, //Life
                                                               1.0f, 1.0f, //Scale
                                                               1));        //spawns
        }
Exemplo n.º 3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            //Mouse Particles
            Vector2 mouseLoc = new Vector2(input.MouseState.X, input.MouseState.Y);

            ParticleManager.Instance().ParticleSystems["mouse"].Update(.1f);
            ParticleManager.Instance().ParticleSystems["mouse"].AddParticles(
                mouseLoc,
                Vector2.Zero);

            // TODO: Add your update logic here
            foreach (Food f in foods)
            {
                if (f.Enabled)
                {
                    if (f.Intersects(pacMan))
                    {
                        pacMan.PowerUp();
                        f.Hit();
                    }
                }
            }

            base.Update(gameTime);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            //spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
            //spriteBatch.Begin();
            ParticleManager.Instance().Draw(spriteBatch);
            spriteBatch.End();

            base.Draw(gameTime);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            float turnAmount = .04f;

            ParticleManager.Instance().ParticleSystems["ghost" + ghostNum].Update(.1f);


            switch (this.ghostState)
            {
            case GhostState.Dead:

                //TODO Dead moving and dead animation.
                //Until then
                this.ghostState = GhostState.Roving;
                //Pick random direction
                Random  r = new Random();
                Vector2 v = new Vector2((float)r.NextDouble() - 0.5f, (float)r.NextDouble() - 0.5f);
                Vector2.Normalize(ref v, out v);        //Normalize
                this.Direction = v;                     //Assign random direction

                break;

            case GhostState.Chasing:
                //Change texture if Chasing
                if (!(this.spriteTexture == this.ghost))
                {
                    //gameConsole.GameConsoleWrite(this.ToString() + " Chasing changed texture to spriteTexture");
                    this.spriteTexture = this.ghost;
                }
                if (pacMan.Location.Y > this.Location.Y)
                {
                    //this.Direction.Y = 1;
                    this.Direction.Y = MathHelper.Clamp(this.Direction.Y += turnAmount, -1, 1);
                }
                else
                {
                    //this.Direction.Y = -1;
                    this.Direction.Y = MathHelper.Clamp(this.Direction.Y -= turnAmount, -1, 1);
                }
                if (pacMan.Location.X > this.Location.X)
                {
                    //this.Direction.X = 1;
                    this.Direction.X = MathHelper.Clamp(this.Direction.X += turnAmount, -1, 1);
                }
                else
                {
                    //this.Direction.X = -1;
                    this.Direction.X = MathHelper.Clamp(this.Direction.X -= turnAmount, -1, 1);
                }
                break;

            case GhostState.Evading:
                //Change texture if evading
                if (this.spriteTexture != this.ghostHit)
                {
                    //gameConsole.GameConsoleWrite(this.ToString() + " Evading changed texture to ghostHit");
                    this.spriteTexture = this.ghostHit;
                }

                if (pacMan.Location.Y > this.Location.Y)
                {
                    this.Direction.Y = -1;
                }
                else
                {
                    this.Direction.Y = 1;
                }
                if (pacMan.Location.X > this.Location.X)
                {
                    this.Direction.X = -1;
                }
                else
                {
                    this.Direction.X = -1;
                }

                ParticleManager.Instance().ParticleSystems["ghost" + ghostNum].AddParticles(
                    new Vector2(this.Location.X + this.LocationRect.Width / 2,
                                this.Location.Y + this.LocationRect.Height / 2),
                    Vector2.Zero);


                break;

            case GhostState.Roving:
                //Change texture if Chasing
                if (!(this.spriteTexture == this.ghost))
                {
                    //gameConsole.GameConsoleWrite(this.ToString() + " Roving changed texture to spriteTexture");
                    this.spriteTexture = this.ghost;
                }
                //check if ghost can see pacman
                Vector2 normD = Vector2.Normalize(this.Direction);
                Vector2 p     = new Vector2(this.Location.X, this.Location.Y);
                while (p.X < graphics.GraphicsDevice.Viewport.Width &&
                       p.X > 0 &&
                       p.Y < graphics.GraphicsDevice.Viewport.Height &&
                       p.Y > 0)
                {
                    if (pacMan.LocationRect.Contains(new Point((int)p.X, (int)p.Y)))
                    {
                        this.ghostState = GhostState.Chasing;
                        gameConsole.GameConsoleWrite(this.ToString() + " saw pacman");
                        break;
                    }
                    p += this.Direction;
                }


                break;
            }

            //Borders
            if ((this.Location.Y + this.spriteTexture.Height / 2 > graphics.GraphicsDevice.Viewport.Height)
                ||
                (this.Location.Y - this.spriteTexture.Height / 2 < 0)
                )
            {
                this.Direction.Y *= -1;
                //this.ghostState = GhostState.Roving;
            }
            if ((this.Location.X + this.spriteTexture.Width / 2 > graphics.GraphicsDevice.Viewport.Width)
                ||
                (this.Location.X - this.spriteTexture.Width / 2 < 0)
                )
            {
                this.Direction.X *= -1;
                //this.ghostState = GhostState.Roving;
            }

            Location += ((this.Direction * (lastUpdateTime / 1000)) * Speed);      //Simple Move

            //Collision
            if (this.Intersects(pacMan))
            {
                //PerPixel Collision
                if (this.PerPixelCollision(pacMan))
                {
                    if (this.ghostState == GhostState.Evading)
                    {
                        this.Visible = false;
                        this.Enabled = false;
                    }
                    else
                    {
                        if (pacMan.PacManState != PacManState.Dying)
                        {
                            pacMan.Die();
                            this.Location   = new Vector2(100, 100);
                            this.ghostState = GhostState.Roving;
                        }
                    }
                }
            }



            base.Update(gameTime);
        }