Computer Science Canada

Help with repeating

Author:  adrian123 [ Tue Jan 17, 2012 7:01 pm ]
Post subject:  Help with repeating

What is it you are trying to achieve?
Have blocks (bullet bill images) continually travel from right to left


What is the problem you are having?
When I run the program, the image only "shoots" to the other side once, and never repeats it. Can anyone tell me how to make it so that I can make a bulletbill object continually look like it is being launched from one side to another?


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


setscreen ("graphics: 900;600, nocursor, offscreenonly, nobuttonbar")
var counter : int := 0
var font1 : int
font1 := Font.New ("Calibri:30")
var w1, w2, button : int
var y : int := 650 div 2
var blockx, blocky : int
var newblock : boolean := true
var highscore : int := 0
var bulletbill, marioup, mariodown : int
bulletbill := Pic.FileNew ("bulletbill.bmp")
marioup := Pic.FileNew ("mariouptest.gif")
mariodown := Pic.FileNew ("mariodown.gif")
var bulletbillx : int := 900
var bulletbilly := Rand.Int (120, 400)


put "CLICK TO START! GAME BY ADRIAN LAU"
put skip, "Press any key to continue!"
Input.Pause
cls
loop

    Pic.ScreenLoad ("bg.bmp", 0, 0, picCopy)

   
        Pic.Draw (bulletbill, bulletbillx, bulletbilly, picMerge)
       
        bulletbillx := bulletbillx -5
       

    Mouse.Where (w1, w2, button)
    if button = 1 then
        y += 4
        Pic.Draw (marioup, 30, y, picMerge)
        View.Update
    else
        y -= 5
        Pic.Draw (mariodown, 30, y, picMerge)
        View.Update
    end if


    Font.Draw ("Score:", 15, 45, font1, black)
    counter := counter + 1
    Font.Draw (intstr (counter), 120, 45, font1, black)
    View.Update

    if y >= 440 then
        exit
    end if

    if y <= 103 then
        exit
    end if

end loop






Please specify what version of Turing you are using
<4.1>

Author:  Dreadnought [ Tue Jan 17, 2012 8:54 pm ]
Post subject:  Re: Help with repeating

Well, lets say you want it to repeat when it goes off the screen on the left. The easiest way is to check if the bullet-bill is offscreen (check the x position), and if so, set its x position back to what it was initially.

Author:  adrian123 [ Tue Jan 17, 2012 9:34 pm ]
Post subject:  Re: Help with repeating

Dreadnought @ Tue Jan 17, 2012 8:54 pm wrote:
Well, lets say you want it to repeat when it goes off the screen on the left. The easiest way is to check if the bullet-bill is offscreen (check the x position), and if so, set its x position back to what it was initially.


ok so i tried that and it looks like this

Pic.Draw (bulletbill , bulletbillx , bulletbilly , picMerge)
bulletbillx := bulletbillx -5
if bulletbillx <= -1 then
bulletbillx:=900
end if

Now how would I make it so that when it resets to the maxx it will make it go off from a different y value?

Author:  Aange10 [ Tue Jan 17, 2012 10:23 pm ]
Post subject:  Re: Help with repeating

adrian123 @ 17/1/2012, 8:34 pm wrote:
Dreadnought @ Tue Jan 17, 2012 8:54 pm wrote:
Well, lets say you want it to repeat when it goes off the screen on the left. The easiest way is to check if the bullet-bill is offscreen (check the x position), and if so, set its x position back to what it was initially.


ok so i tried that and it looks like this

Pic.Draw (bulletbill , bulletbillx , bulletbilly , picMerge)
bulletbillx := bulletbillx -5
if bulletbillx <= -1 then
bulletbillx:=900
end if

Now how would I make it so that when it resets to the maxx it will make it go off from a different y value?


How do you make it go off from the current y value?
Okay, now how do you change that value?

code:

loop
    % Fly Across Screen
    % Reset X
    % yvale += 5
end loop


: