
-----------------------------------
Undr_Xposed
Wed Oct 26, 2005 6:45 pm

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

-----------------------------------
TokenHerbz
Thu Oct 27, 2005 2:00 am


-----------------------------------
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:


if ballx = 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 :(


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) and
        square_y(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) = maxx then
            square_vx(i) *= -1
        end if
        if square_y(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
Thu Oct 27, 2005 2:46 pm


-----------------------------------
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
Sat Oct 29, 2005 10:15 pm


-----------------------------------
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.


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) and 
        square_y(1) = square_y(2) then 
        for i: 1 .. 2 
            square_vx(i) *= -1 
            square_vy(i) *= -1 %