Computer Science Canada RPG character movement |
Author: | gohan [ 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!!! |
Author: | Delos [ Mon May 30, 2005 12:41 pm ] |
Post 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. |
Author: | Mazer [ Mon May 30, 2005 9:11 pm ] | ||||||
Post 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 ) 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)
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:
In that case, you'd draw picsLeft(3) or with 2D arrays:
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. |
Author: | gohan [ Tue May 31, 2005 9:55 am ] |
Post 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!! |
Author: | Mazer [ Tue May 31, 2005 3:11 pm ] |
Post 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 |
Author: | gohan [ Tue May 31, 2005 9:04 pm ] |
Post subject: | |
You guessing pretty good there Coutsos... so would i just use a loop,or what?...lol.... |
Author: | Mazer [ Tue May 31, 2005 9:14 pm ] | ||
Post subject: | |||
Well, you'd have a main game loop certainly. And those if statements would be inside of it.
|