Silverlight游戏设计(Game Design):(十三)帝国时代II (Demo) 之 “战争艺术”②

帝国时代是一部阐述世界战争发展史的游戏巨著,讲究还原真实的历史战争场景,其中的阵型系统为游戏的极大亮点之一;玩家根据兵种的不同搭配上最合适的阵型时常能起到逆转乾坤的神效,经典的如前枪,中骑,后投石,强大的阵型加上玩家精确的微操能瞬间扫荡大规模敌军而毫发不伤。阵型系统不仅仅存在于即时战略游戏中,在《三国志》、《信长野望》等SLG策略游戏中,其同样是一者永远不可缺少的重要机制。

本节,我将在上一节搭建的《帝国时代》Demo的基础上引入比原著更加灵活多变的自定义阵型系统,以让战争游戏更显真实与华丽。

自定义阵型系统的灵感来源于国际象棋,阵型好比“棋盘”,作战单位好比“棋子”;因此从结构出发,我选择使用Grid作为构建阵型系统的最底层载体,通过指定RowColumn即可随意布局棋子到指定方格内:

在本节Demo中,我将“棋盘”摆放在HUD的中下方,并限制其为一个4*12最大容纳48单位的表格型载体。

有了“棋盘”,当然还少不了“棋子”。“棋子”是一个图标,于是我创建一个名为Piece的类,该类包含一个图片控件和一个矩形方块控件(血条)

上图为骑兵对应的“棋子”图标。接下来要实现自定义的棋子布局,我们还需为这些棋子增加座位交互功能:即点击其中一个棋子后,该棋子为选中状态,并与接下来点击的位置或另一个棋子进行位置交换,代码很简单,大致如下:

        Piece hitPiece = null; //点击的棋子

        /// <summary>

        /// 单位位置更换

        /// </summary>

        private void img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {

            if (hitPiece == null && (int)((sender as Piece).Code) != -1) {

                hitPiece = sender as Piece;

                hitPiece.Effect = new DropShadowEffect() { BlurRadius = 8, ShadowDepth = 0, Color = Colors.Red };

            } else if (hitPiece != null) {

                int oldRow = Grid.GetRow(hitPiece);

                int oldColumn = Grid.GetColumn(hitPiece);

                Piece piece = sender as Piece;

                int newRow = Grid.GetRow(piece);

                int newColumn = Grid.GetColumn(piece);

                Grid.SetRow(piece, oldRow);

                Grid.SetColumn(piece, oldColumn);

                Grid.SetRow(hitPiece, newRow);

                Grid.SetColumn(hitPiece, newColumn);

                hitPiece.Effect = null;

                hitPiece = null;

            }

            e.Handled = true;

        }

“棋盘”和“棋子”功能完成后,我们最后要做的仅仅是将这套布局应用到游戏中的作战单位上。上一节中讲解了如何对单位进行范围选取,每次选取后“棋盘”中所显示的即为选择的单位们所对应的“棋子”,这里我通过一个DispatcherTimer每间隔1秒钟刷新一次“棋盘”中所有“棋子”的血条值;当然,这或许并非最好的解决方案,但却是一则通用且简单高效的实现方式之一:

阵型系统的最终实现即是对所选取的作战单位按排列好的布局图进行走位,Grid作为棋盘的优越性及简易性也将从中得以体现,实现起来代码就更简单了:

……

Point p = e.GetPosition(mainScene.Container);

//单个精确移动,多个则按阵型移动

if (mainScene.SelectedArmy.Count == 1) {

     mainScene.SelectedArmy[0].MoveTo(p);

} else {

    for (int i = 0; i < facePlate.formation.Children.Count; i++) {

         Piece piece = facePlate.formation.Children[i] as Piece;

         if (piece.Code != -1) {

             int row = Grid.GetRow(piece);

             int column = Grid.GetColumn(piece);

             piece.CorrespondingSprite.Enemy = null;

             piece.CorrespondingSprite.MoveTo(new Point(p.X + column * pieceSpace, p.Y + row * pieceSpace));

          }

     }

}

……

    自定义阵型是阵型系统中的最高级别,实际游戏开发中,根据需要将“棋盘”定义为相应规格尺寸的Grid后,即可衍生出更加丰富多变的固定或非固定阵型,不仅大幅度增加游戏的趣味性与战略性,同时也是设计师们对游戏艺术的不懈追求。

 

 

 

 

 

以上为随意排列出的一些经典阵型,不禁让我再次重温了一遍从小陪伴我长大的三国志系列。当然了,实际中您可以根据兵种的近、远距离攻击属性及移动速度、相生相克等因素布局出更适合不同战役的阵型。战斗,胜败的关键在策略,而阵型就是其核心之一,这就是战争艺术。

在线演示地址:http://silverfuture.cn

作者:深蓝色右手
教程目录及源码下载: 点击进入
本文版权归作者和CSDN共有,欢迎转载。但未经作者同意必须保留此段声明,且在文章页面显著位置给出原文连接,否则保留追究法律责任的权利。
  • 0
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 30
    评论
C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial)目录 本系列教程目录如下: C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(一)让物体动起来① C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二)让物体动起来 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三)让物体动起来③ C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(四)实现2D人物动画① C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(五)实现2D人物动画 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(六)完美移动 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(七)传说中的A*寻径算法 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(八)完美实现A*寻径动态动画 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(九)2D游戏角色在地图上的移动 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十)斜度α地图的构造及算法 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十一)地图遮罩层的实现 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十二)神奇的副本地图 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十三)牵引式地图移动模式① C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十四)精灵控件横空出世!① C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十五)精灵控件横空出世! C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十六)牵引式地图移动模式 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十七)完美精灵之八面玲珑(WPF Only)① C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十八)完美精灵之八面玲珑(WPF Only) C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(十九)完美精灵之八面玲珑(WPF Only)③ C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十)第一部分拓展小结篇 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十一)主位式地图移动模式 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十二)重构 - 让代码插上翅膀飞翔 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十三)自适应性窗口化与全屏化 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十四)Be careful!前方怪物出没 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十五)完美捕获精灵之神器 -- HitTest C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十六)通用型角色头像面板 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十七)战斗前夜之构建动态障碍物系统 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十八)经典式属性设计及完美的物理攻击系统 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(二十九)人工智能(AI)之追踪者 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十)大法师 - 华丽经典之轮回 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十一) 超酷万变的矢量魔法 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十二) 雷、混、冰、毒、火、风 - 幻化中的魔法魅力! C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十三) 锦上添花之魔法特效装饰 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十四) 地图编辑器诞生啦! C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十五) 地图编辑器的初步使用 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十六) 地图自定义切片与导出 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十七) 地图自适应区域加载 C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十八) 地图间的传送与切换 摘自博客园深蓝色右手文章(原文链接:http://www.cnblogs.com/alamiye010/archive/2009/06/17/1505346.html) 压缩包内的2个文件,chm和exe格式内容一样
Product Description: A hands-on guide to Microsoft's latest rich application development technology: Silverlight 4 Silverlight 4 is the newest version of the rich Internet application toolkit that provides support for .NET capabilities over the Internet. With this latest release of Silverlight, Microsoft has revolutionized the way that Web applications can be created. This book uses the popular Problem – Design – Solution strategy to demonstrate how to harness the power and abilities of Silverlight 4 to add value to the overall user experience of a Web site. Using a Web site created by the author as a reference point, you'll go through the steps of creating a live, fully functional application for the Web using Silverlight 4 and the Silverlight Control Toolkit. Along the way, the book addresses important design considerations, such as the use of Web Services and the SQL Server database. Uses the popular Problem – Design – Solution format show you how to harness the power of the latest version of Silverlight, Microsoft's rich Internet application toolkit Puts the author's own Web site to task as you learn to create rich user interfaces that integrate video, HTML, and social networking components Explains system linking and data flow, end user interface, system architecture based on Silverlight 4 and .NET 4, and more Includes coverage on integrating social networking and Facebook With this book, you'll quickly get started using the new features of Silverlight 4 to enhance the user experience of a Web site.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 30
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值