home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Puzzle
/
HexiomConnect.swf
/
scripts
/
Background.as
< prev
next >
Wrap
Text File
|
2008-08-29
|
5KB
|
181 lines
package
{
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
public class Background extends Sprite
{
public static var GREEN:ColorTransform;
private static var StarField:Class = Background_StarField;
public static var ORANGE:ColorTransform;
public static var RED:ColorTransform;
public static var BLUE:ColorTransform;
public static var YELLOW:ColorTransform;
public var matrix:Matrix;
public var lq:Boolean = false;
public var speed:Number;
public var stars:Array;
public var from:ColorTransform;
public var progress:Number;
public var playing:Boolean = true;
public var targetSpeed:Number;
public var current:ColorTransform;
public var to:ColorTransform;
public function Background()
{
var _loc3_:DisplayObject = null;
super();
progress = 1;
from = new ColorTransform();
to = new ColorTransform();
current = new ColorTransform();
BLUE = new ColorTransform();
RED = new ColorTransform();
GREEN = new ColorTransform();
YELLOW = new ColorTransform();
ORANGE = new ColorTransform();
BLUE.color = 73095;
RED.color = 8912896;
GREEN.color = 2254370;
YELLOW.color = 12303138;
ORANGE.color = 11171635;
from.color = to.color = current.color = BLUE.color;
speed = 1;
targetSpeed = 1;
stars = new Array();
var _loc1_:int = 0;
while(_loc1_ < 10)
{
_loc3_ = new StarField();
_loc3_.scaleX = _loc3_.scaleY = _loc1_ / 10 * 3;
_loc3_.rotation = Math.random() * 360;
_loc3_.x = _loc3_.y = 200;
stars.push(_loc3_);
addChild(_loc3_);
_loc1_++;
}
matrix = new Matrix();
var _loc2_:Number = 400 * Math.sqrt(2);
matrix.createGradientBox(_loc2_,_loc2_,0,(400 - _loc2_) / 2,(400 - _loc2_) / 2);
draw();
addEventListener(Event.ENTER_FRAME,update,false,0,true);
}
public function draw() : void
{
var _loc1_:Graphics = this.graphics;
_loc1_.clear();
_loc1_.beginGradientFill("radial",[current.color,0],[1,1],[0,255],matrix);
_loc1_.moveTo(0,0);
_loc1_.lineTo(0,400);
_loc1_.lineTo(400,400);
_loc1_.lineTo(400,0);
_loc1_.lineTo(0,0);
_loc1_.endFill();
}
public function update(param1:Event) : void
{
var _loc3_:DisplayObject = null;
if(!playing)
{
return;
}
if(speed != targetSpeed)
{
if(speed < targetSpeed)
{
speed = Math.min(targetSpeed,speed + 0.05);
}
else
{
speed = Math.max(targetSpeed,speed - 0.05);
}
}
if(progress < 1)
{
progress += 0.05;
updateColor();
}
if(lq)
{
return;
}
var _loc2_:int = 0;
while(_loc2_ < stars.length)
{
_loc3_ = stars[_loc2_];
_loc3_.rotation += 0.01 * speed;
_loc3_.scaleX -= 0.003 * speed;
_loc3_.scaleY -= 0.003 * speed;
if(_loc3_.scaleX < 0.05)
{
_loc3_.scaleX = _loc3_.scaleY = 3;
}
_loc2_++;
}
}
public function updateColor() : void
{
current = interpolateColor(from,to,progress);
draw();
}
public function interpolateColor(param1:ColorTransform, param2:ColorTransform, param3:Number) : ColorTransform
{
var _loc4_:Number = param1.redOffset + (param2.redOffset - param1.redOffset) * param3;
var _loc5_:Number = param1.greenOffset + (param2.greenOffset - param1.greenOffset) * param3;
var _loc6_:Number = param1.blueOffset + (param2.blueOffset - param1.blueOffset) * param3;
return new ColorTransform(0,0,0,1,_loc4_,_loc5_,_loc6_);
}
public function setColor(param1:ColorTransform) : void
{
progress = 0;
from.color = current.color;
to.color = param1.color;
targetSpeed = 1;
updateColor();
}
public function setDifficulty(param1:Number) : void
{
progress = 0;
from.color = current.color;
if(param1 < 0)
{
to.color = GREEN.color;
}
else
{
to = interpolateColor(BLUE,RED,param1);
}
targetSpeed = Math.max(1,1 + param1 * 2);
updateColor();
}
}
}