Computer Science Canada

Walking animation help

Author:  Monduman11 [ Tue Jun 08, 2010 5:31 pm ]
Post subject:  Walking animation help

What is it you are trying to achieve?
i am trying to make my character look as if he is walking instead of just gliding


What is the problem you are having?
i cant seem to get it to work


Describe what you have tried to solve this problem
everything i can think of


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

Turing:


Input.KeyDown (chars)
if chars (KEY_LEFT_ARROW)
        then
    loop
        steps += 1
        Pic.Draw (PicName (steps mod pic#))
        if chars (KEY_LEFT_ARROW = false)
            steps := 0
            exit
        end if
    end loop



Please specify what version of Turing you are using
4.1.1

Author:  Cezna [ Tue Jun 08, 2010 5:37 pm ]
Post subject:  RE:Walking animation help

The simplest way would be to draw the character at multiple stages of his run, taking pictures of each, and then either draw these pictures sequentially with Turing, or upload them into another program such as Power Point and make a .gif out of it.

You can also check this link to another thread in which someone posted a "Mario Movement Test", which does exactly what it sounds like you are trying to do.

Link:
http://compsci.ca/v3/viewtopic.php?t=24269&highlight=mario

Author:  Monduman11 [ Tue Jun 08, 2010 5:51 pm ]
Post subject:  Re: Walking animation help

ah thank you so much... and btw in your welcome thread i cant reply cause for some reason its set to only mods and admins

Author:  Cezna [ Tue Jun 08, 2010 5:53 pm ]
Post subject:  RE:Walking animation help

Hmmmm.... just mine? Or are all of the welcome threads like that?

Author:  Monduman11 [ Tue Jun 08, 2010 5:54 pm ]
Post subject:  Re: Walking animation help

im not sure cause ive only tried urs.... hold on ill go check Razz
edit: i checked and it seems that everyones is like that... wonder why

Author:  Cezna [ Tue Jun 08, 2010 5:57 pm ]
Post subject:  RE:Walking animation help

They're probably not supposed to develop into full-fledged conversations.
Btw, I'm the chat room right now.
Feel free to jump in.

Author:  Monduman11 [ Tue Jun 08, 2010 5:58 pm ]
Post subject:  Re: Walking animation help

i would but i cant.. for some reason it gives me an error

Author:  Monduman11 [ Tue Jun 08, 2010 6:01 pm ]
Post subject:  Re: Walking animation help

im attaching a picture so u can see for yourself lol

Author:  Cezna [ Tue Jun 08, 2010 6:01 pm ]
Post subject:  RE:Walking animation help

It's probably filtering it out.
Try closing the page, then coming back (I mean close your browser), and then set it to allow "potentially unsafe content" if/when it prompts you
I had the same problem, and doing that fixed it.
edit : just saw the attachment, I had that EXACT same error message

Author:  Monduman11 [ Tue Jun 08, 2010 6:11 pm ]
Post subject:  Re: Walking animation help

here it is
Turing:

var chars : array char of boolean
var x, y : array 0 .. 5 of int
var bullet, Posx, Posy : int := 0
var bullettrue : array 0 .. 5 of boolean := init (false, false, false, false, false, false)
var ball : int := Pic.FileNew ("fire.bmp")
process bulletshoot
    loop
        for z : 0 .. 5
            if bullettrue (z) then
                x (z) += 5
                Pic.Draw (ball, x (z), y (z), picMerge)
                if x (z) > maxx then
                    bullettrue (z) := false
                end if
            end if

        end for
        delay (10)
        cls
        View.Update
    end loop
end bulletshoot
fork bulletshoot
loop
    Input.KeyDown (chars)
    if chars ('s') and bullettrue ((bullet + 1) mod 6) = false
            then
        bullet += 1
        x (bullet mod 6) := Posx
        y (bullet mod 6) := Posy
        bullettrue (bullet mod 6) := true
        loop
            Input.KeyDown (chars)
            exit when chars ('s') = false
        end loop
    end if
end loop


Author:  Cezna [ Tue Jun 08, 2010 6:16 pm ]
Post subject:  RE:Walking animation help

Here's a link to a post that explains why processes are bad.
http://compsci.ca/v3/viewtopic.php?t=7842

Author:  Monduman11 [ Tue Jun 08, 2010 6:48 pm ]
Post subject:  Re: Walking animation help

Here is the shooting without a process.

Turing:

View.Set ("graphics:500;500,offscreenonly,nobuttonbar,title:Shooting")
var ball1 : int := Pic.FileNew ("fire.bmp")
const NUM_BULLETS := 6


type bullet :
    record
        x : int
        y : int
        isAlive : boolean
    end record


function newBullet (newX, newY : int, newIsAlive : boolean) : bullet
    var b : bullet
    b.x := newX
    b.y := newY
    b.isAlive := newIsAlive
    result b
end newBullet


var bullets : array 0 .. NUM_BULLETS of bullet

var keys : array char of boolean
var preKeys : array char of boolean

for i : 1 .. NUM_BULLETS
    bullets (i) := newBullet (0, 0, false)
end for

procedure Update ()
    Input.KeyDown (keys)


    if (keys ('s') and ~preKeys ('s')) then

        for i : 1 .. NUM_BULLETS
            if ( ~bullets (i).isAlive) then
                bullets (i).x := 0
                bullets (i).y := 50
                bullets (i).isAlive := true
                exit
            end if
        end for
    end if


    for i : 1 .. NUM_BULLETS

        if (bullets (i).isAlive) then

            bullets (i).x += 10


            if (bullets (i).x > maxx) then
                bullets (i).isAlive := false
            end if
        end if
    end for


    preKeys := keys
end Update

procedure Draw_ ()
    cls

    for i : 1 .. NUM_BULLETS
        if (bullets (i).isAlive) then

            Pic.Draw (ball1, bullets (i).x, bullets (i).y, picMerge)
        end if
    end for

    View.Update ()
end Draw_

loop
    Update ()
    Draw_ ()

    Time.DelaySinceLast (33)
end loop


I didint really want to use this one cause TerranceN helped me with it when i couldnt figure out how to do it without a process.
but yea if you could somehow help id appreciate it

Author:  Cezna [ Wed Jun 09, 2010 7:12 pm ]
Post subject:  RE:Walking animation help

I can't do anything without the picture Wink

Author:  Monduman11 [ Wed Jun 09, 2010 7:59 pm ]
Post subject:  Re: Walking animation help

lol its the pic in the attachment Razz

Author:  Insectoid [ Wed Jun 09, 2010 8:01 pm ]
Post subject:  RE:Walking animation help

@Cezna, You could keep a stock image around for just this type of situation. I find it very helpful.

Anyway, what you want is an array of images with the character in different stages of walking. Keep a counter of what image is being used, and then say, if the left arrow key is pressed, increment the counter by 1 and instead of

Pic.Draw ("Whatever.bmp"), you'd have

Pic.Draw (picArray(counter)).

Using a 2d array of left and right images, you can swap which direction the character is facing for left or right movement using a direction variable. For example (a very pseudo-code-y, incomplete example),

code:

%pics at (0)(0-24) are left-facing, pics at (1)(0-24) are right-facing
var picArray : array 0..1, 0..24 of int
var counter : int := 0
var direction : int := 0

proc animate
        if counter = 24 then
            counter := 0
        else
            counter += 1
        end if
end animate
loop
    if (left arrow pressed) then
        direction := 0
       animate
    elsif (right arrow pressed) then
        direction := 1
        animate
    end if
    Pic.Draw (x, y, picArray(direction)(counter))
end loop


You could add an idle pic so if no key is pressed it switches to a default image so he doesn't freeze mid-stride (lawl).

Author:  Cezna [ Wed Jun 09, 2010 8:10 pm ]
Post subject:  RE:Walking animation help

Listen to Insectoid, once again, he has pwned me and hopefully helped you solve your problem Smile

Anyway, Embarassed on missing that first attachment, and I never thought of keeping a stock image, but it sounds like a good idea, as it would come in very handy in going through some of the code I find in the help sections of this site.

Even though I probably won't be able to improve much on what help Insectoid has given you, I will look through the code regardless with the picture now at my disposal, and if I come up with anything, you'll find it here.

Author:  Monduman11 [ Wed Jun 09, 2010 8:12 pm ]
Post subject:  Re: Walking animation help

ah kk i see what your getting at . thx insectoid ill try it out and see how it goes

Author:  Monduman11 [ Wed Jun 09, 2010 8:14 pm ]
Post subject:  Re: RE:Walking animation help

Cezna @ Wed Jun 09, 2010 8:10 pm wrote:
Listen to Insectoid, once again, he has pwned me and hopefully helped you solve your problem Smile

Anyway, Embarassed on missing that first attachment, and I never thought of keeping a stock image, but it sounds like a good idea, as it would come in very handy in going through some of the code I find in the help sections of this site.

Even though I probably won't be able to improve much on what help Insectoid has given you, I will look through the code regardless with the picture now at my disposal, and if I come up with anything, you'll find it here.

kk thx , and insectoid helped with the walking animation not the shooting thing, he just gave me a suggestion on how else i could do it

Author:  Cezna [ Wed Jun 09, 2010 8:16 pm ]
Post subject:  RE:Walking animation help

Dang, was about to post an edit Sad

Here is a link to another topic where there was a discussion on the same stuff Insectoid was talking about:
http://compsci.ca/v3/viewtopic.php?t=25497

Author:  Monduman11 [ Wed Jun 09, 2010 8:18 pm ]
Post subject:  Re: Walking animation help

ah kk thanks again lol

Author:  Insectoid [ Wed Jun 09, 2010 8:24 pm ]
Post subject:  RE:Walking animation help

Shooting is pretty easy to do. Have a flexible array (or just a big enough regular array to hold the maximum number of shots possible on screen at a time) and whenever the 'shoot' button is pressed, add the character's x, y and direction coordinates to the array (either use 3 arrays for the 3 elements or a record if you know how). Then, in your main loop, have a separate loop that moves all the bullets (direction should be either -1 or 1 for ease of use). Keep a counter to control how soon a bullet can be fired off (set it to like, 10 or something and then decrement it every frame and don't let the gun fire unless the counter's less than 0, then set to 10 again). Or use Time.SinceLast or whatever it's called.

Author:  Monduman11 [ Wed Jun 09, 2010 8:27 pm ]
Post subject:  Re: RE:Walking animation help

Insectoid @ Wed Jun 09, 2010 8:24 pm wrote:
Shooting is pretty easy to do. Have a flexible array (or just a big enough regular array to hold the maximum number of shots possible on screen at a time) and whenever the 'shoot' button is pressed, add the character's x, y and direction coordinates to the array (either use 3 arrays for the 3 elements or a record if you know how). Then, in your main loop, have a separate loop that moves all the bullets (direction should be either -1 or 1 for ease of use). Keep a counter to control how soon a bullet can be fired off (set it to like, 10 or something and then decrement it every frame and don't let the gun fire unless the counter's less than 0, then set to 10 again). Or use Time.SinceLast or whatever it's called.

i already have the shooting thing and it works seperatly but when i try to add it to the game, whenever i press the shoot button the fireball is shot but it doenst blend in with the game it just shoots leaving a white line behind it

Author:  Insectoid [ Wed Jun 09, 2010 8:31 pm ]
Post subject:  RE:Walking animation help

Does it freeze the rest of your game?

Author:  Monduman11 [ Wed Jun 09, 2010 8:34 pm ]
Post subject:  Re: RE:Walking animation help

Insectoid @ Wed Jun 09, 2010 8:31 pm wrote:
Does it freeze the rest of your game?

no once the shooting is done the game continues to work, the only problem im having is that i cant seem to make it be one with the game

Author:  Insectoid [ Wed Jun 09, 2010 8:40 pm ]
Post subject:  RE:Walking animation help

I assume your game looks a bit like this

code:

loop
%do stuff
     loop
         exit when bullet hits something
         move bullet
     end loop
%draw stuff
end loop


It really should look more like this
code:

var bullets: array 1..num_bullets of int %array of bullets
loop
%do stuff
    for x: 1..num_bullets
        move bullets(x) ONCE
    end for
%draw stuff
end loop


What's happening in yours is when you fire a bullet, the program enters a loop which effectively pauses the program and focuses all its attention on moving that bullet. Rather, the bullet should be moved like a character; only once per loop. Moving two things at the same time is a vital part of animation and learning how will be invaluable.

Author:  Monduman11 [ Wed Jun 09, 2010 8:42 pm ]
Post subject:  Re: Walking animation help

ah kk ill try to edit my code and see if i can make it work Smile if not ill keep on trying till i get it lol

Author:  Cezna [ Thu Jun 10, 2010 11:47 am ]
Post subject:  RE:Walking animation help

You just need to redraw the background every time you move the fireball to prevent that white line from showing up, and use setscreen ("offscreenonly")


: