Posted: Fri May 05, 2006 12:28 pm Post subject: bouncing picture ?
Alright i need to make a picture that bounces around the screen and the picture does not get cut off okay my problem is that it shows the picture and the errow at my second Pic.Draw and my teacher wants us to use Draw.Pic and i have to use the psuedo code that he gave us and he won't explain why mine does not work and i tried searching for what Draw.Pic was and it said that it was drawpic .
code:
%Amy Gilbank
%May 5 2006
%bounce.t
%a progrsm that allows picture to bounce around
var pic1,pic1w,pic1h,pic1x,pic1y,x,y,speedx,speedy:int
var backg : int
pic1:=Pic.FileNew("screwU.jpg")
pic1w:=Pic.Width(pic1)
pic1h:=Pic.Height(pic1)
pic1x:=100
pic1y:=150
x:=60
y:=60
speedx:=10
speedy:=10
loop
backg:=Pic.New(x,y,x+pic1w,y-pic1h)
Pic.Draw(pic1,x,y ,0)
delay(1000)
Pic.Draw(backg,600,800,0)
if pic1y>=450-pic1w or pic1x<=0 then
speedx:=-speedx
end if
if pic1x >=700 - pic1w or pic1x<=0 then
speedx:=-speedx
end if
pic1y:=pic1y+speedy
pic1x:=pic1x + speedx
end loop
Sponsor Sponsor
do_pete
Posted: Fri May 05, 2006 12:40 pm Post subject: (No subject)
You'll need to use Pic.Width and Pic.Height
gilbamy
Posted: Fri May 05, 2006 12:44 pm Post subject: (No subject)
pic1h and pic1w equal the Pic.Width stuff and the Pic.Height
do_pete
Posted: Fri May 05, 2006 12:52 pm Post subject: (No subject)
Okay, then you'll have to detect when the picture is touching the edge of the screen by going
code:
if pic1x >=0 and pic1x <= maxx - pic1w then
and the same thing for the y values.
gilbamy
Posted: Sat May 06, 2006 9:04 pm Post subject: (No subject)
but the problem is that my program won't run with that Draw.PIc thing and i nedd it their
codemage
Posted: Mon May 08, 2006 8:10 am Post subject: (No subject)
Try
Pic.Draw
gilbamy
Posted: Mon May 08, 2006 1:19 pm Post subject: (No subject)
so its Pic.Draw(pic1,x,y,mode) but what is mode and what does it do
gilbamy
Posted: Mon May 08, 2006 1:34 pm Post subject: (No subject)
okay i got that pic.draw thing to work but now my picture won't bounce around the screen so here is my code updated
code:
%Amy Gilbank
%May 5 2006
%bounce.t
%a progrsm that allows picture to bounce around
var pic1,pic1w,pic1h,pic1x,pic1y,x,y,speedx,speedy:int
var backg : int
pic1:=Pic.FileNew("screwU.jpg")
pic1w:=Pic.Width(pic1)
pic1h:=Pic.Height(pic1)
pic1x:=100
pic1y:=150
x:=60
y:=60
speedx:=10
speedy:=10
loop
backg:=Pic.New(x,y,x+pic1w,y-pic1h)
Pic.Draw(pic1,x,y,picCopy)
delay(1000)
Pic.Draw(pic1,x,y,picCopy)
if pic1y>=450-pic1w or pic1x<=0 then
speedx:=-speedx
end if
if pic1x >=700 - pic1w or pic1x<=0 then
speedx:=-speedx
end if
pic1y:=pic1y+speedy
pic1x:=pic1x + speedx
end loop
Sponsor Sponsor
Albrecd
Posted: Mon May 08, 2006 1:42 pm Post subject: (No subject)
Your picture does not move because you draw your picture at point (x, y), which does not change, then you change pic1x and pic1y which, at the moment, do nothing.
Also:
code:
if pic1y >= 450 - pic1w or pic1x <= 0 then
speedx := -speedx
end if
if pic1x >= 700 - pic1w or pic1x <= 0 then
speedx := -speedx
end if
pic1y := pic1y + speedy
pic1x := pic1x + speedx
has a problem. You have speedx changing based on speedy and speedy doesn't change and a bunch more messed up stuff, but this should be easy to fix once you sort out your variable troubles.
gilbamy
Posted: Mon May 08, 2006 1:52 pm Post subject: (No subject)
the code you gave me is the same as mine and i have no idea how that would effect it anyway
Albrecd
Posted: Mon May 08, 2006 1:59 pm Post subject: (No subject)
I know it's your code. That's the point. It has errors. I am pointing them out.
gilbamy
Posted: Tue May 09, 2006 11:19 am Post subject: (No subject)
how do i know what the problem is if know one tells me
gilbamy
Posted: Tue May 09, 2006 12:48 pm Post subject: (No subject)
alright i changed some things around that i did not see at the time and it still does not bounce around the screen so here is my code updated again
code:
%Amy Gilbank
%May 5 2006
%bounce.t
%a progrsm that allows picture to bounce around
var winMain : int := Window.Open ("graphics:800;600")
var pic1, pic1w, pic1h, pic1x, pic1y, x, y, speedx, speedy,backg : int
pic1 := Pic.FileNew ("screwU.jpg")
pic1w := Pic.Width (pic1)
pic1h := Pic.Height (pic1)
pic1x := 100
pic1y := 200
x := 200
y := 130
speedx := 90
speedy := 80
loop
backg := Pic.New (x, y, x + pic1w, y - pic1h)
Pic.Draw (pic1, x, y, picCopy)
delay (500)
Pic.Draw ( backg,x, y, picCopy)
if pic1y >= 400 - pic1h or pic1y <= 0 then
speedy := -speedy
end if
if pic1x >= 700 - pic1w or pic1x <= 0 then
speedx := -speedx
end if
pic1y := pic1y + speedy
pic1x := pic1x + speedx
end loop
Clayton
Posted: Tue May 09, 2006 12:58 pm Post subject: (No subject)
the problem is you are drawing the picture at (your variable names) (x,y) not (pic1x,pick1y), so when you update pic1x and pic1y you arent doing anything, eliminate x and y or pic1x and pic1y and use the other to move your pic (this was stated above as well)
gilbamy
Posted: Wed May 10, 2006 10:55 am Post subject: (No subject)
sweet that worked thx but now it says that thir is something wrong with Draw.Pic(backg,pic1x,pic1y,PicCopy)its like an illegal pic id number'0'