
-----------------------------------
Camo
Tue Jan 20, 2004 5:43 pm

A COLLISION COUNTER BEWTEEN 2 BALLS ,CONFUES NEED ASSISTANCE
-----------------------------------
kk this is the code that i have*******
but i cant seem to find a way to make a counter that will count the amount of times that the 2 balls hit each other :( .... if u know how to fix this in the simplest way please reply THANKS ALOT!!!!! :) 

View.Set ("graphics:631;451,offscreenonly")

%bottom boarder

drawfilloval (15, 15, 15, 15, blue)
drawfilloval (45, 15, 15, 15, green)
drawfilloval (75, 15, 15, 15, yellow)
drawfilloval (105, 15, 15, 15, blue)
drawfilloval (135, 15, 15, 15, green)
drawfilloval (165, 15, 15, 15, yellow)
drawfilloval (195, 15, 15, 15, blue)
drawfilloval (225, 15, 15, 15, green)
drawfilloval (255, 15, 15, 15, yellow)
drawfilloval (285, 15, 15, 15, blue)
drawfilloval (315, 15, 15, 15, green)
drawfilloval (345, 15, 15, 15, yellow)
drawfilloval (375, 15, 15, 15, blue)
drawfilloval (405, 15, 15, 15, green)
drawfilloval (435, 15, 15, 15, yellow)
drawfilloval (465, 15, 15, 15, blue)
drawfilloval (495, 15, 15, 15, green)
drawfilloval (525, 15, 15, 15, yellow)
drawfilloval (555, 15, 15, 15, blue)
drawfilloval (585, 15, 15, 15, green)
drawfilloval (615, 15, 15, 15, yellow)
View.Update
% left boarder

drawfilloval (15, 15, 15, 15, blue)
drawfilloval (15, 45, 15, 15, green)
drawfilloval (15, 75, 15, 15, yellow)
drawfilloval (15, 105, 15, 15, blue)
drawfilloval (15, 135, 15, 15, green)
drawfilloval (15, 165, 15, 15, yellow)
drawfilloval (15, 195, 15, 15, blue)
drawfilloval (15, 225, 15, 15, green)
drawfilloval (15, 255, 15, 15, yellow)
drawfilloval (15, 285, 15, 15, blue)
drawfilloval (15, 315, 15, 15, green)
drawfilloval (15, 345, 15, 15, yellow)
drawfilloval (15, 375, 15, 15, blue)
drawfilloval (15, 405, 15, 15, green)
drawfilloval (15, 435, 15, 15, yellow)


%top border

drawfilloval (15, 435, 15, 15, blue)
drawfilloval (45, 435, 15, 15, green)
drawfilloval (75, 435, 15, 15, yellow)
drawfilloval (105, 435, 15, 15, blue)
drawfilloval (135, 435, 15, 15, green)
drawfilloval (165, 435, 15, 15, yellow)
drawfilloval (195, 435, 15, 15, blue)
drawfilloval (225, 435, 15, 15, green)
drawfilloval (255, 435, 15, 15, yellow)
drawfilloval (285, 435, 15, 15, blue)
drawfilloval (315, 435, 15, 15, green)
drawfilloval (345, 435, 15, 15, yellow)
drawfilloval (375, 435, 15, 15, blue)
drawfilloval (405, 435, 15, 15, green)
drawfilloval (435, 435, 15, 15, yellow)
drawfilloval (465, 435, 15, 15, blue)
drawfilloval (495, 435, 15, 15, green)
drawfilloval (525, 435, 15, 15, yellow)
drawfilloval (555, 435, 15, 15, blue)
drawfilloval (585, 435, 15, 15, green)
drawfilloval (615, 435, 15, 15, yellow)

%right boarder

drawfilloval (615, 15, 15, 15, blue)
drawfilloval (615, 45, 15, 15, green)
drawfilloval (615, 75, 15, 15, yellow)
drawfilloval (615, 105, 15, 15, blue)
drawfilloval (615, 135, 15, 15, green)
drawfilloval (615, 165, 15, 15, yellow)
drawfilloval (615, 195, 15, 15, blue)
drawfilloval (615, 225, 15, 15, green)
drawfilloval (615, 255, 15, 15, yellow)
drawfilloval (615, 285, 15, 15, blue)
drawfilloval (615, 315, 15, 15, green)
drawfilloval (615, 345, 15, 15, yellow)
drawfilloval (615, 375, 15, 15, blue)
drawfilloval (615, 405, 15, 15, green)
drawfilloval (615, 435, 15, 15, blue)


var xpos : int := 55
var xmove : int := 1
var xmove1 : int := 1
var ypos : int := 55
var ymove : int := 1
var ymove1 : int := 1
var counter : int := 0
var xypos : int := 200 
var yxpos : int := 110 


loop

    %ball 1

    drawfilloval (xpos, 300, 20, 20, 124)
    View.Update
    delay (0)
    drawfilloval (xpos, 300, 20, 20, white)
    if xpos > maxx - 55 then
        xmove := xmove * -1
    end if
    if xpos < 55 then
        xmove := xmove1 * 1
    end if
    xpos := xpos + xmove

    %ball 2

    drawfilloval (200, ypos, 20, 20, 134)
    View.Update
    delay (0)
    drawfilloval (200, ypos, 20, 20, white)
    if ypos > maxy - 55 then
        ymove := ymove * -1
    end if
    if ypos < 55 then
        ymove := ymove1 * 1
    end if
    ypos := ypos + ymove

    %counter

    Text.Locate (3, 5)
     if (xpos + 20) + (ypos + 20) =(xypos + 20) + (yxpos +20) then
        counter := counter + 1
    end if
    put "Collision: ", counter
   

end loop

-----------------------------------
Cervantes
Tue Jan 20, 2004 6:22 pm


-----------------------------------
wow.................

okay first
use for statements for when you draw the boarder, will save you a LOT of trouble

second
when drawing the 2 balls, draw them at the same point..

like this 
%draw the balls

drawfilloval (xpos, 300, 20, 20, 124) 
drawfilloval (200, ypos, 20, 20, 134) 
View.Update
delay (8)
drawfilloval (xpos, 300, 20, 20, white)
drawfilloval (200, ypos, 20, 20, white) 

third
don't use this crazy xypos stuff, use if statements to determine whether the x and y pos of the 2 balls are in the same place...

there's help, figure out how to impliment that yourself.

-----------------------------------
Camo
Tue Jan 20, 2004 7:13 pm

thanks but it doesnt relly help
-----------------------------------
this is for a project and i cant do what u said becuase u need to have my balls where they are u need help as it is now.....

-----------------------------------
AsianSensation
Tue Jan 20, 2004 9:02 pm


-----------------------------------
check the position of the two circles. if one is inside the other, then they have collided once. Use the circle formula to check for whether the circles are inside each other or not.

-----------------------------------
mike3
Tue Jan 20, 2004 9:20 pm


-----------------------------------
Alright, im in the same class as Dan and i need help bad too. Here's my code, it looks almost identical to Dan cause we sit beside each other. Please help us out. Also, the only commands we can use are ifs, loops, and puts and gets. We didnt learn anything else.


View.Set ("graphics:481;481,offscreenonly")

%BORDER

%left side
drawfilloval (15, 15, 15, 15, red)
drawfilloval (15, 45, 15, 15, blue)
drawfilloval (15, 75, 15, 15, green)
drawfilloval (15, 105, 15, 15, blue)
drawfilloval (15, 135, 15, 15, green)
drawfilloval (15, 165, 15, 15, blue)
drawfilloval (15, 195, 15, 15, green)
drawfilloval (15, 225, 15, 15, blue)
drawfilloval (15, 255, 15, 15, green)
drawfilloval (15, 285, 15, 15, blue)
drawfilloval (15, 315, 15, 15, green)
drawfilloval (15, 345, 15, 15, blue)
drawfilloval (15, 375, 15, 15, green)
drawfilloval (15, 405, 15, 15, blue)
drawfilloval (15, 435, 15, 15, green)
drawfilloval (15, 465, 15, 15, red)

%bottom
drawfilloval (45, 15, 15, 15, blue)
drawfilloval (75, 15, 15, 15, green)
drawfilloval (105, 15, 15, 15, blue)
drawfilloval (135, 15, 15, 15, green)
drawfilloval (165, 15, 15, 15, blue)
drawfilloval (195, 15, 15, 15, green)
drawfilloval (225, 15, 15, 15, blue)
drawfilloval (255, 15, 15, 15, green)
drawfilloval (285, 15, 15, 15, blue)
drawfilloval (315, 15, 15, 15, green)
drawfilloval (345, 15, 15, 15, blue)
drawfilloval (375, 15, 15, 15, green)
drawfilloval (405, 15, 15, 15, blue)
drawfilloval (435, 15, 15, 15, green)
drawfilloval (465, 15, 15, 15, red)

%right side
drawfilloval (465, 45, 15, 15, green)
drawfilloval (465, 75, 15, 15, blue)
drawfilloval (465, 105, 15, 15, green)
drawfilloval (465, 135, 15, 15, blue)
drawfilloval (465, 165, 15, 15, green)
drawfilloval (465, 195, 15, 15, blue)
drawfilloval (465, 225, 15, 15, green)
drawfilloval (465, 255, 15, 15, blue)
drawfilloval (465, 285, 15, 15, green)
drawfilloval (465, 315, 15, 15, blue)
drawfilloval (465, 345, 15, 15, green)
drawfilloval (465, 375, 15, 15, blue)
drawfilloval (465, 405, 15, 15, green)
drawfilloval (465, 435, 15, 15, blue)
drawfilloval (465, 465, 15, 15, red)

%top
drawfilloval (45, 465, 15, 15, green)
drawfilloval (75, 465, 15, 15, blue)
drawfilloval (105, 465, 15, 15, green)
drawfilloval (135, 465, 15, 15, blue)
drawfilloval (165, 465, 15, 15, green)
drawfilloval (195, 465, 15, 15, blue)
drawfilloval (225, 465, 15, 15, green)
drawfilloval (255, 465, 15, 15, blue)
drawfilloval (285, 465, 15, 15, green)
drawfilloval (315, 465, 15, 15, blue)
drawfilloval (345, 465, 15, 15, green)
drawfilloval (375, 465, 15, 15, blue)
drawfilloval (405, 465, 15, 15, green)
drawfilloval (435, 465, 15, 15, blue)

var xpos1 : int := 55
var move : int := 1
var move1 : int := 1
var ypos1 : int := 155
var ymove : int := 1
var ymove1 : int := 1
var counter : real := 0
var xpos2 : int := 200
var ypos2 : int := 110

% counter

loop
    drawfilloval (xpos1, ypos2, 25, 25, brightgreen)
    delay (1)
    View.Update
    drawfilloval (xpos1, ypos2, 25, 25, white)
    if xpos1 > maxx - 58 then
        move := move * -1
    end if
    if xpos1 < 58 then
        move := move1 * 1
    end if
    xpos1 := xpos1 + move

    % other ball

    drawfilloval (xpos2, ypos1, 25, 25, black)
    delay (1)
    View.Update
    drawfilloval (xpos2, ypos1, 25, 25, white)

    if ypos1 > maxy - 58 then
        ymove := ymove * -1
    end if
    if ypos1 < 58 then
        ymove := ymove1 * 1
    end if
    ypos1 := ypos1 + ymove

    % counter

    Text.Locate (3, 5)
    put "Collision: ", counter ..
    if (xpos1 + 25) = (xpos2 - 25) and (ypos2 = ypos1 + 50 or ypos1 = ypos2 + 50) then
        counter := counter + 1
    elsif (ypos1 + 25) = (ypos2 - 25) and (xpos1 = xpos2 + 50 or xpos2 = xpos1 + 50)
            then
        counter := counter + 1
    end if
end loop

-----------------------------------
Camo
Tue Jan 20, 2004 9:35 pm

thanks to AsianSensation
-----------------------------------
what u said was verry good advice (referring to WWAD) ill go by that more often BUT ther is a problem.......WHAT U SAID TO MADE NO SENSE!!!!!!!!!!!!!!!!!!!!! please clear it up for me

-----------------------------------
AsianSensation
Tue Jan 20, 2004 10:40 pm


-----------------------------------
let's say x1, y1 is the center of the first circle and x2, y2 is the center of the second circle. and let's say they both have a radius of 10. use the distance formula and check the distance between the centers of the 2 circles. If the distance is 20, then they are tangent to each other, if the distance is less than 20, then they are overlapping, and if the distance is greater than 20, then they are not touching at all.

btw, this is the first time someone refered me as the WWAD guy. Usually people call me Meng or Azn, but I guess WWAD might work too  :lol:

-----------------------------------
Camo
Wed Jan 21, 2004 8:14 am

WWAD!!!!!!!!!!!!!!
-----------------------------------
thanks alot for that but im afraid its tooo late.... im screwed over already the dead line has come and im up to my a$$ in work but i tried so its cool thanks n e ways guys
