Pong Tutorial

gameBall undeclared

Page 1 of 1

5 Replies - 3002 Views - Last Post: 22 November 2010 - 10:39 AM Rate Topic: -----

#1 hifistyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-October 10

Pong Tutorial

Posted 22 November 2010 - 09:56 AM

Hi,
I'm coding the game timer, but am noticing that the gameBall is undeclared and don't see it in the tutorial. Can anyone tell me why?

 Private Sub gameTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gameTimer.Tick

        'Set the computer player to move according to the ball's position."
        If gameBall.Location.Y > 5 And gameBall.Location.Y < Me.Height - 40 _
        - paddlePlayer.Height Then _
        paddleComputer.Location = New Point(paddleComputer.Location.X, gameBall.Location.Y)

        ' Move the game ball.
        gameBall.Location = New Point(gameBall.Location.X + xVel, gameBall.Location.Y + yVel)

        ' Check for top wall.
        If gameBall.Location.Y < 0 Then
            gameBall.Location = New Point(gameBall.Location.X, 0)
            yVel = -yVel
        End If

        ' Check for bottom wall.
        If gameBall.Location.Y > Me.Height - gameBall.Size.Height - 45 Then
            gameBall.Location = New Point(gameBall.Location.X, Me.Height - gameBall.Size.Height - 45)
            yVel = -yVel
        End If

        ' Check for player paddle.
        If gameBall.Bounds.IntersectsWith(paddlePlayer.Bounds) Then
            gameBall.Location = New Point(paddlePlayer.Location.X - gameBall.Size.Width, _
            gameBall.Location.Y)
            xVel = -xVel
        End If


This post has been edited by macosxnerd101: 22 November 2010 - 10:00 AM
Reason for edit:: Fixed end code tag and moved to VB.NET


Is This A Good Question/Topic? 0
  • +

Replies To: Pong Tutorial

#2 hlx  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 135
  • Joined: 13-November 10

Re: Pong Tutorial

Posted 22 November 2010 - 10:05 AM

In the context of this tutorial, I think the gameball is a picturebox. Need to see the whole thing to be sure though.

Yes, if you are referring to the "Create a fully-functional pong game" tutorial, the gameball is a picturebox.


Quote

Now, whats a room without furniture? We need to add some controls now, so add three PictureBox controls to the form. Set the Name properties to paddleComputer, paddlePlayer and gameBall. For both paddlePlayer and paddleComputer, set the Size property to 16x128. For gameBall, set the Size property to 20x20. Select all three controls, and set the BackColor to a color of your preference; I chose LimeGreen.


Cited from: http://www.dreaminco...onal-pong-game/

This post has been edited by hlx: 22 November 2010 - 10:15 AM

Was This Post Helpful? 1
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

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

Re: Pong Tutorial

Posted 22 November 2010 - 10:14 AM

Yes, hlx is correct,
This is directly out of the tutorial:

Quote

Now, whats a room without furniture? We need to add some controls now, so add three PictureBox controls to the form. Set the Name properties to paddleComputer, paddlePlayer and gameBall. For both paddlePlayer and paddleComputer, set the Size property to 16x128. For gameBall, set the Size property to 20x20. Select all three controls, and set the BackColor to a color of your preference; I chose LimeGreen.

Was This Post Helpful? 2
  • +
  • -

#4 hifistyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-October 10

Re: Pong Tutorial

Posted 22 November 2010 - 10:21 AM

View PostCharlieMay, on 22 November 2010 - 09:14 AM, said:

Yes, hlx is correct,
This is directly out of the tutorial:

Quote

Now, whats a room without furniture? We need to add some controls now, so add three PictureBox controls to the form. Set the Name properties to paddleComputer, paddlePlayer and gameBall. For both paddlePlayer and paddleComputer, set the Size property to 16x128. For gameBall, set the Size property to 20x20. Select all three controls, and set the BackColor to a color of your preference; I chose LimeGreen.



Interesting. I do have a picturebox control for the ball. But, it's still underlined in blue as being undeclared. Admitting that this is the most advanced coding for me to date.

Thanks!
Was This Post Helpful? 0
  • +
  • -

#5 hlx  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 135
  • Joined: 13-November 10

Re: Pong Tutorial

Posted 22 November 2010 - 10:26 AM

View Posthifistyle, on 22 November 2010 - 09:21 AM, said:

View PostCharlieMay, on 22 November 2010 - 09:14 AM, said:

Yes, hlx is correct,
This is directly out of the tutorial:

Quote

Now, whats a room without furniture? We need to add some controls now, so add three PictureBox controls to the form. Set the Name properties to paddleComputer, paddlePlayer and gameBall. For both paddlePlayer and paddleComputer, set the Size property to 16x128. For gameBall, set the Size property to 20x20. Select all three controls, and set the BackColor to a color of your preference; I chose LimeGreen.



Interesting. I do have a picturebox control for the ball. But, it's still underlined in blue as being undeclared. Admitting that this is the most advanced coding for me to date.

Thanks!


Did you ensure that the name property of your game ball picturebox was set to gameBall?

This post has been edited by hlx: 22 November 2010 - 10:26 AM

Was This Post Helpful? 1
  • +
  • -

#6 hifistyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-October 10

Re: Pong Tutorial

Posted 22 November 2010 - 10:39 AM

View Posthlx, on 22 November 2010 - 09:26 AM, said:

View Posthifistyle, on 22 November 2010 - 09:21 AM, said:

View PostCharlieMay, on 22 November 2010 - 09:14 AM, said:

Yes, hlx is correct,
This is directly out of the tutorial:

Quote

Now, whats a room without furniture? We need to add some controls now, so add three PictureBox controls to the form. Set the Name properties to paddleComputer, paddlePlayer and gameBall. For both paddlePlayer and paddleComputer, set the Size property to 16x128. For gameBall, set the Size property to 20x20. Select all three controls, and set the BackColor to a color of your preference; I chose LimeGreen.



Interesting. I do have a picturebox control for the ball. But, it's still underlined in blue as being undeclared. Admitting that this is the most advanced coding for me to date.

Thanks!


Did you ensure that the name property of your game ball picturebox was set to gameBall?


Thanks!

That was it, alright. I had it set to "paddleGameBall".

John
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1