我正在制作一个java游戏,其中有随机掉落的点都连接在一起,形成无限的曲折。我已经在AS3中做过了,但我被困在需要连接点的地方。这是我的AS3代码:
package
{
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class FallingThings extends Sprite
{
// set width
private var w:Number = 0;
// set height
private var h:Number = 0;
private var objectSpawner:Timer;
private var fallers:Array;
private var speed:Number = 10;
public function FallingThings(w:Number, h:Number)
{
this.w = w;
this.h = h;
init();
}
private function init():void
{
fallers = [];
objectSpawner = new Timer(1000);
objectSpawner.addEventListener(TimerEvent.TIMER, createEnemy);
objectSpawner.start();
addEventListener(Event.ENTER_FRAME, dropEnemies);
}
private function createEnemy(e:TimerEvent):void
{
var enemy:Faller = new Faller();
enemy.y = -h;
enemy.x = Math.random() * w;
MovieClip(enemy).cacheAsBitmap = true;
addChild(enemy);
fallers.push(enemy);
drawConnectors();
}
private function dropEnemies(e:Event):void
{
for each (var mc:Faller in fallers)
{
mc.y += speed;
if (mc.y > h * 2)
fallers.splice(fallers.indexOf(removeChild(mc)), 1);
}
drawConnectors();
}
private function drawConnectors():void
{
if (fallers.length == 0)
return;
var g:Graphics = this.graphics;
g.clear();
g.lineStyle(10,0xFFFFFF);
var mc:Faller = fallers[0];
g.moveTo(mc.x, mc.y);
for each (mc in fallers)
g.lineTo(mc.x, mc.y);
import flash.events.Event;
}
}
}