ControlC
· Pastebin
Login
Register
ControlC
/
Create paste
Paste content
Up to 100 KB of text. BBCode formatting is supported.
Title
- optional
Content
B
I
U
S
</>
Colors ↓
Sizes ↓
Size 1
Size 2
Size 3
Size 4
Size 5
Size 6
Size 7
'I added this to a module\r\nPublic Type POINTAPI\r\n X As Long\r\n Y As Long\r\nEnd Type\r\n\r\nPublic Declare Function GetCursorPos Lib \"user32\" (lpPoint As POINTAPI) As Long\r\nPublic ballDirectionX As Integer\r\nPublic ballDirectionY As Integer\r\nPublic ballSpeed As Integer\r\n\r\nPublic Declare Sub Sleep Lib \"kernel32\" (ByVal dwMilliseconds As Long)\r\n\r\n\r\n' I added everything below to my form - performance will depend on your machine, just try to tweak it\r\nPrivate Sub Form_Load()\r\n ' Initialize ball direction and speed\r\n ballDirectionX = 12\r\n ballDirectionY = 3\r\n ballSpeed = 8250\r\n\r\n ' Initialize the starting positions of the paddles\r\n ' Place the left paddle (paddle1) towards the left side of the form\r\n paddle1.Top = 222\r\n paddle1.Left = 310 ' Adjust this value to move paddle1 more to the left as needed\r\n\r\n ' Place the ball towards the left side, near the left paddle\r\n ball.Top = 0\r\n ball.Left = 0 ' Adjust this value to position the ball more to the left as needed\r\n\r\n ' Initialize the position of the right paddle (paddle2)\r\n paddle2.Top = Me.InsideHeight / 2 - paddle2.Height / 2\r\n\r\n ' Set the Timer Interval for continuous movement\r\n Me.TimerInterval = 2\r\n \r\nEnd Sub\r\n\r\nPrivate Sub Form_Resize()\r\n ' If you need to reposition elements on form resize\r\n ball.Left = (Me.InsideWidth - ball.Width) / 22\r\n ball.Top = (Me.InsideHeight - ball.Height) / 220\r\nEnd Sub\r\n\r\nPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)\r\n ' Move paddle1 with the mouse (Optional)\r\n If Y > 4 And Y < Me.InsideHeight - paddle1.Height Then\r\n paddle1.Top = Y\r\n End If\r\n \r\n If Y < Box7.Top Then\r\n paddle1.Top = Box7.Top\r\n ElseIf Y + paddle1.Height > Box7.Top + Box7.Height Then\r\n paddle1.Top = Box7.Top + Box7.Height - paddle1.Height\r\n Else\r\n paddle1.Top = Y\r\n End If\r\n\r\nEnd Sub\r\n\r\nPrivate Sub Form_Timer()\r\n ' Ball movement logic\r\n ball.Left = ball.Left + ballDirectionX\r\n ball.Top = ball.Top + ballDirectionY\r\n\r\n ' Collision detection with the top and bottom of Box7\r\n If ball.Top < Box7.Top Then\r\n ball.Top = Box7.Top ' Position the ball at the top boundary of Box7\r\n ballDirectionY = -ballDirectionY ' Reverse the vertical direction\r\n ElseIf ball.Top + ball.Height > Box7.Top + Box7.Height Then\r\n ball.Top = Box7.Top + Box7.Height - ball.Height ' Position the ball at the bottom boundary of Box7\r\n ballDirectionY = -ballDirectionY ' Reverse the vertical direction\r\n End If\r\n\r\n ' Collision detection with the paddles\r\n If (ball.Left <= paddle1.Left + paddle1.Width And ball.Top + ball.Height >= paddle1.Top And ball.Top <= paddle1.Top + paddle1.Height) _\r\n Or (ball.Left + ball.Width >= paddle2.Left And ball.Top + ball.Height >= paddle2.Top And ball.Top <= paddle2.Top + paddle2.Height) Then\r\n ballDirectionX = -ballDirectionX\r\n End If\r\n\r\n ' Check for collision with the right side of Box7\r\n If ball.Left + ball.Width > Box7.Left + Box7.Width Then\r\n If ball.Top + ball.Height < paddle2.Top Or ball.Top > paddle2.Top + paddle2.Height Then\r\n Me.decision.Caption = \"Player 1 Wins!\"\r\n Me.TimerInterval = 0 ' Stop the game\r\n Else\r\n ballDirectionX = -ballDirectionX ' Reflect the ball\r\n End If\r\n End If\r\n\r\n ' Check for collision with the left side of Box7\r\n If ball.Left < Box7.Left Then\r\n If ball.Top + ball.Height < paddle1.Top Or ball.Top > paddle1.Top + paddle1.Height Then\r\n Me.decision.Caption = \"Player 2 Wins!\"\r\n Me.TimerInterval = 0 ' Stop the game\r\n Else\r\n ballDirectionX = -ballDirectionX ' Reflect the ball\r\n End If\r\n End If\r\n\r\n ' Refresh the form to update the positions of the controls\r\n Me.Repaint\r\nEnd Sub\r\n\r\n\r\nPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)\r\n Const KEY_UP As Integer = 38 ' Up Arrow Key for paddle1\r\n Const KEY_DOWN As Integer = 40 ' Down Arrow Key for paddle1\r\n Const KEY_P As Integer = 80 ' P key for paddle2\r\n Const KEY_L As Integer = 76 ' L key for paddle2\r\n Const PaddleMoveSpeed As Integer = 40 ' Increase this value to make paddle1 move faster\r\n Const PaddleMoveSpeed2 As Integer = 40 ' Increase this value to make paddle2 move faster\r\n\r\n Select Case KeyCode\r\n Case KEY_UP\r\n ' Move paddle1 up faster\r\n If paddle1.Top > Box7.Top Then\r\n paddle1.Top = paddle1.Top - PaddleMoveSpeed\r\n End If\r\n KeyCode = 0 ' Prevent further processing of the key\r\n\r\n Case KEY_DOWN\r\n ' Move paddle1 down faster\r\n If paddle1.Top + paddle1.Height < Box7.Top + Box7.Height Then\r\n paddle1.Top = paddle1.Top + PaddleMoveSpeed\r\n End If\r\n KeyCode = 0 ' Prevent further processing of the key\r\n\r\n Case KEY_P\r\n ' Move paddle2 up\r\n If paddle2.Top > Box7.Top Then\r\n paddle2.Top = paddle2.Top - PaddleMoveSpeed2\r\n End If\r\n KeyCode = 0 ' Prevent further processing of the key\r\n\r\n Case KEY_L\r\n ' Move paddle2 down\r\n If paddle2.Top + paddle2.Height < Box7.Top + Box7.Height Then\r\n paddle2.Top = paddle2.Top + PaddleMoveSpeed2\r\n End If\r\n KeyCode = 0 ' Prevent further processing of the key\r\n End Select\r\nEnd Sub
Password
Anyone with the link will still need this password to view.
Expires
1 hour
3 hours
6 hours
12 hours
24 hours
48 hours
72 hours
Sign in to enable "Never expires".
Create paste
Please verify you are human
Cancel