Formula for checking points in a cirumference?
Author 
Message 
Paul

Posted: Sat Apr 03, 2004 6:47 pm Post subject: Formula for checking points in a cirumference? 


Im looking for the formula that can check the coordinates on any/all points on the circumference on a circle, it was vaguely mentioned in the tutorials section (?) I dunno, I need it so that the ball when it hits the corner of the paddle, it bounces, checking only vertical and horizontal axis won't work, so far Im using this and it works:
code: 
if BallX + 11 <= PaddleX + PaddleLength and BallX  11 >= PaddleX and BallY  11 <= PaddleY + PaddleWidth then
incY := incY
score += 5
%This part is to check if it has hit the edge
elsif BallX11 < PaddleX+PaddleLength and BallX11 > PaddleX and BallY11 > PaddleY and BallY11<PaddleY+PaddleWidth then
incX:=incX
incY:=incY
elsif BallX+11 < PaddleX+PaddleLength and BallX+11 > PaddleX and BallY11 > PaddleY and BallY11<PaddleY+PaddleWidth then
incX:=incX
incY:=incY
end if

is there a formula for this?
and while Im on the subject, 2 questions,
why does the ball flash and the paddle doesn't, and why when you loose a life, when I use getch, it doesn't run the cls, eventhough the getch is after the cls? I thought getch pauses the program.
heres my program
Description: 

Download 
Filename: 
paddleball.t 
Filesize: 
2.26 KB 
Downloaded: 
74 Time(s) 






Sponsor Sponsor



zylum

Posted: Sat Apr 03, 2004 7:01 pm Post subject: (No subject) 


to solve you blinking problem, have the View.Update at the end of the main loop and remove the other ones... also remove the code which draws white over the last positions of the ball and paddle and instead add a cls after the View.update...
code:  setscreen ("graphics: 400, 500")
setscreen ("offscreenonly")
setscreen ("noecho")
var PaddleX, PaddleY : int := 11
var BallX, BallY : int := 50
var incX, incY : int := 3
var score, lives : int := 0
var chars : array char of boolean
var anykey : string (1)
var PaddleLength, PaddleWidth := 76
PaddleWidth := 15
proc border
drawbox (0, 0, maxx, maxy, black)
drawbox (10, 10, maxx  10, maxy  10, black)
drawfill (5, 5, 12, black)
end border
proc drawPaddle
drawfillbox (PaddleX, PaddleY, PaddleX + 75, PaddleY + PaddleWidth, 43)
drawbox (PaddleX  1, PaddleY  1, PaddleX + 76, PaddleY + 16, black)
end drawPaddle
proc movePaddle
Input.KeyDown (chars)
if chars (KEY_LEFT_ARROW) and PaddleX  2 > 0 then
PaddleX = 4
elsif chars (KEY_RIGHT_ARROW) and PaddleX + 77 < maxx then
PaddleX += 4
end if
end movePaddle
proc Drawball
drawoval (BallX, BallY, 10, 10, black)
drawfilloval (BallX, BallY, 9, 9, 12)
end Drawball
proc Moveball
BallX += incX
BallY += incY
delay (7)
end Moveball
lives := 3
proc checkBall
if BallX + 11 >= maxx or BallX  11 < 0 then
incX := incX
end if
if BallY  11 <= 0 or BallY + 11 >= maxy then
incY := incY
end if
if BallY  11 <= 0 then
lives = 1
cls
put "Press AnyKey"
getch (anykey)
cls
BallX := maxx div 2
BallY := maxy div 2
end if
if BallX + 11 <= PaddleX + PaddleLength and BallX  11 >= PaddleX and BallY  11 <= PaddleY + PaddleWidth then
incY := incY
score += 5
elsif BallX  11 < PaddleX + PaddleLength and BallX  11 > PaddleX and BallY  11 > PaddleY and BallY  11 < PaddleY + PaddleWidth then
incX := incX
incY := incY
elsif BallX + 11 < PaddleX + PaddleLength and BallX + 11 > PaddleX and BallY  11 > PaddleY and BallY  11 < PaddleY + PaddleWidth then
incX := incX
incY := incY
end if
end checkBall
proc scoreshow
locate (1, 1)
put "Score: ", score, " Lives: ", lives
end scoreshow
loop
drawPaddle
Drawball
Moveball
movePaddle
checkBall
if lives < 0 then
exit
end if
scoreshow
View.Update
cls
end loop
put "Your score: ", score 
and as for the collision detection, if you want really accurate collision detection the i suggest you use the quadratic formula... if you need help with it i'll try to explain, but it's sort of hard to use with collision detection
zylum






Paul

Posted: Sat Apr 03, 2004 7:06 pm Post subject: (No subject) 


would you explain the formula please?






recneps

Posted: Sat Apr 03, 2004 8:00 pm Post subject: (No subject) 


well if you mean all the points on a circle, then isnt that technically my "circlify"? just change the drawdot to whatever command needed, it goes through the whole screen checking if the dot fits the circle's equation (x,y,and radius)
If not then i misunderstood






Paul

Posted: Fri Apr 09, 2004 4:10 pm Post subject: (No subject) 


waa? I completely missed what your saying, how does it apply to my paddleball (in which I called the inperfect collision detection a cheat "feature")






recneps

Posted: Fri Apr 09, 2004 7:06 pm Post subject: (No subject) 


well you could use what i was saying on the ball, then, if:
dot>one corner of paddle and < other corner of paddle then collision happened, and reverse direction.
The other one workds just as fine, but thats what im interpreting that you needed






Paul

Posted: Fri Apr 09, 2004 7:23 pm Post subject: (No subject) 


thats what I used, but there are still minor glitches happening. the ball still slips thru some times.






gamer

Posted: Fri Apr 09, 2004 7:29 pm Post subject: (No subject) 


i hav a similar problem too......how should we fix this?






Sponsor Sponsor



gamer

Posted: Sat Apr 10, 2004 6:18 pm Post subject: (No subject) 


please help!!
anyone??






equs

Posted: Sat Apr 17, 2004 1:39 pm Post subject: (No subject) 


the quadratic formaul is
b +/ sqrt b squared  4ac / 2a
sqrt everything after the b and you have to do both equations for 2 points. The plus and  answer.






zylum

Posted: Sat Apr 17, 2004 9:43 pm Post subject: (No subject) 


the formula is the easy part... making an equation that uses the velocity of the ball, the velocity of the paddle and the positions of the ball and paddle to find the time of the collision.... if the time is less than 1 then the collision took place.... otherwise the collision didnt take place... if a collision does take place you multiply the velocty by the time ( < 1 ) and add it to the position and something like that and update the position of the ball and paddle... meh it's something pretty complex but its THE most accurate collision detection... i rember reading it somewhere and trying to implelemt it in one of my flash projects but it was pretty difficult..
zylum







