Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 bouncing pictures with two
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gilbamy




PostPosted: Mon May 15, 2006 11:49 am   Post subject: bouncing pictures with two

alright well i need my two pictures to bounce around on the screen and they don't work one comes then goes then the second picture appears in its place i need help here is my code
code:
%Amy Gilbank
%May 10 2006
%bounce2.t
%a progrsm that allows pictures to bounce around
var winMain : int := Window.Open ("graphics:800;600")
var pic1, pic1w, pic1h, pic1x, pic1y, speed1x, speed1y,backg : int
var pic2,pic2w,pic2h,pic2x,pic2y,speed2x,speed2y:int
pic1 := Pic.FileNew ("screwU.jpg")
pic1w := Pic.Width (pic1)
pic1h := Pic.Height (pic1)
pic1x := 100
pic1y := 200
pic2:=Pic.FileNew("1104710-movie-resized200.jpg")
pic2w:=Pic.Width(pic2)
pic2h:=Pic.Height(pic2)
pic2x:=200
pic2y:=150
speed1x := 90
speed1y := 80
speed2x:=700
speed2y:=450
loop
    backg := Pic.New (pic1x,pic1y, pic1x + pic1w,pic1y - pic1h)
             Pic.Draw (pic1, pic1x, pic1y,picCopy)
            delay (500)
    Pic.Draw ( backg,pic1x, pic1y, picCopy)
    backg:=Pic.New(pic2x,pic2y,pic2x+pic2w,pic2y-pic2h)
     Pic.Draw(pic2,pic2x,pic2y,picCopy)
     delay (200)
    Pic.Draw(pic2x,pic2y,backg,picCopy)
        if pic1y >= 400 - pic1h or pic1y <= 0 then
        speed1y := -speed1y
    end if
    if pic1x >= 700 - pic1w or pic1x <= 0 then
        speed1x := -speed1x
            end if
        if pic2y>=550-pic2h or pic2y<=0 then
    speed2y:=speed2x
    end if
    if pic2x>=600-pic2w or pic2x <=0 then
    speed2x:=-speed2x
    end if
      pic1y := pic1y + speed1y
    pic1x := pic1x + speed1x
    pic2y:=pic2y+speed2y
    pic2x:=pic2x+speed2x
    end loop
Sponsor
Sponsor
Sponsor
sponsor
ZeroPaladn




PostPosted: Mon May 15, 2006 12:29 pm   Post subject: (No subject)

Allright, first off, if you want pictures to bounce off the screen, scrap the Pic.New, what you need is Pic.Draw. To make Pic.Draw work, you'll need a few things first.
(1) You need to set the screen...
code:
View.Set ("offscreenonly")

This should stop any flicker when drawing the pictures if used in tandem with this...
code:
View.Update


Next, your code to make the picture change direction when the collision detection kicks in, is all wrong. Here is something I cooked up, check it out, and see how it works...
code:
var number := 1
loop
    const numberput := number * -1
    number := numberput
    put numberput
end loop


Since this is (or seems to be) a school project, look at these and you should be able to figure out yoru problem.[/code]
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: