7 Replies - 953 Views - Last Post: 01 October 2012 - 08:31 AM Rate Topic: -----

#1 TheVoliand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 25-September 12

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


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



Is This A Good Question/Topic? 0
  • +

Replies To: Progress Bar as Health bar

#2 TheVoliand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 25-September 12

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...
Was This Post Helpful? 0
  • +
  • -

#3 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Progress Bar as Health bar

Posted 01 October 2012 - 07:30 AM

look here:
ProgressBar1.Value = 100 - 20
you 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

Was This Post Helpful? 0
  • +
  • -

#4 TheVoliand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 25-September 12

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
Was This Post Helpful? 0
  • +
  • -

#5 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Progress Bar as Health bar

Posted 01 October 2012 - 07:47 AM

View PostTheVoliand, on 01 October 2012 - 07:37 AM, said:

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

Ofcourse , if the MIN value of the progress bar is 0 then you can't set ProgressBar.Value=-20
Was This Post Helpful? 0
  • +
  • -

#6 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1355
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Progress Bar as Health bar

Posted 01 October 2012 - 07:48 AM

You already have a thread about this project, here. I'd suggest that this thread be merged with the other one, to avoid needless clutter in this forum. Please do not open multiple threads about the same issues.
Was This Post Helpful? 0
  • +
  • -

#7 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

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.
Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

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

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1