Computer Science Canada [n00b]Character/enemy movement synchronization |
Author: | Nigrev [ Tue Dec 05, 2006 9:38 pm ] | ||
Post subject: | [n00b]Character/enemy movement synchronization | ||
It's pretty hard to find a specific question using the surtshenjin. So I resort to posting. I'm at a predicament, which most of you pros probably have been through when the almighty said " ![]() ![]() You will see here, with incomplete comments:
Monster of a code, innit? Sorry about the pictures, modify it a bit so you can run it without messing with the movement mechanism. As you can see, it plays like a damn board game ![]() ![]() This is for an assignment, so plx no code rewriting. And plx no "LEARN CLASSES, [s]n00b[/s] ![]() ![]() I'm on basically pre-pre-pre-pre-alphastage. Thnx. |
Author: | ericfourfour [ Tue Dec 05, 2006 10:32 pm ] | ||
Post subject: | |||
Don't worry, most people won't recommend classes to someone who has trouble spelling search engine. What you basically need is a variable that keeps track of each characters movement. Every frame update that variable for each character. You should also disable the character's ability to change directions while it is moving. Say you want to move 16 pixels at 1 pixel/frame (it will take 16 frames to complete the character's movement). You would create a variable to store the character's movement and a flag that prevents the character from changing directions. A bit of code to work with.
|
Author: | Nigrev [ Thu Dec 07, 2006 9:52 pm ] | ||
Post subject: | |||
This helps how? Disable why? I don't get the code... The character does not change directions while moving anyway(which one are you talking about?) So.. okay, i keep track of the movements, then disable the control if it goes to far? This is what I have so far
|
Author: | ericfourfour [ Thu Dec 07, 2006 10:30 pm ] |
Post subject: | |
This is how you should try to solve this problem. Think of a way that does not require for loops. The way I suggest is to instead of using for loops, update the characters position every iteration of the main loop. This means you will need to keep track of every characters position. The position I'm referring to is the movement that is happening in the for loops. |
Author: | Nigrev [ Fri Dec 08, 2006 10:34 am ] |
Post subject: | |
how do I get my character to go a full 20 pixels if i do not have a for loop? also, my character changes sprites every 10 or 5 pixels to immitate walking steps. I don't want to move the sprite every ten or five pixels, I want it updated every 1 pixel for smooth animation, that's why i used the for loops. |
Author: | Nigrev [ Fri Dec 08, 2006 2:09 pm ] |
Post subject: | |
This sucks, i can't edit my post. anyway, how is controls_disabled supposed to work? y:=y? |
Author: | ericfourfour [ Fri Dec 08, 2006 8:14 pm ] |
Post subject: | |
Instead of moving them in a for loop move them in the main loop. It requires a bit more logical thinking but is more flexible. If you look at the for loop you will see that you declare a variable that either increases or decreases. Think of the main loop as a giant for loop except you have to make actual variables that increase or decrease for every character. Do you follow me yet? And don't worry about disabling the character's controls yet. You will understand why you need it when you get the first part working. |
Author: | Nigrev [ Sat Dec 09, 2006 9:25 am ] | ||
Post subject: | |||
i hear ya.
but now if the controllable character is at a standstill, the other sprites move faster than wanted. do i have to put an extra piece of coding in on the players part to give an extra delay when not moving? |
Author: | ericfourfour [ Sat Dec 09, 2006 7:07 pm ] | ||
Post subject: | |||
Just one suggestion before you continue. Make it so you only have 1 View.Update, 1 cls (or Draw.FillBox over the screen), and one delay in the program. Make sure those go in the main loop. The order I always use is:
About the characters going faster. With the above implemented into your code all your characters will need is a speed variable which is how many pixels they move per frame. If you get that implemented then you may want to make the characters speed a real number. That way they can move at a more precise speed. You would need to use the round () function though (it rounds a real number to an integer number). |
Author: | Nigrev [ Sun Dec 10, 2006 5:55 pm ] |
Post subject: | |
i don't use cls, hehe |