well on the first look the code seems right.
but if you declared the x and the y variable as integers you will probably get a bad movement... try declaring them as singles or scale your numbersystem up (dunno some people like not to use float values )
Ok...I've got some errors that i hope anyone of you can find...
I've added border loading, but the collition detection is a bit wrong...
1. Sometimes the ball gets stuck and moves along one of the sides
2. Sometimes (maybe all the time (not sure)) when the ball bounces on the roof, the new angle is wrong!
3. When the ball moves through the bricks, it sometimes moves between two bricks...
The zip contains the source and the compiled program with 2 test borders....
1. Sometimes the ball gets stuck and moves along one of the sides
I can't see what you are meaning by this...But it is wery easy to get the ball to move from left to right and back again without moving very much in Y direction. And this way it will hit all bricks...
2. Sometimes (maybe all the time (not sure)) when the ball bounces on the roof, the new angle is wrong!
I can't see anything wrong with the angle when it hits the roof...
3. When the ball moves through the bricks, it sometimes moves between two bricks...
Yes you need bether collision detection. I havn't looked at you code, but I'm guessing that you are only checking the left property of the ball. You would have to add the width to and check for the whole ball...
I'm so tired no so I won't try to give you a solution now....but I will see what I can do tomorow...
Originally posted by NoteMe I can't see what you are meaning by this...But it is wery easy to get the ball to move from left to right and back again without moving very much in Y direction. And this way it will hit all bricks...
Originally posted by cyborg If you care....
here's a new and improved version!
I never stop caring about your games . This game is turning out great. But I'm not sure if it is only my machine or if it is because I have a lot of apps running in the background, but I don't think the ball moves that smooth anymore, and the it seems like the speed is increasing after the ball has hit the "roof" and some bricks (or is this just something I imagine my self??)...
the speed is allways incresing untill it reaches a certain value...
the new angle gets wrong after hitting the roof and the bricks...
maybe it doesnt move that smooth anymore, but that can be fixed...
the colition detection that i've made it checking all pixels on the ball every 10th millisecond....
i think that code can be improved...i'll look into that in a few days!
Originally posted by cyborg the speed is allways incresing untill it reaches a certain value...
the new angle gets wrong after hitting the roof and the bricks...
maybe it doesnt move that smooth anymore, but that can be fixed...
the colition detection that i've made it checking all pixels on the ball every 10th millisecond....
i think that code can be improved...i'll look into that in a few days!
Looking forward to it...you are starting to be good at game programming...
I haven't looked at your code, but when you said about your collision detection.. Ok.. so you have a ball and a brick... the collision detect should use angles and distance.. ..
What you need is to get the distance between the ball and al bricks. Any bricks with a distance below the balls speed (add a bit of leway.. just in case) are checked for collision.
To check for collision:
Get the angle to the 4 corners of a brick
If the ball is going to hit the brick, it's movement angle will be within those angles (Don't to compensate for ball size!!)..so..
Let's assume that A(1) = 45 (top left), A(2) = 40 (bottom left), a(3) = 35 (top right) and A(4) = 30 (bottom right)
*its up to you to get angles
First, you find the lowest number...
Low = 360
for b = 1 to 4
if a(b) < low then low = a(b)
next b
then the highest..
High = 0
for b = 1 to 4
if a(b) > High then High = a(b)
next b
and near finally:
If Low <= High *(this is explained below)* then
if BallAngle > Low and BallAngle < High then msgbox " BOOM "
ELSE
*Because 360 = 0, 361 = 1 in angles.. you could potentially get a *5 and a 355.. where 355 would actually be the lower one.. So *just do:
for b = 1 to 4
a(b) = a(b)+180
if a(b) > 360 then a(b) = a(b) - 360
next b
**redo low-high here
**redo angle check, dont forget to change Ballangle (+180 *-360)
for b = 1 to 4
a(b) = a(b)-180
if a(b) < 0 then a(b) = a(b) + 360
next b
End if
THIS IS UNTESTED AND I MADE IT UP HERE, NO GUARANTEES ON BUG-FREE.
Ok, now for colliding with sides:
BallAngle = AngleofWhatYouHit-Ballangle
So if your headed straight up (90) and hit the ceiling (0) you will get -90 (270), which is the way it should be.
If you hit side (90) and are going at 45 (up+right) it will change to 135 (up+LEFT)
Don't pay attention to this signature, it's contradictory.
alright since you have to calculate the x and the y component of your movement every time you should directly store those values instead of doing the same calculation over and over again. that way collision gets easier too. if it hits the side take the x-component *-1 if it hists the top take the y-component *-1. If you hit something that requires you to change the angle you can always get the angle back from the x and the y component using the tan but I would store the angle anyways (again to save calculations and avoide rounding mistakes and lines of code)
Can you tell me what the angle is her (from what to what)...
When the ball hits the top, i use this code:
Ball(i).Angle = 180 - Ball(i).Angle
Look at my drawing and tell me...because on my drawing I have marked angle A and B but I can't see your code calculation those...or am I not able to see it...
Last edited by NoteMe; Dec 15th, 2002 at 09:27 AM.
Originally posted by alkatran Top is 180, Ball.angle on left of equation is B, Ball.angle on right of equation is A
He should be using 0 and not 180 I think
I still can't see what he is thinking...because if the angle moves from A to B, and in A it has 60degrees, then he want an angle of -60degress or 300degress after the hit...
i didnt want to use radians in this game, because im always getting trouble when the ball is moving many Y values in one X value...then the ball moves too fast!
Originally posted by cyborg i didnt want to use radians in this game, because im always getting trouble when the ball is moving many Y values in one X value...then the ball moves too fast!
This doesn’t make sense. You can have the exact same X and Y movements using Rad, but I have to admit that I like to use Degrees too...
And the calculations of the angle looks fine with me, so I think that there has to be another place in the code there is a BUG...But I can't see the ball moving in the wrong direction on my PC
This is used in the collition detection to check the new direction of the ball (which side of the brick it hits)
TempCol holds the X value of the brick that the ball hits
TempRow holds the Y value of the brick that the ball hits
These are not in pixels, but in count of bricks...
One brick are 30*15 pixels
X holds the X value of the ball when hitting a brick
Y holds the Y value of the ball when hitting a brick
VB Code:
If X < TempCol * 30 - 29 Or X > TempCol * 30 - 2 Then
If X < TempCol * 30 - 28 Then
'hit left side
Form1.ChangeDirection BallNr, "L"
ElseIf X > TempCol * 30 - 2 Then
'hit right side
Form1.ChangeDirection BallNr, "R"
End If
Else
If Y < TempRow * 15 + 29 Then
Form1.ChangeDirection BallNr, "U"
Else
Form1.ChangeDirection BallNr, "D"
End If
End If
This code is not correct, and there must be a better way of doing this...
Last edited by cyborg; Dec 15th, 2002 at 04:09 PM.
Originally posted by alkatran When I went from level 1 to 2.. there was a block that wasn't ever detected as hit.. it didn't fit pattern either, here's a picture:
I'm not really sure, I like my system , but don't forget to increase the 'range' of detection as ball speeds up (and check angle, so it doesn't catch a right hit on left side)
Don't pay attention to this signature, it's contradictory.