package { import flash.display.Sprite; import flash.display.Bitmap; import flash.geom.Point; import flash.geom.Rectangle; /** * ... * @author R J Morris */ public class Target extends Sprite { [Embed(source="/Assets/blinker1.gif")] public var blinker1Image:Class; [Embed(source="/Assets/blinker2.gif")] public var blinker2Image:Class; private var p1:Point; private var img1:Bitmap; private var img2:Bitmap; public function Target(parentSprite:Sprite,x:Number,y:Number) { this.x = x; this.y = y; p1 = new Point(this.x, this.y); parentSprite.addChild(this); img1 = new blinker1Image() as Bitmap; img1.x = - 2; img1.y = - 2; addChild( img1 ); img2 = new blinker2Image() as Bitmap; img2.x = - 2; img2.y = - 2; } private var count:int = 0; public function hit(ball:Ball):Boolean { ++count; if (count == 10) { this.removeChild(img1); this.addChild(img2); } if (count == 20) { this.removeChild(img2); this.addChild(img1); count = 0; } var rad:Number = 2; var minx:Number = ball.x < ball.lastx ? ball.x : ball.lastx; var miny:Number = ball.y < ball.lasty ? ball.y : ball.lasty; var maxx:Number = ball.x > ball.lastx ? ball.x : ball.lastx; var maxy:Number = ball.y > ball.lasty ? ball.y : ball.lasty; var rect:Rectangle = new Rectangle(minx - rad, miny - rad, maxx-minx + rad, maxy-miny + rad); var flag:Boolean = rect.containsPoint(p1); rect.offset( -395, -127); if ((ball.x > 380 && ball.x < 410) && (ball.y > 112 && ball.y < 142)) trace(rect.toString()); // trace("(" + ball.x + "," + ball.y + "," + ball.lastx + "," + ball.lasty + ")"); return flag; //return (Point.distance(p1, p2) < 2); } } }