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

Username:   Password: 
 RegisterRegister   
 Blinking problem with proc commands
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Xianxin




PostPosted: Mon Jan 22, 2007 7:03 pm   Post subject: Blinking problem with proc commands

I keep getting this blinking problem for my game I am making AND while one character moves, the other one can't. How can I fix this? I'm not good at Turing so my proc's are probably messed up. Well, here's my coding...

code:

proc knight
    setscreen ("offscreenonly")
    Input.KeyDown (chars)
    if chars ('o') then     % Up Jump
        for a : 1 .. 15
            y := y + 7
            View.Update
            cls
            delay (10)
            Pic.Draw (jump1, x, y, picMerge)
        end for
        for a : 1 .. 15     % Down Sequence
            y := y - 7
            View.Update
            cls
            delay (10)
            Pic.Draw (jump1, x, y, picMerge)
        end for
    elsif chars ('p') then     % Backward Jump
        for a : 1 .. 15
            y := y + 7
            x := x + 3
            View.Update
            cls
            delay (10)
            Pic.Draw (jump1, x, y, picMerge)
        end for
        for a : 1 .. 15     % Down Sequence
            y := y - 7
            x := x + 2
            View.Update
            cls
            delay (10)
            Pic.Draw (jump1, x, y, picMerge)
        end for
    elsif chars ('i') then     % Forward Jump
        for a : 1 .. 15
            y := y + 7
            x := x - 3
            View.Update
            cls
            delay (10)
            Pic.Draw (jump1, x, y, picMerge)
        end for
        for a : 1 .. 15     % Down Sequence
            y := y - 7
            x := x - 2
            View.Update
            cls
            delay (10)
            Pic.Draw (jump1, x, y, picMerge)
        end for
    elsif chars ('k') then     % Walk forward
        for a : 1 .. 2
            x := x - 7
            View.Update
            cls
            delay (40)
            Pic.Draw (walk1, x + 10, y - 5, picMerge)
            x := x - 7
            View.Update
            cls
            delay (40)
            Pic.Draw (walk2, x + 10, y - 5, picMerge)
            x := x - 7
            View.Update
            cls
            delay (40)
            Pic.Draw (walk3, x + 10, y - 5, picMerge)
            x := x - 7
            View.Update
            cls
            delay (40)
            Pic.Draw (walk4, x + 10, y - 5, picMerge)
        end for
    elsif chars (';') then     % Walk Backwards
        for a : 1 .. 2
            x := x + 7
            View.Update
            cls
            delay (40)
            Pic.Draw (walk4r, x + 10, y - 5, picMerge)
            x := x + 7
            View.Update
            cls
            delay (40)
            Pic.Draw (walk3r, x + 10, y - 5, picMerge)
            x := x + 7
            View.Update
            cls
            delay (40)
            Pic.Draw (walk2r, x + 10, y - 5, picMerge)
            x := x + 7
            View.Update
            cls
            delay (40)
            Pic.Draw (walk1r, x + 10, y - 5, picMerge)
        end for
    elsif chars ('l') then     % Defence Sequence
        for a : 1 .. 1
            View.Update
            cls
            delay (75)
            Pic.Draw (def1, x - 20, y - 10, picMerge)
            View.Update
            cls
            delay (75)
            Pic.Draw (def2, x - 20, y - 10, picMerge)
            View.Update
            cls
            delay (75)
            Pic.Draw (def3, x - 20, y - 10, picMerge)
            View.Update
            cls
            delay (75)
            Pic.Draw (def4, x - 20, y - 10, picMerge)
            View.Update
            cls
            delay (75)
            Pic.Draw (def5, x - 20, y - 10, picMerge)
            View.Update
            cls
            delay (800)
            Pic.Draw (def6, x - 20, y - 10, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (def7, x - 20, y - 10, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (def8, x - 20, y - 10, picMerge)
        end for
    elsif chars ('m') then     % Power Smash
        x := x - 2
        View.Update
        cls
        delay (100)
        Pic.Draw (atk1, x - 40, y, picMerge)
        x := x - 5
        View.Update
        cls
        delay (100)
        Pic.Draw (atk2, x - 40, y, picMerge)
        x := x - 5
        View.Update
        cls
        delay (100)
        Pic.Draw (atk3, x, y + 15, picMerge)
        x := x - 5
        View.Update
        cls
        delay (150)
        Pic.Draw (atk4, x - 145, y - 35, picMerge)
        x := x - 5
        View.Update
        cls
        delay (300)
        Pic.Draw (stance1, x - 15, y - 3, picMerge)
        View.Update
        cls
        delay (400)
    elsif chars ('n') then     % Stab Attack
        x := x - 2
        View.Update
        cls
        delay (100)
        Pic.Draw (stab1, x - 40, y, picMerge)
        x := x - 5
        View.Update
        cls
        delay (100)
        Pic.Draw (stab2, x - 40, y, picMerge)
        x := x - 5
        View.Update
        cls
        delay (100)
        Pic.Draw (stab3, x - 10, y, picMerge)
        x := x - 5
        View.Update
        cls
        delay (100)
        Pic.Draw (stab4, x - 145, y - 15, picMerge)
        x := x - 5
        View.Update
        cls
        delay (150)
        Pic.Draw (stance1, x - 15, y - 3, picMerge)
        View.Update
        cls
        delay (200)
    end if
    View.Update
    cls
    Pic.Draw (stand1, x + 10, y - 7, picMerge)
    %Pic.Draw (background, 0, 0, picMerge)
end knight

proc ninja
    setscreen ("offscreenonly")
    what := 0
    locate (1, 85)
    Input.KeyDown (chars2)
    if chars2 ('w') then     %jump
        if yes then     % true statment, if certan key is pressed then this happens, look below for key
            for a : 1 .. 40     %jumping distance
                y2 := y2 + 4     %jumping speed
                View.Update     % updates image, prevents flickering
                cls     %clears screen for new image
                delay (5)     % delays image
                Pic.Draw (pic10, x2, y2, picMerge)     % outputs image
            end for
            for a : 1 .. 40
                y2 := y2 - 4
                View.Update
                cls
                delay (5)
                Pic.Draw (pic11, x2, y2, 2)
            end for
            for a : 1 .. 10
                View.Update
                cls
                delay (5)
                Pic.Draw (pic12, x2, y2, 2)
            end for
        else
            for a : 1 .. 40
                y2 := y2 + 3
                View.Update
                cls
                delay (5)
                Pic.Draw (pic10, x2, y2, 2)
            end for
            for a : 1 .. 40
                y2 := y2 - 3
                View.Update
                cls
                delay (5)
                Pic.Draw (pic11, x2, y2, 2)
            end for
            for a : 1 .. 10
                View.Update
                cls
                delay (5)
                Pic.Draw (pic12, x2, y2, picMerge)
            end for
        end if
    end if
    if chars2 ('d') then     %jumps certain direction
        if chars2 ('g') then     %differnt jump key
            if yes then
                for a : 1 .. 35
                    y2 := y2 + 4     %values for jumping on an angle
                    x2 := x2 + 4
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic10, x2, y2, picMerge)
                end for
                for a : 1 .. 35
                    y2 := y2 - 4
                    x2 := x2 + 4
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic11, x2, y2, picMerge)
                end for
                for a : 1 .. 10
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic12, x2, y2, picMerge)
                end for
            else
                for a : 1 .. 35
                    y2 := y2 + 3
                    x2 := x2 + 3
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic10, x2, y2, picMerge)
                end for
                for a : 1 .. 35
                    y2 := y2 - 3
                    x2 := x2 + 3
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic11, x2, y2, picMerge)
                end for
                for a : 1 .. 10
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic12, x2, y2, picMerge)
                end for
            end if
        end if
    end if
    if chars2 ('a') then
        if chars2 ('g') then
            if yes then
                for a : 1 .. 35
                    y2 := y2 + 4
                    x2 := x2 - 4
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic13, x2, y2, picMerge)
                end for
                for a : 1 .. 35
                    y2 := y2 - 4
                    x2 := x2 - 4
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic14, x2, y2, picMerge)
                end for
                for a : 1 .. 10
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic15, x2, y2, picMerge)
                end for
            else
                for a : 1 .. 35
                    y2 := y2 + 3
                    x2 := x2 - 3
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic13, x2, y2, picMerge)
                end for
                for a : 1 .. 35
                    y2 := y2 - 3
                    x2 := x2 + -3
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic14, x2, y2, picMerge)
                end for
                for a : 1 .. 10
                    View.Update
                    cls
                    delay (5)
                    Pic.Draw (pic15, x2, y2, picMerge)
                end for
            end if
        end if
    end if
    if chars2 ('d') then     % run certain direction
        if yes then
            what := 1     % assings value to varible, see last couple of lines for example
            delay (75)
            View.Update
            cls
            Pic.Draw (pic2, x2, y2, picMerge)
            x2 := x2 + 30     %when image is outputed, image moves according to x or y axis
            View.Update
            cls
            delay (75)
            Pic.Draw (pic3, x2, y2, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (75)
            Pic.Draw (pic4, x2, y2, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (75)
            Pic.Draw (pic5, x2, y2, picMerge)
            x2 := x2 + 30
        else
            what := 1
            delay (75)
            View.Update
            cls
            Pic.Draw (pic2, x2, y2, picMerge)
            x2 := x2 + 10
            View.Update
            cls
            delay (75)
            Pic.Draw (pic3, x2, y2, picMerge)
            x2 := x2 + 10
            View.Update
            cls
            delay (75)
            Pic.Draw (pic4, x2, y2, picMerge)
            x2 := x2 + 10
            View.Update
            cls
            delay (75)
            Pic.Draw (pic5, x2, y2, picMerge)
            x2 := x2 + 10
        end if
    end if
    if chars2 ('a') then
        if yes then     % if yes:=true
            for a : 1 .. 2
                x2 := x2 - 30
                View.Update
                cls
                delay (75)
                Pic.Draw (pic6, x2, y2, picMerge)
                x2 := x2 - 30
                View.Update
                cls
                delay (75)
                Pic.Draw (pic7, x2, y2, picMerge)
                x2 := x2 - 30
                View.Update
                cls
                delay (75)
                Pic.Draw (pic8, x2, y2, picMerge)
                x2 := x2 - 30
                View.Update
                cls
                delay (75)
                Pic.Draw (pic9, x2, y2, picMerge)
            end for
            View.Update
            cls
            Pic.Draw (pic1, x2, y2, picMerge)
        else     % if yes doesnt = 1 then this happens
            for a : 1 .. 2
                x2 := x2 - 10
                View.Update
                cls
                delay (75)
                Pic.Draw (pic6, x2, y2, picMerge)
                x2 := x2 - 10
                View.Update
                cls
                delay (75)
                Pic.Draw (pic7, x2, y2, picMerge)
                x2 := x2 - 10
                View.Update
                cls
                delay (75)
                Pic.Draw (pic8, x2, y2, picMerge)
                x2 := x2 - 10
                View.Update
                cls
                delay (75)
                Pic.Draw (pic9, x2, y2, picMerge)
            end for
            View.Update
            cls
            Pic.Draw (pic1, x2, y2, picMerge)
        end if
    end if
    if chars2 ('f') then
        View.Update
        cls
        delay (75)
        Pic.Draw (pic18, x2, y2, picMerge)
        View.Update
        cls
        delay (100)
        Pic.Draw (pic19, x2 - 5, y2 - 5, picMerge)
        View.Update
        cls
        delay (100)
        Pic.Draw (pic20, x2 - 5, y2 - 5, picMerge)     % certain values for x,y to make pic fit more properly
        View.Update
        cls
        delay (100)
        Pic.Draw (pic21, x2 - 5, y2 - 5, picMerge)
        View.Update
        cls
        delay (100)
        Pic.Draw (pic22, x2 - 5, y2 - 5, picMerge)
        View.Update
        cls
        delay (100)
        Pic.Draw (pic23, x2 - 5, y2 - 5, picMerge)
        View.Update
        cls
        delay (100)
        Pic.Draw (pic24, x2 - 5, y2 - 5, picMerge)
    end if
    if chars2 ('s') then
        cls
        delay (100)
        Pic.Draw (pic16, x2, y2, picMerge)

        View.Update
        cls
        delay (500)
        Pic.Draw (pic16, x2, y2, picMerge)
    end if
    if chars2 ('d') then
        if chars2 ('h') then     % two keys needs to be inputed for image to appear
            View.Update
            cls
            Pic.Draw (pic30, x2, y2, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic31, x2, y2, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic32, x2, y2 - 3, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic33, x2, y2 - 6, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic34, x2, y2 - 7, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic35, x2, y2 - 9, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic36, x2, y2 - 11, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic37, x2 - 3, y2 - 9, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic38, x2, y2 - 10, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic39, x2, y2 - 5, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic40, x2, y2 - 5, picMerge)     %
            View.Update
            cls
            delay (100)
            Pic.Draw (pic41, x2, y2 - 5, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic42, x2, y2 - 3, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic39, x2, y2 - 5, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic40, x2, y2 - 5, picMerge)     %parts of image are repeated to add a nicer effect
            View.Update
            cls
            delay (100)
            Pic.Draw (pic41, x2, y2 - 5, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic42, x2, y2 - 3, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic43, x2, y2, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic44, x2, y2 - 7, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (100)
            Pic.Draw (pic45, x2, y2, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (100)
            Pic.Draw (pic46, x2, y2, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (100)
            Pic.Draw (pic47, x2, y2, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (100)
            Pic.Draw (pic48, x2, y2, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (100)
            Pic.Draw (pic49, x2, y2, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (100)
            Pic.Draw (pic50, x2, y2, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (100)
            Pic.Draw (pic51, x2, y2, picMerge)
            x2 := x2 + 30
            View.Update
            cls
            delay (100)
            Pic.Draw (pic52, x2, y2, picMerge)
            View.Update
            cls
            delay (500)
            Pic.Draw (pic52, x2, y2, picMerge)
        end if
    end if
    if chars2 ('d') then
        if chars2 ('a') then     % so image doesnt draw twice,now image only does one thing even if
            % left and right is pressed
            what := 1
            delay (5)
            Pic.Draw (pic2, x2, y2, picMerge)
            View.Update
            cls
            delay (5)
            Pic.Draw (pic3, x2, y2, picMerge)
            View.Update
            cls
            delay (5)
            Pic.Draw (pic4, x2, y2, picMerge)
            View.Update
            cls
            delay (5)
            Pic.Draw (pic5, x2, y2, picMerge)
            x2 := x2 + 2
        end if
    end if
    if chars2 ('s') then
        if chars2 ('h') then
            yes := true     % yes is true, now certain things will happen when this image is outputed
            %able to combine this with if commands
            View.Update
            cls
            delay (100)
            Pic.Draw (pic53, x2, y2, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic54, x2, y2, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic55, x2, y2, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic53, x2, y2, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic54, x2, y2, picMerge)
            View.Update
            cls
            delay (100)
            Pic.Draw (pic55, x2, y2, picMerge)
        end if
    end if
    View.Update
    cls
    Pic.Draw (pic1, x2, y2, picMerge)
    %Pic.Draw (background, 0, 0, picMerge)
end ninja

loop
    %cls
    Pic.Draw (background, 0, 0, picMerge)
    knight
    ninja
end loop



I was kinda playing with the cls at the last loop. Thanks in advance!
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Mon Jan 22, 2007 7:35 pm   Post subject: RE:Blinking problem with proc commands

Your problem for the issue with one character moving while the other isn't has to do with the for loop in the procedures. When it is in that for loop, it can't do anything else. The way you are doing this is wrong. Your game should be updating only once within the main loop (i.e use only one View.Update).
Xianxin




PostPosted: Mon Jan 22, 2007 9:17 pm   Post subject: Re: Blinking problem with proc commands

Oh, okay. To clarify what you mean (what I got but I'm not sure...) by like putting only one View.Update for like each for structure? Like for the Walking command, only put the View.Update at the last picture?
Xianxin




PostPosted: Mon Jan 22, 2007 9:24 pm   Post subject: Re: Blinking problem with proc commands

Wait, should I just take out the for statement for the walking? I think that's what you meant but I misread. However, for the jumping, wouldn't it be awkward not using a for statement for it?
CodeMonkey2000




PostPosted: Tue Jan 23, 2007 4:28 pm   Post subject: RE:Blinking problem with proc commands

Change the positions of the characters. Get rid of the for statements all together. Draw the pictures, but dont update the screen yet. Update the screen right before the end loop (that is your main loop).
Xianxin




PostPosted: Tue Jan 23, 2007 5:22 pm   Post subject: Re: Blinking problem with proc commands

Do I take out the cls too? And when I take out the View.Updates, it doesn't work...
CodeMonkey2000




PostPosted: Tue Jan 23, 2007 5:40 pm   Post subject: Re: Blinking problem with proc commands

Sigh... here is an example of what you should be doing:
Turing:
View.Set ("graphics:300;300,offscreenonly")
var x, y, x2, y2 : int := 0
var vy, vy2 : int := 0
var key : array char of boolean
proc move
%player 1 w,s,a,d
    if key ('w') then
        y2 += 5
    end if
    if key ('s') then
        y2 -= 5
    end if
    if key ('d') then
        x2 += 5
    end if
    if key ('a') then
        x2 -= 5
    end if
%player2 i,k,l,j
    if key ('i') then
        y += 5
    end if
    if key ('k') then
        y -= 5
    end if
    if key ('l') then
        x += 5
    end if
    if key ('j') then
        x -= 5
    end if
end move
proc refresh
    Draw.FillOval (x, y, 10, 10, red)
    Draw.FillOval (x2, y2, 10, 10, blue)
end refresh

%main loop
loop
    Input.KeyDown (key)
    move %changes corrdinates
    refresh %draws it
    View.Update%update it
    delay (100)
    cls
end loop

this isnt the best way, but it should give you the idea.
Xianxin




PostPosted: Tue Jan 23, 2007 7:40 pm   Post subject: Re: Blinking problem with proc commands

Thanks! We never learned y -= or y += and etc. in class though, I'll try to look up a guide for them then =)
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Tue Jan 23, 2007 7:54 pm   Post subject: RE:Blinking problem with proc commands

-= or += just means increase the variable on the left side by the right(ie x+=1 is the same as x=x+1)
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  [ 9 Posts ]
Jump to:   


Style:  
Search: