Welcome to Dream.In.Code
Getting Help is Easy!

Join 105,774 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,272 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Help making a pong game: how many timers i need and what do i put for

 
Reply to this topicStart new topic

Help making a pong game: how many timers i need and what do i put for

Learner15
post 13 Dec, 2007 - 04:23 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 intformsize 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

This post has been edited by Learner15: 13 Dec, 2007 - 04:25 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/21/08 04:11PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month