私はJavaScriptを使ってゲームを作っています。私は、垂直方向に移動し、ランダムなx
ポジションを選んだ小惑星を1つ作成しました。複数の小惑星をコード化した後、どうすればいいですか?
どのようにランダムな開始点を選ぶ複数の小惑星を作成できますか?
//create asteroid
asteroid={
x:width/2,
y:-6,
min:1.6,
max:2.2,
speed:1.6
}
// move asteroid
if(asteroid.y<height){
asteroid.y+=asteroid.speed;
}else{
asteroid.y=-6;
asteroid.x=Math.random()*(width-0)-0;
}
//draw asteroid
ctx.beginPath();
ctx.fillStyle = "#D9BA5F";
ctx.arc(asteroid.x, asteroid.y,3,0,2*Math.PI,false);
ctx.closePath();
ctx.fill();
これは5つの票を得ます...ハァッ。 –