GDE-silverlight是我和几个朋友准备在silverlight上开发一款金庸群侠传X版的游戏引擎部分。

之前一直没鼓起干劲搞,这个周末终于得空,把silverlight的几个基本功能自己动手实验了一下。基本弄明白了,准备开始鼓起干劲把GDE-silverlight完成!

感觉silverlight的UI开发还是比之前HGE好多了……之前那个呼呼累啊,梦魇~

非常简单的测试了以下几点

1. 图片加载

2. 之前部分C++代码逻辑上的移植(如寻找移动、攻击区域)

3. 地图单元格绘制

4. 动画(左上角那个爆炸是个动画。。)

5. 复用QXENGINE提供的A*寻路算法,如下图红色部分所示(它这个可以斜着寻路。。到时候需要根据具体要求改)

6. 动态加载控件(如右下的对话框)

7. 加载XML数据(可作为游戏脚本及配置文件)

接下来就是准备开始着手开始写我们的游戏引擎了。

附上代码

using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Media.Imaging; using System.Windows.Threading; using QXGame_Silverlight3.AStar; using System.Xml.Linq; namespace BattleTest { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); //加载背景图片测试 DrawBackImage(); //寻路测试 FindMoveZone(4, 5, 3); //地图单元格 DrawMapBack(); //静态图片测试 DrawElementPic("/pic/MM.png",4, 5); DrawElementPic("/pic/rolebig1.png",3, 2); DrawElementPic("/pic/2.png", 7, 7); //动画测试 DrawAnimation(2, 2); //寻路 FindPath(3, 3, 1, 8); //动态加载控件 LoadUserControl(); //加载XML数据 LoadXMLData(); } //加载图片 public static BitmapSource GetImage(string address) { return new BitmapImage(new Uri(string.Format(@"{0}", address), UriKind.Relative)); } //绘制地图单元格 public void DrawMapBack() { for (int i = 0; i < MAP_SIZE_X; ++i) for (int j = 0; j < MAP_SIZE_Y; ++j) { DrawMapBlock(i,j); } } //加载背景图片 private void DrawBackImage() { Brush brush_instance = new ImageBrush { ImageSource = GetImage("/pic/battle_back.jpg") }; Carrier.Background = brush_instance; } //搜索角色移动范围 bool[,] m_MoveZoneResult; static int[] dx = new int[4] { 0,1,0,-1 }; static int[] dy = new int[4] { 1,0,-1,0 }; private void FindMoveZone(int x, int y, int move_ability) { m_MoveZoneResult = new bool[MAP_SIZE_X, MAP_SIZE_Y]; MoveZoneSearch(x, y, move_ability); } private void MoveZoneSearch(int x, int y, int v) { int tmpx,tmpy; m_MoveZoneResult[x, y] = true; if( v == 0) return; for( int i=0;i<4;i++ ) { tmpx = x + dx[i]; tmpy = y + dy[i]; if( Visitable( tmpx ,tmpy ) ) MoveZoneSearch(tmpx, tmpy, v - 1); } } private bool Visitable(int x,int y) { return true; } //绘制地图单元格 public void DrawMapBlock(int x, int y) { Rectangle rect = new Rectangle(); if (m_MoveZoneResult[x, y]) rect.Fill = new SolidColorBrush(Colors.Green); else rect.Fill = new SolidColorBrush(Colors.Yellow); rect.Opacity = 0.3;//透明度 //rect.Stroke = new SolidColorBrush(Colors.Black); rect.Width = block_size; rect.Height = block_size; rect.RadiusX = block_radius; rect.RadiusY = block_radius; Carrier.Children.Add(rect); Canvas.SetLeft(rect, Transfer_X(x)); Canvas.SetTop(rect, Transfer_Y(y)); } //绘制元素(方块) public void DrawElement(int x, int y) { Rectangle rect = new Rectangle(); rect.Fill = new SolidColorBrush(Colors.Red); rect.Width = block_size; rect.Height = element_height; rect.RadiusX = block_radius; rect.RadiusY = block_radius; Carrier.Children.Add(rect); Canvas.SetLeft(rect, Transfer_X(x)); Canvas.SetTop(rect, Transfer_Y_Element(y)); } //绘制图片元素 public void DrawElementPic(string image,int x, int y) { Image SpiritInstance = new Image() { Source = GetImage(image) }; SpiritInstance.Width = block_size; SpiritInstance.Height = element_height; Carrier.Children.Add(SpiritInstance); Canvas.SetLeft(SpiritInstance, Transfer_X(x)); Canvas.SetTop(SpiritInstance, Transfer_Y_Element(y)); } //坐标系转换 public int Transfer_X(int x) { return (block_size + block_blank) * x; } public int Transfer_Y(int y) { return y_offset + (block_size + block_blank) * y; } //人物元素纵坐标转换 public int Transfer_Y_Element(int y) { return y_offset + (block_size + block_blank) * y - (element_height - block_size); } //动画 int count = 0; Image Animation; public void DrawAnimation(int x, int y) { Animation = new Image(); Animation.Width = 150; Animation.Height = 150; Carrier.Children.Add(Animation); DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = TimeSpan.FromMilliseconds(150); dispatcherTimer.Start(); } private void dispatcherTimer_Tick(object sender, EventArgs e) { Animation.Source = GetImage("/magic/0-" + count + ".png"); count++; if (count > 9) count = 0; } private IPathFinder PathFinder = null; private byte[,] Matrix = new byte[16, 16];//只能是2的次方……QX ENGINE的问题估计是。。 //寻路 public void FindPath(int start_x, int start_y, int end_x, int end_y) { Point Start = new Point(start_x, start_y); Point End = new Point(end_x, end_y); for (int i = 0; i < 16; i++) for (int j = 0; j < 16; j++) Matrix[i,j] = 1;//假设没有障碍物 //使用QXEngine提供的A*算法,此处可以斜方向寻路,到时候需要改…… PathFinder = new PathFinderFast(Matrix) { HeavyDiagonals = false, HeuristicEstimate = 2, SearchLimit = 2000 }; List<PathFinderNode> path = PathFinder.FindPath(Start, End); if (path == null) MessageBox.Show("没有路径"); else { for (int i = 0; i < path.Count; i++) { Rectangle rect = new Rectangle(); rect.Fill = new SolidColorBrush(Colors.Red); rect.Width = block_size; rect.Height = block_size; rect.Opacity = 0.3;//透明度 Carrier.Children.Add(rect); Canvas.SetLeft(rect, Transfer_X(path[i].X)); Canvas.SetTop(rect, Transfer_Y(path[i].Y)); } } } //加载用户控件 public void LoadUserControl() { SilverlightControl1 test = new SilverlightControl1(); Carrier.Children.Add(test); test.Opacity = 0.5; Canvas.SetLeft(test, 400); Canvas.SetTop(test, 200); } //加载XML数据 public void LoadXMLData() { XElement mapdata = GetTreeNode(XElement.Load("XMLFile1.xml"), "Map", "Name", "大地图"); string value = mapdata.Attribute("Value").Value; MessageBox.Show(value); } public static XElement GetTreeNode(XElement XML, string newroot, string attribute, string value) { return XML.DescendantsAndSelf(newroot).Single(X => X.Attribute(attribute).Value == value); } //常数 private static int element_height = 80; private static int block_radius = 5; private static int block_size = 50; private static int y_offset = 30; private static int block_blank = 2; private static int MAP_SIZE_X = 10; private static int MAP_SIZE_Y = 10; } }

silverlight C#实验成果,GDE-silverlight准备开始启动相关推荐

  1. Silverlight C# 游戏开发:Silverlight开发环境

    Silverlight C# 游戏开发:Silverlight开发环境 所谓工欲善其事必先利其器,没有好的工具也没有办法做事,我以前曾经想学习C++以外的程序语言,当时有java和C#来选择,当时考虑 ...

  2. Silverlight 4 新特性之Silverlight as Drop Target

    在上次项目中写过多篇关于拖拽的实现. 这些拖拽都是控件之间的效果. Silverlight 4 中我们甚至可以直接把文件系统中文件拖拽到Silverlight Application中承载. 这就是 ...

  3. [导入]Silverlight 的 Data Bindings:Silverlight 與 ASP.NET Ajax

    摘要: 不可否認,對於網頁美工人員或是動畫設計師而言,Silverlight 提供了 Flash 以外的一個畫布,令她們可盡情揮灑創意!但對於設計師而言,Silverlight 如何結合資料庫來呈現資 ...

  4. 分享Silverlight 3D开源项目和Silverlight/WPF/Windows Phone一周学习导读(4月25日-4月29日)...

    Silverlight 5 Beta版本中最引人注目的特性是3D功能,Silverlight 5与XNA Framework的结合,使Silverlight完美支持3D效果. 在微软MIX11大会后, ...

  5. Silverlight实用窍门大集合+Silverlight 5 最全新特性【目录索引】

    在最近的几个月内整理出了Silverlight的一些相关的比较实用的功能讲解文章,并且随着Silverlight 5 beta版本的发布整理出的新特性系列文章,在这里做一个总的概括和索引,以方便大家观 ...

  6. Silverlight学习之——如何在 Silverlight 中使用 Deep Zoom

    Deep Zoom 使您能够快速缩放和平移高分辨率图像.Deep Zoom 可以使用多分辨率图像来实现上述功能. 下面演示如何创建使用 Deep Zoom 的非常简单的 Silverlight 应用程 ...

  7. 运动,由Silverlight助力 / Sports, Powered by Silverlight

    Sports, Powered by Silverlight  运动,由Silverlight助力  原文链接:http://team.silverlight.net/announcement/spo ...

  8. Silverlight前景One World One Silverlight

    Silverlight前景:       Silverlight是微软的下一代Web技术的原形,支持多种操作系统:Windows/Mas   OS/Linux(Moonlight),支持多浏览器:IE ...

  9. Silverlight学习笔记(3):Silverlight的界面布局

    在上一篇中讲述了使用VS2010开发Silverlight的一些基础知识,并且讲述了Silverlight的部署和代码安全知识,这一篇主要是讲述如何在Silverlight中摆放界面元素. 记得早年前 ...

最新文章

  1. [转]几种最短路径算法的比较
  2. ntoskrnl损坏
  3. 数据结构与算法的八股文自述(持续更新)
  4. 最后 24 小时,赶紧来领取这 50 本送书福利吧!
  5. 【ArcGIS风暴】ArcGIS10.6图斑椭球面积计算原理与方法
  6. HDU 5730 Shell Necklace(生成函数 多项式求逆)
  7. linux操作系统信号捕捉函数之回调函数小结
  8. C# 微信开发-----微信会员卡(一)
  9. python获取windows路径,Python中的Windows路径
  10. 树莓派4做服务器哪个系统好,【树莓派】树莓派4无痛安装系统(NOOBS篇)
  11. JavaScript基本数据类型
  12. 为什么在java中不能创建泛型数组
  13. 使用RAID 5虚拟磁盘时,dell的perc控制器H310的性能较差
  14. 常用网站网址、名称、logo列表
  15. linux测试硬盘读写速度
  16. 人工神经网络与遗传算法,遗传算法和神经算法
  17. 求购二手《良葛格Java JDK 5.0学习笔记》
  18. C语言--正弦、余弦函数
  19. js重写alert事件,避免alert弹框标题出现网址
  20. 解决微信群服务管理难题,只需要一个助手

热门文章

  1. DolphinScheduler启用Kerberos(亲测)
  2. mysql重启时报错 /etc/my.cnf is ignored
  3. python关键字数据驱动_携程大牛谈自动化测试里的数据驱动和关键字驱动思路的理解...
  4. 2021河南高考成绩查询郸城一高,河南某县中高考成绩严重刷屏:11人超过700分!凌晨校园照,震撼无数家长!...
  5. Linux CentOS 8中Docker的安装与卸载
  6. LINUX 查看硬件配置命令
  7. java.beans 包_javabeans是什么
  8. 惠普340 g3拆机教程
  9. android opencv 数码变焦,Android开发(53) 摄像头自动对焦。在OpenCV图像识别中连续拍照时自动对焦和拍照。......
  10. 记录一个下载的皮肤资源包问题