/* 繪製自動元件
* view_id : 圖層
* x : 地圖x坐標
* y : 地圖y坐標
* value : 自動元件值
*/
private function draw_autotile(view_id:int,x:int,y:int,value:int)
{
var autotile_id:int=Math.floor(value/48)-1; //判斷是哪一個自動元件
value=value%48+48;
var list:Array=new Array();
//下面決定哪些值該繪製些什麼
list[48]=["water"];
list[49]=["water","cornerA"];
list[50]=["water","cornerB"];
list[51]=["water","cornerA","cornerB"];
list[52]=["water","cornerD"];
list[53]=["water","cornerA","cornerD"];
list[54]=["water","cornerB","cornerD"];
list[55]=["water","cornerA","cornerB","cornerD"];
list[56]=["water","cornerC"];
list[57]=["water","cornerA","cornerC"];
list[58]=["water","cornerB","cornerC"];
list[59]=["water","cornerA","cornerB","cornerC"];
list[60]=["water","cornerC","cornerD"];
list[61]=["water","cornerA","cornerC","cornerD"];
list[62]=["water","cornerB","cornerC","cornerD"];
list[63]=["cornerA","cornerB","cornerC","cornerD"];
list[64]=["area_4"];
list[65]=["water","line_left","cornerB"];
list[66]=["water","line_left","cornerD"];
list[67]=["line_left","cornerB","cornerD"];
list[68]=["area_8"];
list[69]=["area_8","cornerD"];
list[70]=["water","cornerC","line_top"];
list[71]=["water","cornerC","cornerD","line_top"];
list[72]=["area_6"];
list[73]=["water","cornerC","line_right"];
list[74]=["water","cornerA","line_right"];
list[75]=["cornerA","cornerC","line_right"];
list[76]=["area_2"];
list[77]=["water","cornerA","line_bottom"];
list[78]=["water","cornerB","line_bottom"];
list[79]=["water","cornerA","cornerB","line_bottom"];
list[80]=["line_left","line_right"];
list[81]=["line_top","line_bottom"];
list[82]=["area_7"];
list[83]=["line_left","line_top","area_7","cornerD"];
list[84]=["area_9"];
list[85]=["line_top","line_right","area_9","cornerC"];
list[86]=["area_3"];
list[87]=["line_bottom","line_right","area_3","cornerA"];
list[88]=["area_1"];
list[89]=["line_bottom","line_left","area_1","cornerB"];
list[90]=["area_7h","area_9h"];
list[91]=["area_7h2","area_1h2"];
list[92]=["area_1h","area_3h"];
list[93]=["area_9h2","area_3h2"];
list[94]=["hole"];
//下面是一些繪畫模板
if (list[value]!=null)
{
for (var i:int=0;i<list[value].length;i++)
{
switch (list[value][i])
{
case "water":
copy_autotile(view_id,x,y,autotile_id,32,64); //畫水背景(在圖中是大東西最中間的圖塊)
break;
case "hole":
copy_autotile(view_id,x,y,autotile_id); //畫水坑(在圖中是最上面一排左邊的那個)
break;
case "grass":
copy_autotile(view_id,x,y,autotile_id,32,0); //畫草地、木板背景(在圖中是最上面一排中間的那個)
break;
case "area_7":
copy_autotile(view_id,x,y,autotile_id,0,32); //主區域左上角(根據小鍵盤的數字分佈可確定)
break;
case "area_8":
copy_autotile(view_id,x,y,autotile_id,32,32); //主區域中上角
break;
case "area_9":
copy_autotile(view_id,x,y,autotile_id,64,32); //主區域右上角
break;
case "area_4":
copy_autotile(view_id,x,y,autotile_id,0,64); //主區域左中角
break;
case "area_6":
copy_autotile(view_id,x,y,autotile_id,64,64); //主區域右中角
break;
case "area_1":
copy_autotile(view_id,x,y,autotile_id,0,96); //主區域左下角
break;
case "area_2":
copy_autotile(view_id,x,y,autotile_id,32,96); //主區域中下角
break;
case "area_3":
copy_autotile(view_id,x,y,autotile_id,64,96); //主區域右下角
break;
case "cornerA":
copy_autotile(view_id,x,y,autotile_id,64,0,16,16); //左上角補口
break;
case "cornerB":
copy_autotile(view_id,x,y,autotile_id,80,0,16,16,16); //右上角補口
break;
case "cornerC":
copy_autotile(view_id,x,y,autotile_id,64,16,16,16,0,16); //左下角補口
break;
case "cornerD":
copy_autotile(view_id,x,y,autotile_id,80,16,16,16,16,16); //右下角補口
break;
case "line_left":
copy_autotile(view_id,x,y,autotile_id,0,64,16,32); //左邊線
break;
case "line_right":
copy_autotile(view_id,x,y,autotile_id,80,64,16,32,16); //右邊線
break;
case "line_top":
copy_autotile(view_id,x,y,autotile_id,32,32,32,16); //上邊線
break;
case "line_bottom":
copy_autotile(view_id,x,y,autotile_id,32,112,32,16,0,16); //下邊線
break;
/*
關於nHn的規定:
在小鍵盤上,「7鍵」位於[左上]角,因此規定7h為[左]邊線,鉤向[上]
同理,「3鍵」位於[右下]角,所以規定3h為[右]邊線,鉤向[下]
但如果想表示[上]邊線,鉤向[左]([左]邊線,鉤向[上]反過來),只需要在h後面補上2:7h2
copy_autotile函數autotile_id後面的參數:
(自動元件圖中開始坐標x,y),(寬度,高度),(螢幕上相對於要繪製的單元格的左上角的 開始繪製點坐標x,y)
*/
case "area_7h":
copy_autotile(view_id,x,y,autotile_id,0,32,16,32); //左邊線,鉤向上
break;
case "area_7h2":
copy_autotile(view_id,x,y,autotile_id,0,32,32,16); //上邊線,鉤向左
break;
case "area_9h":
copy_autotile(view_id,x,y,autotile_id,80,32,16,32,16); //右邊線,鉤向上
break;
case "area_9h2":
copy_autotile(view_id,x,y,autotile_id,64,32,32,16); //上邊線,鉤向右
break;
case "area_1h":
copy_autotile(view_id,x,y,autotile_id,0,96,16,32); //左邊線,鉤向下
break;
case "area_1h2":
copy_autotile(view_id,x,y,autotile_id,0,112,32,16,0,16); //下邊線,鉤向左
break;
case "area_3h":
copy_autotile(view_id,x,y,autotile_id,80,96,16,32,16,0); //右邊線,鉤向下
break;
case "area_3h2":
copy_autotile(view_id,x,y,autotile_id,64,112,32,16,0,16); //下邊線,鉤向右
break;
}
}
}
else
trace("無法識別的圖塊「自動元件:"+value+"」");
除了95,其餘全部計算好了