package
{
import flash.display.Sprite;
import flash.events.Event;
public class Car2 extends Sprite
{
private var vs:Array = [];
public function Car2()
{
var c:int = 10;
while (c-->0) {
vs.push(new Vehicle);
}
addEventListener(Event.ENTER_FRAME, enterFrame);
}
private function enterFrame(e:Event):void
{
graphics.clear();
graphics.lineStyle(0);
for each(var v:Vehicle in vs) {
v.x += v.vx;
v.y += v.vy;
if (v.x < 0) {
v.x = 0;
v.vx = Math.abs(v.vx);
}
if (v.x > 400) {
v.x = 400;
v.vx = -Math.abs(v.vx);
}
if (v.y < 0) {
v.y = 0;
v.vy = Math.abs(v.vy);
}
if (v.y > 400) {
v.y = 400;
v.vy = -Math.abs(v.vy);
}
graphics.drawCircle(v.x, v.y, 1);
}
}
}
}
class Vehicle
{
public var x:Number = 0;
public var y:Number = 0;
public var vx:Number = 2 * Math.random();
public var vy:Number = 2 * Math.random();
public var maxSpeed:Number = 5;
public var mass:Number = 1;
}
|