2015-03-13 192 views
-1

有人可以告訴我這段代碼有什麼問題...如何解決這個代碼我使用這段代碼讓怪物移動到檢查點......但是所有的檢查點從22-30行得到一些警告1136 :不正確的參數數目。預計0錯誤1136:參數的數量不正確。預期0

package Game 
{ 
    import flash.display.MovieClip; 
    import flash.events.*; 
    import flash.geom.*;  

    public class Monster extends MovieClip 
    {  
     public var currLife:Number; 
     private var maxLife, gold, speed, currIndex, slowTimer:Number; 
     private var checkPoints:Array; 

     public function Monster() 
     { 
      maxLife = C.MONSTER_LIFE; 
      currLife = maxLife; 
      speed = C.MONSTER_SPEED; 

      currIndex = 0; 

      checkPoints = new Array(); 
      checkPoints.push(new Point(85,140)); 
      checkPoints.push(new Point(85,320)); 
      checkPoints.push(new Point(325,320)); 
      checkPoints.push(new Point(325,200)); 
      checkPoints.push(new Point(265,200)); 
      checkPoints.push(new Point(265,80)); 
      checkPoints.push(new Point(505,80)); 
      checkPoints.push(new Point(505,380)); 
      checkPoints.push(new Point(630,380)); 
     } 

     public function update() 
     { 
      var finalSpeed:Number; 

      if (slowTimer > 0) 
      { 
       finalSpeed = speed/2; 
       slowTimer--; 
      } 
      else 
       finalSpeed = speed; 

      if (currIndex < checkPoints.length) 
      { 
       //move in the direction of the checkpoint 
       if (this.x < checkPoints[currIndex].x) 
        this.x += Math.min(finalSpeed, Math.abs(this.x - 
               checkPoints[currIndex].x)); 
       else if (this.x > checkPoints[currIndex].x) 
        this.x -= Math.min(finalSpeed, Math.abs(this.x - 
               checkPoints[currIndex].x)); 

       if (this.y < checkPoints[currIndex].y) 
        this.y += Math.min(finalSpeed, Math.abs(this.y - 
               checkPoints[currIndex].y)); 
       else if (this.y > checkPoints[currIndex].y) 
        this.y -= Math.min(finalSpeed, Math.abs(this.y - 
               checkPoints[currIndex].y)); 

       if ((this.x == checkPoints[currIndex].x) && 
        (this.y == checkPoints[currIndex].y)) 
       { 
        currIndex += 1; 
       } 
      } 

      //display 
      if (currLife > 0) 
       mcLifeBar.width = Math.floor((currLife/maxLife)* 
                C.LIFEBAR_MAX_WIDTH); 
      else 
       mcLifeBar.width = 0; 
     } 

     public function takeDamage(amtDamage) 
     { 
      if (this.currLife <= 0) 
       return; 

      this.currLife -= amtDamage; 

      if (this.currLife <= 0) 
      { 
       this.gotoAndPlay("death"); 
      } 
     } 

     public function slowDown(amt) 
     { 
      slowTimer = amt; 
     } 

     public function hasReachedDestination() 
     { 
      return (this.currIndex == checkPoints.length); 
     } 
    } 
} 

請幫我解決這個問題......我只是在AS3一個小白

我使用該代碼在上面GameController.as ,這是更新GameController

public function update(evt:Event) 
     { 
      //Update the mobs 
      if ((currWave < maxWave) && (monsters.length == 0)) 
      { 
       currWave++; 

       //spawn the monsters 
       spawnWave(currWave); 
      } 

      for (i=monsters.length - 1; i >= 0; i--) 
      { 
       if (monsters[i].currLife > 0) 
       { 
        monsters[i].update(); 
       } 

       //Check if monster reaches the end of their path 
       if (monsters[i].hasReachedDestination()) 
       { 
        monsters[i].gotoAndStop("remove"); 
        life -= 1; 
        currGold -= C.MONSTER_GOLD; 
       } 

       if (monsters[i].currentLabel == "remove") 
       { 
        mcGameStage.removeChild(monsters[i]); 
        monsters.splice(i,1); 

        //Award Gold 
        currGold += C.MONSTER_GOLD; 
       } 
      } 

      //Update all the towers 
      for (i in towers) 
      { 
       towers[i].update(); 
      } 

      //Update all the bullets 
      for (i=bullets.length - 1; i >= 0; i--) 
      {    
       bullets[i].update(); 

       if (bullets[i].currentLabel == "remove") 
       { 
        mcGameStage.removeChild(bullets[i]); 
        bullets.splice(i,1); 
       } 
      } 

      //****************** 
      //Handle Display 
      //******************    
      //Display new Score 
      mcGameUI.txtLife.text = String(life); 
      mcGameUI.txtGold.text = String(currGold); 
      mcGameUI.txtWave.text = String(currWave) + "/" + String(maxWave); 

      //Check for end game 
      if (life <= 0) 
      { 
       gameOver(); 

       //stop all subsequent code in this update to run 
       return; 
      } 
      else if ((currWave == maxWave) && (monsters.length == 0)) 
      { 
       gameWin(); 
      } 
     } 

    private function spawnMonster(xPos, yPos) 
    { 
     var monsterToSpawn = new Monster(); 
     monsterToSpawn.x = xPos; 
     monsterToSpawn.y = yPos; 
     monsters.push(monsterToSpawn); 
     mcGameStage.addChild(monsterToSpawn); 
    } 

    private function spawnWave(currWave) 
    { 
     if (currWave == 1) 
     { 
      spawnMonster(C.MONSTER_START_X, C.MONSTER_START_Y); 
     } 
     else if (currWave == 2) 
     { 
      for (i = 0; i < 2; i++) 
      { 
       spawnMonster(C.MONSTER_START_X - 40*i, C.MONSTER_START_Y); 
      } 
     } 
} 
+0

在哪條線路上出現此錯誤?嘗試調試並找到 – ketan 2015-03-13 09:11:17

+0

從行checkPoints.push(新Point(85,140))開始;直到checkPoints.push(新點(630,380));全部都有錯誤1136:參數的數量不正確。預計0. @ketan ...你能告訴我這有什麼問題? – 2015-03-13 09:15:57

+0

沒有。沒有什麼像錯誤。 C.MONSTER_LIFE中'c'是什麼意思? – ketan 2015-03-13 09:19:19

回答

1

您好我不明白爲什麼你收到此錯誤,但是這可以幫助你,

嘗試後續代碼,而不是點();

var checkPoints:Array=new Array({x:85,y:140}, 
      {x:85,y:320}, 
      {x:325,y:320}, 
      {x:325,y:200}, 
      {x:265,y:200}, 
      {x:265,y:80}, 
      {x:505,y:80}, 
      {x:505,y:380}, 
      {x:630,y:380} 
      ); 
+0

謝謝,先生@mdemir它的工作 – 2015-03-13 11:13:25

相關問題