----------------------------------- coolgirl97 Wed May 29, 2013 5:47 pm bouncing a ball... PLEASE HELP ----------------------------------- I need to make a ball bounce within a box... i got the box done and the bouncing boundaries for the x and y.... NOW I NEED TO ADD A Z.. so the ball can bounce front and back as well.. PLEASE HELP ME!! This is what i have so far.... drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) %Ball bouncing const RADIUS := 15 const DELTA_TIME := 0.10 const TIME_DELAY := 10 const x_right_boundary := 480 const x_left_boundary := 220 const y_top_boundary := 330 const y_bottom_boundary := 70 var x, y, x0, y0, v0x, v0y, t : real x0 := 100 y0 := 100 v0x := 30 v0y := 10 t := 0 loop x := x0 + v0x * t y := y0 + v0y * t drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS),black) delay (TIME_DELAY) drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS), white) if x > x_right_boundary then x0 := 2 * x_right_boundary - x y0 := y v0x := -v0x t := 0 end if if x < x_left_boundary then x0 := 2 * x_left_boundary - x v0x := -v0x y0 := y t := 0 end if if y > y_top_boundary then y0 := 2 * y_top_boundary - y v0y := -v0y x0 := x t := 0 end if if y < y_bottom_boundary then y0 := 2 * y_bottom_boundary - y v0y := -v0y x0 := x t := 0 end if t := t + DELTA_TIME cls drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) end loop ----------------------------------- Nathan4102 Wed May 29, 2013 5:55 pm RE:bouncing a ball... PLEASE HELP ----------------------------------- Your z coord would reflect how close the ball is to the user. When the z is bigger(or smaller), the ball would get bigger. So you could change the radius by some amount based on the z coord. ----------------------------------- coolgirl97 Wed May 29, 2013 5:59 pm Re: bouncing a ball... PLEASE HELP ----------------------------------- Thanks, but the thing is i'm really new to comp sci.. (have no idea y i took the course), and my teacher does not know how to teach :S so... how exactly do i add the z coord??? Thank you so much!! ----------------------------------- Nathan4102 Wed May 29, 2013 6:02 pm RE:bouncing a ball... PLEASE HELP ----------------------------------- Well "z" would be another variable, just like x and y, and you'd increase it the same way you increase your other variables. Then when you draw the ball, just have the radius relative in some way to z, instead of the constant RADIUS. E: You'd have to remember to make the ball "bounce" in the z plane as well, just like your x and y's. ----------------------------------- coolgirl97 Wed May 29, 2013 6:18 pm Re: bouncing a ball... PLEASE HELP ----------------------------------- so would i do something like this??.. (sorry for all the questions btw)... drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) %Ball bouncing const RADIUS := 15 const DELTA_TIME := 0.10 const TIME_DELAY := 10 const x_right_boundary := 480 const x_left_boundary := 220 const y_top_boundary := 330 const y_bottom_boundary := 70 var x, y, z0 := v0z :=z:= z0 + v0z * tif z > z_front_boundary then z0 := 2 * z_front _boundary - z v0z := -v0z x0 := x t := 0 end if if z < z_back_boundary then z0 := 2 * z_back_boundary - z v0z := -v0z x0 := x t := 0 end if[/color] t := t + DELTA_TIME cls drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) end loop ----------------------------------- coolgirl97 Wed May 29, 2013 6:19 pm Re: bouncing a ball... PLEASE HELP ----------------------------------- ignore.. the colour red thing... i did it to show what i added.. but it is html coding, so you won't see the difference right away , anyways... Thanks! ----------------------------------- Nathan4102 Wed May 29, 2013 6:26 pm RE:bouncing a ball... PLEASE HELP ----------------------------------- No problem, and that should work, except you need to draw your circle based on your z coord aswell. ----------------------------------- onedirectionlover Wed May 29, 2013 6:31 pm Re: bouncing a ball... PLEASE HELP ----------------------------------- i did... didn't i ?? drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS), black) delay (TIME_DELAY) drawfilloval (round (x), round (y), round (RADIUS), round (RADIUS), white) drawfilloval (round(z), round (x), round (RADIUS), round (RADIUS), black) delay (TIME_DELAY) drawfilloval (round(z), round (x), round (RADIUS), round (RADIUS), white) drawfilloval (round(z), round (y), round (RADIUS), round (RADIUS), black) delay (TIME_DELAY) drawfilloval (round (z), round (y), round (RADIUS), round (RADIUS), white) ----------------------------------- Nathan4102 Wed May 29, 2013 6:39 pm RE:bouncing a ball... PLEASE HELP ----------------------------------- Youre only changing the x and y parameters of "drawfilloval". round(x) and round(y) should stay as the x and y parameters. The thing you need to change is the x and y radius(3'rd and 4'th parameter). Assuming we're looking at this ball straight down the z plane, as z increases, the ball would appear bigger, correct? Thus, as z increases, we need to draw the ball larger. ----------------------------------- coolgirl97 Thu May 30, 2013 8:01 am Re: bouncing a ball... PLEASE HELP ----------------------------------- Okay... i kinda get what u r saying.. thank you! but.. just one more question... so instead of this: if z > z_front_boundary then z0 := 2 * z_front _boundary - z v0z := -v0z x0 := x t := 0 end if if z < z_back_boundary then z0 := 2 * z_back_boundary - z v0z := -v0z x0 := x t := 0 end if will it be something like this?? : if z > z_front_boundary then RADIUS := 20 v0z := -v0z x0 := x t := 0 end if if z < z_back_boundary then RADIUS := 10 v0z := -v0z x0 := x t := 0 end if THANK U SO MUCH !! x_right_boundary then x0 := 2 * x_right_boundary - x y0 := y v0x := -v0x t := 0 end if if x < x_left_boundary then x0 := 2 * x_left_boundary - x v0x := -v0x y0 := y t := 0 end if if y > y_top_boundary then y0 := 2 * y_top_boundary - y v0y := -v0y x0 := x t := 0 end if if y < y_bottom_boundary then y0 := 2 * y_bottom_boundary - y v0y := -v0y x0 := x t := 0 end if if z > z_front_boundary then z0 := 2 * z_front _boundary - z v0z := -v0z x0 := x t := 0 end if if z < z_back_boundary then z0 := 2 * z_back_boundary - z v0z := -v0z x0 := x t := 0 end if t := t + DELTA_TIME cls drawline (510,360,510,40, black) drawline (510,360,190,360,black) drawline (190,360,190,40, black) drawline (190,40,510,40, black) drawline (450,300,450,100, black) drawline (450,300,250,300,black) drawline (250,300,250,100, black) drawline (250,100,450,100, black) drawline (190,360,250,300, black) drawline (450,300,510,360,black) drawline (190,40,250,100, black) drawline (510,40,450,100, black) end loop ----------------------------------- Nathan4102 Thu May 30, 2013 1:00 pm RE:bouncing a ball... PLEASE HELP ----------------------------------- A good way to see if it's correct is to run it, and see if it does what you want it to do. ;) ----------------------------------- coolgirl97 Thu May 30, 2013 1:07 pm Re: bouncing a ball... PLEASE HELP ----------------------------------- yea.. good idea!, but the thing is that i only have macs at home.. so i don't have the turing program.... i tried searching for turing programs for macs, but i wasn't able to find one... the only chance i have to run it is during class, and that is if my teacher lets us use the computers.. ----------------------------------- Insectoid Thu May 30, 2013 1:38 pm RE:bouncing a ball... PLEASE HELP ----------------------------------- [url=http://portingteam.com/files/file/7553-turing/]Here is a mac port of Turing. You'll have to make an account on that site to download it though. ----------------------------------- coolgirl97 Thu May 30, 2013 4:19 pm Re: bouncing a ball... PLEASE HELP ----------------------------------- thank you, i'll try it out :)