Computer Science Canada Help with collision detection |
Author: | jedi-bob [ Mon Jan 19, 2004 10:30 am ] |
Post subject: | Help with collision detection |
i cant get the oval collision detection working, i will post the code, if i could get some help that would be great. I copied the oval collision detection code into my program, but it get errors. I am using Turing 4.0.4c var chars : array char of boolean var A1,B1,A2,B2: int var radius1,radius2:int A1:=50 A2:=10 B1:=50 B2:=10 radius1:=10 loop drawfilloval(A1,B1,A2,B2,7) Input.KeyDown (chars) if chars (KEY_RIGHT_ARROW) then cls A1:=A1+15 elsif chars (KEY_LEFT_ARROW) then cls A1:=A1-15 elsif chars (KEY_DOWN_ARROW) then cls B1:=B1-15 elsif chars (KEY_UP_ARROW) then cls B1:=B1+15 end if delay(100) drawfilloval(200,200,50,50,yellow) drawfilloval(200,200,10,10,black) var distance := ((A2-A1)*(A2-A1) + (B2-B1)*(B2-B1))**0.5 %you take the square of differences of X coordinates and add %a square of differences of Y coordinates then take a square %root of the sum %%%%%% %I did (x)*(x) instead of x**2 because exponents is a function %and it takes up more resourses then *, thus its faster %Also **0.5 is the same as sqrt() - learn your math guys if distance < radius1 + radius2 %might be a good idea to save radious1+radious2 as const/var then collision = true end if end loop Mod Edit: Moved it to the right forum, don't post in tutorial next time when you have a question. |
Author: | Thuged_Out_G [ Mon Jan 19, 2004 3:20 pm ] |
Post subject: | |
you could use whatdotcolor for your collision detection....but if you dont do it correct(according to dodge), he'll get mad |
Author: | jedi-bob [ Mon Jan 19, 2004 3:28 pm ] |
Post subject: | |
i don't quite understand. Maybe you could copy my code above, correct it, and repost it. I am very new to turing, so don't think i am retarded. |
Author: | Tony [ Mon Jan 19, 2004 5:17 pm ] |
Post subject: | |
you can't expect to paste some base code at the end of your program and expect things to work see the collision = true line? thats where you place the code that does whatever after collision occurts. replace that with put "collision occured" to see if the code works |
Author: | jedi-bob [ Tue Jan 20, 2004 9:53 am ] |
Post subject: | |
thanks, sorry for me being a dumbass |