我的代码有一个小问题。我想链接所有三个类来制作一个简单的平台游戏。这是代码:
数组类:
package
{
import flash.display.*;
public dynamic class setupStage extends Thiny
{
var mapWid = 24;
var mapHei = 40;
var tileSide = 10;
var totalTiles = mapWid * mapHei;
var cell:tile=new tile();
var firstStage:Array=[
/*1*/[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
/*2*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1]
/*3*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1]
/*4*/[1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1]
/*5*/[1,0,0,0,1,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,1]
/*6*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
/*7*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
/*8*/[1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1]
/*9*/[1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1]
/*10*/[1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1]
/*11*/[1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1]
/*12*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
/*13*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
/*14*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1]
/*15*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
/*16*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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0,0,0,0,0,0,0,0,0,0,0,1]
/*36*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
/*37*/[1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
/*38*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
/*39*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
/*40*/[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];
function setupStage()
{
trace("access granted");
}
function drawMap():void
{
for (var i:int=0; i<mapWid; i++)
{
for (var u:int=0; u<mapHei; u++)
{
cell.gotoAndStop(firstStage[i][u]+1);
cell.x = tileSide * i;
cell.y = tileSide * u;
with (stage)
{
stage.addChild(cell);
}
}
}
}
}
}
运动类:
package
{
import flash.display.*;
import flash.utils.*;
import flash.events.*;
import flash.sampler.StackFrame;
public dynamic class JAJEBIE extends Thiny{
var granica:setupStage = new setupStage();
var thinX = 0;
var thinY = 0;
var acc = 6;
var thin:thiny1 = new thiny1();
var przycisk:Object = {};
stage.addEventListener(KeyboardEvent.KEY_DOWN,Move);
stage.addEventListener(KeyboardEvent.KEY_UP,Halt);
//with (thin){addEventListener(Event.ENTER_FRAME,Opadanie);}
function wrzut():void
{
addChild(thin);
thin.x = 200;
thin.y = 390;
}
function Move(k:KeyboardEvent):void
{
przycisk[k.keyCode] = true;
if (przycisk[Keyboard.LEFT] && granica.firstStage[thinX][thinY] == 0 && granica.firstStage[thinX - 1][thinY] == 0)
{
thin.x = thin.x - 10;
}
if (przycisk[Keyboard.RIGHT] && granica.firstStage[thinX][thinY] == 0 && granica.firstStage[thinX - 1][thinY] == 0)
{
thin.x = thin.x + 10;
}
if (przycisk[Keyboard.SPACE])
{
acc = 3;
thin.y = thin.y + 30;
}
}
//function Opadanie(Event);
//{
//thin.y = thin.y - 30;
//}
function Halt(k:KeyboardEvent):void
{
przycisk[k.keyCode] = false;
}
}
}
主fla文件:
stop();
import flash.events.Event;
import flash.display.DisplayObject;
import flash.utils.*;
import flash.events.*;
import flash.sampler.StackFrame;
stage.addEventListener(Event.ENTER_FRAME,initialize);
function initialize(main_event:Event):void{
with(setupStage){drawMap();};
with(JAJEBIE){wrzut();};
stage.removeEventListener(Event.ENTER_FRAME,initialize);
}
我们尝试了很多东西,但编译器一直抛出错误,即使我们设法删除了所有代码问题,主类似乎不想修补所有内容。任何帮助,将不胜感激!谢谢!