简体   繁体   中英

Collision isn't working properly?

I'm working on a survival like game and i have two types of collision, 1 being enemies on the player and bullet on the enemies. I also have a health bar and for some reason after the picbox is removed the health still goes down like the enemies are interacting with the player.

private void checkbulletcollsion()
{
    for (int i = 0; i < bulletlistupright.Count; i++)
    {
        for (int u = 0; u < infectedlistdownleft.Count; u++)
        {
            if (bulletlistupright[i].Bounds.IntersectsWith(infectedlistdownleft[u].Bounds))
            {
                this.Controls.Remove(infectedlistdownleft[u]);
                this.Controls.Remove(bulletlistupright[i]);
            }
        }
    }
}

this is one block of the code for the bullet collision (all the code is the same for all 8 directions)

for (int i = 0; i < infectedlistupright.Count; i++)
{
    if (infectedlistupright[i].Bounds.IntersectsWith(picplayer.Bounds))
    {
        infectedcount6 = 0;

        if (infectedcounter % 15 == 0)
        {
            health--;
        }

        infectedcounter++;
    }                
}

this is the code for the collision between the enemy and the player

即使您删除了UI控件,也没有将其从infectedlist*数组中删除。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM