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

Username:   Password: 
 RegisterRegister   
 fork/process help?!?!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
blaster0




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
blaster0




PostPosted: 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


finalproduct21.t
 Description:

Download
 Filename:  finalproduct21.t
 Filesize:  14.33 KB
 Downloaded:  126 Time(s)

md




PostPosted: Mon Feb 27, 2006 7:50 pm   Post subject: (No 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.
blaster0




PostPosted: 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
blaster0




PostPosted: 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)
Martin




PostPosted: Mon Feb 27, 2006 9:54 pm   Post subject: (No subject)

You'll want your main loop to look like this.

code:

const PUNCH := 0
const KICK := 1
const JUMP := 2
...
var player1_animation : int %What the player is currently doing
var player1_animation_frame : int %The frame of the animation
var player2_animation : int
var player2_animation_frame : int

loop
  (check to see if one of the palyers is dead)
  1.  check to see what keys are down (Input.KeyDown)
  2.  react accordingly. For example, if player 1's punch key is down and player1_animation is not= PUNCH, then cancel their current animation and begin the punch animation by setting player1_animation to PUNCH and player1_animation_frame to 0.
  3. Update both player's frames. For example, the punching animation would progress one step or the player would move forward one step.
  4. Update the player's health and position based on what happens. A punched player would get hurt and might fall down, for example
  5. Draw the background, health bars, timers, etc.
  6. Draw the characters.

end loop


make sense?
blaster0




PostPosted: 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).
Martin




PostPosted: Mon Feb 27, 2006 11:29 pm   Post subject: (No 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:

code:
View.Set("offscreenonly")

var keys : array char of boolean
var p1x, p1y : int := 50 % player 1's coordinates
var p2x, p2y : int := 200 % player 2's coordinates

proc DrawScene
    cls
    Draw.FillCircle (p1x,p1y,10,10,red)
    Draw.FillCircle (p2x,p2y,10,10,blue)
    Draw.Update()
end DrawScene

loop
    Input.KeyDown(keys)

    exit when keys('q') %quit when the player presses q
    if (keys('a') or keys('A')) then
        p1x := p1x- 5
    end if
    if (keys('s') or keys('S')) then
        p1y := p1y - 5
    end if
    ...
    if (keys(KEY_LEFT_ARROW)) then
       p2x := p2x - 1
    end if
    if ...
    ...
    end if
    DrawScene %now we draw everything
end loop


EDIT: Switched to seperate if statements.
Sponsor
Sponsor
Sponsor
sponsor
blaster0




PostPosted: Mon Feb 27, 2006 11:56 pm   Post subject: (No 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
blaster0




PostPosted: Tue Feb 28, 2006 12:16 am   Post subject: (No 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
md




PostPosted: Tue Feb 28, 2006 12:29 am   Post subject: (No 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.
blaster0




PostPosted: Tue Feb 28, 2006 12:35 am   Post subject: (No 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.
Martin




PostPosted: Tue Feb 28, 2006 2:17 am   Post subject: (No 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.
codemage




PostPosted: Tue Feb 28, 2006 9:34 am   Post subject: (No 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.
iker




PostPosted: Tue Feb 28, 2006 7:18 pm   Post subject: (No 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 Sad... anyways, try it out, if you don't like it, don't use it. And if you do chose to use it, read the READ ME and help and to download the one at the bottom.
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  [ 15 Posts ]
Jump to:   


Style:  
Search: