Colission Is Killing ME!
Author |
Message |
Pacman
|
Posted: Sun Nov 26, 2006 5:31 pm Post subject: Colission Is Killing ME! |
|
|
Ok, im sorry guys, i may be a little retarded, but the ONLY thing i dont really understand is collsion, with circles, i cant get it, i just cant lmao, if Someone could please help me understand in a simple way i would honestly love you... cuz its driving me crazy the only thing i cant do, please, thanks guys <3 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
ericfourfour
|
Posted: Sun Nov 26, 2006 6:22 pm Post subject: (No subject) |
|
|
Use the distance formula (Math.Distance). It will give you the distance between between two points. In this case the distance between the centre of a circle and another point.
If your version of Turing does not have Math.Distance then use this:
code: | fcn distance (x1, y1, x2, y2 : real)
return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
end fcn |
Here is an example:
code: | var dist := distance (centre_x, centre_y, point_x, point_y) |
It gets the distance between the centre of a circle and a point. |
|
|
|
|
![](images/spacer.gif) |
Pacman
|
Posted: Sun Nov 26, 2006 11:28 pm Post subject: (No subject) |
|
|
well, i tried that, but just so u dont have to worry about me anymore I GOT IT i think, well it works, I made this crap program in 5 minutes so, tell me if i doing something wrong please? And, it seems to work, im also using the same formula for my actual pacman game, ty guys
(LoL Try It, It Makes Me Laugh)
code: |
View.Update
var pacx, pacy, pacrad : int
var dotx, doty, dotrad : int
var distapart : real
var chars : array char of boolean
pacx := 50
pacy := 200
pacrad := 20
dotx := 200
doty := 200
dotrad := 5
loop
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
pacy:=pacy+5
end if
if chars (KEY_RIGHT_ARROW) then
pacx:=pacx+5
end if
if chars (KEY_LEFT_ARROW) then
pacx:=pacx-5
end if
if chars (KEY_DOWN_ARROW) then
pacy:=pacy-5
end if
cls
drawfillarc (pacx, pacy, pacrad, pacrad,25,330, yellow)
drawfilloval (dotx, doty, dotrad, dotrad, black)
delay (20)
distapart := sqrt ((dotx - pacx) ** 2 + (doty - pacy) ** 2)
if distapart <= pacrad + dotrad then
put "YOU SCORE TEN POINTS"
drawfilloval (dotx, doty, dotrad, dotrad, white)
exit
end if
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
NikG
|
Posted: Mon Nov 27, 2006 12:00 pm Post subject: (No subject) |
|
|
I didn't run your code, but you seem to be using colission detection (for circles) correctly. Good job. |
|
|
|
|
![](images/spacer.gif) |
Prince Pwn
|
Posted: Mon Nov 27, 2006 2:21 pm Post subject: (No subject) |
|
|
Another thing about your code, try to memorize how to do View.Update correctly, comes in handy.
code: |
View.Set ("graphics;offscreenonly")
var x, y : int := 50
var keys : array char of boolean
loop
Input.KeyDown (keys)
if keys ('d') then
x += 1
elsif keys ('a') then
x -= 1
end if
drawfilloval (x, y, 10, 10, red)
View.Update
cls
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
|
|