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

Username:   Password: 
 RegisterRegister   
 RPG character movement
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gohan




PostPosted: Mon May 30, 2005 11:01 am   Post subject: RPG character movement

We all know that it is FINAL PROJECT TIME!!!...BOOO
Anyways...i need to know how to make a character move on the screen.
I have four different pics of a character...I just wanna know how to make the character switch from 1 pic to the other.(I want it to look like Link off of Zelda, or Ash off of Pokemon)

Plzzzzzz help me with this please!!!

THANK YOU!!!
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon May 30, 2005 12:41 pm   Post subject: (No subject)

Speak to Legolas. Or Bacchus. The former has an amazing emulated version of Zelda up here somewhere. The latter has released a working Sprite engine.
Mazer




PostPosted: Mon May 30, 2005 9:11 pm   Post subject: (No subject)

I assume you mean four pics of walking? Otherwise if you mean four directional pictures, there's nothing we can do for you as there's nothing to work with.

But assuming you meant walking, each picture is a frame in an animation and corresponds to movement of legs (and arms) to make it look like the character is walking. What you need to do first is decide how long a walk cycle lasts.
Let's say that'll be 1.5 seconds (1500 milliseconds).

This means, while we are walking, beginning with taking a step with our right foot, it takes 1500 milliseoncds to:
- shift our weight onto the right leg
- move our left leg in front of us and swing our body mass over
- put our left foot down to prevent us from falling (that's what walking is)
- shift our weight onto the left leg
- move our right leg in front of us to swing our body mass over
- put our right foot down to prevent us from falling

See how it repeats? When we walk we're not doing anything new (unless your doing some kind of dance-walk thing), it's the same simple routine over and over and over.

That is (hopefully) what those four pictures are. Though it'll likely be condensed and less detailed if there are only four frames. That last step wouldn't exist though. You'd start with setting your right foot down, and end with bringing your right foot forward. Since it's repeating, the "end" is actually the beginning of the walk procedure all over again. You should also have a picture of the character standing still.

So, we've got the steps it takes to walk, and we know how long it takes if we want to take two steps (one complete cycle). So where do we go? Left! (well, assuming you hit the "left" arrow key, at least Razz )

We should also be aware of how long we've been walking so we know at what time our character should move his/her body.
Let's have a simple loop (using some messed up mix of pseudocode and turing, because I don't want to think about actual Turing syntax due to the incredible pain in my legs)

thisIsNotCode:

timeWalking = 0 % we aren't walking, we're standing still!
timeSinceLast = 0 % the amount of time (ms) that have passed since we last checked the time
direction = 1 % 1 = left, 2 = right, 3 = up, 4 = down, just for the sake of consistency (enumeration would be a better way to do this, but forget it for now)
walkFrame = 1 % 1, 2, 3, 4! 4 frames! ah ah ah!

proc steps()
    timeWalking += timeSinceLast % we've been walking another timeSinceLast milliseconds in this loop
    walkFrame = ceil (timeWalking / 1500 * 4) % take the percentage of the 1500ms walk cycle that we've walked, then find out which frame we should be in at this time
end steps

if key = left
    if direction not= 1 % if we aren't facing left, we have to turn to face left and begin walking
        direction = 1 % now we face left
        timeWalking = 0 % now we just begin walking
    end if

    steps()
end if
else if key = right
    if direction not= 2 % if we aren't facing left, we have to turn to face left and begin walking
        direction = 2 % now we face left
        timeWalking = 0 % now we just begin walking
    end if

    steps()
else if key = up
    if direction not= 3 % if we aren't facing left, we have to turn to face left and begin walking
        direction = 3 % now we face left
        timeWalking = 0 % now we just begin walking
    end if

    steps()
else if key = down
    if direction not= 4 % if we aren't facing left, we have to turn to face left and begin walking
        direction = 4 % now we face left
        timeWalking = 0 % now we just begin walking
    end if

    steps()
else
end if

timeSinceLast = Time.Elapsed - timeTotal % timeSinceLast is the total time that has passed since starting the program minus the total time that has passed up to  the end of the last loop
timeTotal = Time.Elapsed % the total time passed up to the last loop (that is now ending) is equal to the total time elapsed


Something like that. You wouldn't believe how much my knees are hurting now. I apologize in advance if I've made errors (I know the code could've been written better), but there's no chance of me going back and fixing it.

So that code would be used to give you the frame number of the walk cycle you should be using. So, supposing you were facing left, had the left arrow key down, and walkFrame was equal to 3. You would draw the 3rd pic of the character facing left at the character's position. Ideally, you'd have arrays (or one 2D array) of the pictures.
Like so:
code:

var picsLeft : array 1 .. 4 of int
var picsRight : array 1 .. 4 of int
var picsUp : array 1 .. 4 of int
var picsDown : array 1 .. 4 of int

In that case, you'd draw picsLeft(3)
or with 2D arrays:
code:

var pics : array 1 .. 4, 1 .. 4 of int

Where the first 1 .. 4 represents the direction, and the second 1 .. 4 is the frame. So again from the example you'd draw pics(1)(3).
Of course, you should be using better variable names than that.
gohan




PostPosted: Tue May 31, 2005 9:55 am   Post subject: (No subject)

Hey Coutsos, Thnx for the reply!!! Yes, I meant four pics of walking. (really I have 12 pics.) 3 for each direction!!! and I'm sorry that i didnt make it as clear as possible...lol...you made it sound like i am really slow and don't know what ur talking about...lol

Well to be honest, I am still a little confused on the part where you have to draw the pic...are you talking about the 4 directions of the character?


Quote:
You should also have a picture of the character standing still.

I do have a picture of the character standing still.

I wish I could get something a little clearer, now that i have told you that i have 12 pics..lol..sry!!
Mazer




PostPosted: Tue May 31, 2005 3:11 pm   Post subject: (No subject)

Well, make that three pictures instead of four now that you've cleared it up. I'm guessing your 3 pictures are:
- left leg forward
- standing
- right leg forward
gohan




PostPosted: Tue May 31, 2005 9:04 pm   Post subject: (No subject)

You guessing pretty good there Coutsos... so would i just use a loop,or what?...lol....
Mazer




PostPosted: Tue May 31, 2005 9:14 pm   Post subject: (No subject)

Well, you'd have a main game loop certainly. And those if statements would be inside of it.

code:
% variables here

loop
    % get input here

    % check for direction/movement (the crap in my previous post)

    % process as necessary

    % draw stuff

    % lather, rinse, repeat
end loop
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  [ 7 Posts ]
Jump to:   


Style:  
Search: