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

Username:   Password: 
 RegisterRegister   
 moving a character help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
syphon4




PostPosted: Mon Jun 06, 2005 2:41 pm   Post subject: 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

code:
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
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon Jun 06, 2005 2:45 pm   Post subject: (No subject)

You'll want to read these two first:
Tutorial 1
Tutorial 2

Now that you've found out that Input.KeyDown() is far superior to getch()ing or hasch()ing your way through life, you'll no doubt 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




PostPosted: Mon Jun 06, 2005 3:10 pm   Post subject: move

how exaclty would i make the if statement..........thx i used Input key down(much better)...............

if x2 <=0 then
???????????
if x2 >=maxx then
???????????
if y2 <=0 then
???????????
if y2 >=maxy then
???????????
Delos




PostPosted: Mon Jun 06, 2005 4:24 pm   Post subject: (No subject)

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




PostPosted: Mon Jun 06, 2005 4:52 pm   Post subject: 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

code:
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
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  [ 5 Posts ]
Jump to:   


Style:  
Search: