Public Class Form1
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Z Then
PictureBox1.Hide()
PictureBox2.Show()
End If
If e.KeyCode = Keys.X Then
PictureBox3.Hide()
PictureBox4.Show()
End If
If e.KeyCode = Keys.A Then
PictureBox5.Show()
PictureBox1.Hide()
End If
If e.KeyCode = Keys.S Then
PictureBox6.Show()
PictureBox3.Hide()
End If
If e.KeyCode = Keys.Up Then
PictureBox1.Top -= 3
PictureBox2.Top -= 3
PictureBox5.Top -= 3
End If
If e.KeyCode = Keys.Down Then
PictureBox1.Top += 3
PictureBox2.Top += 3
PictureBox5.Top += 3
End If
If e.KeyCode = Keys.Right Then
PictureBox1.Left += 3
PictureBox2.Left += 3
PictureBox5.Left += 3
End If
If e.KeyCode = Keys.Left Then
PictureBox1.Left -= 3
PictureBox2.Left -= 3
PictureBox5.Left -= 3
End If
If e.KeyCode = Keys.I Then
PictureBox3.Top -= 3
PictureBox4.Top -= 3
PictureBox6.Top -= 3
End If
If e.KeyCode = Keys.K Then
PictureBox3.Top += 3
PictureBox4.Top += 3
PictureBox6.Top += 3
End If
If e.KeyCode = Keys.L Then
PictureBox3.Left += 3
PictureBox4.Left += 3
PictureBox6.Left += 3
End If
If e.KeyCode = Keys.J Then
PictureBox3.Left -= 3
PictureBox4.Left -= 3
PictureBox6.Left -= 3
End If
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Z Then
PictureBox1.Show()
PictureBox2.Hide()
End If
If e.KeyCode = Keys.X Then
PictureBox3.Show()
PictureBox4.Hide()
End If
If e.KeyCode = Keys.A Then
PictureBox5.Hide()
PictureBox1.Show()
End If
If e.KeyCode = Keys.S Then
PictureBox6.Hide()
PictureBox3.Show()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
End Sub
Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ProgressBar1_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs)
End Sub
Private Sub ProgressBar1_MarginChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If ProgressBar1.Value = 0 Then
MsgBox("White Player Wins!")
Close()
End If
End Sub
Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If PictureBox2.Bounds.IntersectsWith(PictureBox3.Bounds) Then
ProgressBar2.Value = 100 - 20
ProgressBar2.Refresh()
End If
If PictureBox4.Bounds.IntersectsWith(PictureBox1.Bounds) Then
ProgressBar1.Value = 100 - 20
ProgressBar1.Refresh()
End If
End Sub
Private Sub ProgressBar2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar2.Click
End Sub
Private Sub ProgressBar2_MarginChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProgressBar2.MarginChanged
If ProgressBar2.Value = 0 Then
MsgBox("Black Player Wins!")
Close()
End If
End Sub
End Class
Progress Bar as Health bar
Page 1 of 17 Replies - 326 Views - Last Post: 01 October 2012 - 08:31 AM
#1
Progress Bar as Health bar
Posted 01 October 2012 - 07:23 AM
Iv'e been attempting to make 2 pictureboxes attack each other and then each ones progress bar drain by 20%. I can get them to drain by 20% once. then they don't change at all. the way i have this set up is i have 6 pictureboxes. each picturebox is used for a different action (ie. standing attacking defending.) i have set certain keys to attack defend and to move. i have a timer which is where i am putting the code here is my code
Replies To: Progress Bar as Health bar
#2
Re: Progress Bar as Health bar
Posted 01 October 2012 - 07:30 AM
Sorry for all the messiness of the code, lots of unused lines...
#3
Re: Progress Bar as Health bar
Posted 01 October 2012 - 07:30 AM
look here:
If you want to decrease value then you will do something like this:
ProgressBar1.Value = 100 - 20you will get the same result if you put this:
ProgressBar1.Value = 80
If you want to decrease value then you will do something like this:
ProgressBar1.Value = ProgressBar1.Value - 20 'short version: ProgressBar1.Value -= 20
#4
Re: Progress Bar as Health bar
Posted 01 October 2012 - 07:37 AM
that works until it drains to 0 then the form stops responding and you get an error message that says -20 is not a valid value
#5
Re: Progress Bar as Health bar
Posted 01 October 2012 - 07:47 AM
#7
Re: Progress Bar as Health bar
Posted 01 October 2012 - 07:50 AM
In other words, you can decrease ProgressBar.Value -=20 only if ProgressBar.Value >= 20.
#8
Re: Progress Bar as Health bar
Posted 01 October 2012 - 08:31 AM
Or check it and if it will go below 0, make it 0
If ProgressBar.Value - 20 < 0 then ProgressBar.Value = 0 'Call you routine for no more health Else ProgressBar.Value -= 20 End If
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote








|