示例#1
0
        public Sword()
        {
            hitbox.X            = 48.0f;
            hitbox.Y            = 48.0f;
            item_state_time     = 0.0f;
            sword_damage        = 5;
            knockback_magnitude = 1.0f;

            sword_state = Sword_State.preslash;

            swordAnim = AnimationLib.getFrameAnimationSet("swordPic");
        }
示例#2
0
        public void update(Player parent, GameTime currentTime, LevelState parentWorld)
        {
            item_direction  = parent.Direction_Facing;
            parent.Velocity = Vector2.Zero;

            item_state_time += currentTime.ElapsedGameTime.Milliseconds;

            if (sword_state == Sword_State.preslash)
            {
                //sword is on the right hand side of the player, if hitboxes are different dimensions, need to adjust the position of sword.
                parent.Animation_Time = 0.0f;

                if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Right_Item : GameCampaign.Player2_Item_1) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem1))
                {
                    parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lSlash" : "rSlash");
                }
                else if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Left_Item : GameCampaign.Player2_Item_2) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem2))
                {
                    parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rSlash" : "lSlash");
                }

                switch (item_direction)
                {
                case GlobalGameConstants.Direction.Right:
                    position.X = parent.Position.X + parent.Dimensions.X;
                    position.Y = parent.Position.Y;
                    break;

                case GlobalGameConstants.Direction.Left:
                    position.X = parent.Position.X - hitbox.X;
                    position.Y = parent.Position.Y;
                    break;

                case GlobalGameConstants.Direction.Up:
                    position.Y = parent.Position.Y - hitbox.Y;
                    position.X = parent.CenterPoint.X - hitbox.X / 2;
                    break;

                default:
                    position.Y = parent.CenterPoint.Y + parent.Dimensions.Y / 2;
                    position.X = parent.CenterPoint.X - hitbox.X / 2;
                    break;
                }
                if (item_state_time > delay)
                {
                    sword_state = Sword_State.slash;
                    sword_swing = true;

                    AudioLib.playSoundEffect(swordSound);
                }
            }
            else if (sword_state == Sword_State.slash)
            {
                for (int i = 0; i < parentWorld.EntityList.Count; i++)
                {
                    if (parentWorld.EntityList[i] is Enemy || parentWorld.EntityList[i] is ShopKeeper || parentWorld.EntityList[i] is Key || parentWorld.EntityList[i] is Coin || parentWorld.EntityList[i] is Pickup)
                    {
                        if (hitTest(parentWorld.EntityList[i]))
                        {
                            Vector2 direction = parentWorld.EntityList[i].CenterPoint - parent.CenterPoint;
                            parentWorld.EntityList[i].knockBack(direction, knockback_magnitude, sword_damage, parent);
                            AudioLib.playSoundEffect(hitSound);
                        }
                    }
                }

                sword_state = Sword_State.endslash;
            }
            //time delay for the player to be in this state
            else if (sword_state == Sword_State.endslash)
            {
                parent.State            = Player.playerState.Moving;
                item_state_time         = 0.0f;
                parent.Disable_Movement = true;
                sword_swing             = false;
                sword_state             = Sword_State.preslash;
            }
        }