Computer Science Canada fork/process help?!?! |
Author: | blaster0 [ Mon Feb 27, 2006 7:41 pm ] |
Post subject: | fork/process help?!?! |
I am creating a fighting game and I have several questions. 1)I have a process, that activates everytime I press a key. ex:if I press right my person will move right and then my opponent will jump, but because jumping takes longer than moving right if I move right twice and it jumps twice the second jump will be before the first jump is finished=screwed up backgrounds etc. p.s. for some reason though the opponent will land either way it's just that the graphics are screwed up from the picxor's (not overlapping?) 2)is there a way to set a time limit for pressing keys. ex: Easter egg- if press "dude" then other guy dies. Thanks so much in advance |
Author: | blaster0 [ Mon Feb 27, 2006 7:48 pm ] |
Post subject: | File |
Here is the file there are many things to be done to it, but I rehauled it so that I could try to fix this problem |
Author: | md [ Mon Feb 27, 2006 7:50 pm ] |
Post subject: | |
DO NOT USE PROCESSES. They break things and are definitely not needed for what you are doing. Using procedures and functions is a much better idea. This topic has been brought up many a time; search for fork or processes and see. |
Author: | blaster0 [ Mon Feb 27, 2006 8:05 pm ] |
Post subject: | Help |
here's some potentially useful information. I set the program to not need any user at all and it ran differently each time even though they were told to do the same moves. (ex: the blurs were in different places |
Author: | blaster0 [ Mon Feb 27, 2006 8:23 pm ] |
Post subject: | thanks, but... |
Thanks a lot I just read the tutorial, but how would I make them run at the same time? (I didn't really understand that part of the tutorial) |
Author: | Martin [ Mon Feb 27, 2006 9:54 pm ] | ||
Post subject: | |||
You'll want your main loop to look like this.
make sense? |
Author: | blaster0 [ Mon Feb 27, 2006 10:07 pm ] |
Post subject: | Not really |
It doesn't really make so much sense to me because my program is like this, basically: if up is pressed drawxor the current pic, xor pic 1, delay, xor pic 1, xor pic 2..... The same for the opponent so how do I get them to both run at the same time. (my program is here if you need). |
Author: | Martin [ Mon Feb 27, 2006 11:29 pm ] | ||
Post subject: | |||
It's like this. Suppose that your game just consists of two circles, each one can be moved around by a player. Player 1 moves their circle with WASD, player 2 uses the arrow keys. The proper way to code this would be as follows:
EDIT: Switched to seperate if statements. |
Author: | blaster0 [ Mon Feb 27, 2006 11:56 pm ] |
Post subject: | |
I'll try, but Iam not simply moving a picture I am importing several pictures depending on the movement. ex:6 jump pics and 2 duck pics. This makes the updating much harder, but I will try to seeparate them into steps. Also, I have different delays. Thanks again |
Author: | blaster0 [ Tue Feb 28, 2006 12:16 am ] |
Post subject: | |
Also elsif doesn't work for computer player because elsif occurs only if the 1st is false. For example if I say: If a is pressed move left Elsif d is pressed move right .... elsif the computer randomly chose to move right move right would not work because it would only move right if the human chose not to move, in which case because of getkey (procedure if you don't know look in built in turing manual under getchar or the like)the loop would not even be activated. Also I think I may have thought of a solution, but delays accumulate=problem. A possible solution may be to subtract larger from smaller and update there. sorry for bothering you contuously thanks again |
Author: | md [ Tue Feb 28, 2006 12:29 am ] |
Post subject: | |
you can always use more then one if statement... Doing animation is not easy; it's definitely not something you want to be doing unless you are willing to think hard about what you are doing. This would be one of those times where figuring it out on your own is much more satisfying then having someone tell you; and much better for your understanding. |
Author: | blaster0 [ Tue Feb 28, 2006 12:35 am ] |
Post subject: | |
ya I guess. Thanks I'll try and ask if I need help. And the moral of the story is the Turing people are idiots for not making a working process program. |
Author: | Martin [ Tue Feb 28, 2006 2:17 am ] |
Post subject: | |
No, Turing processes work exactly how they should. The problem is that you are using them for things that you shouldn't be using them for. To fix the delay problem, you could instead not delay at all but use relative motion to the fps - this way, the game'll play at the same speed on all computers (although it would be choppy on slower ones). To do this, you calculate the current time and the time that the action was started on and draw the frame appropraitely. For example, if your punching animation was 5 frames long and a punch took a second to execute, you would switch the frame every 200ms (otherwise just drawing the old frame). This way, the game wouldn't lag (for example, if it was taking 300ms to draw a frame, it'd only draw frames 1(0ms), 2(300ms), 4(600ms),5(900ms), skipping frame 3 to keep the animation in time. I fixed up my code by the way. Sorry about that. |
Author: | codemage [ Tue Feb 28, 2006 9:34 am ] |
Post subject: | |
You can figure out what a good universal delay is at the beginning of the program. For multi-frame animations, have some sort of variable that keeps track of what picture should be playing based on what the last movement command was. |
Author: | iker [ Tue Feb 28, 2006 7:18 pm ] |
Post subject: | |
codemage wrote: You can figure out what a good universal delay is at the beginning of the program.
For multi-frame animations, have some sort of variable that keeps track of what picture should be playing based on what the last movement command was. You could try using the spryte module I made aswell. Its easy to use, comes with full help and a full example of each command and works with multiple sprites/animations. It was probly extremely underlooked seeing as how it only has one response other then my own ![]() |