Exemple #1
0
 public override bool HitObject(BasicObject Object, GameTime gameTime)
 {
     if (Object.GetType().Equals(typeof(Block)))
     {
         if (Vector2.Distance(Vector2.Zero, Speed) < MaxSpeed)
         {
             Speed = Vector2.Zero;
             StickTo(Object);
         }
         else
         {
             Speed *= 0.85f;
             Speed  = Object.Bounce(MyRectangle, Speed, (int)Math.Max(Speed.X, Speed.Y) * gameTime.ElapsedGameTime.Milliseconds);
         }
     }
     return(true);
 }
        private BasicObject UpdateGravity(GameTime gameTime)
        {
            if (!IsDashing)
            {
                PushTime  -= 1f * (float)gameTime.ElapsedGameTime.Milliseconds / (1000f / 60f);
                JumpTimer -= 1f * (float)gameTime.ElapsedGameTime.Milliseconds / (1000f / 60f);

                BasicObject Other = GameManager.MyLevel.CheckForSolidCollision(GravityRectangle);

                if (Other == null)
                {
                    Speed += Gravity * gameTime.ElapsedGameTime.Milliseconds;
                }
                else
                {
                    JumpTimer = 60;
                    Jumps     = 1;
                }

                List <BasicObject> Victims = new List <BasicObject>();

                Vector2 ToPosition = Position + ((Speed * gameTime.ElapsedGameTime.Milliseconds));
                int     Reps       = 1;
                if (GameManager.MyLevel.CheckForSolidCollision(ToPosition, Size) != null)
                {
                    Reps = (int)Vector2.Distance(Vector2.Zero, Speed * gameTime.ElapsedGameTime.Milliseconds);
                }

                for (int i = 1; i < Reps + 1; i++)
                {
                    ToPosition = Position + ((Speed * gameTime.ElapsedGameTime.Milliseconds) / Reps);

                    BasicObject Other2 = GameManager.MyLevel.CheckForSolidCollision(ToPosition, Size);

                    if (Other2 == null)
                    {
                        Position = ToPosition;
                    }
                    else
                    {
                        if (PushTime > 0)
                        {
                            if (!Victims.Contains(Other2))
                            {
                                Other2.TakeDamage((Math.Abs(Speed.X) + Math.Abs(Speed.Y)) * 150, null, Speed);
                                Victims.Add(Other2);
                                Speed *= 0.85f;
                            }
                            if (Other2.Damage <= Other2.Life)
                            {
                                Speed = Other2.Bounce(MyRectangle, Speed, (int)Math.Max(Speed.X, Speed.Y) * gameTime.ElapsedGameTime.Milliseconds / Reps);
                            }


                            Position = ToPosition;
                        }
                        else
                        {
                            Speed = Vector2.Zero;
                        }
                    }
                }

                if (Position.Y > GameManager.MyLevel.MyRectangle.Y + GameManager.MyLevel.MyRectangle.Height + 500)
                {
                    Die();
                }

                ChangePosition();



                return(Other);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
 public override bool HitObject(BasicObject Object, GameTime gameTime)
 {
     Speed *= 0.85f;
     Speed  = Object.Bounce(MyRectangle, Speed, (int)Math.Max(Speed.X, Speed.Y) * gameTime.ElapsedGameTime.Milliseconds);
     return(true);
 }
        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);
        }