【发布时间】:2014-12-03 15:32:33
【问题描述】:
我得到了一个名为对象的敌人列表和一个子弹列表。
private List<enemyObjects> objects = new List<enemyObjects>();
list 对象在 Game1 类中。
我用这个方法在列表中添加和删除敌人:
public void LoadEnemies() {
int Y = 100;
if (spawn >= 1)
{
spawn = 0;
if (objects.Count() < 4)
objects.Add(new enemyObjects(Content.Load<Texture2D>("obstacle"), new Vector2(1100, Y)));
}
for (int i = 0; i < objects.Count; i++)
{
if (!objects[i].isVisible)
{
//If the enemy is out of the screen delete it
objects.RemoveAt(i);
i--;
}
}
}
我还得到了一个子弹列表:public List<Bullet> bullets = new List<Bullet>();
我发射子弹的方法:
private void ShootFireBall() {
if (mCurrentState == State.Walking)
{
bool aCreateNew = true;
foreach (Bullet aBullet in bullets)
{
if (aBullet.bulletVisible == false)
{
aCreateNew = false;
aBullet.Fire(position + new Vector2(Size.Width / 2, Size.Height / 2),
new Vector2(200, 0), new Vector2(1, 0));
}
}
if (aCreateNew)
{
Bullet aBullet = new Bullet();
aBullet.LoadContent(contentManager, "bullet");
aBullet.Fire(position + new Vector2(Size.Width / 2, Size.Height / 2),
new Vector2(200, 0), new Vector2(1, 0));
bullets.Add(aBullet);
}
}
}
问题是我需要一个矩形,所以我可以检查是否有碰撞。 如何检查与 2 个列表的冲突? 有什么办法可以将其转换为矩形? 卡在这个问题上几个小时了,真的想不通。
【问题讨论】: