2017-07-26 118 views
-1

我试图使用flashDevelop和starling制作瓷砖阵列系统。 我想我完成了,但我不明白我是如何使界限,瓦阵列和我的英雄相交。 请注意,我使用互联网上的教程,而不是沿着它。as3八哥瓷砖阵列

这里有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?

+0

嗨Savvas蚂蚁,不幸的是,这个问题目前不是很适合Stackoverflow格式;它包含太多不相关的代码。它也不能确定代码的哪一部分与你所要求的相关。请[编辑]您的问题,将其重点放在您正在努力解决的代码基本部分上,并澄清您想知道的内容。 – Brian

+0

请参阅https://stackoverflow.com/help/how-to-ask&https://stackoverflow.com/help/mcve – Atriace

回答

0

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

+0

你能解释一下吗? –