• Advertisement
Sign in to follow this  

FINALLY!!

This topic is 4792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know it is about the most basic version of the game to possibly make but i got my pong game to work.... Ill post the code in here and if anyone would like to try it out on Visual basic and give me ideas on improvements to it that would help... Right now all the ball does is bounce off the top and bottom, off the paddles and go through the sides. If it goes through the sides it doesnt restart.... Like i said im a beginner and its the most basic you'll see... Dim xmovement, ymovement As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Randomize() xmovement = 20 + Int(Rnd() * 5) ymovement = 20 + Int(Rnd() * 3) End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick PicBall.Left = PicBall.Left + xmovement PicBall.Top = PicBall.Top + ymovement If PicBall.Top < 0 Then PicBall.Top = 0 ymovement = -ymovement ElseIf (PicBall.Top - PicBall.Height) > Form1.ActiveForm.Height Then PicBall.Top = Form1.ActiveForm.Height ymovement = -ymovement End If If (PicBall.Top + PicBall.Height) > Paddle1.Top Then If PicBall.Left + PicBall.Width >= Paddle1.Left And PicBall.Left <= Paddle1.Left + Paddle1.Width Then xmovement = -xmovement ElseIf PicBall.Left + PicBall.Width >= paddle2.Left And PicBall.Left <= paddle2.Left + paddle2.Width Then xmovement = -xmovement End If End If End Sub Private Sub form1_mousemove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove Paddle1.Top = e.Y End Sub Private Sub keyboardmove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Up Then paddle2.Top -= 20 ElseIf e.KeyCode = Keys.Down Then paddle2.Top += 20 End If End Sub End Class

Share this post


Link to post
Share on other sites
Advertisement
Congratulations on making your first little game - everybody has to start somewhere :)

Since I'm not a VB user/programmer, if you could provide a compiled download of the application I'd test it out for you then.

Good job, happy coding.

-Mezz

Share this post


Link to post
Share on other sites
Good Job.

Note that you can use source tags ([ source][ /source] without spaces) like this:



Dim xmovement, ymovement As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()

xmovement = 20 + Int(Rnd() * 5)
ymovement = 20 + Int(Rnd() * 3)
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
PicBall.Left = PicBall.Left + xmovement
PicBall.Top = PicBall.Top + ymovement

If PicBall.Top < 0 Then
PicBall.Top = 0
ymovement = -ymovement

ElseIf (PicBall.Top - PicBall.Height) > Form1.ActiveForm.Height Then
PicBall.Top = Form1.ActiveForm.Height
ymovement = -ymovement

End If
If (PicBall.Top + PicBall.Height) > Paddle1.Top Then

If PicBall.Left + PicBall.Width >= Paddle1.Left And PicBall.Left <= Paddle1.Left + Paddle1.Width Then
xmovement = -xmovement
ElseIf PicBall.Left + PicBall.Width >= paddle2.Left And PicBall.Left <= paddle2.Left + paddle2.Width Then
xmovement = -xmovement

End If
End If
End Sub

Private Sub form1_mousemove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Paddle1.Top = e.Y

End Sub

Private Sub keyboardmove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Up Then
paddle2.Top -= 20
ElseIf e.KeyCode = Keys.Down Then
paddle2.Top += 20
End If
End Sub

End Class







Edit: That's ugly with VB code but it is still better than nothing. I'm not too familiar with VB, but shouldn't your "Class" start somewhere ? I suspect missing code [grin]

[Edited by - xMcBaiNx on January 5, 2005 12:32:07 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement