Computer Science Canada

please help as fast as possible

Author:  Rocky [ Thu Dec 19, 2002 4:51 am ]
Post subject:  please help as fast as possible

Arrow my program got two circles and one of them is bouncing all over the screen and the only thing i want is to give me a code that makes the bouncy circle bounce back if it hit the other circle and not pass throu it.
plz answer quickly Crying or Very sad

Author:  azndragon [ Thu Dec 19, 2002 9:13 am ]
Post subject: 

Read the tutorial for the pool game in the other Turing forum. It explains how to develop a very realistic physics system.

Author:  Rocky [ Thu Dec 19, 2002 7:12 pm ]
Post subject:  thankx but..

thank you but i still can't understand . let me just tell what iam doing

i made two circles one is big and the other one is small . i made the small one bounce all over the screen and i made the big one move usin the keyboared and the only thing is missing now is to make the small ball bounce back if hits the big one .... so please answer quickly ..plz.plz...i really need it today ...plz the code

Author:  krishon [ Thu Dec 19, 2002 7:41 pm ]
Post subject: 

i'm not to sure bout how to do this, maybe if you can use the equation of a circle. Like if they touch, then since the x y co-ordinates ont he side change, you could make them bounce off. i not really sure how to do it with a circle, but i know how to do it with a straight line, like pong.

Author:  krishon [ Thu Dec 19, 2002 7:47 pm ]
Post subject: 

well, actually, nm
u should reread the tutorial, with the code about the length between the centers and the if the distance of the length is less than the sum of the length of the radiuses, then it will bounce off. that is ur best bet.

Author:  Rocky [ Thu Dec 19, 2002 8:29 pm ]
Post subject:  ok can you..

ok u said that u can do it with a line right? i think that would be better because iam actully making a program that it's related to pong so clould u please show me the code or send it to aho_vip@hotmail.com

plz hurry up Embarassed Crying or Very sad

Author:  Rocky [ Thu Dec 19, 2002 8:34 pm ]
Post subject:  i ask a lot sorry

could u please include the way of moving the line if u decided to send the code ...... i know i asked alot but i am new on turing and i don't know alot about it ...sorry Embarassed

Author:  Dan [ Thu Dec 19, 2002 8:59 pm ]
Post subject:  time sucks

with all the stuff going on i dont have any time to wire this up for you but we do have two difrent pong progames that may help you out.

go to:

ftp://swat@danco.no-ip.com/

then go in to the turing dir, progames then there is dan pong and another one made by some one i know.

Author:  Dan [ Thu Dec 19, 2002 9:01 pm ]
Post subject:  oh

oh, one more thing they are made for turing 3.0.1 so if you dont have a sprite comblet turing you may have some problems but the code for colasion dection is still good.

P.S. next time plz give your post a better title it will help us and poleop that are looking for help.

Author:  Rocky [ Thu Dec 19, 2002 9:10 pm ]
Post subject:  sorry

iam have been trying to do what u said scence last week but as i said iam not really good at turing and i just found ur site yesterday and my program is due tommorw sooooooooooo pleaseeeeeeee help plz plz Crying or Very sad Crying or Very sad

Author:  Rocky [ Thu Dec 19, 2002 9:20 pm ]
Post subject: 

this what i got tell now

-----------------------------------------------------------------------

%-----------------------------------------------------------------------------
%Variable Dictionary
%-----------------------------------------------------------------------------
var b, n : int %Cordenates of the cercle centre
var chars : array char of boolean %Arrys
var x : int % the center of the circle
var y : int % the center of the circle
var dx : int %The Change in x
var dy : int %The Change in y
var picID : int %The ball image
var picBack : int %the Background Picture
var t : array 1 .. 8 of int := init (100, 100, 135, 185, 220, 220, 185, 135) %initiling the lines of the polygon
var z : array 1 .. 8 of int := init (100, 150, 185, 185, 150, 100, 65, 65) %initiling the lines of the polygon
%-----------------------------------------------------------------------------
%Setting Values For Variables
%-----------------------------------------------------------------------------

x := 100 %assigning where the centre of the circle must be
y := 240 %assigning where the centre of the circle must be
dx := Rand.Int (10, 15) %setting the changes of x to random number
dy := Rand.Int (10, 15) %setting the changes of y to random number
b := 100 %Centre of the Circle
n := 100 %Centre of the Circle

%-----------------------------------------------------------------------------
% SET SCREEN SETTINGS
%-----------------------------------------------------------------------------

setscreen ("graphics:v16") % sets the screen for vga mode 640 x 480
setscreen ("nocursor") % Turn off cursor
setscreen ("noecho")% Do not echo keys

%----------------------------------------------------------------------------
%Drawing the intor screen
%----------------------------------------------------------------------------

Draw.FillBox (0, 0, maxx, maxy, black)
delay (1000)
Draw.FillPolygon (t, z, 8, brightblue)
Draw.Polygon (t, z, 8, cyan)
delay(1000)
var font4 : int
font4 := Font.New ("Palatino:40:bold,italic")
Font.Draw ("Wellcome", 200, 300, font4, green)
delay(1000)
put"Try to prevent the bouncy ball from going behind your big circle"
delay(3000)

%----------------------------------------------------------------------------
%Play Music while the program is running
%----------------------------------------------------------------------------

process Rock
loop
Music.PlayFile ("pong2.mid")
end loop
end Rock

fork Rock


%----------------------------------------------------------------------------
%Drawing Background
%----------------------------------------------------------------------------

Draw.FillBox (0, 0, maxx, maxy, 10)
for v : 80 .. 640 by 80
Draw.Line (v, 0, v, 480, 0)
end for

for h : 60 .. 640 by 60
Draw.Line (0, h, 640, h, 0)
end for

%---------------------------------------------------------------------------
% Capture Image as Background and Draw it
%---------------------------------------------------------------------------

picBack := Pic.New (0, 0, maxx, maxy)
Pic.Draw (picBack, 0, 0, picCopy)
cls

%---------------------------------------------------------------------------
%Drawing the Ball
%---------------------------------------------------------------------------

Draw.Oval (x, y, 10, 10, blue)
Draw.Dot (105, 240, 3)
Draw.Fill (105, 240, blue, blue)
picID := Pic.New (90, 200, 115, 250)


%---------------------------------------------------------------------------
%looping and setting the walls
%---------------------------------------------------------------------------

loop

Pic.Draw (picBack, 0, 0, picCopy)
Pic.Draw (picID, x, y, picMerge)
delay (40)
x := x + dx

if x >= maxx - 20 or x <= 0 then
dx:=-dx
end if

y := y + dy
if y >= maxy - 50 or y <= -30 then
dy := -dy
end if

%-----------------------------------------------------------------------------
%Make The Big Circle move using the Keyboared
%-----------------------------------------------------------------------------
Input.KeyDown (chars)

if chars (KEY_UP_ARROW) then
n := n + 5

elsif chars (KEY_RIGHT_ARROW) then
b := b + 5

elsif chars (KEY_LEFT_ARROW) then
b := b - 5

elsif chars (KEY_DOWN_ARROW) then
n := n - 5
end if

drawoval (b, n, 40, 40, red)
delay (5)

end loop
-----------------------------------------------------------------------------------
and as i said the only thing i want is to make the bouncy ball bounce back if it hits the big ball


plzzz help

Author:  Rocky [ Thu Dec 19, 2002 9:23 pm ]
Post subject:  if u..

if u dont know how make the ball bounce back pretend that it's aline and tell me how to move it

sorry about allt these posts

Author:  Tony [ Thu Dec 19, 2002 10:48 pm ]
Post subject:  solution

listen kid, you were told to read the tutorial on pool like 5 times already. By different people... I mean come on! It has all the code you need and it explains how to use it.

Quote:
if x >= maxx - 20 or x <= 0 then
dx:=-dx
end if


you obvisoly understand how to bounce the ball of the wall, now just make another if statment to bounce it of the other ball...

http://www.compsci.ca/bbs/viewtopic.php?t=129

here, just in case you don't know how to use links, I'll post the code up again from my tutorial that you were told to read:

code:

distance := ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))** 0.5

if distance < 10 %if collision
then
sp2x := round(sp1x*sp1x + sp1y*sp1y)**0.5 * ((x2-x1)/(x2-x1 + y2-y1))
sp2y := round(sp1x*sp1x + sp1y*sp1y)**0.5 * ((y2-y1)/(x2-x1 + y2-y1))
end if


follow the link above for the explanation of functions and how they were found and how to use them properly.

Author:  Rocky [ Thu Dec 19, 2002 10:55 pm ]
Post subject:  man iam sorry

man i have read the tutourial more than 2 times but i still can't understand it but i'll keep reading but plz if u have time just tell how do do it Crying or Very sad

Author:  Tony [ Thu Dec 19, 2002 11:05 pm ]
Post subject: 

ok, how about you try to follow the tutorial? I made it with steps.

It explains what variables stand for and what steps you need to take to make realistic physics.

hey, you can just do if distance < 50 then dx:=-dx

the ball will bounce off, just in the wrong direction. It would be as if it hit the solid vertical wall there.

tutorial explains how to find right angle after colision of 2 balls.

Author:  Rocky [ Thu Dec 19, 2002 11:22 pm ]
Post subject: 

this the fourth time of reading the tutorial and i still can't find a relation between this and my program , i actually made another if statement as u told me but still don't know what is the code.
looks like iam dumb and can't understand the tutorial.
HELP NEED CODE Crying or Very sad

Author:  Tony [ Thu Dec 19, 2002 11:38 pm ]
Post subject: 

ok... how should I say this... When I give you working code for your program... you don't say
Quote:
i don't understand it, give me another code
... instead you should read the explanation suppiled for that code.

listen, you do realize that the tutorial is made up of 2 posts, its not me replying to myself Confused The code I gave you comes from 2nd post from that link... you have to scroll down

besides, its a working code. Just replace the variable names with the those you use and you're all set.

Author:  Rocky [ Thu Dec 19, 2002 11:46 pm ]
Post subject:  sorry

sorry about what i said before but man iam really doing my best and reading everything u have said but when i put the code u gave me which is

if distance < 50 then
dx := -dx

nothing happened and the bouncy ball had just passed through the big circle

man i swear on god that iam reading every thing u say and doing my best but .....it's not working

Author:  Tony [ Thu Dec 19, 2002 11:51 pm ]
Post subject: 

ya, well how are you calculating the distance between the two balls?

and does the sum of their radioses add up to 50?

Author:  Rocky [ Thu Dec 19, 2002 11:58 pm ]
Post subject:  ok

ok iam caculating the distance using the equation u gave and the radiuoses does add to 50 because 10 + 40 is 50

Author:  Rocky [ Fri Dec 20, 2002 12:03 am ]
Post subject: 

ok look that what i have done run in ur computer and u will see that it's not working

code:

%-----------------------------------------------------------------------------
%  Title of Program :  Ping Pong Game
%  Purpose : It's a game with some crazy rules or let's say No rules
%  Author :  Anas Obaisi
%  Date : last edited December 19, 2002, 9:18 e
%-----------------------------------------------------------------------------

%-----------------------------------------------------------------------------
%Variable Dictionary
%-----------------------------------------------------------------------------
var b, n : int %Cordenates of the cercle centre
var chars : array char of boolean  %Arrys
var x : int % the center of the circle
var y : int % the center of the circle
var dx : int %The Change in x
var dy : int %The Change in y
var picID : int %The ball image
var picBack : int %the Background Picture
var t : array 1 .. 8 of int := init (100, 100, 135, 185, 220, 220, 185, 135) %initiling the lines of the polygon
var z : array 1 .. 8 of int := init (100, 150, 185, 185, 150, 100, 65, 65) %initiling the lines of the polygon
var distance : real
var cx : int := 5
var cy : int := 5
%-----------------------------------------------------------------------------
%Setting Values For Variables
%-----------------------------------------------------------------------------

x := 100 %assigning where the centre of the circle must be
y := 240 %assigning where the centre of the circle must be
dx := Rand.Int (10, 15) %setting the changes of x to random number
dy := Rand.Int (10, 15) %setting the changes of y to random number
b := 100 %Centre of the Circle
n := 100 %Centre of the Circle
% distance := ((b - x) * (b - x) + (n - y) * (n - y)) ** 0.5

%-----------------------------------------------------------------------------
% SET SCREEN SETTINGS
%-----------------------------------------------------------------------------

setscreen ("graphics:v16") % sets the screen for vga mode 640 x 480
setscreen ("nocursor") % Turn off cursor
setscreen ("noecho") % Do not echo keys

%----------------------------------------------------------------------------
%Drawing the intor screen
%----------------------------------------------------------------------------

Draw.FillBox (0, 0, maxx, maxy, black)
delay (1000)
Draw.FillPolygon (t, z, 8, brightblue)
Draw.Polygon (t, z, 8, cyan)
delay (1000)
var font4 : int
font4 := Font.New ("Palatino:40:bold,italic")
Font.Draw ("Welcome", 200, 300, font4, green)
delay (1000)
put "Try to prevent the bouncy ball from going behind your big circle"
delay (3000)

%----------------------------------------------------------------------------
%Play Music while the program is running
%----------------------------------------------------------------------------

process Rock
    loop
        Music.PlayFile ("Seymor.mid")
    end loop
end Rock

fork Rock


%----------------------------------------------------------------------------
%Drawing Background
%----------------------------------------------------------------------------

Draw.FillBox (0, 0, maxx, maxy, 10)
for v : 80 .. 640 by 80
    Draw.Line (v, 0, v, 480, 0)
end for

for h : 60 .. 640 by 60
    Draw.Line (0, h, 640, h, 0)
end for

drawbox (0, 0, maxx, maxy, 1)
drawbox (4, 4, maxx - 4, maxy - 4, 1)
drawfill (1, 1, 1, 1)

%---------------------------------------------------------------------------
% Capture Image as Background and Draw it
%---------------------------------------------------------------------------

picBack := Pic.New (0, 0, maxx, maxy)
Pic.Draw (picBack, 0, 0, picCopy)
cls

%---------------------------------------------------------------------------
%Drawing the Ball
%---------------------------------------------------------------------------
procedure ran
    for j : 1 .. 2
        randint (x, 200, maxx - 400)
        randint (y, 300, maxy - 200)
        randint (dx, 1, 5)
        randint (dy, 1, 5)
    end for
end ran

Draw.Oval (x, y, 10, 10, blue)
Draw.Dot (105, 240, 3)
Draw.Fill (105, 240, blue, blue)
picID := Pic.New (90, 200, 115, 250)

%---------------------------------------------------------------------------
%looping and setting the walls
%---------------------------------------------------------------------------

loop
    distance := ((b - x) * (b - x) + (n - y) * (n - y)) ** 0.5
    if distance < 10 %if collision
            then
        cx := round(dx * dx + dy * dy) ** 0.5 * ((b - x) / (b - x + n - y))
        cy := round(dx * dx + dy * dy) ** 0.5 * ((n - y) / (b - x + n - y))
    end if

    if distance < 50 then
        dx := -dx
    end if
    Pic.Draw (picBack, 0, 0, picCopy)
    Pic.Draw (picID, x, y, picMerge)
    delay (40)
    x := x + dx

    if x >= maxx - 20 or x <= 0 then
        dx := -dx
    end if

    y := y + dy
    if y >= maxy - 50 or y <= -30 then
        dy := -dy
    end if

    %-----------------------------------------------------------------------------
    %Make The Big Circle move using the Keyboared
    %-----------------------------------------------------------------------------
    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        n := n + cy

    elsif chars (KEY_RIGHT_ARROW) then
        b := b + cx

    elsif chars (KEY_LEFT_ARROW) then
        b := b - cx

    elsif chars (KEY_DOWN_ARROW) then
        n := n - cy
    end if

    drawoval (b, n, 40, 40, red)
    delay (5)

end loop



please answer me

Author:  Rocky [ Fri Dec 20, 2002 12:16 am ]
Post subject:  Finally

Thankx alot man i finally got it my proplem was the decleration .

now i could finish my program thankx man ur name will be the first one on my credit

thankx thankx Wink Wink Smile Very Happy

Author:  Tony [ Fri Dec 20, 2002 12:39 am ]
Post subject: 

its nice to hear that you figured your problems out Very Happy


sujestions for the next time - use variables that make more sence. such as b,n don't really show that its the coordinates for the ball. Wink

Author:  Rocky [ Fri Dec 20, 2002 1:00 am ]
Post subject:  promise

i promise that i will


: