Computer Science Canada Shooting the radius of a circle |
Author: | Luffy [ Mon May 24, 2004 3:01 pm ] |
Post subject: | Shooting the radius of a circle |
Ok well I'm trying to figure out how do I shoot a line and when it hits the radius of a circle, it makes the circle disappear. Also I read the tutorial for collision but I don't really get it...and I'm trying to make it as well for if the rock hits my ship then it disappears. Heres my coding below... Use the arrow keys to move around and push CTRL to shoot. Quote: setscreen ("graphic: 500,500") var move : array char of boolean var change, change2 : int := 0 var fire : int := 0 var rock : int := 0 var fall : int := 1 procedure rockfall randint (rock, 1, 1) if rock = 1 then fall := fall - 1 drawfilloval (10, 400 + fall, 10, 10, brown) end if end rockfall procedure movement Input.KeyDown (move) if move (KEY_RIGHT_ARROW) then change := change + 1 if change = maxx - 20 then change := change - 1 end if end if if move (KEY_LEFT_ARROW) then change := change - 1 if change = 0 then change := change + 1 end if end if if move (KEY_UP_ARROW) then change2 := change2 + 1 if change2 = maxy - 20 then change2 := change2 - 1 end if end if if move (KEY_DOWN_ARROW) then change2 := change2 - 1 if change2 = 0 then change2 := change2 + 1 end if end if if move (KEY_CTRL) then delay (10) fire := fire + 1 drawline (10 + change, change + (change2 + fire), 10 + change, 10 + change2, red) if fire = rock then cls end if end if drawfilloval (10 + change, 10 + change2, 10, 10, blue) end movement loop View.Update cls setscreen ("offscreenonly") movement rockfall end loop |
Author: | Tony [ Mon May 24, 2004 3:21 pm ] |
Post subject: | |
the the line/circle collision - you can ether check if the distance between the line and the center of the circle is <= radious or try to find a real solution for the point of intersection by making the two equations (that of circle and the line) equate to each other. whatever geometry approach is easier for you. I think the distance would be easier to find... You'd need to find a normal to the line that passes though circle's center and find the distance between circle's center and point where the line and it's normal intersect. |
Author: | Luffy [ Mon May 24, 2004 3:25 pm ] |
Post subject: | |
Boo...geometry...I dislike those things but meah I'll try that...thanks for helping Edit: BTW can you give me an example of a coding so it'll be easier for me...o.O |
Author: | Luffy [ Mon May 24, 2004 3:56 pm ] |
Post subject: | |
Bla...I still don't get this geometry thing...my line is still going pass the circle and the circle isn't disappearing...do I find the x and y of the line or the circle? |
Author: | Paul [ Mon May 24, 2004 3:59 pm ] |
Post subject: | |
The y value of the tip of the line, compared to the y value of the center of the circle - the radius of the circle. PLUS the x value of the tip of the line compared to the x value of the circle - radius and x value of the circle +radius (to find if the line is within the width of the circle. |
Author: | Luffy [ Mon May 24, 2004 4:05 pm ] |
Post subject: | |
So I'll need a variable for radius, x and y of the circle and the x and y of the line? |
Author: | Cervantes [ Mon May 24, 2004 5:06 pm ] | ||
Post subject: | |||
i don't know if you have turing 4.0.5; if you do, in the exit when line, where it says "MathDistance" you can change that to "Math.Distance", and get rid of the function at the beginning. |
Author: | Luffy [ Mon May 24, 2004 5:26 pm ] |
Post subject: | |
I have v.3...hey thanks man I really appreciate it ![]() |
Author: | LiquidDragon [ Mon May 24, 2004 7:07 pm ] |
Post subject: | |
Nuts to all that geometry stuff. Just use whatdotcolor and check if the x and y of the top of the line is the same colour of the other falling circle thing |