r/visualbasic • • May 02 '22
VB.NET Help having troubles figuring this out (I'll put the related code in the comments)
Enable HLS to view with audio, or disable this notification
8
Upvotes
r/visualbasic • • May 02 '22
Enable HLS to view with audio, or disable this notification
3
u/sa_sagan VB.Net Master May 02 '22
What exactly are you having problems figuring out?
1
u/[deleted] May 02 '22
Code:
Dim playerGunner As Boolean = False
Dim playerLeft As Boolean = False
Dim playerRight As Boolean = False
Dim playerUp As Boolean = False
Dim playerDown As Boolean = False
Dim bullet1 As Boolean = False
Dim bullet2 As Boolean = False
Dim bullet3 As Boolean = False
Dim bullet4 As Boolean = False
Case Keys.Space
If playerGunner = True Then
If picBullet1.Visible = False Then
bullet1 = True
CentreOn(picChar, picBullet1)
picBullet1.Visible = True
tmrBullet.Enabled = True
picAmmo1.Visible = False
ElseIf picBullet1.Visible = True And
picBullet2.Visible = False Then
bullet2 = True
CentreOn(picChar, picBullet2)
picBullet2.Visible = True
tmrBullet.Enabled = True
picAmmo2.Visible = False
ElseIf picBullet1.Visible = True And
picBullet2.Visible = True And
picBullet3.Visible = False Then
bullet3 = True
CentreOn(picChar, picBullet3)
picBullet3.Visible = True
tmrBullet.Enabled = True
picAmmo3.Visible = False
ElseIf picBullet1.Visible = True And
picBullet2.Visible = True And
picBullet3.Visible = True And
picBullet4.Visible = False Then
bullet4 = True
CentreOn(picChar, picBullet4)
picBullet4.Visible = True
tmrBullet.Enabled = True
picAmmo4.Visible = False
End If
End If
Private Sub tmrBullet_Tick(sender As Object, e As EventArgs) Handles tmrBullet.Tick
If playerRight = True Then
If bullet1 = True Then
picBullet1.Left += 20
End If
If bullet2 = True Then
picBullet2.Left += 20
End If
If bullet3 = True Then
picBullet3.Left += 20
End If
If bullet4 = True Then
picBullet4.Left += 20
End If
End If
If playerLeft = True Then
If bullet1 = True Then
picBullet1.Left -= 20
End If
If bullet2 = True Then
picBullet2.Left -= 20
End If
If bullet3 = True Then
picBullet3.Left -= 20
End If
If bullet4 = True Then
picBullet4.Left -= 20
End If
End If
If playerUp = True Then
If bullet1 = True Then
picBullet1.Top -= 20
End If
If bullet2 = True Then
picBullet2.Top -= 20
End If
If bullet3 = True Then
picBullet3.Top -= 20
End If
If bullet4 = True Then
picBullet4.Top -= 20
End If
End If
If playerDown = True Then
If bullet1 = True Then
picBullet1.Top += 20
End If
If bullet2 = True Then
picBullet2.Top += 20
End If
If bullet3 = True Then
picBullet3.Top += 20
End If
If bullet4 = True Then
picBullet4.Top += 20
End If
End If
End Sub
Edit: just so u know this is in different private subs in case its not obvious
1
u/RJPisscat May 02 '22
Where's the code?
1
u/[deleted] May 02 '22
You call this a bug, I call it the last bullet bender. Based on that code, well, you should store the directions of each bullet fired because you make them go in the direction the player is facing right now. You can simplify the code by making a Dim bullet1dir As Integer, Dim bullet2dir As Integer and inside these if Bullet1 = true you nest some ifs, example:
If bullet1dir = 1 Then (lets say move the bullet upwards with picBullet1.Top -= 40), if Bullet1Dir = 2 Then move it to the left etc.
Although I'd strongly recommend learning OOP and making classes and collections to better and easier manage such things in games, when I will have some time I bookmarked this post and I will make a game similar to this but with OOP principles... and yes, you can create PictureBoxes programatically for as many bullets as you wish to fire.