コード例 #1
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            var color = Color.White;

            if (_isHovering)
            {
                color = HoverColor;
            }

            if (IsFlipped.Equals(true))
            {
                spriteBatch.Draw(_texture, destinationRectangle: Rectangle, color: color, effects: SpriteEffects.FlipHorizontally);
            }
            else
            {
                spriteBatch.Draw(_texture, Rectangle, color);
            }

            if (!string.IsNullOrEmpty(Text))
            {
                var x = (_font.MeasureString(Text).X / 2);
                var y = (_font.MeasureString(Text).Y / 2);

                Vector2 origin = new Vector2(x, y);

                spriteBatch.DrawString(_font, Text, new Vector2(Rectangle.X + (Rectangle.Width - Rectangle.Width / 2), Rectangle.Y + (Rectangle.Height - Rectangle.Height / 2)), PenColor, 0, origin, Scale, SpriteEffects.None, 1);
            }
        }
コード例 #2
0
 void Start()
 {
     gravityRotate   = player.GetComponent <rotate> ();
     isFlippedScript = player.GetComponent <IsFlipped> ();
 }
コード例 #3
0
        public void CombatInput(KeyboardState keyboardState)
        {
            var mouseState = Mouse.GetState();

            if (PreviousKeyboardState.IsKeyDown(Keys.X) && keyboardState.IsKeyUp(Keys.X))
            {
                IsAttacking = true;
                Sprite.PlayAnimation(Spr_Punch);
                Console.WriteLine($"Punch!");
            }
            else if (PreviousKeyboardState.IsKeyDown(Keys.Z) && keyboardState.IsKeyUp(Keys.Z))
            {
                /*
                 * IsAttacking = true;
                 * IsUsingWeapon = true;
                 * WeaponIsThrown = true;
                 * Sprite.PlayAnimation(Spr_Punch);
                 * HandleWeaponAnimations(1);
                 * Console.WriteLine($"Swing!");
                 */
                IsAttacking = true;
                Sprite.PlayAnimation(Spr_Kick);
                Console.WriteLine($"Kick!");
            }
            else if (PreviousKeyboardState.IsKeyDown(Keys.C) && keyboardState.IsKeyUp(Keys.C))
            {
                IsAttacking = true;
                Sprite.PlayAnimation(Spr_Uppercut);
                Console.WriteLine($"Uppercut!");
            }
            else
            {
                CurrentWeapon.Sprite.PlayAnimation(CurrentWeapon.Spr_Idle);
            }

            if (IsAttacking.Equals(true))
            {
                Sprite.Animation.IsStill   = false;
                Sprite.Animation.IsLooping = false;

                foreach (var ent in CurrentMapState.NPCs)
                {
                    if (Hitbox.Intersects(ent.Hitbox) && ent.IsDamaged.Equals(false))
                    {
                        if (IsFlipped.Equals(false))
                        {
                            // facing left
                            if (ent.Position.X < Position.X)
                            {
                                // player is facing entity
                                ent.TakeDamage();
                            }
                        }
                        else
                        {
                            // facing right
                            if (ent.Position.X > Position.X)
                            {
                                // player is facing entity
                                ent.TakeDamage();
                            }
                        }
                    }
                }
            }

            PreviousMouseState    = mouseState;
            PreviousKeyboardState = keyboardState;
        }