Computer Science Canada

bouncing picture ?

Author:  gilbamy [ 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

Author:  do_pete [ Fri May 05, 2006 12:40 pm ]
Post subject: 

You'll need to use Pic.Width and Pic.Height

Author:  gilbamy [ Fri May 05, 2006 12:44 pm ]
Post subject: 

pic1h and pic1w equal the Pic.Width stuff and the Pic.Height

Author:  do_pete [ Fri May 05, 2006 12:52 pm ]
Post 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.

Author:  gilbamy [ Sat May 06, 2006 9:04 pm ]
Post subject: 

but the problem is that my program won't run with that Draw.PIc thing and i nedd it their

Author:  codemage [ Mon May 08, 2006 8:10 am ]
Post subject: 

Try
Pic.Draw

Author:  gilbamy [ Mon May 08, 2006 1:19 pm ]
Post subject: 

so its Pic.Draw(pic1,x,y,mode) but what is mode and what does it do

Author:  gilbamy [ Mon May 08, 2006 1:34 pm ]
Post 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

Author:  Albrecd [ Mon May 08, 2006 1:42 pm ]
Post 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.

Author:  gilbamy [ Mon May 08, 2006 1:52 pm ]
Post subject: 

the code you gave me is the same as mine and i have no idea how that would effect it anyway Twisted Evil

Author:  Albrecd [ Mon May 08, 2006 1:59 pm ]
Post subject: 

I know it's your code. That's the point. It has errors. I am pointing them out.

Author:  gilbamy [ Tue May 09, 2006 11:19 am ]
Post subject: 

how do i know what the problem is if know one tells me

Author:  gilbamy [ Tue May 09, 2006 12:48 pm ]
Post 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 Twisted Evil
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

Author:  Clayton [ Tue May 09, 2006 12:58 pm ]
Post 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)

Author:  gilbamy [ Wed May 10, 2006 10:55 am ]
Post 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'

Author:  gilbamy [ Wed May 10, 2006 11:20 am ]
Post subject: 

alright here is my new code with that stupid line
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
speedx := 90
speedy := 80
loop
    backg := Pic.New (pic1x,pic1y, pic1x + pic1w,pic1y - pic1h)
    Pic.Draw (pic1, pic1x, pic1y,picCopy)
    delay (500)
    Pic.Draw ( backg,pic1x, pic1y, 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

Author:  do_pete [ Wed May 10, 2006 11:21 am ]
Post subject: 

That means that the picture was not succesfully created. Check to see if it is in the same folder as your code or that you specify the folder. Also check that you have hte picture name right when you create it using Pic.FileNew.

Author:  gilbamy [ Wed May 10, 2006 1:40 pm ]
Post subject: 

the picture appears and moves but then it stops and then comes up with the illgeal picture id
code:
Pic.Draw ( backg,pic1x, pic1y, picCopy)

thats that stupid line code that won't work

Author:  do_pete [ Wed May 10, 2006 2:42 pm ]
Post subject: 

Sorry about my previous comment; I didn't see you were using Pic.New so disregard what I said about folders and Pic.FileNew. Anyways, you shouldn't use Pic.New that way because it takes up a lot of memory and the reason you get an error is because it can't create the picture fast enough.

Author:  gilbamy [ Thu May 11, 2006 11:52 am ]
Post subject: 

so how do i get the error to go away though thats the problem because i don't know if changing it to Pic.New will help

Author:  gilbamy [ Thu May 11, 2006 11:59 am ]
Post subject: 

hehe i truly hate turing right now i will take a my copy and smash it with a hammer that might though cost more money in which i lack so i will copy this stupid program and smash it into tiny little pieces . Evil or Very Mad


: