博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FLASH STUDY LOG
阅读量:5277 次
发布时间:2019-06-14

本文共 5136 字,大约阅读时间需要 17 分钟。

 

//绘制一个菱形地图的代码
ExpandedBlockStart.gif
View Code
package com.joyairport.model{
    
    import flash.display.Sprite;
    import flash.display.DisplayObject;
    import flash.display.Shape;
    import flash.geom.Point;
    import flash.events.MouseEvent;
    
    import org.puremvc.as3.core.Model;
    
    
    public class BaseMap {
        
        private 
var
 MapWidth: Number;        
//
760x2=1520
        private 
var
 MapHeight: Number;        
//
680x2=1360
        private 
var
 TileWidth :Number;        
//
tile=60
        private 
var
 TileHeight :Number;        
//
tile=30
        private 
var
 HalfTileWidth:
int
;
        private 
var
 HalfTileHeight:
int
;
        
        public 
function
 BaseMap() {
            
//
 constructor code
            
//
drawBaseMap(1520, 1360, 60, 30);
        }
        
        
        
        
        
//
绘制地图
        public 
function
 drawBaseMap(mapWidth:
int
, mapHeight:
int
, tileWidth:
int
, tileHeight:
int
):DisplayObject {
            
this
.MapWidth 
=
 mapWidth;
            
this
.MapHeight 
=
 mapHeight;
            
this
.TileWidth 
=
 tileWidth;
            
this
.TileHeight 
=
 tileHeight;
            
            
var
 col:
int
 
=
 
this
.MapWidth 
/
 
this
.TileWidth;
            
var
 row:
int
 
=
 
this
.MapHeight 
/
 
this
.TileHeight;
            
            
this
.HalfTileWidth 
=
 
int
(
this
.TileWidth 
/
 
2
);
            
this
.HalfTileHeight 
=
 
int
(
this
.TileHeight 
/
 
2
);
            
            trace(
"
mapWidth = 
"
 
+
 mapWidth 
+
 
"
 __  row = 
"
 
+
 row);
            trace(
"
mapHeight = 
"
 
+
 mapHeight 
+
 
"
 __  col = 
"
 
+
 col);
            
            
            
var
 grid:Shape 
=
 
new
 Shape();
            grid.graphics.lineStyle(
1
0xC3C3C3
1
);
            
            
var
 dblMapWidth:
int
 
=
 col 
*
 
2
 
+
 
1
;
            
var
 dblMapHeight:
int
 
=
 row 
*
 
2
 
+
 
1
;
            
            
for
 (
var
 i:
int
 
=
 
1
; i 
<
 dblMapWidth; i 
=
 i 
+
 
2
 ) {
                grid.graphics.moveTo(i 
*
 
this
.HalfTileWidth, 
0
);
                
if
 (dblMapHeight 
+
 i 
>=
 dblMapWidth) {
                    grid.graphics.lineTo(dblMapWidth 
*
 
this
.HalfTileWidth, (dblMapWidth 
-
 i) 
*
 
this
.HalfTileHeight);
                }
else
 {
                    grid.graphics.lineTo((dblMapHeight 
+
 i) 
*
 
this
.HalfTileWidth, dblMapHeight 
*
 
this
.HalfTileHeight);
                }
                
                grid.graphics.moveTo(i 
*
 
this
.HalfTileWidth, 
0
);
                
if
 (i 
<=
 dblMapHeight) {
                    grid.graphics.lineTo(
0
, i 
*
 
this
.HalfTileHeight);
                }
else
 {
                    grid.graphics.lineTo((i 
-
 row 
-
 
1
*
 
this
.HalfTileWidth, dblMapHeight 
*
 
this
.HalfTileHeight);
                }
            }
            
            
            
for
 (
var
 j:
int
 
=
 
1
; j 
<
 dblMapHeight; j 
=
 j 
+
 
2
) {
                grid.graphics.moveTo(
0
, j 
*
 
this
.HalfTileHeight);
                
if
 (dblMapHeight 
-
 j 
>=
 dblMapWidth) {
                    grid.graphics.lineTo(dblMapWidth 
*
 
this
.HalfTileWidth, (dblMapWidth 
+
 j) 
*
 
this
.HalfTileHeight);
                }
else
 {
                    grid.graphics.lineTo((dblMapHeight 
-
 j) 
*
 
this
.HalfTileWidth, dblMapHeight 
*
 
this
.HalfTileHeight);
                }                
            }
            
/*
            for (var m:int = 0; m < dblMapHeight; m = m + 2) {
                grid.graphics.moveTo(dblMapWidth * this.HalfTileWidth, m * this.HalfTileHeight);
                if (dblMapWidth - dblMapHeight + m < 0) {
                    grid.graphics.lineTo(0, (dblMapWidth + m) * this.HalfTileHeight);
                }else {
                    grid.graphics.lineTo((dblMapWidth - dblMapHeight + m) * this.HalfTileWidth, dblMapHeight * this.HalfTileHeight);
                }
            }
            
*/
            
            
return
 grid;
            
        }
    }
    
}

//

 

//用小菱形块拼接的Rhombus地图,45度角的

ExpandedBlockStart.gif
View Code
package com.joyairport.model
{
    import flash.display.DisplayObject;
    import flash.display.Shape;
    import flash.display.SpreadMethod;
    import flash.display.Sprite;
    
    
/*
*
     * ...
     * @author guolichun
     
*/
    public class RhombusMap  
    {
        
    
/*
    private var rhombus_width:Number = 80;
        private var rhombus_height:Number = 40;
        private var rhombus_pointx:Number = 0;
        private var rhombus_pointy:Number = 0;
        
        private var map_width:Number = 1024;
        private var map_height:Number = 1024;
*/
        
        
        
        public 
function
 RhombusMap() {
            
        }
        
        
/*
*
         * 绘制一个菱形
         * @param    _point_x = 起点坐标x
         * @param    _point_y = 起点坐标y
         * @param    _rhombus_width = 小菱形所在矩形的宽度
         * @param    _rhombus_height = 小菱形所在矩形的高度
         * @return
         
*/
        public 
function
 drawRhombus(_point_x:Number, _point_y:Number, _rhombus_width:Number, _rhombus_height:Number):Sprite {
            
            
var
 r:Sprite 
=
 
new
 Sprite();
            
var
 s:Shape 
=
 
new
 Shape();
            
            s.graphics.lineStyle(
1
0x000000
);
            s.graphics.beginFill(
0x00666CC
0.3
);
            s.graphics.moveTo(_point_x, _point_y);
            s.graphics.lineTo(_point_x 
+
 _rhombus_height, _point_y 
+
 (_rhombus_height 
/
 
2
));
            s.graphics.lineTo(_point_x, _point_y 
+
 _rhombus_height);
            s.graphics.lineTo(_point_x 
-
 _rhombus_height, _point_y 
+
 (_rhombus_height 
/
 
2
));
            
//
s.graphics.lineTo(rh, px);
            s.graphics.endFill();
            
            r.addChild(s);
            
            
return
 r;            
        }
        
        
/*
*
         * 绘制菱形地图
         * @param    rw = rhombus宽度
         * @param    rh = rhombus高度
         * @param    mw = map宽度
         * @param    mh = map高度
         * @return
         
*/
        public 
function
 drawMap(rw:Number,rh:Number,mw:Number,mh:Number):Sprite {
            
var
 grid:Sprite 
=
 
new
 Sprite();
            
            
for
 (
var
 i:
int
 
=
 
0
; i 
<
 (mw 
/
 rw); i
++
 ) {                
                
                
for
 (
var
 j:
int
 
=
 
0
; j 
<
 (mh 
/
 rh); j
++
 ) {                
                    
var
 rhombus:Sprite 
=
 drawRhombus(rw 
*
 i 
+
 rw, rh
*
j  
+
 rh, rw, rh);
                    
                    
                    trace(
"
i = 
"
 
+
 i 
+
 
"
 j = 
"
 
+
 i);
                    grid.addChild(rhombus);
                }                            
            }            
            
return
 grid;            
        }
    }
    
}
//

 

//拖动容器的代码sprite

ExpandedBlockStart.gif
View Code
stage.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMovefun);
stage.addEventListener(MouseEvent.CLICK,onclickfun);
stage.addEventListener(MouseEvent.MOUSE_DOWN,onmousedownfun);
stage.addEventListener(MouseEvent.MOUSE_UP,onmouseupfun);
function
 onmouseupfun(e:MouseEvent):
void
{
    trace(
"
mouse UP
"
);
    
this
.stopDrag();    
}
function
 onmousedownfun(e:MouseEvent):
void
{
    trace(
"
mouse DOWN 
"
);
    
this
.startDrag();
    
}
function
 onMouseMovefun(e:MouseEvent):
void
{
    
//
trace("_"+ e.localX + "_" + e.localY);
}
function
 onclickfun(e:MouseEvent):
void
{
    trace(
"
CLICK==>_X=
"
+
 e.stageX  
+
 
"
_Y=
"
 
+
 e.stageY 
+
 
"
__local:_
"
 
+
 e.localX 
+
 
"
_
"
 
+
 e.localY);
}
//
//
//
//
//

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/didi/archive/2011/07/25/2116477.html

你可能感兴趣的文章
51nod1076 (边双连通)
查看>>
Linux pipe函数
查看>>
java equals 小记
查看>>
2019春 软件工程实践 助教总结
查看>>
Zerver是一个C#开发的Nginx+PHP+Mysql+memcached+redis绿色集成开发环境
查看>>
程序的静态链接,动态链接和装载 (补充)
查看>>
关于本博客说明
查看>>
[Kaggle] Sentiment Analysis on Movie Reviews
查看>>
价值观
查看>>
mongodb命令----批量更改文档字段名
查看>>
国外常见互联网盈利创新模式
查看>>
android:scaleType属性
查看>>
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>
【雷电】源代码分析(二)-- 进入游戏攻击
查看>>
Linux中防火墙centos
查看>>
如何设置映射网络驱动器的具体步骤和方法
查看>>
centos下同时启动多个tomcat
查看>>
Leetcode Balanced Binary Tree
查看>>
[JS]递归对象或数组
查看>>