| 1 | package hatesuta { |
|---|
| 2 | import flash.display.Sprite; |
|---|
| 3 | import flash.events.Event; |
|---|
| 4 | import sketchbook.colors.ColorSB; |
|---|
| 5 | import flash.geom.Point; |
|---|
| 6 | import caurina.transitions.Tweener; |
|---|
| 7 | import flash.utils.setTimeout; |
|---|
| 8 | import flash.filters.DropShadowFilter; |
|---|
| 9 | public class FallingStars extends Sprite { |
|---|
| 10 | public var size:Number; |
|---|
| 11 | public var color:uint; |
|---|
| 12 | public var length:uint; |
|---|
| 13 | public var delay:Boolean = true; |
|---|
| 14 | |
|---|
| 15 | public var stars:Array = []; |
|---|
| 16 | public function FallingStars(x:Number, y:Number, size:Number, color:uint, length:uint) { |
|---|
| 17 | this.x = x; |
|---|
| 18 | this.y = y; |
|---|
| 19 | this.size = size; |
|---|
| 20 | this.color = color; |
|---|
| 21 | this.length = length; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | public function createStars():void { |
|---|
| 25 | var csb:ColorSB = new ColorSB(color); |
|---|
| 26 | var star:Star; |
|---|
| 27 | for (var i:uint = 0; i < length; i++) { |
|---|
| 28 | star = new Star(); |
|---|
| 29 | star.rotation = Math.random() * 50; |
|---|
| 30 | var iSize:Number = size * (1 + i * 0.25); |
|---|
| 31 | var margin:Number = i * (iSize * 2.5); |
|---|
| 32 | star.x = -margin; |
|---|
| 33 | star.y = margin; |
|---|
| 34 | star.drawStar(csb.value, iSize); |
|---|
| 35 | colorRotate(csb); |
|---|
| 36 | stars.push(star); |
|---|
| 37 | addChild(star); |
|---|
| 38 | } |
|---|
| 39 | var p:Point = star.localToGlobal(new Point(star.x , star.y)); |
|---|
| 40 | var self:FallingStars = this; |
|---|
| 41 | var delayTime:uint = 0; |
|---|
| 42 | if (delay) { |
|---|
| 43 | delayTime = Math.random() * 200; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | setTimeout(function():void { |
|---|
| 47 | Tweener.addTween(self, { |
|---|
| 48 | x: x + p.y + (Math.random() * 500 - 250), |
|---|
| 49 | y: y - p.y - 200, |
|---|
| 50 | transition: 'easeInSine', |
|---|
| 51 | time:3 |
|---|
| 52 | }); |
|---|
| 53 | }, delayTime); |
|---|
| 54 | self.addEventListener(Event.ENTER_FRAME, enterFrameHandler); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | public function colorRotate(csb:ColorSB):void { |
|---|
| 58 | csb.hue += 15; |
|---|
| 59 | csb.saturation += 15; |
|---|
| 60 | // csb.brightness += 5; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | public static var zeroPoint:Point = new Point(0, 0); |
|---|
| 64 | private function enterFrameHandler(e:Event):void { |
|---|
| 65 | //x += size; |
|---|
| 66 | //y -= size; |
|---|
| 67 | var star:Star; |
|---|
| 68 | for (var i:uint = 0; i < stars.length; i++) { |
|---|
| 69 | star = stars[i]; |
|---|
| 70 | star.rotation += 10; |
|---|
| 71 | } |
|---|
| 72 | if(star.localToGlobal(FallingStars.zeroPoint).y < -(star.height / 2)) { |
|---|
| 73 | destroy(); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | public function destroy():void { |
|---|
| 78 | parent.removeChild(this); |
|---|
| 79 | removeEventListener(Event.ENTER_FRAME, enterFrameHandler); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | public function fail():void { |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|