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

Username:   Password: 
 RegisterRegister   
 make a program look smooth
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
UnTiteled




PostPosted: Wed Jan 13, 2010 8:41 am   Post subject: make a program look smooth

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
i am trying to make my program look mooth and not flash (the program flashes for a split second : how to make not do that??)

What is the problem you are having?
<Answer Here>
the program flashes for a split second : how to make not do that??


Describe what you have tried to solve this problem
<Answer Here>
ive tryed the view update and the offscreen, everything i know

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

Turing:


colourback (70)
cls
locate (15, 20)
put "___________.__"
locate (16, 20)
put "\\__    ___/|  |__   ____ "
locate (17, 20)
put "  |    |   |  |  \\_/ __ \\ "
locate (18, 20)
put "  |    |   |   Y  \\  ___/ "
locate (19, 20)
put "  |____|   |___|  /\\___  >"
locate (20, 20)
put "                \\/     \\/ "
locate (21, 20)
put "   _____  .__         .__                   .__          __  "
locate (22, 20)
put "  /  _  \\ |  |   ____ |  |__   ____   _____ |__| _______/  |_ "
locate (23, 20)
put " /  /_\\  \\|  | _/ ___\\|  |  \\_/ __ \\ /     \\|  |/  ___/\\   __\\"
locate (24, 20)
put "/    |    \\  |_\\  \\___|   Y  \\  ___/|  Y Y  \\  |\\___ \\  |  |  "
locate (25, 20)
put "\\____|__  /____/\\___  >___|  /\\___  >__|_|  /__/____  > |__|  "
locate (26, 20)
put "        \\/          \\/     \\/     \\/      \\/        \\/ "

put "Instructions: Move with the 'up, down, left, and right buttons', shoot with the space bar"
put ""
put "On the first day, God created the Heavens and The earth..."
put "On the sixth day, God created the creatures of the earth, and with them"
put "came a soul devouring beast, once the humans were put on the earth, so"
put "did the demon start to hunt for souls"
put ""
put "your quest iss to defeat these demons and save the world from darkness"
put "hit any key to begin"
Input.Pause
colourback (white)
colour (white)
cls
View.Set ("graphics,offscreenonly:max;max")



const GROUND_HEIGHT := 120
const RUN_SPEED := 10
const JUMP_SPEED := 30
const GRAVITY := 2

var manfig1 := Pic.FileNew ("stand.gif")
var manfig2 := Pic.FileNew ("face.gif")
var monsterfig2 := Pic.FileNew ("monster_face.gif")
var monster := Pic.FileNew ("monster.gif")

var chars : array char of boolean
var position := 1000

var posx, posy : int
var velx, vely : real

posx := 20
velx := 0
posy := 400
vely := 0


setscreen ("graphics:max;max")


locate (16, 20)
colour (black)

put " _______________"
locate (17, 20)
put "|prepare        |"
locate (18, 20)
put "|to             |"
locate (19, 20)
put "|be destroyed.  |"
locate (20, 20)
put "| ______________|"
locate (21, 20)
put "|/"
Pic.Draw (manfig2, 120, 240, picMerge)
Pic.Draw (manfig1, 50, 50, picMerge)
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
locate (41, 10)
put "hit any key to continue"
Input.Pause

locate (16, 90)
put " _______________"
locate (17, 90)
put "|               |"
locate (18, 90)
put "|GRAAAWWWWRRRRR |"
locate (19, 90)
put "|______________ |"
locate (20, 90)
put "               |/"
Pic.Draw (monsterfig2, 790, 250, picMerge)
locate (41, 10)
Pic.Draw (monster, position, 60, picMerge)

loop


    colour (black)
    colourback (white)
    cls
    locate (16, 20)
    put " _______________"
    locate (17, 20)
    put "|prepare        |"
    locate (18, 20)
    put "|to             |"
    locate (19, 20)
    put "|be destroyed.  |"
    locate (20, 20)
    put "| ______________|"
    locate (21, 20)
    put "|/"
    Pic.Draw (manfig2, 120, 240, picMerge)
    Pic.Draw (manfig1, 50, 50, picMerge)
    drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
    locate (41, 10)

    locate (16, 90)
    put " _______________"
    locate (17, 90)
    put "|               |"
    locate (18, 90)
    put "|GRAAAWWWWRRRRR |"
    locate (19, 90)
    put "|______________ |"
    locate (20, 90)
    put "               |/"
    Pic.Draw (monsterfig2, 790, 250, picMerge)
    locate (41, 10)
    Pic.Draw (monster, position, 60, picMerge)
    position := position - 1
    delay (15)
    exit when position = 750
end loop
locate (5, 50)
put "press s to start..."
Input.Pause




loop
    Input.KeyDown (chars)
    if chars ('q') then
        exit
    end if


    if chars (KEY_LEFT_ARROW) then
        velx := -RUN_SPEED
    elsif chars (KEY_RIGHT_ARROW) then
        velx := RUN_SPEED
    else
        velx := 0
    end if


    if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT then
        vely := JUMP_SPEED
    end if


    var y := posx
    var x := posy
    var pic := Pic.FileNew ("fireball2.gif")
    cls


    Input.KeyDown (chars)
    if chars (' ') then
        loop
            View.Update
            cls



            Input.KeyDown (chars)
            if chars ('q') then
                exit
            end if


            if chars (KEY_LEFT_ARROW) then
                velx := -RUN_SPEED
            elsif chars (KEY_RIGHT_ARROW) then
                velx := RUN_SPEED
            else
                velx := 0
            end if


            if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT then
                vely := JUMP_SPEED
            end if



            Pic.Draw (manfig1, posx, posy, picMerge)


            drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)

            vely -= GRAVITY
            posx += round (velx)
            posy += round (vely)


            if posy < GROUND_HEIGHT then
                posy := GROUND_HEIGHT
                vely := 0
            end if





            delay (35)


            if posx < 0 then
                posx := -1
            elsif posx > 600 then
                posx := 600
            end if

            Pic.Draw (pic, y, x, picMerge)

            y += 5

            if y > 699 then
                y := -10
                exit
            end if
        end loop
    end if


    vely -= GRAVITY
    posx += round (velx)
    posy += round (vely)


    if posy < GROUND_HEIGHT then
        posy := GROUND_HEIGHT
        vely := 0
    end if




    Pic.Draw (manfig1, posx, posy, picMerge)


    drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)

    delay (35)


    if posx < 0 then
        posx := -1
    elsif posx > 600 then
        posx := 600
    end if
end loop




Please specify what version of Turing you are using
<Answer Here>
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
bc123




PostPosted: Wed Jan 13, 2010 8:47 am   Post subject: Re: make a program look smooth

nice program but im not sure how to fix :S
Ktomislav




PostPosted: Wed Jan 13, 2010 8:51 am   Post subject: Re: make a program look smooth

I think you just made a double thread. Rolling Eyes
Anyway, if you have tried using View.Update you must have
used it the wrong way. You should put View.Update right before delay.

And I recommend you to put this outside the loop because you could easily get
an error saying you have to much pictures or something like that.

Turnig:
var pic := Pic.FileNew ("fireball2.gif")
UnTiteled




PostPosted: Wed Jan 13, 2010 3:12 pm   Post subject: RE:make a program look smooth

ok...if i put the view update before the delay...it doesnt change anything
UnTiteled




PostPosted: Wed Jan 13, 2010 4:34 pm   Post subject: RE:make a program look smooth

i figured it all out
thanks for your help
and by the way you have to put the View.Update, cls
after the delay
TerranceN




PostPosted: Wed Jan 13, 2010 4:57 pm   Post subject: Re: make a program look smooth

Your game is flashing because View.Update() is only getting called when your fireball is active, adding a View.Update() to your first game loop, will stop the flashing (I think).

But there is still a problem with how you are coding your game loop. This problem wont stop what you have from running, but you will find it difficult to add more things to draw, and if you wanted to change any of your code, you would have to change it in more than one place. Say you wanted to draw a second fireball when you hit a different key, would you add another loop inside your main loop and your fireball loop? But then what if both are active? I hope you can see this would take a lot of duplicate code. Another, more expandable way, is to use boolean values to indicate whether or not each fireball is active.

Turing:
View.Set("graphics:500;500,offscreenonly,nobuttonbar")

var isFireballActive : boolean := false

var keys : array char of boolean

loop

    Input.KeyDown(keys)

    if (keys(' ') and not isFireballActive) then
        isFireballActive := true
    end if

    cls()

    % main code here

    if (isFireballActive) then
        % fireball update code here

        if (fireballOffScreen) then % replace with a condition, you used something like y > 699 in your code
            isFireballActive := false
        end if
    end if

    View.Update()

    Time.DelaySinceLast(1000 div 60)

end loop


Of course, if you don't need to add any more fireballs (or conditional drawings) then you dont need to use this, but I thought I should mention it

Hope this helps.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: