BP Forums
Remove Enemy [Game Issue] - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9)
+----- Thread: Remove Enemy [Game Issue] (/showthread.php?tid=566)



Remove Enemy [Game Issue] - Vinwarez - 07-14-2012

When you hit an enemy, it removes from the screen, but if you shoot at the position it was, you will still get score. I need help removing it from the screen FOREVER.

Here is the code:
Code:
'TODO: Check for collisions with enemies here
If bullet.Bounds.IntersectsWith(Me.enemy.Bounds) Then
    bulletsToRemove.Add(bullet)
    Controls.Remove(enemy)
    Score += 5
End If



Re: Remove Enemy [Game Issue] - brandonio21 - 07-14-2012

Well, just like the player's bullets, for the enemy you need to setup an array and scroll through the array to check for collisions.

However, if you don't want to do that, and you have only one enemy, you can simply say..

Code:
'TODO: Check for collisions with enemies here
If bullet.Bounds.IntersectsWith(Me.enemy.Bounds) AndAlso Me.Controls.Contains(enemy) Then
    bulletsToRemove.Add(bullet)
    Controls.Remove(enemy)
    Score += 5
End If

So this makes it so before we check for collisions, we make sure that the enemy actually exists inside of the form.


Re: Remove Enemy [Game Issue] - Vinwarez - 07-14-2012

Alright. There will be multiple enemies, but I am testing stuff with only one before I add more.

Thank you!


Re: Remove Enemy [Game Issue] - brandonio21 - 07-14-2012

No problem!