Snow Test
=== Snow Test ===
This is just a snow test.
Use the arrow keys to control the wind.
(Click on the flash before it recieves key input.)
/*
=== Snow Test ===
This is just a snow test.
Use the arrow keys to control the wind.
(Click on the flash before it recieves key input.)
*/
package {
import flash.display.*;
import flash.events.*;
[SWF(backgroundColor="#444444", frameRate=30)]
public class Snow extends Sprite {
public var keyboard:Array = new Array(255);
public var windX:Number = 0;
public var windZ:Number = 0;
public var snow:Object = new Object();
public var id:Number = 0;
public var snowInt:Number = 0;
public var __bg:Sprite;
public var md:Boolean = false;
public const snowTime:Number = 10;
public const maxWindX:Number = 20;
public const maxWindZ:Number = 20;
public function Snow() {
stage.quality = StageQuality.LOW;
bg(0x444444, stage.stageWidth, stage.stageHeight);
makePlane(-stage.stageWidth, stage.stageHeight);
makePlane(0, stage.stageHeight);
makePlane(stage.stageWidth, stage.stageHeight);
makePlane(-stage.stageWidth, 0);
makePlane(0, 0);
makePlane(stage.stageWidth, 0);
makeSnow();
stage.addEventListener(Event.ENTER_FRAME, main);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
}
public function keyDown(e:KeyboardEvent):void {
keyboard[e.keyCode] = true;
}
public function keyUp(e:KeyboardEvent):void {
keyboard[e.keyCode] = false;
}
public function mouseDown(e:MouseEvent):void {
md = true;
}
public function mouseUp(e:MouseEvent):void {
md = false;
}
public function bg(color:uint, w:Number, h:Number):void {
var _bg:Sprite = new Sprite();
_bg.graphics.lineStyle(1, color, 1);
_bg.graphics.beginFill(color, 1);
_bg.graphics.lineTo(w, 0);
_bg.graphics.lineTo(w, h);
_bg.graphics.lineTo(0, h);
_bg.graphics.lineTo(0, 0);
_bg.graphics.endFill();
this.addChild(_bg);
__bg =_bg;
}
public function makeSnow():void {
var c_snow:Sprite = new Sprite();
c_snow.graphics.lineStyle(1, 0xFFFFFF, 1);
c_snow.graphics.beginFill(0xFFFFFF, 1);
c_snow.graphics.drawCircle(0, 0, 8);
c_snow.graphics.endFill();
c_snow.x = -(stage.stageWidth/2) + Math.floor(Math.random()*(stage.stageWidth*2));
c_snow.z = Math.floor(Math.random()*(stage.stageWidth*2));
c_snow.y = -c_snow.z;
this.addChild(c_snow);
snow["snow"+id] = c_snow;
id++;
}
public function makePlane(x:Number, z:Number):void {
var plane:Sprite = new Sprite();
plane.graphics.lineStyle(3, 0x000000, 1);
plane.graphics.beginFill(0x555555, 1);
plane.graphics.lineTo(stage.stageWidth, 0);
plane.graphics.lineTo(stage.stageWidth, stage.stageHeight);
plane.graphics.lineTo(0, stage.stageHeight);
plane.graphics.lineTo(0, 0);
plane.graphics.endFill();
plane.graphics.lineTo(stage.stageWidth, stage.stageHeight);
plane.graphics.moveTo(0, stage.stageHeight);
plane.graphics.lineTo(stage.stageWidth, 0);
plane.x = x;
plane.z = z;
plane.rotationX=90;
plane.y = stage.stageHeight;
this.addChild(plane);
}
public function main(e:Event = null):void {
for(var i:String in snow) {
snow[i].x += (-1 + Math.floor(Math.random()*3)) + windX;
snow[i].y += 5;
snow[i].z += (-1 + Math.floor(Math.random()*3)) + windZ;
if(snow[i].x > stage.stageWidth*1.5) {
snow[i].x = stage.stageWidth*1.5;
}
if(snow[i].x < -(stage.stageWidth/2)) {
snow[i].x = -(stage.stageWidth/2);
}
if(snow[i].z > stage.stageWidth*2) {
snow[i].z = stage.stageWidth*2;
}
if(snow[i].z < 0) {
snow[i].z = 0;
}
if(snow[i].y > stage.stageHeight-8){
snow[i].y =stage.stageHeight-8;
delete snow[i];
}
}
snowInt++;
if(snowInt > snowTime){
makeSnow();
snowInt = 0;
}
if(keyboard[37]) windX -= 1;
if(keyboard[38]) windZ += 1;
if(keyboard[39]) windX += 1;
if(keyboard[40]) windZ -= 1;
if(windX > maxWindX || windX < -maxWindX) windX = windX > 0 ? maxWindX : -maxWindX;
if(windZ > maxWindZ || windZ < -maxWindZ) windZ = windZ > 0 ? maxWindZ : -maxWindZ;
}
}
}