actionScript 3.0 소스 코드:
var maps:Array = [1,1,2,1,1,1,1,1,2,2,
1,1,1,2,2,1,1,4,1,1,
2,1,1,1,2,1,1,1,1,1,
2,1,1,1,2,1,1,1,1,2,
1,3,1,1,2,1,1,1,1,1,
1,1,1,1,1,1,1,1,2,1,
1,1,1,1,1,1,1,1,2,2,
1,1,1,1,1,1,1,1,1,1,
]; //배경 블럭 형태 담을 배열
var maps2:Array=new Array(); //배경 블럭 무비 담을 배열
var mapsContainer = new Sprite(); //배경 블럭 무비 담을 컨테이너
//var changeTimer:Timer=new Timer(200);
var startN:MovieClip=new ballM();
var goalN;
var openNode:Array=new Array();
var closeNode:Array=new Array();
var aniIng:Boolean = false; //애니 중 여부
var dx=0, dy=0; //움직일 거리용 변수
var moveTo:String=""; //가로 세로 움직임 여부
function init(){//초기화
mapSetting(maps);
addChild(startN);
startN.now = 42;
startN.next = -1;
startN.x = maps2[startN.now].x;
startN.y = maps2[startN.now].y;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keysDown);
stage.addEventListener(Event.ENTER_FRAME, loop);
}
function loop(e:Event){//움직임 애니 처리
if(aniIng){
switch(moveTo){
case "xMove":{
if(Math.abs(dx) > 0.1){
startN.x += dx/2;
dx = dx/2;
}else{
dx = 0;
startN.x = maps2[startN.now].x;
aniIng=false;
moveTo = "";
}
break;}
case "yMove":{
if(Math.abs(dy) > 0.1){
startN.y += dy/2;
dy = dy/2;
}else{
dy = 0;
startN.y = maps2[startN.now].y;
aniIng=false;
moveTo = "";
}
break;}
}
trace(dx, dy, aniIng);
}
}
function keysDown(e:KeyboardEvent){//키보드 입력 처리
//trace(e.keyCode);
if(!aniIng){
switch(e.keyCode){
case 38: movMoving(startN, "up"); break;//위쪽 화살표
case 40: movMoving(startN, "down"); break;//아래쪽 화살표
case 37: movMoving(startN, "left"); break;//왼쪽 화살표
case 39: movMoving(startN, "right"); break;//오른쪽 화살표
}
}
}
function movMoving(mov:MovieClip, directions:String){//움직임 처리
switch(directions){
case "up":{
mov.next = mov.now - 10;
if(mov.next < 0){trace("out"); break;}
if(maps2[mov.next].num != 2){
//mov.y -= 50;
mov.now -= 10;
aniIng = true;
moveTo = "yMove";
dy = -50;
}
mov.next = -1;
break;
}
case "down":{
mov.next = mov.now + 10;
if(mov.next > maps2.length-1){trace("out"); break;}
if(maps2[mov.next].num != 2){
//mov.y += 50;
mov.now += 10;
aniIng = true;
moveTo = "yMove";
dy = 50;
}
mov.next = -1;
break;
}
case "left":{
mov.next = mov.now - 1;
if(mov.next%10 ==9 || mov.next ==-1){trace("out"); break;}
if(maps2[mov.next].num != 2){
//mov.x -= 50;
mov.now -= 1;
aniIng = true;
moveTo = "xMove";
dx = -50;
}
mov.next = -1;
break;
}
case "right":{
mov.next = mov.now + 1;
if(mov.next%10 ==0){trace("out"); break;}
if(maps2[mov.next].num != 2){
//mov.x += 50;
mov.now += 1;
aniIng = true;
moveTo = "xMove";
dx = 50;
}
mov.next = -1;
break;
}
}
trace(mov.now);
}
function mapSetting(map){//배경 블럭 처리
for(var i = 0; i < map.length; i++){
var form = map[i];
blockArrange(blockM, form, i);
}
}
function blockArrange(mov, frameNumber, intervalX){ //배경 블럭 생성
var b = new mov();
addChild(b);
b.gotoAndStop(frameNumber);
b.num = frameNumber;
b.x = (0 + intervalX * 50)%500;
b.y = (0 + Math.floor(intervalX / 10) * 50);
maps2.push(b);
}
init(); |