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

C#开发WPF/Silverlight动画及游戏系列教程(Game Course):(十一)地图遮罩层的实现

 2009-06-22 08:32:35 来源:WEB开发网   
核心提示: 匆忙了点,截得不好可不要见怪哪!谁让这两棵树长得如此奇怪呢?嘿嘿,C#开发WPF/Silverlight动画及游戏系列教程(Game Course):(十一)地图遮罩层的实现(3), OK,接下我以第九节的代码为基础进行修改

匆忙了点,截得不好可不要见怪哪!谁让这两棵树长得如此奇怪呢?嘿嘿。

OK,接下我以第九节的代码为基础进行修改,首先构建障碍物:

            //构建障碍物
            for (int y = 22; y <= 24; y++) {
                for (int x = 5; x <= 16; x++) {
                    //障碍物在矩阵中用0表示
                    Matrix[x, y] = 0;
                    rect = new Rectangle();
                    rect.Fill = new SolidColorBrush(Colors.GreenYellow);
                    rect.Opacity = 0.3;
                    rect.Stroke = new SolidColorBrush(Colors.Gray);
                    rect.Width = GridSize;
                    rect.Height = GridSize;
                    Carrier.Children.Add(rect);
                    Canvas.SetLeft(rect, x * GridSize);
                    Canvas.SetTop(rect, y * GridSize);
                }
            }
            for (int y = 11; y <= 14; y++) {
                for (int x = 27; x <= 31; x++) {
                    //障碍物在矩阵中用0表示
                    Matrix[x, y] = 0;
                    rect = new Rectangle();
                    rect.Fill = new SolidColorBrush(Colors.GreenYellow);
                    rect.Opacity = 0.3;
                    rect.Stroke = new SolidColorBrush(Colors.Gray);
                    rect.Width = GridSize;
                    rect.Height = GridSize;
                    Carrier.Children.Add(rect);
                    Canvas.SetLeft(rect, x * GridSize);
                    Canvas.SetTop(rect, y * GridSize);
                }
            }
            for (int y = 18; y <= 21; y++) {
                for (int x = 33; x <= 37; x++) {
                    //障碍物在矩阵中用0表示
                    Matrix[x, y] = 0;
                    rect = new Rectangle();
                    rect.Fill = new SolidColorBrush(Colors.GreenYellow);
                    rect.Opacity = 0.3;
                    rect.Stroke = new SolidColorBrush(Colors.Gray);
                    rect.Width = GridSize;
                    rect.Height = GridSize;
                    Carrier.Children.Add(rect);
                    Canvas.SetLeft(rect, x * GridSize);
                    Canvas.SetTop(rect, y * GridSize);
                }
            }

上一页  1 2 3 4  下一页

Tags:开发 WPF Silverlight

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