Posted: Thu Jun 09, 2011 12:12 pm Post subject: Collision Detection and Bounces
Im looking to make a game of tag.
There is a circle and a square.
You start at opposite corners and you cant go outside of the window.
Whoever is "red" color has to chase after the other "your it" and when you
tag them you get 1 point. When you tag them, they then become "red", "it"
and they chase after you. First to 10 points wins
Turing
----------
%%%%%%%%%%%boundries%%%%%%%%
if bally > 380 then
bally := 380
boxY := 370
end if
if bally < 20 then
bally := 20
boxY :=10
end if
if ballx > 620 then
ballx := 620
boxX := 610
end if
if ballx < 20 then
ballx := 20
boxX := 10
end if
if boxy > 360 then
boxy := 360
end if
if boxy < 0 then
boxy := 0
end if
if boxx > 600 then
boxx := 600
end if
if boxx < 0 then
boxx := 0
end if
That is used in a program to create boundaries between a circle and a square. When they touch eachother a point is then sent.
How is this used? I dont understand what the 360 and that means. Help please xD
Sponsor Sponsor
Raknarg
Posted: Thu Jun 09, 2011 3:31 pm Post subject: RE:Collision Detection and Bounces
This is just used to make sure that the shape can't escape the boundaries. If it's past the boundaries, it puts it back on the edge.
JumpingLimaBean
Posted: Thu Jun 09, 2011 7:05 pm Post subject: RE:Collision Detection and Bounces
I dont get how this detects if the players touch
eachother and when they do, they reset to again starter positions can someone explain in simple form?
var ballx, bally :int :=300
var boxX,boxY :int :=290
var boxx,boxy :int :=50
if colour1=40 and boxx < boxX +20 and boxx +20 > boxX and boxy < boxY +20 and boxy +20 > boxY then %?
colour1 :=0
colour2 :=40
boxx :=100
boxy :=100
score1 +=1
end if
if colour2=40 and boxX < boxx +20 and boxX +20 > boxx and boxY < boxy +20 and boxY +20 > boxy then %?
colour2 :=0
colour1 :=40
boxX :=290
boxY :=290
ballx :=300
bally :=300
score2 +=1
end if
Zren
Posted: Thu Jun 09, 2011 7:28 pm Post subject: RE:Collision Detection and Bounces
Combining circle and rectangular collision detection is annoying (possible but annoying). Why not just make both of them circles but different colours? Maybe even draw a number inside them with Font.Draw?
Posted: Thu Jun 09, 2011 11:02 pm Post subject: RE:Collision Detection and Bounces
I successfully drew the "1" in the same location of the circle. But how do i get it to follow with it
JumpingLimaBean
Posted: Thu Jun 09, 2011 11:37 pm Post subject: RE:Collision Detection and Bounces
Okay i ended up doing this prgram.
I got collision to work, but the problem is
that im going to use it to make TAG. If i
move past the circle, it says negative value
passed to Sqrt. I need it not to do this.
And sometimes it goes into the circle and not
stopping so its detecting it late or something.
Please test out and help me make it better
so i can turn it into TAG.
Turing:
var x :=320 var y :=200 var circlex1, circley1, circlerad1 :int var circlex2, circley2, circlerad2 :int var distance :real var number :int