
-----------------------------------
syphon4
Mon Jun 06, 2005 2:41 pm

moving a character help
-----------------------------------
i have made a program where you control a picture of luigi but want to make it so when you control him he cant "fly"...i need to restrict him from moving up if there isnt anything to help him up i.e. ladder

p.s. i anywayz need to restrict him from moving off screen too so could anyone tell me how to make it so he wont move off scrren.....here is my program

View.Set ("graphics;maxx;maxy,offscreenonly")

var mypic : int
var x, x2, y2, i2 : int
var y, i : int
var Contin : string
var input : string (1) := "x"

i := 0
i2 := 0

    drawfillbox (0, 0, maxx, maxy, 9)
    drawfillbox (400, 310, 435, 350, 10)
    drawfilloval (417, 350, 25, 3, 10)
    drawfilloval (417, 350, 15, 2, 7)
    drawfillstar (200, 5, 250, 50, 14)

    mypic := Pic.FileNew ("C:\\luigifront.bmp") % Importing picture into turing

    x2 := 100
    y2 := 1

    loop
        drawfillbox (0, 0, maxx, maxy, 9) % Backgound
        drawfillbox (400, 310, 435, 350, 10) % Tube
        drawfilloval (417, 350, 25, 3, 10)
        drawfilloval (417, 350, 15, 2, 7)
        drawfillstar (200, 5, 250, 50, 14)
        Pic.Draw (mypic, x2, y2, picCopy) % Drawing imported picture on screen
        delay (10)
        View.Update
        View.Update
        if hasch then
            getch (input)
        end if
        if input = chr (119) then % w = up
            y2 := y2 + 4
            input := "x"
            Pic.Free (mypic)
            mypic := Pic.FileNew ("C:\\luigiback.bmp")
        elsif input = chr (100) then % d = right
            x2 := x2 + 4
            input := "x"
            Pic.Free (mypic)
            mypic := Pic.FileNew ("C:\\luigiside.bmp")
        elsif input = chr (97) then % a = left
            x2 := x2 - 4
            input := "x"
            Pic.Free (mypic)
            mypic := Pic.FileNew ("C:\\luigiside2.bmp")
        elsif input = chr (115) then % s = down
            y2 := y2 - 4
            input := "x"
            Pic.Free (mypic)
            mypic := Pic.FileNew ("C:\\luigifront.bmp")
        end if
        View.Update
        exit when x2 >= 600 and y2 >= 200
    end loop

-----------------------------------
Delos
Mon Jun 06, 2005 2:45 pm


-----------------------------------
You'll want to read these two first:
Rewrite your proggie to this style.

As for your restrictions, simply set conditions on when movement can occur.  So, if the character's x-position in greater than 0 (or whatever else you wish the left bound to be), they may move LEFT...etc etc.

-----------------------------------
syphon4
Mon Jun 06, 2005 3:10 pm

move
-----------------------------------
how exaclty would i make the if statement..........thx i used Input key down(much better)...............

if x2 =maxx then
???????????
if y2 =maxy then
???????????

-----------------------------------
Delos
Mon Jun 06, 2005 4:24 pm


-----------------------------------
Your ????'s can be replaced with what you already have.  Remember that you're trying to limit where the character can move.  Movement is generated by changing the character's position.
Thus,
?????= 'char_x += {some number}

-----------------------------------
syphon4
Mon Jun 06, 2005 4:52 pm

luigi
-----------------------------------
i understand your thinking but when i put what you have into my program it wont work........can you edit my program with the restrictions needed so i can learn from what you have done......thx in advance man

View.Set ("graphics;maxx;maxy,offscreenonly")

var mypic : int
var x, x2, y2, i2 : int
var y, i : int
var Contin : string
var input : array char of boolean

    drawfillbox (0, 0, maxx, maxy, 9)
    drawfillbox (400, 310, 435, 350, 10)
    drawfilloval (417, 350, 25, 3, 10)
    drawfilloval (417, 350, 15, 2, 7)
    drawfillstar (200, 5, 250, 50, 14)

    mypic := Pic.FileNew ("C:\\luigifront.bmp") % Importing picture into turing

    x2 := 100
    y2 := 1

    loop
        drawfillbox (0, 0, maxx, maxy, 9) % Backgound
        drawfillbox (400, 310, 435, 350, 10) % Tube
        drawfilloval (417, 350, 25, 3, 10)
        drawfilloval (417, 350, 15, 2, 7)
        drawfillstar (200, 5, 250, 50, 14)
        Pic.Draw (mypic, x2, y2, picCopy) % Drawing imported picture on screen
        delay (10)
        View.Update
        View.Update

        Input.KeyDown (input)

        if input (KEY_UP_ARROW) then % up
            y2 := y2 + 2
            Pic.Free (mypic)
            mypic := Pic.FileNew ("C:\\luigiback.bmp")
        elsif input (KEY_RIGHT_ARROW) then % right
            x2 := x2 + 2
            Pic.Free (mypic)
            mypic := Pic.FileNew ("C:\\luigiside.bmp")
        elsif input (KEY_LEFT_ARROW) then % left
            x2 := x2 - 2
            Pic.Free (mypic)
            mypic := Pic.FileNew ("C:\\luigiside2.bmp")
        elsif input (KEY_DOWN_ARROW) then % down
            y2 := y2 - 2
            Pic.Free (mypic)
            mypic := Pic.FileNew ("C:\\luigifront.bmp")
        end if
        View.Update
        exit when x2 >= 600 and y2 >= 200
    end loop
end if

