C#开发WPF/Silverlight动画及游戏系列教程(Game Course):(二十八) 经典式属性设计及完美的物理攻击系统
2010-09-30 20:47:09 来源:WEB开发网这里的处理调用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;
}
}
Tags:开发 WPF Silverlight
编辑录入:爽爽 [复制链接] [打 印]- ››开发Android 日历教程
- ››开发学院总结 Win 8实用技巧大全
- ››开发学院原创教程:把win8的IE10放桌面上方法(非...
- ››silverlight全屏显示图片
- ››Silverlight MVVM 模式(一) 切近实战
- ››开发者眼中的Windows Phone和Android
- ››开发学院教你用SQL 语句最快速清空MySQL 数据表的...
- ››WPF学习笔记12. Binding (5)
- ››WPF学习笔记11. Binding (4)
- ››WPF学习笔记10. Binding (3)
- ››WPF学习笔记9. Binding (2)
- ››WPF学习笔记8. Binding
更多精彩
赞助商链接