6 Replies - 1373 Views - Last Post: 15 October 2012 - 07: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

4 pictureboxes 1 should be attacking others not at all

Posted 08 October 2012 - 06:23 AM

I am making a game where there are 4 pictureboxes(stick figures) 2 have swords and are only visible if i press a certain key. i have 2 progress bars for hp bars. the problem is the invisible swordsmen still hurt the other guy even when not visible. is there a way to make them untouchable as well?
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.Up Then
            PictureBox1.Top -= 3
            PictureBox2.Top -= 3
        End If
        If e.KeyCode = Keys.Down Then
            PictureBox1.Top += 3
            PictureBox2.Top += 3
        End If
        If e.KeyCode = Keys.Right Then
            PictureBox1.Left += 3
            PictureBox2.Left += 3
        End If
        If e.KeyCode = Keys.Left Then
            PictureBox1.Left -= 3
            PictureBox2.Left -= 3
        End If
        If e.KeyCode = Keys.I Then
            PictureBox3.Top -= 3
            PictureBox4.Top -= 3
        End If
        If e.KeyCode = Keys.K Then
            PictureBox3.Top += 3
            PictureBox4.Top += 3
        End If
        If e.KeyCode = Keys.L Then
            PictureBox3.Left += 3
            PictureBox4.Left += 3
        End If
        If e.KeyCode = Keys.J Then
            PictureBox3.Left -= 3
            PictureBox4.Left -= 3
        End If
    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
    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 Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If PictureBox2.Bounds.IntersectsWith(PictureBox3.Bounds) Then
            ProgressBar2.Value -=20
            ProgressBar2.Refresh()
        End If
        If PictureBox4.Bounds.IntersectsWith(PictureBox1.Bounds) Then
            ProgressBar1.Value -= 20
            ProgressBar1.Refresh()
        End If
        If ProgressBar1.Value <= 0 Then
            ProgressBar1.Value = 0
        End If
        If ProgressBar2.Value <= 0 Then
            ProgressBar2.Value = 0
        End If
        If ProgressBar2.Value = 0 Then
            Timer1.Enabled = False
            MsgBox("Black Player Wins!")
            Close()
        End If
        If ProgressBar1.Value = 0 Then
            Timer1.Enabled = False
            MsgBox("White Player Wins!")
            Close()
        End If
    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: 4 pictureboxes 1 should be attacking others not at all

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: 4 pictureboxes 1 should be attacking others not at all

Posted 08 October 2012 - 07:19 AM

can't you only perform IF the visible property of the picturebox is True?
Was This Post Helpful? 0
  • +
  • -

#3 TheVoliand  Icon User is offline

  • New D.I.C Head

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

Re: 4 pictureboxes 1 should be attacking others not at all

Posted 09 October 2012 - 06:05 AM

You would think, but no it acts as if its visible, even though its not
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: 4 pictureboxes 1 should be attacking others not at all

Posted 09 October 2012 - 06:13 AM

       If PictureBox2.Bounds.IntersectsWith(PictureBox3.Bounds) Then
	  ProgressBar2.Value -=20
	  ProgressBar2.Refresh()
       End If
       If PictureBox4.Bounds.IntersectsWith(PictureBox1.Bounds) Then
          ProgressBar1.Value -= 20
          ProgressBar1.Refresh()
       End If

Where are you only causing damage if .Visible = True in that code?

This isn't something that just happen magically, you have to code it. The visible property of the object doesn't take it out of existence. It just hides it's interface from you. It's still there I assure you so why not check to make sure it's visible property is set to true before you apply any damage to it.
Was This Post Helpful? 0
  • +
  • -

#5 TheVoliand  Icon User is offline

  • New D.I.C Head

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

Re: 4 pictureboxes 1 should be attacking others not at all

Posted 10 October 2012 - 05:23 AM

so how the would you code that like
if picturebox2.visible=true and if picturebox2.bounds.intersectswith(picturebox3.bounds) then
      progressbar2.value-=20
      progressbar2.refresh

?
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: 4 pictureboxes 1 should be attacking others not at all

Posted 10 October 2012 - 06:14 AM

close, but you don't need the second if
If (picturebox2.Visible = True And PictureBox2.bounds.instersectswith(picturebox3.bounds)) then
'do for true
End If

Was This Post Helpful? 0
  • +
  • -

#7 TheVoliand  Icon User is offline

  • New D.I.C Head

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

Re: 4 pictureboxes 1 should be attacking others not at all

Posted 15 October 2012 - 07:31 AM

Resolved! thanks charlie!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1