Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,928 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,835 people online right now. Registration is fast and FREE... Join Now!




help making a pong game: how many timers and what are their codes

 
Reply to this topicStart new topic

help making a pong game: how many timers and what are their codes

Learner15
13 Dec, 2007 - 03:29 PM
Post #1

New D.I.C Head
*

Joined: 15 Nov, 2007
Posts: 5


My Contributions
Public Class Form1
Const intformsize As Integer = 407
Const intxformsize As Integer = 333
Const intwidthPaddle As Integer = 20
Const intheightPaddle As Integer = 90
Const intwidthball As Integer = 15
Const intwidthPaddle2 As Integer = 20
Const intheightPaddle2 As Integer = 90
Const intheightball As Integer = 15
Dim intxBall As Integer
Dim intyBall As Integer
Dim intxPaddle As Integer = 367
Dim intyPaddle As Integer = 106
Dim intxPaddle2 As Integer = 12
Dim intyPaddle2 As Integer = 26

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Down Then
intyPaddle = intyPaddle - 10
End If
If e.KeyCode = Keys.Up Then
intyPaddle = intyPaddle + 10
End If
If e.KeyCode = Keys.A Then
intyPaddle2 = intyPaddle - 10
End If
If e.KeyCode = Keys.S Then
intyPaddle2 = intyPaddle2 + 10
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
intxPaddle = picPaddle1.Width
intxBall = intxformsize - 200
intyball = Rnd() * intyformsize
tmrLeft.Start()
End Sub

Private Sub tmrRight_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRight.Tick
intxBall = intxBall + 1
picBlueBall.Location = New System.Drawing.Point(intxBall, intyBall)
If intxBall > intxformsize Then
intxBall = 0
intyBall = Rnd() * (intyformsize - intheightball)
Else
If (intxBall >= intxPaddle2 - intwidthpaddle2) Then
If (intyBall + intwidthball > intyPaddle2) And (intyBall + intwidthball < intyPaddle2 + intheightPaddle2) Then
tmrRight.Stop()
tmrLeft.Start()
End If
End If
End If
End Sub

Private Sub tmrLeft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLeft.Tick
intxBall = intxBall - 1
picBlueBall.Location = New System.Drawing.Point(intxBall, intyBall)
If intxBall > intxformsize Then
intxBall = 0
intyBall = Rnd() * (intyformsize - intheightball)
Else
If (intxBall <= intxPaddle + intwidthPaddle) Then
If (intyBall + intwidthball > intyPaddle) And (intyBall + intwidthball < intyPaddle + intheightPaddle) Then
tmrLeft.Stop()
tmrRight.Start()
End If
End If
End If

End Sub

End Class


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 03:10PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month