VB 6 Breakout Pad
VB 6 Breakout Pad
VB 6 Breakout Pad
VB 6 Breakout Pad
VB 6 Breakout Pad
VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad
VB 6 Breakout Pad VB 6 Breakout Pad
VB 6 Breakout Pad
Go Back  Xtreme Visual Basic Talk > > > VB 6 Breakout Pad


Reply
 
Thread Tools Display Modes
  #1  
Old 04-30-2008, 04:51 AM
Darth Revan Darth Revan is offline
Newcomer
 
Join Date: Apr 2008
Posts: 8
Default VB 6 Breakout Pad


Hi all, after designing a few levels of breakout i thought that having the ball's angles changed when the pad is moving a certain way would give the player much more control over the ball and indeed the game.

Now this is were i become stuck;

Here is the code that affects the movement of the pad.

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Pad.Left = X - Pad.Width / 2
End Sub

Here is the code that affects the ball's contact with the pad.

If Ball.Top + Ball.Height >= Pad.Top Then
If (Ball.Left + Ball.Width < Pad.Left) Or (Ball.Left > Pad.Left + Pad.Width) Then
MsgBox "Game Over"
End
Else
Y = Y * -1# 'speed up the ball
X = X * 1#
End If
End If

At the moment i have no code for the actual ball and the pad itself, though i have not needed any code for them at the minute.

I would greatly appreciate any help on this.

Thanks in advance.
Reply With Quote
  #2  
Old 04-30-2008, 07:08 AM
darkforcesjedi's Avatar
darkforcesjediVB 6 Breakout Pad darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

Barring some extraordinary circumstances, you should NEVER use the End keyword to terminate an application. Also, you should have posted this in your previous thread.

Why are you multiplying Y by -1? Y=-Y is more efficient.

I assume you want to know what to do with the "X=X*1" line.

Given the Left and Right (Left+Width) X values of the paddle, try something like this:

BallCenter = Ball.Left + Ball.Width/2
PaddleCenter = Paddle.Left + Paddle.Width/2
Contact = 2*(BallCenter-PaddleCenter)/(Paddle.Width+Ball.Width)

Now "Contact" should be in the range [-1,1]. If Contact < 1 then it hit the left half of the paddle. If Contact > 1 then it hit the right half. Then you could do something like X = X * Contact.

You should probably preserve the total speed at the paddle like this:

BallCenter = Ball.Left + Ball.Width/2
PaddleCenter = Paddle.Left + Paddle.Width/2
Contact = 2*(BallCenter-PaddleCenter)/(Paddle.Width+Ball.Width)
Factor = SQRT((Y*Y + X*X)/(Y*Y + (X*Contact)^2))
Y = -Y * Factor
X = X * Contact * Factor
__________________
To err is human; to debug, divine.
Reply With Quote
  #3  
Old 05-01-2008, 04:13 AM
Darth Revan Darth Revan is offline
Newcomer
 
Join Date: Apr 2008
Posts: 8
Default

Thanks for your help again darkforcesjedi,

Firstly, sorry for not posting correctly.

I have tryed the code you submitted and i keep getting the error;

Sub or Function not defined

When i stop running the program it highlights SQRT

How do i define this?

Sorry im not very good with VB at the moment

Thanks in advance
Reply With Quote
  #4  
Old 05-01-2008, 06:50 AM
darkforcesjedi's Avatar
darkforcesjediVB 6 Breakout Pad darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

square root. in vb it's sqr(). sorry i've been using Excel too much.
__________________
To err is human; to debug, divine.
Reply With Quote
  #5  
Old 05-01-2008, 08:42 AM
Darth Revan Darth Revan is offline
Newcomer
 
Join Date: Apr 2008
Posts: 8
Default

I have changed it and now an error comes up saying;

Argument not optional

and it highlights sqr
Reply With Quote
  #6  
Old 05-01-2008, 11:19 AM
darkforcesjedi's Avatar
darkforcesjediVB 6 Breakout Pad darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

It says argument not optional, because the argument... is not optional. Sqr() is a function that returns a value, specifically the square root of its argument. If you don't pass it an argument it can't tell you what the square root of it is. Try passing the argument to the function as I demonstrated.

It is clear at this point that you're not looking for help; you're looking for someone to essentially give you step-by-step instructions, which defeats the entire purpose of programming. I am not interested in sitting here and outlining everything you need to do to make a functioning game. You're not going to learn anything by having code spoon-fed to you.

If you don't know what an argument is, look it up. If you don't know what "argument not optional" means, try VB help or Google. If you don't know what a function is, you're never going to be able to complete your project. If you don't know what a square root is (and for the love of god I hope that's not the case), then you will need to learn arithmetic.
__________________
To err is human; to debug, divine.
Reply With Quote
  #7  
Old 05-02-2008, 03:46 AM
Darth Revan Darth Revan is offline
Newcomer
 
Join Date: Apr 2008
Posts: 8
Default

I took into account what you said and i spent some time researching what the error was that i was getting i sorted the 'arguement not optional' error to then come accross another problem.

As it turned out i was missing a Dim statement (for the second problem) and now it has been corrected and the ball reflects well.

Thank you for your time.

P.S. Sorry for being a noob :P

Last edited by Darth Revan; 05-02-2008 at 04:01 AM. Reason: Additional comment added
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
VB 6 Breakout Pad
VB 6 Breakout Pad
VB 6 Breakout Pad VB 6 Breakout Pad
VB 6 Breakout Pad
VB 6 Breakout Pad
VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad VB 6 Breakout Pad
VB 6 Breakout Pad
VB 6 Breakout Pad
 
VB 6 Breakout Pad
VB 6 Breakout Pad
 
-->