1 Replies - 693 Views - Last Post: 05 May 2013 - 04:38 PM Rate Topic: -----

#1 tbay007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-May 13

Creating a simple game - Problem with PictureBoxArray

Posted 05 May 2013 - 11:41 AM

Hello All,

I have been doing some simple programming for a year now with my boss on VB.NET. Then I had a great idea, to try to make small windows games at home for fun learning experience while at the same time learning more stuff at work.

I am essentially making a game where there is a timer, and a picture(The picture is a black blob). Essentially I have it jumping around on the screen every 3 seconds; however, I want to make it so that if someone click on the blob before 2 seconds that the blob goes away, otherwise the blob stays there and a new blob is generated.

I am right now making it put each random location of the picture be put in a picture array; however, I am unable to actually get the pictures to appear.

Private Sub StartGameTimer_Tick(sender As Object, e As System.EventArgs) Handles StartGameTimer.Tick
        pbPicture.Visible = True

        Dim x1 As Integer = pnlPicture.Width * Rnd(0.3)
        Dim y1 As Integer = pnlPicture.Height * Rnd(0.3)

        If x1 < pnlPicture.Location.X Then
            x1 += 24
        ElseIf x1 > (pnlPicture.Location.X + pnlPicture.Width) Then
            x1 -= 24
        End If

        If y1 < pnlPicture.Location.Y Then
            y1 += 24
        ElseIf y1 > (pnlPicture.Location.Y + pnlPicture.Height) Then
            y1 -= 24
        End If
        X3 = x1
        Y3 = y1
        pbPicture.Location = New Point(x1, y1)
        picture1(count1) = New PictureBox
        picture1(count1).ImageLocation = "C:\Users\Venom\Documents\Visual Studio 2010\Projects\RandomPictureGame\RandomPictureGame\Resources\Blob.jpg"
        picture1(count1).Location = New Point(X3, Y3)
        picture1(count1).Image = pbPicture.Image

        count1 += 1
        'For pos = 1 To 100
        '    Y = RandomClass.Next(300)
        '    pbPicture.Location = New Point(100, y)
        'Next pos
        TimeKeeper = Now
    End Sub

Public Sub LoadImages()

        For i As Integer = 0 To picture1.Length - 1
            If picture1(i) IsNot Nothing Then
                Using g As Graphics = Graphics.FromImage(picture1(i).Image)
                    g.DrawImage(picture1(i).Image, New Point(picture1(i).Location.X, picture1(i).Location.Y))
                End Using
                Dim pic As PictureBox = New PictureBox
                pic = GetImage(i)
                pic.Load("C:\Users\Venom\Documents\Visual Studio 2010\Projects\RandomPictureGame\RandomPictureGame\Resources\Blob.jpg")

            End If


    End Sub

I know the code looks primitive, but I am not sure how to get the pictures in the picturebox array to appear on the form.

attached is a screenshot of the programming running, however, that is the third time it changed locations, and there should be two other blobs that haven't gone away, yet they don't appear. What am I doing wrong?

Any help is appreciative.


Whoops, forgot to attach the file. Here it is.

Attached image(s)

  • Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a simple game - Problem with PictureBoxArray

#2 tbay007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-May 13

Re: Creating a simple game - Problem with PictureBoxArray

Posted 05 May 2013 - 04:38 PM

Nevermind, I figured it out after watching a youtube video on how to create a snake game.

I forgot to ad a me.controls.add(picturebox1(i)) to the program.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1