예제 #1
0
 public override void Update(GameTime gameTime)
 {
     ms      = Mouse.GetState();
     _hitbox = new Rectangle((int)_position.X, (int)_position.Y, _sourceRectangle.Width, _sourceRectangle.Height);
     //_hitbox = new Rectangle((int)_position.X, (int)_position.Y, _texture.Width, _texture.Height);
     if (isVisible)
     {
         if (ms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && lms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
         {
             if (Hitbox.Contains(ms.X, ms.Y))
             {
                 Clicked = true;
             }
             else
             {
                 Clicked = false;
             }
         }
         else
         {
             Clicked = false;
         }
     }
     lms = ms;
     base.Update(gameTime);
 }
예제 #2
0
 public override void Collided(Entity other)
 {
     if (opacity == 1 && (other as Player).state == PlayerState.GROUND && Hitbox.Contains(other.Center))
     {
         opacity = 0.5f;
         (other as Player).Dash(facing);
     }
 }
예제 #3
0
        public void Update(GameTime gameTime)
        {
            Vector2 mousePosition = KeyMouseReader.MouseScreenPosition;

            IsMouseHovered = Hitbox.Contains(mousePosition.ToPoint());

            if (IsMouseHovered && KeyMouseReader.LeftClick() && Action != null && KeyMouseReader.oldMouseState.LeftButton != Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                Action();
            }
        }
예제 #4
0
        public override void Update(GameTime gameTime)
        {
            Vector2 Distance = m_player.Hitbox.Location.ToVector2() - m_position;
            {
                if (Hitbox.Contains(Input.WorldMousePosition) && Input.isMouseJustClicked() && Distance.Length() < 200)
                {
                    OnEnemyClick();
                }
            }
            Vector2 Direction = Vector2.Normalize(Distance);

            m_position += Direction * 2;
            base.Update(gameTime);
        }
예제 #5
0
        public void Update()
        {
            var mouseState = Mouse.GetState();

            if (mouseState.LeftButton == ButtonState.Pressed && Hitbox.Contains(mouseState.Position))
            {
                if (mouseState != prevMouseState)
                {
                    Clicked?.Invoke(this, new MouseEventArgs(mouseState.Position));
                }
            }

            prevMouseState = mouseState;
        }
예제 #6
0
        private void ProcessDamage()
        {
            foreach (Player player in PlayerManager.Players)
            {
                if (player.Character.AttackHitbox.Intersects(Hitbox) && player.Character.CharacterState == CharacterStates.AttackState)
                {
                    Health -= 10;
                    if (Health <= 0)
                    {
                        EnemyState = EnemyStates.Dead;
                    }
                    else
                    {
                        SelectAnimation(DamagedAnimation);
                        EnemyState = EnemyStates.Damaged;
                    }
                }
            }
            foreach (Entity entity in PlayerManager.EntityManager.Entities.ToList())
            {
                if (Hitbox.Intersects(entity.Hitbox))
                {
                    if (entity.GetType() == typeof(ShootBall))
                    {
                        ShootBall ball         = (ShootBall)entity;
                        Point     targetCenter = ShootTarget.Sprite.Bounds.Center;
                        if (Hitbox.Contains(ball.DestinationPosition.X + targetCenter.X, ball.DestinationPosition.Y + targetCenter.Y))
                        {
                            // select damaged animation
                            Health -= PlayerManager.GetPlayer(ball.SourcePlayer).Character.ShootAttack;
                            if (Health <= 0)
                            {
                                EnemyState = EnemyStates.Dead;
                            }
                            else
                            {
                                SelectAnimation(DamagedAnimation);
                                EnemyState = EnemyStates.Damaged;
                            }
                        }
                    }

                    //bounce passball
                    if (entity.GetType() == typeof(PassBall))
                    {
                        PassBall ball       = (PassBall)entity;
                        Point    ballCenter = PassBall.Sprite.Bounds.Center;
                        if (Hitbox.Contains(ball.Position.X + ballCenter.X, ball.Position.Y + ballCenter.Y))
                        {
                            //change angle of incidence
                            //maybe swap?
                            float tempX = ball.Velocity.X;
                            float tempY = ball.Velocity.Y;
                            ball.Velocity.X = tempX;
                            ball.Velocity.Y = tempY;
                        }
                    }
                }

                if (DisruptPassHitbox.Intersects(entity.Hitbox))
                {
                    //checks if the passball intersects with swatter's arm
                    if (entity.GetType() == typeof(PassBall))
                    {
                        PassBall ball       = (PassBall)entity;
                        Point    ballCenter = PassBall.Sprite.Bounds.Center;

                        /*if(DisruptPassHitbox.Contains(ball.Position.X + ballCenter.X, ball.Position.Y + ballCenter.Y) && ball.Knocked == false)
                         * {
                         *  EnemyState = EnemyStates.Swat;
                         *  ball.Knocked = true;
                         *  ball.SourcePosition = Position;
                         *  ball.DestinationPosition = PlayerManager.GetPlayer(Player.PlayerIndex).Target.Position;
                         *  ball.Velocity.X = (PlayerManager.GetPlayer(Player.PlayerIndex.get()).Target.Position.X - Position.X) / 60;
                         *  ball.Velocity.Y = -(PlayerManager.GetPlayer(Player.PlayerIndex).Target.Position.Y - .5F * 60 * 60 / 2 - Position.Y) / 60;
                         *
                         * }*/
                    }
                }
            }
        }