Kablooey!
Kablooey!
(c) 2009 Carlos Nazareno
aka Object404
http://www.object404.com
http://twitter.com/object404
go ahead, make your day!
/******************************
Kablooey!
(c) 2009 Carlos Nazareno
aka Object404
http://www.object404.com
http://twitter.com/object404
go ahead, make your day!
******************************/
package {
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import flash.utils.Timer;
// CONSTRUCTOR
public class Kablooey extends Sprite
{
private var boingCount:int = 50;
private var boings:Array = new Array();
private var boingWidth:int = 30;
private var boingHeight:int = 20;
private var bRateX:Array = new Array();
private var bRateY:Array = new Array();
private var timer:Timer;
private var xMin:Number = 0;
private var xMax:Number;
private var yMin:Number = 0;
private var yMax:Number;
private var speedMin:Number = 1;
private var speedMax:Number = 15;
public function Kablooey()
{
this.xMax = this.stage.stageWidth - boingWidth;
this.yMax = this.stage.stageHeight - boingHeight;
initBoing();
timer = new Timer(33);
timer.addEventListener(TimerEvent.TIMER, loop);
timer.start();
}
private function initBoing():void
{
var i:Number = 0;
while (i < boingCount)
{
boings[i] = new TextField();
addChild(boings[i]);
boings[i].text = "[" + i + "]";
boings[i].x = Math.floor(Math.random() * (xMax - xMin));
boings[i].y = Math.floor(Math.random() * (yMax - yMin));
bRateX[i] = Math.random() * (speedMax - speedMin) + speedMin;
bRateY[i] = Math.random() * (speedMax - speedMin) + speedMin;
i ++;
}
}
private function loop(event:TimerEvent):void
{
var i:Number = 0;
while (i < boingCount)
{
boings[i].x += bRateX[i];
boings[i].y += bRateY[i];
if (boings[i].x < xMin)
{
bRateX[i] = Math.random() * (speedMax - speedMin) + speedMin;
}
else if (boings[i].x > xMax)
{
bRateX[i] = -Math.random() * (speedMax - speedMin) + speedMin;
}
if (boings[i].y < yMin)
{
bRateY[i] = Math.random() * (speedMax - speedMin) + speedMin;
}
else if (boings[i].y > yMax)
{
bRateY[i] = -Math.random() * (speedMax - speedMin) + speedMin;
}
i ++;
}
}
}
// END CLASS
}
// END