WEB开发网
开发学院软件开发C语言 C#开发WPF/Silverlight动画及游戏系列教程(Game C... 阅读

C#开发WPF/Silverlight动画及游戏系列教程(Game Course):(二十八) 经典式属性设计及完美的物理攻击系统

 2010-09-30 20:47:09 来源:WEB开发网   
核心提示: 这里的处理调用DoInjure方法进行伤害计算、输出及值更新: /// <summary> /// 精灵攻击并产生伤害及输出 /// </summary> /// <param name="spirit">发起攻击精灵</param&

这里的处理调用DoInjure方法进行伤害计算、输出及值更新:

        /// <summary>

        /// 精灵攻击并产生伤害及输出

        /// </summary>

        /// <param name="spirit">发起攻击精灵</param>

        public static void DoInjure(QXSpirit spirit) {

            //捕获敌人精灵

            QXSpirit Enemy = (spirit.Parent as Canvas).FindName(spirit.LockObject) as QXSpirit;

            //产生随机数

            Random random = new Random();

            //首先进行闪避判断

            if (random.Next(100) >= (spirit.VHit - Enemy.VDodge)) {

                Super.ShowText(Enemy, true, true, "Avoid", "Miss", 34, Colors.SkyBlue, 2);

            } else {

                int Injure = 0;

                if (spirit.Action == Actions.Attack) {

                    Injure = Convert.ToInt32(spirit.VAttackMin + random.Next((int)(spirit.VAttackMax - spirit.VAttackMin)) - Enemy.VDefense);

                } else if (spirit.Action == Actions.Magic) {

                    Injure = Convert.ToInt32(spirit.VMagicMin + random.Next((int)(spirit.VMagicMax - spirit.VMagicMin)) - Enemy.VMagicDefense);

                }

                //判断是否暴击

                if (random.Next(100) <= (spirit.VBurst - Enemy.VBlock)) {

                    Injure *= 2;

                    Super.ShowText(Enemy, true, true, "Avoid", string.Format("Burst!{0}", Injure >= 0 ? Injure.ToString() : "0"), 30, Colors.Red, 2);

                } else {

                    Super.ShowText(Enemy, true, false, "Avoid", Injure >= 0 ? Injure.ToString() : "0", 30, Colors.Yellow, 0.5);

                }

                //实际产生去血效果

                Enemy.VLife = Enemy.VLife < Injure ? 0 : Enemy.VLife - Injure;

            }

        }

上一页  1 2 3 4 5 6 7  下一页

Tags:开发 WPF Silverlight

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接