AS3 椋鸟瓷砖阵列



我试图使用flashDevelop和starling制作一个瓦片阵列系统。 我想我完成了,但我不明白我是如何在瓷砖数组和我的英雄之间划定界限、相交的。 请注意,我使用互联网上的教程而不是一起使用。

以下是 2 类

public class level1 extends Sprite 
{
public var map:Array = [
[1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1],
];
//public var object:Image;
//public var data:int;

public function level1() 
{
super();
this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAdd);
}
private function onAdd(event:Event):void
{
drawScreen(map, 90);
}
public function drawScreen(map:Array, cellSize:int = 90):void
{
for(var row:int = 0; row < map.length; row++)
{
for(var column:int = 0; column < map[row].length; column++)
{
var data:int = map[row][column];
// Empty tile, move onto the next item.
if(data == 0) continue;
var object:Image;
if (data == 1) object = new Image(Assets.getTexture("ESAYBTN"));
if (data == 2) object = new Image(Assets.getTexture("TITLE"));
if(object != null)
{
object.x = column * 94;
object.y = row * 29;
stage.addChild(object);
}
}
}
}
}

public class inGame extends Sprite 
{
public var Hero:heroClass;
private var enem2:enemy2Class;
private var enemiesArray:Vector.<enemy2Class>;
private var posX:int;
private var posY:int;
private var hitpoints:int;
private var _level1:level1;
public function inGame() 
{
super();
this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAdd);
}
private function onAdd(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAdd);
enemiesArray = new Vector.<enemy2Class>();
drawScreen();
}
private function drawScreen():void
{

Hero = new heroClass(50, 50, 1);
this.addChild(hero);
_level1 = new level1();
this.addChild(_level1);
createenemies(450, 50, 6);
createenemies(400, 50, 5);
createenemies(350, 50, 4);
createenemies(300, 50, 3);
createenemies(250,50, 2);
}
public function createenemies(posX:int, posY:int, hitpoints:int):void
{
var enemies:enemy2Class = new enemy2Class(posX,posY,hitpoints);
this.addChild(enemies);
enemiesArray.push(enemies);
}
public function hideInGame():void
{
this.visible = false;
}
public function showInGame():void
{
this.visible = true;
this.addEventListener(Event.ENTER_FRAME, gameLoop);
}
private function gameLoop(Event):void
{
var enemiestoloop:enemy2Class;
for (var i:uint = 0; i < enemiesArray.length; i++)
{
enemiestoloop = enemiesArray[i];
//enemiestoloop.x-=2;
if (enemiestoloop.bounds.intersects(enem.bounds))
{
enemiestoloop.x = 400;
enemiestoloop._hitpoints--;
}
if (enemiestoloop._hitpoints <= 0)
{
enemiesArray.splice(i, 1);
this.removeChild(enemiestoloop);
}
}
hero.y++;
if(hero.bounds.intersects("here goes the map???"))
{
hero.y--;
}
}
}

那么如果英雄击中了地图数组对象 1,我该怎么写呢?

将磁贴数组的所有部分添加到单个显示对象,然后只需调用单个显示对象上的相交边界。

最新更新