Basically, i'm creating a space invaders like-game that is 2D Mario-themed (sprites used).
I am using a panel for my enemies and Mario is being controlled by the movement of arrow keys and space button shoots.
The problem is I can not make my bullets collide with the enemies to make them disappear.
This piece of code is what i've got so far with the collision detection :
'*******************************************************************************************************
' Collision occurs whenever the pctShoot(podoboo) hits any of the enemy
' When blnTrue, both pctShoot and the enemy disappear '*******************************************************************************************************
Private Sub tmrCollisionDetect_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCollisionDetect.Tick
'****************************************************************************************
'Current method using; no collision occurs
'not positive on what ctlEnemy is suppose to be (a single picturebox or the panel (?))
'purpose of the tags are like "health" when they reach to zero, enemy disappears
' ->purpose of this function is to help the timing issue
'time interval set to 1
'***************************************************************************************
Dim rect As New Rectangle
Dim intScore As Integer
Dim ctlEnemy As Control = pnlEnemies
For Each c As Control In pnlEnemies.Controls 'all picture boxes in the panel are controlled
If TypeOf c Is PictureBox Then 'and "c" is a picture box in the panel
If pnlEnemies.Visible = True AndAlso pctBullet.Visible = True AndAlso rect.IntersectsWith(pctBullet.Bounds) Then
pnlEnemies.Tag = CType(pnlEnemies.Tag, Integer) - 1 'converts the tag to integer to claim an enemies "health"
blnCollison = True 'collision happens
pctBullet.Visible = False 'bullet disappears
If CInt(pnlEnemies.Tag) <= 0 Then 'when enemies health reaches 0 or lower
blnCollison = True 'collision activated
c.Visible = False 'enemy disappears
intScore = intScore + 100 'score accumulated by 100
End If
End If
End If
Next
Me.lblScore.Text = intScore 'score becomes updated
'*****************************************************************************************
'Last method used, it works but when playing, the bullet doesn't hit exactly on the enemy
' -> bullet hits enemy from one side, the collision occurs on the opposite side
' ->said to be due to a timing issue
'*****************************************************************************************
'For Each c As Control In pnlEnemies.Controls 'all picture boxes in the panel are controlled
' If TypeOf c Is PictureBox Then
' If pctBullet.Visible And c.Visible Then
' If c.Bounds.IntersectsWith(pctBullet.Bounds) Then
' blnCollison = True 'Collsion is true
' c.Visible = False
' Else
' blnCollison = False
' c.Visible = True
' End If
' End If
' End If
'Next
End Sub
While I'm at it, i have another question in concern; but this is not really related to collision but:
How do you make an object move down automatically using a timer but make it appear randomly??
Like any space invader game, the enemies are shooting back at the hero to make it appear more challenging right?
Any help is appreciative! Please and THANK YOUS IN ADVANCE!
(using Visual Basic 2008)

New Topic/Question
Reply




MultiQuote




|