如何使我的项目符号从X轴开始到y轴随机化+3 -3像素
public void UpdateBullets()
{
//For each bullet in our bulletlist: Update the movment and if the bulet hits side of the screen remove it form the list
foreach(Bullet bullet in bulletList)
{
//set movment for bullet
bullet.position.X = bullet.position.X + bullet.speed;
//if bullet hits side of screen, then make it visible to false
if (bullet.position.X >= 800)
bullet.isVisible = false;
}
//Go thru bulletList and see if any of the bullets are not visible, if they aren't then remove bullet form bullet list
for (int i = 0; i < bulletList.Count; i++)
{
if(!bulletList[i].isVisible)
{
bulletList.RemoveAt(i);
i--;
}
}
}当我按住空格键的时候,只要往前走就行了,我也想让它一点一点地沿Y轴飞来飞去。
这是我想要做的http://www.afrc.af.mil/shared/media/photodb/photos/070619-F-3849K-041.JPG。
永远不要只在一个点上击球。只是为了让Y轴随机化一点。我想要改变的是
//set movment for bullet
bullet.position.X = bullet.position.X + bullet.speed;类似这样的东西
BUllet.position.X = Bullet.position.X + Bullet.random.next(-3,3).Y + bullet.speed.差不多吧。
发布于 2014-09-02 08:18:21
您需要为表示y轴随时间变化的每个项目符号定义一个常量值:
更改你的Bullet类
public Class Bullet
{
// ....
public int Ychange;
System.Random rand;
public Bullet()
{
// ....
rand = new Random();
Ychange = rand.Next(-3, 3);
}
// Add the above stuff to your class and constructor
}新的UpdateBullets方法
public void UpdateBullets()
{
//For each bullet in our bulletlist: Update the movment and if the bulet hits side of the screen remove it form the list
foreach(Bullet bullet in bulletList)
{
//set movment for bullet
bullet.position.X += bullet.speed;
bullet.position.Y += bullet.Ychange;
// Above will change at a constant value
//if bullet hits side of screen, then make it visible to false
if (bullet.position.X >= 800)
bullet.isVisible = false;
}
//Go thru bulletList and see if any of the bullets are not visible, if they aren't then remove bullet form bullet list
for (int i = 0; i < bulletList.Count; i++)
{
if(!bulletList[i].isVisible)
{
bulletList.RemoveAt(i);
i--;
}
}
}这应该是可行的。
https://stackoverflow.com/questions/25611404
复制相似问题