Brick Beaker Help
Author |
Message |
quintin3
|
Posted: Fri Oct 08, 2010 7:54 pm Post subject: Brick Beaker Help |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
What is the problem you are having?
trying to get the ball to rebound and bounce at different angles
Describe what you have tried to solve this problem
<Answer Here>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
View.Set ("graphics")
View.Set ("offscreenonly")
var chars : array char of boolean
var x, y : int
var midx := maxx div 2
var midy := maxy div 2
x := 250
y := 0
loop
cls
Input.KeyDown (chars)
if chars (KEY_LEFT_ARROW) then
x -= 1
end if
if chars (KEY_RIGHT_ARROW) then
x += 1
end if
if x = maxx then
x -= 190
end if
if midy = midy then
midy -= 1
end if
if midy = then
midy += 1
end if
Draw.FillOval (midx, midy, 10, 10, brightred)
Draw.FillBox (x, y + 0, x + 125, y + 15, purple)
View.Update
end loop
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DtY
|
Posted: Fri Oct 08, 2010 8:11 pm Post subject: RE:Brick Beaker Help |
|
|
What is it you are trying to achieve?
What is the problem you are having?
Describe what you have tried to solve this problem
They're there for a reason. |
|
|
|
|
|
quintin3
|
Posted: Fri Oct 08, 2010 8:51 pm Post subject: RE:Brick Beaker Help |
|
|
i said that |
|
|
|
|
|
DanShadow
|
Posted: Fri Oct 08, 2010 9:08 pm Post subject: Re: Brick Beaker Help |
|
|
quintin3 wrote: trying to get the ball to rebound and bounce at different angles
Well.. your code hurts my eyes, so i'll just give you some pointers.
If your ball hits the outside of your screen (0 .. maxx, 0 .. maxy), you likely want it to move on an alternate vector.
For example:
Your ball is moving at a rate of +1 on the x-axis, and +1 to the y-axis through each loop iteration.
Your check the location of your ball relative to the boundaries of the screen (ie. < 0, or > maxx/maxy).
You find your ball has moved past the right of the screen (ball_x > maxx).
So rather than continuing moving +1 on the x-axis, your change your vector to -1 on the x-axis.
Now your ball is still moving up, but in the opposite direction (it is bouncing off the side of the screen).
As for your box, you do a check to see if particular points of your ball have intersected the rectangle.
You can think of these points as Up, Down, Left & Right - each representing the center point on the Top, Bottom, Left & Right sides of your ball.
You do a check for each of these.
Has the bottom of your ball intersected the rectangle?
if it has, it is most likely moving on a downward vector, so you multiply your y-vector by -1, to make it "bounce" in the opposite direction.
As for checking if a side of the ball has intersected your rectangle, you do this as follows:
[YOUR BALL]
Top Point = Center Point + 10 (on the y-axis)
Bottom Point = Center Point - 10 (on the y-axis)
Right Point = Center Point + 10 (on the x-axis)
Left Point = Center Point - 10 (on the x-axis)
The dimensions of your box are:
x, y, x + 125, y + 15
Here is how you check if your ball has intersected the box:
IF (x_point > box_ x) AND (x_point < box_x+125) AND (y_point > box_ y) AND (y_point < box_y+15) THEN
___you can confirm that your ball @ x_point / y_point is within the bounds of your box.
If you were looking for us to write the code for you, that's not what this web-site is about.
We help you figure out problems by giving your (potential) solutions. It's up to you to put those solutions to use
Hope this helps. |
|
|
|
|
|
quintin3
|
Posted: Fri Oct 08, 2010 9:10 pm Post subject: RE:Brick Beaker Help |
|
|
thanks,
and no, i was just expecting some tips |
|
|
|
|
|
DanShadow
|
Posted: Fri Oct 08, 2010 9:10 pm Post subject: RE:Brick Beaker Help |
|
|
Np |
|
|
|
|
|
|
|