public void updatestars(GameTime gameTime)
{
foreach (Gameobjects star in Stars)
{
if (star.Alive)
{
star.Position += star.Velocity;
if (!Viewportrect.Contains(new Point
((int)star.Position.X,
(int)star.Position.Y)))
{
star.Alive = false;
}
}
else
{
if (elapsedtime > 4)
{
elapsedtime = gameTime.TotalRealTime.Seconds - elapsedtime;
previouselapsedtime = gameTime.TotalRealTime.Seconds;
star.Alive = true;
star.Position = new Vector2(Viewportrect.Right,
MathHelper.Lerp(
(float)Viewportrect.Height * starminheight,
(float)Viewportrect.Height * starmaxheight,
(float)random.NextDouble()));
star.Velocity = new Vector2(MathHelper.Lerp(
-starminvelocity,
-starmaxvelocity,
(float)random.NextDouble()), 0);
star.Rotation = (float)random.Next(0, 4);
star.Size = (float)random.Next(1,3);
switch (random.Next(0, 2))
{
case 0:
star.ObjectColor = Color.White;
break;
case 1:
star.ObjectColor = Color.Gold;
break;
case 2:
star.ObjectColor = Color.Lime;
break;
}
}
else
{
elapsedtime = gameTime.TotalRealTime.Seconds - previouselapsedtime;
}
}
}
}
|