ball bounce off the brick
Author |
Message |
uknowhoiam
|
Posted: Tue Apr 14, 2009 9:12 pm Post subject: ball bounce off the brick |
|
|
What is it you are trying to achieve?
I want the ball to bounce off the brick
What is the problem you are having?
the ball will not bounce off the bricks
Describe what you have tried to solve this problem
Turing: | if ballx >= brickx and ballx <= brickx2 and bally = bricky2 then
ypos := 10 - gravity
end if |
That is what i have done
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
View.Set ("graphics:650;400,offscreenonly")
var ballx, bally, xpos, xpos2, ypos, gravity : real
var line, Colour, face, brick_colour, brickx, bricky, brickx2, bricky2 : int
var keys : array char of boolean
Colour := 119
face := 255
line := 50
ballx := line + maxx - 100
bally := line
xpos := 1
xpos2 := - 1
ypos := 8
gravity := . 25
brickx := Rand.Int (0, maxx - 10)
brickx2 := brickx + 40
bricky := Rand.Int (10, 170)
bricky2 := bricky + 15
brick_colour := brown
procedure Player
drawfilloval (round (ballx ), round (bally ), 10, 10, Colour ) %body
drawoval (round (ballx ), round (bally ), 10, 10, face ) %body outline
drawfilloval (round (ballx ) - 3, round (bally ) + 2, 1, 1, face ) %left eye
drawfilloval (round (ballx ) + 3, round (bally ) + 2, 1, 1, face ) %right eye
drawfillarc (round (ballx ), round (bally ) - 2, 2, 4, 180, 360, face ) %smile
end Player
procedure Brick
drawfillbox (brickx, bricky, brickx2, bricky2, brick_colour )
end Brick
loop
Brick
Player
View.Update
delay (10)
cls
ballx - = xpos
bally + = ypos
ypos - = gravity
if ballx >= brickx and ballx <= brickx2 and bally = bricky2 + 25 then
ypos := 10 - gravity
end if
if bally <= 15 then
ypos := 10 - gravity
end if
if ballx > maxx + 10 then
ballx := - 10
end if
if ballx < - 10 then
ballx := maxx + 10
end if
if xpos >= 3 then
xpos := 2
end if
if xpos <= - 3 then
xpos := - 2
end if
Input.KeyDown (keys )
if keys (KEY_RIGHT_ARROW) then
xpos - = 1
end if
if keys (KEY_LEFT_ARROW) then
xpos + = 1
end if
end loop
%Just test it your self
|
Please specify what version of Turing you are using
<Answer Here>
[syntax=""][/syntax][syntax=""][/syntax] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Tue Apr 14, 2009 9:26 pm Post subject: RE:ball bounce off the brick |
|
|
I'm not exactly sure what those variables are, but
code: |
and bally = bricky2
|
sounds awfully specific. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
TokenHerbz
|
Posted: Wed Apr 15, 2009 3:15 am Post subject: Re: ball bounce off the brick |
|
|
hey bud, yea you gotta make your var's names better anyways check out the part i changed in your code,
code: |
%if ballx >= brickx and ballx <= brickx2 and bally = bricky2 + 25 then
% ypos := 10 - gravity
% end if
%%may i recomend you use a ball size variable, if you dicide to change the size later it would suck to change all the numbers in your code.
%%Need to find point of contact with the brick...
if bally <= bricky2 and bally +10 >= bricky and ballx <= brickx2 and ballx+10 >= brickx then %%i assume 10 is the size of the ball?
put "POINT OF CONTACT"
Input.Pause
end if
|
try to understand why that works, its rough lol but better then nothing, it IS 4:15 am lol im off to bed.. |
|
|
|
|
|
uknowhoiam
|
Posted: Wed Apr 15, 2009 6:54 pm Post subject: RE:ball bounce off the brick |
|
|
Turing: | if bally <= bricky2 |
The problem with the above code is that, if the ball if below the brick (like not even touching it)
the ball will boucne off
But Hey you got it to bounce |
|
|
|
|
|
Dusk Eagle
|
Posted: Wed Apr 15, 2009 10:03 pm Post subject: Re: RE:ball bounce off the brick |
|
|
uknowhoiam @ Wed Apr 15, 2009 7:54 pm wrote: Turing: | if bally <= bricky2 |
The problem with the above code is that, if the ball if below the brick (like not even touching it)
the ball will boucne off
That's true, but you've seen the basic idea so now you know how it's done. Now you just have to apply your knowledge to all four sides of the ball and brick to make collision detection complete. |
|
|
|
|
|
|
|