collision help
Author |
Message |
Undr_Xposed
|
Posted: Wed Oct 26, 2005 6:45 pm Post subject: collision help |
|
|
could someone plz help me understand collision better i only started to learn to about 2 weeks ago and can do very few things i get a bit of it but i want to fully understand it and i looked at the help for it and couldnt really make a whole lot of sense out of it |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TokenHerbz
|
Posted: Thu Oct 27, 2005 2:00 am Post subject: (No subject) |
|
|
Well it works like this..
Each object has variables which tell it where it is on the map.
Now if we have an oval moving, say its chords at at X = 0, and y = 40
This means that the ball is infact on the border of the screen, we can detect this by:
code: |
if ballx <= 0 then
%%We execute code, but this means its on the left border.
end if
|
We can also set it for the top, bottom, or right of the screen by knowing how big our picture is, essentially its what you make it...
code: |
setscreen("Graphics:300;300")
%%or
setscreen("Graphics:max;max")
|
Above we set the screen to its maximum space, or 300X300 screen, so to see a collistion, we would essentially do...
code: |
if ballx+radius >= 300 then
%%we hit the right side
end if
%%you can also use maxx/maxy, thats for maximum x and y length, though setscreen is of max/max.
|
we ADD the radius so that the outer part of the balls stoped, instead of the bottomleft x/y chords of the ball.
When we collide with other obsticles, especially from each and every way, we must cover all the angles.
bah im a horrible teacher... i cant really explain it
code: |
setscreen("Graphics:max;max,offscreenonly")
var square_x, square_y, square_size, square_vx, square_vy: array 1 .. 2 of int
square_x(1) := 50
square_x(2) := 400
square_y(1) := 400
square_y(2) := 400
for i: 1 .. 2
square_vy(i) := 2
square_vx(i) := 2
square_size(i) := 40
end for
loop
cls
for i: 1 .. 2
square_x(i) += square_vx(i)
square_y(i) += square_vy(i)
end for
if square_x(1) <= square_x(2)+square_size(2) and square_x(1)+square_size(1) >= square_x(2) and
square_y(1) <= square_y(2)+square_size(2) and square_y(1)+square_size(1) >= square_y(2) then
for i: 1 .. 2
square_vx(i) *= -1
square_vy(i) *= -1
end for
end if
for i : 1 .. 2
if square_x(i) <= 0 or square_x(i)+square_size(i) >= maxx then
square_vx(i) *= -1
end if
if square_y(i) <= 0 or square_y(i)+square_size(i) >= maxy then
square_vy(i) *= -1
end if
end for
drawfillbox(square_x(1),square_y(1),square_x(1)+square_size(1),square_y(1)+square_size(1),black)
drawfillbox(square_x(2),square_y(2),square_x(2)+square_size(2),square_y(2)+square_size(2),red)
View.Update
delay(5)
end loop
|
|
|
|
|
|
|
Undr_Xposed
|
Posted: Thu Oct 27, 2005 2:46 pm Post subject: (No subject) |
|
|
dont worry about beeing the greatest teacher i just need a basic outline that i can follow and learn form and that for the help greatly appriciated 8) |
|
|
|
|
|
Jekate
|
Posted: Sat Oct 29, 2005 10:15 pm Post subject: (No subject) |
|
|
I'm trying to learn this myself again, and was looking around for tuts on it. I'm not fully sure about it yet but it's coming back. I noticed though that when your balls hit, they reverse horizontal direction and vertical which isn't right so I made a guess and fixed it lol.
code: |
setscreen("Graphics:max;max,offscreenonly")
var square_x, square_y, square_size, square_vx, square_vy: array 1 .. 2 of int
square_x(1) := 50
square_x(2) := 400
square_y(1) := 400
square_y(2) := 400
for i: 1 .. 2
square_vy(i) := 2
square_vx(i) := 2
square_size(i) := 40
end for
loop
cls
for i: 1 .. 2
square_x(i) += square_vx(i)
square_y(i) += square_vy(i)
end for
if square_x(1) <= square_x(2)+square_size(2) and square_x(1)+square_size(1) >= square_x(2) and
square_y(1) <= square_y(2)+square_size(2) and square_y(1)+square_size(1) >= square_y(2) then
for i: 1 .. 2
square_vx(i) *= -1
square_vy(i) *= -1 %<------------------------- take this line out
end for
end if
for i : 1 .. 2
if square_x(i) <= 0 or square_x(i)+square_size(i) >= maxx then
square_vx(i) *= -1
end if
if square_y(i) <= 0 or square_y(i)+square_size(i) >= maxy then
square_vy(i) *= -1
end if
end for
drawfillbox(square_x(1),square_y(1),square_x(1)+square_size(1),square_y(1)+square_size(1),black)
drawfillbox(square_x(2),square_y(2),square_x(2)+square_size(2),square_y(2)+square_size(2),red)
View.Update
delay(5)
end loop
|
I made reference to the text that should be taken out. |
|
|
|
|
|
|
|