How do you do two functions at one time?
if you need to know, im using borland C++ dos compiler mkay?
Soo.....If you need to know more golly gosh just ask me
How do you do two functions at once?
How do you do two functions at one time?
if you need to know, im using borland C++ dos compiler mkay?
Soo.....If you need to know more golly gosh just ask me
How do you do two functions at once?
Code:#if _emo #define stereo_type_i_dislike #endif
The first answer would be to use threading (running two functions seperately at the same time), but since you're using a borland dos compiler, I'm not sure if it's possible. The simple answer is that you can't, and you should redesign your program to round robin the functions you need to run at "the same time", allowing them to keep their state between each run.. (static variables, or a repository of structures... or just a buffer of raw memory...). What are you writing?
...and now a more knowledgeable member will come and tell you a simple clean way of doing this
.sect signature
err.....english please! im only 12 years old
Code:#if _emo #define stereo_type_i_dislike #endif
ok, I'll give you an example:
it's a bit messy, but you can see that between each time the function runs it will "remember" the way it was the last time it ran, and do different work depending on where it is.Code:int function1(int arg, int *state) { switch(*state) { case 1: printf("state 1!: %d\n", arg); break; case 2: printf("state 2!: %d\n", arg*2); *state = -1; break; }; *state++; return 0; };
.sect signature
Ok....I dont remember well but someone told me an easy way, it was like:
___sync___();
it had sync in it: i remember because i started to laugh when i say that word: can you fill in the blank?
Code:#if _emo #define stereo_type_i_dislike #endif
Please gimme something that works!!!
I want something that can, let say this:
#include <iostream.h>
#include <conio.h>
void right()
{
//blah blah makes the char move to the right
}
void shoot()
{
// yadaya makes the char shoot a little bullet
}
int main()
{
while(1)
{
//whatever i want here
char action = getch();
if (action == 77)
{
//Ok, this is what i want to know, how to make him able to
//walk right and shoot at the same time
}
if (action == 27)
break;
}
return 0;
}
without the function that allows you to do two functions at once, when you shoot you have to wait till it finishes shooting then be allowed to move and i dont want that. please help me
Code:#if _emo #define stereo_type_i_dislike #endif
In this case you need something a little more complex than a function that causes the guy to shoot a bullet and the function that causes the guy to move. Here's the solution I would use:
I would create a particle system for the game you're writing, something with a structure like this:
it's a bit ugly and simplistic, but it would probably do the trick. the setvars function would set each of the variables in the class, and the tick() function would do the motion for the particle for a single tick. example:Code:class particle { public: particle(); ~particle(); int setvars(int xp, int yp, int xf, int yf, int t); int tick(void); private: int xpos, ypos; int xforce, yforce; int type; };
if this is a bit more complex than you want, you might try posting your question to the c programming board (and get it in plainer structures..), or to the game programming board and ask how to get a guy moving and shooting at once.Code:int particle::tick(void) { /* handle differences in motion system for different particles */ switch(this->type) { case BULLET: this->x += this->xf; this->y += this->yf; break; }; };
.sect signature
Well if i understanded all that i would be happy but im not old enough to understand or i mean not good enough but i'll try your other suggestions