예제 #1
0
        private void UpdateGuns(GameTime gameTime)
        {
            if (PushTime <= 0 && !IsDashing)
            {
                GunCurrent.Update(gameTime);

                if (PadState.IsButtonDown(FirePrimary))
                {
                    GunCurrent.Primary.Shoot(Position + Size / 2 - new Vector2(0, 20) + Direction * 48, Direction);
                }

                if (PadState.IsButtonDown(FireSecondary))
                {
                    GunCurrent.Secondary.Shoot(Position + Size / 2 - new Vector2(0, 20) + Direction * 48, Direction);
                }
            }
        }
예제 #2
0
        public override void Update(GameTime gameTime)
        {
            PushTime -= 1f * (float)gameTime.ElapsedGameTime.Milliseconds / (1000f / 60f);
            if (PushTime < 0)
            {
                if (MyGun != null)
                {
                    MyGun.Update(gameTime);

                    if (MyGun.Primary != null)
                    {
                        MyGun.Primary.Shoot(Position + Size / 2, Direction);
                    }
                    if (MyGun.Secondary != null)
                    {
                        MyGun.Secondary.Shoot(Position + Size / 2, Direction);
                    }
                }
            }

            Vector2   ToPosition  = Position + ((Speed * gameTime.ElapsedGameTime.Milliseconds));
            int       Reps        = 1;
            Rectangle ToRectangle = new Rectangle((int)ToPosition.X, (int)ToPosition.Y, (int)Size.X, (int)Size.Y);

            if (GameManager.MyLevel.CheckForSolidCollision(ToRectangle) != null)
            {
                Reps = Math.Max(1, (int)Vector2.Distance(Vector2.Zero, Speed * gameTime.ElapsedGameTime.Milliseconds));
            }

            bool CountedBounce = false;

            for (int i = 1; i < Reps + 1; i++)
            {
                ToPosition  = Position + ((Speed * gameTime.ElapsedGameTime.Milliseconds) / Reps);
                ToRectangle = new Rectangle((int)ToPosition.X, (int)ToPosition.Y, (int)Size.X, (int)Size.Y);


                BasicObject Other2 = GameManager.MyLevel.CheckForSolidCollision(ToRectangle);

                if (Other2 == null)
                {
                    Position = ToPosition;
                }
                else
                {
                    if (!CountedBounce && Other2.GetType().Equals(typeof(Block)))
                    {
                        Other2.TakeDamage(DamageToBlock, null, Vector2.Zero);
                        CountedBounce = true;
                        Bounces++;
                    }

                    Speed *= 0.75f;
                    if (Other2.Damage <= Other2.Life)
                    {
                        Speed = Other2.Bounce(MyRectangle, Speed, (int)Math.Max(Speed.X, Speed.Y) * gameTime.ElapsedGameTime.Milliseconds / Reps);
                    }
                    Position = ToPosition;
                }
            }

            ChangePosition();

            foreach (BasicObject Object in GameManager.MyLevel.DynamicCollidables)
            {
                if (Object.Team != Team)
                {
                    if (Object.MyRectangle.Intersects(MyRectangle))
                    {
                        CollideWithEnemy(Object);
                        break;
                    }
                }
            }

            base.Update(gameTime);
        }