0
개체 목록과 총알 목록이 있습니다.목록으로 충돌 감지
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 목록과의 충돌을 어떻게 확인할 수 있습니까? 사각형으로 변환 할 수있는 방법이 있습니까? 몇 시간 동안 붙어있어 정말 알아낼 수 없습니다.