| 1 |
class Bullet { |
|---|
| 2 |
private static var tmr:Number; |
|---|
| 3 |
private static var bullets:Array; |
|---|
| 4 |
|
|---|
| 5 |
private static function register(bullet:Bullet):Void { |
|---|
| 6 |
if(bullets == null) { |
|---|
| 7 |
bullets = new Array(); |
|---|
| 8 |
tmr = setInterval(function(){ |
|---|
| 9 |
for(var i = 0; i < bullets.length; i++) { |
|---|
| 10 |
if(bullets[i].tick.apply(bullets[i])) { |
|---|
| 11 |
bullets[i].dispose(); |
|---|
| 12 |
delete bullets[i]; |
|---|
| 13 |
bullets = bullets.slice(0, i).concat(bullets.slice(i+1)); |
|---|
| 14 |
} |
|---|
| 15 |
} |
|---|
| 16 |
if(bullets.length === 0) { |
|---|
| 17 |
clearInterval(tmr); |
|---|
| 18 |
bullets = null; |
|---|
| 19 |
} |
|---|
| 20 |
}, 25); |
|---|
| 21 |
} |
|---|
| 22 |
bullets.push(bullet); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
private var mc:MovieClip; |
|---|
| 26 |
|
|---|
| 27 |
public function Bullet(parent:MovieClip, init:Object) { |
|---|
| 28 |
this.mc = parent.attachMovie('bullet', 'bullet_mc_' + parent.getNextHighestDepth(), parent.getNextHighestDepth(), init); |
|---|
| 29 |
register(this); |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
public function tick():Boolean { |
|---|
| 33 |
return (this.mc._y -= 2) < -5; |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
public function dispose():Void { |
|---|
| 37 |
this.mc.removeMovieClip(); |
|---|
| 38 |
} |
|---|
| 39 |
} |
|---|