VB 6 breakout brick problem
VB 6 breakout brick problem
VB 6 breakout brick problem
VB 6 breakout brick problem
VB 6 breakout brick problem
VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem
VB 6 breakout brick problem VB 6 breakout brick problem
VB 6 breakout brick problem
Go Back  Xtreme Visual Basic Talk > > > VB 6 breakout brick problem


Reply
 
Thread Tools Display Modes
  #1  
Old 04-23-2008, 07:09 AM
Darth Revan Darth Revan is offline
Newcomer
 
Join Date: Apr 2008
Posts: 8
Default VB 6 breakout brick problem


Hello all, im new here and i have been looking for a little help on my game, this is the code i have for a single brick:

Dim X As Integer, Y As Integer, Score As Integer

If (Ball.Left > Image10.Left And Ball.Left < Image10.Left + Image10.Width) And (Ball.Top < Image10.Top + Image10.Height And Ball.Top > Image10.Top) Then
If Image10.Visible = True Then
Score = Score + 10
ScoreCard.Caption = "Score: " & Score
Me.Caption = "Score: " & Score
X = -80
Y = -80
X = 80
Y = 80
End If
Image10.Visible = False
End If

The problem is that when the ball is coming from the left to the right the ball reflects/bounces off the brick fine but when the ball is coming from the right to the left it bounces back on itself, please help.

Thanks in advance
Reply With Quote
  #2  
Old 04-23-2008, 08:27 AM
darkforcesjedi's Avatar
darkforcesjediVB 6 breakout brick problem darkforcesjedi is offline
Trust me, I'm an

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

I assume X and Y are the ball velocity in the X and Y directions. Look at this snippet:

X = -80
Y = -80
X = 80
Y = 80

When the ball hits the brick, you just need to reflect it in the Y direction:

Y = -Y

This way if it hits the top of a brick it will bounce up as well. This assumes that you can't bounce off the side of a brick though.

What you really need to do for breakout is to have an array of edges and normals. If the ball encounters an edge, it should be reflected about the normal. (A normal is the direction perpendicular to an edge.) Then you can either draw the bricks within the bounds of the edges or put controls there. You never have to draw the edges, they can be stored in memory. This apllies to bricks that aren't on a structured grid or may be oriented at an angle.

On a structured grid you don't have to compare the ball position to the position of all the bricks, or ANY of them for that matter. Given the position and direction of the ball it is easy to calculate what edge the ball hits next. If there is a corresponding block at that location you can bounce the ball, otherwise continue moving.

Lets say the grid elements are 10 units wide by 5 high. The velocity of the ball is (vx,vy) and its position is (x,y).

If vx > 0 then the next vertical gridline it encounters is (x mod 10) + 1, otherwise it's (x mod 10). It will strike that gridline in time=(gridlineX - x)/vx

Likewise for vy.

Now you store an array corresponding to the entire grid. Put a value in that array in all grid positions corresponding to a brick. That way you know whether to bounce the ball off a gridline or let it pass through.
__________________
To err is human; to debug, divine.

Last edited by darkforcesjedi; 04-23-2008 at 09:05 AM.
Reply With Quote
  #3  
Old 04-24-2008, 05:58 AM
Darth Revan Darth Revan is offline
Newcomer
 
Join Date: Apr 2008
Posts: 8
Default

Thank you for your help darkforcesjedi, the Y = -Y works wonderfully and now the ball reflects of both the top and bottom of each block. You mentioned about the sides if each block as well, when the ball goes to the side of a block it goes into it and then hits the top and/or bottom from within instead of hitting the outside of the block and reflecting, is there another axis i need to place in?

Thanks again for your help it is very much appreciated.
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 brick problem
VB 6 breakout brick problem
VB 6 breakout brick problem VB 6 breakout brick problem
VB 6 breakout brick problem
VB 6 breakout brick problem
VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem VB 6 breakout brick problem
VB 6 breakout brick problem
VB 6 breakout brick problem
 
VB 6 breakout brick problem
VB 6 breakout brick problem
 
-->