Computer Science Canada

~~!Moving Background!~~

Author:  biggmak [ Fri Mar 21, 2003 7:05 pm ]
Post subject:  ~~!Moving Background!~~

im trying to make this game where this character walks around but i cant get the background to move over to the right by, let say five, so i set up an if statement for it and this is what i got...
code:


var win : int := Window.Open ("fullscreen")
View.Set ("graphics:max;max")
var ruine : int := Pic.FileNew ("Ruine.bmp")
var u1 : int := Pic.FileNew ("u1.bmp")
var u2 : int := Pic.FileNew ("u2.bmp")
var u3 : int := Pic.FileNew ("u3.bmp")
var r1 : int := Pic.FileNew ("r1.bmp")
var r2 : int := Pic.FileNew ("r2.bmp")
var r3 : int := Pic.FileNew ("r3.bmp")
var l1 : int := Pic.FileNew ("l1.bmp")
var l2 : int := Pic.FileNew ("l2.bmp")
var l3 : int := Pic.FileNew ("l3.bmp")
var d1 : int := Pic.FileNew ("d1.bmp")
var d2 : int := Pic.FileNew ("d2.bmp")
var d3 : int := Pic.FileNew ("d3.bmp")

x := 400       %character
y := 250        %character
xruine := 0        %background
yruine := 0       %background

loop

    View.Update
    Input.KeyDown (chars)
    Pic.Draw (ruine, xruine, yruine, 0) %backround picture


    if chars (KEY_UP_ARROW) then

        y := y + 10
        Pic.Draw (u1, x, y, 0)

        delay (200)
        View.Update
        cls
        y := y + 10
        Pic.Draw (u2, x, y, 0)

        delay (200)
        View.Update
        cls
        y := y + 10
        Pic.Draw (u3, x, y, 0)

        delay (200)
        View.Update
        cls
        y := y + 10
        Pic.Draw (u2, x, y, 0)

        delay (200)
        View.Update
        cls

    end if
    if chars (KEY_RIGHT_ARROW) then
        cls
        x := x + 10
        Pic.Draw (r1, x, y, 0)
        View.Update
        delay (200)
        cls
        x := x + 10
        Pic.Draw (r2, x, y, 0)
        View.Update
        delay (200)
        cls
        x := x + 10
        Pic.Draw (r3, x, y, 0)
        View.Update
        delay (200)
        cls
        x := x + 10
        Pic.Draw (r2, x, y, 0)
        View.Update
        delay (200)
        cls

    end if
    if chars (KEY_LEFT_ARROW) then
        cls
        x := x - 10
        Pic.Draw (l1, x, y, 0)
        View.Update
        delay (200)
        cls
        x := x - 10
        Pic.Draw (l2, x, y, 0)
        View.Update
        delay (200)
        cls
        x := x - 10
        Pic.Draw (l3, x, y, 0)
        View.Update
        delay (200)
        cls
        x := x - 10
        Pic.Draw (l2, x, y, 0)
        View.Update
        delay (200)
        cls
    end if
    if chars (KEY_DOWN_ARROW) then
        cls
        y := y - 10
        Pic.Draw (d1, x, y, 0)
        View.Update
        delay (200)
        cls
        y := y - 10
        Pic.Draw (d2, x, y, 0)
        View.Update
        delay (200)
        cls
        y := y - 10
        Pic.Draw (d3, x, y, 0)
        View.Update
        delay (200)
        cls
        y := y - 10
        Pic.Draw (d2, x, y, 0)
        View.Update
        delay (200)
        cls
    end if
    delay (10)
    if x <= 50 then
        x := x + 40
    elsif y <= 50 then
        y := y + 40
    end if

 %RIGHT HERE IS MY IF STATEMENT
    if x >= 500 then
        xruine := xruine - 10
    end if
end loop

This is not working correctly because the background constantly keeps on moving to the left by 10 as long as the guy is past 500. I need to make it move only when the character moves further to the right (past 500), and need it to stop when the character stops(past 500).

Author:  Tony [ Fri Mar 21, 2003 7:11 pm ]
Post subject: 

Crying or Very sad Why cant you people just read the tutorials first and see if there's anything there?

its called "MOVING BACKGROUND" - http://www.compsci.ca/bbs/viewtopic.php?t=193

Author:  Delta [ Fri Mar 21, 2003 7:24 pm ]
Post subject: 

hahahahahahaha I WIN! wait no I don't this post was useless

Author:  biggmak [ Sat Mar 22, 2003 3:14 pm ]
Post subject: 

i read that tutorial but that only works if i have one character pic, but i have a total of 12. so do i have to set x and y variables for each picture?

Author:  Asok [ Sat Mar 22, 2003 3:59 pm ]
Post subject: 

anything that is not the background should be on a sperate layer.


: