/* */ package { import flash.display.Sprite; public class prize extends Sprite { private var mySymbol : prizeSymbol; private var myBangSymbol : prizeBangSymbol; private var vx, vy:Number; private var prizeMode:int; //0=>normal, 1=>celebrate! private const youSpeed = 30; // how fast the enemy moves // constructor. makes platform appear in the right place public function prize(myX, myY: Number) { mySymbol = new prizeSymbol(); mySymbol.x = myX; mySymbol.y = myY; addChild(mySymbol); myBangSymbol = new prizeBangSymbol(); myBangSymbol.x = myX - 10000.0; myBangSymbol.y = myY; addChild(myBangSymbol); vx = (Math.random()-0.5)*12; vy = (Math.random()-0.5)*12; } // call this function every frame to move the enemy public function touched(playerX, playerY:Number):int { var dx, dy:Number; // use pythagorean theorem to detect touches dx = mySymbol.x - playerX; dy = mySymbol.y - playerY; if (Math.sqrt(dx*dx+dy*dy)<20) { return 1; } return 0; } // call this function every frame to move the enemy public function explode():void { prizeMode = 1; myBangSymbol.x = mySymbol.x; myBangSymbol.y = mySymbol.y; mySymbol.x = -2000; } // call this function every frame to move the enemy public function updater():void { if (prizeMode==0) { if (Math.random()<0.1) { vx = (Math.random()-0.5)*12; vy = (Math.random()-0.5)*12; } mySymbol.x += vx; mySymbol.y += vy; } else { myBangSymbol.x += vx myBangSymbol.y += vy; } } } }