首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 開發 WPF/Silverlight 動畫與遊戲系列教程(十一)地圖遮罩層實現(三)—— 障礙物構建代碼

     編輯:關於C語言

截圖略顯粗糙,請見諒。兩棵樹長相奇特請包涵。

障礙物構建(三區域,基於第九節修改)


// 區域 1
for (int y = 22; y <= 24; y++)
    for (int x = 5; x <= 16; x++) {
        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);
    }

// 區域 2
for (int y = 11; y <= 14; y++)
    for (int x = 27; x <= 31; x++) {
        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);
    }

// 區域 3
for (int y = 18; y <= 21; y++)
    for (int x = 33; x <= 37; x++) {
        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. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved