Thread: [Dev-C++] Help with Game Problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Brian S. <blu...@at...> - 2003-03-12 00:16:21
|
Hello, I'm programming my first game and need a little help. Well I'm making a = simple (well it was supposed to be simple lol) two player shooter game. = Each player uses a series of keys on the keyboard to move/fire the ship. = Well my first problem (that I was able to solve on my own - go me!) was = that the ships were slowing each other down when they were both moving = at the same time. I fixed this by placing a rest() function at the end = of each getInput functions instead of at each key input. (I have two = getInput()'s - One for each player) My problem now is, I'm wondering how = to incorporate the shoot functions. I have two functions (One that = shoots up, and another that shoots down) to handle the shooting. They = are simple and only involve drawing a circle that increases or decreases = its y-axis. If I place a rest() or vsync() every time it redraws, it = hinders either ship from moving (because it is caught in that loop). How = can I incorporate it so that the bullet can still be moving up and I = would still be able to maneuver the ship(s) and/or fire again? Any help = would be greatly appreciated! Thanks! -Brian |
|
From: Brian S. <blu...@at...> - 2003-03-12 00:47:18
|
Oh yes, forgot to mention that I am using the Allegro library. Ill try the method that you gave me and see if that gets me anywhere. -Brian ----- Original Message ----- From: "Robson Bernard" <rob...@su...> To: "Brian Savells" <blu...@at...> Sent: Tuesday, March 11, 2003 6:43 PM Subject: Re: [Dev-C++] Help with Game Problem > Have you tried allegro game library (compatible with Dev-C++)? With allegro > you have some great stuff to make games. Try www.talula.demon.co.uk and > click the link to allegro library. > > Below a brief example of how to set interrupt handlers to manage game timing > with allegro and c++. It makes a very stable timing: > > Hope it helps! > > > // this boolean variable prevents from jumping for the next game step before > the time expected; > volatile bool doInterrupt; > > > > void refresh() > { > doInterrupt = false; > } > END_OF_FUNCTION(refresh) > > > > void doGame() > { > do { > doInterrupt = true; //sets another step > > //game stuff > > while(doInterrupt); //while doInterrup is true, the game does > not advance for the next step. > //this interval is set by the > argument in the Install_Int funtion (in miliseconds). > > } while(!key[KEY_ESC]); > > } > > > > // this function sets an interrupt handler calling function 'refresh()' > every 50ms. > Install_int(refresh, 50); > |
|
From: Brian S. <blu...@at...> - 2003-03-12 01:23:59
|
While trying to implement your code, I noticed that it was very similar to
my own method that I was using. I was setting a flag called end_game to 0
and if the escape key was pressed it would change to 1, therefore ending the
game and shutting down. I implemented the new code anyways in hopes that it
would work, but got the same results as with mine. Heres what my code looks
like:
void do_game()
{
do {
doInterrupt=true;
drawtext(); //Displays amount of bullets remaining
player1(); //These functions look at all the possible input keys
player2();
}while(!key[KEY_ESC]);
}
My bullet function looks like this:
void upbullet() //For bottom ship, bullet moving up
{
if(bcb<=0) { //check the counter. If 0, do nothing
}
else { //otherwise do this
bcb--; //subtract one from the counter
bottomb.x = bottom.x3; //bottomb is the name of my bullet structure
//bottom.x3 is reffering to the
bottom ship.
bottomb.y = bottom.y3 - 12;
do {
bottomb.draw(screen); //Draw the bullet
rest(1); // rest so that you can see it moving
bottomb.undraw(screen); // Undraw it
bottomb.y-=2; //move it up the screen 2
}while (bottomb.y >=-15); //do it until off the screen
}
}
Now this works, but every time that you shoot, you can see the bullet moving
up, but are not able to do anything else (like move the ship or fire again),
because it is caught in the do-while loop for the bullet. How would I get
around this and let it shoot/do anything else while the bullet is still
moving upwords?
Thanks!
-Brian
----- Original Message -----
From: "Brian Savells" <blu...@at...>
To: <Dev...@li...>
Sent: Tuesday, March 11, 2003 6:45 PM
Subject: Re: [Dev-C++] Help with Game Problem
> Oh yes, forgot to mention that I am using the Allegro library. Ill try the
> method that you gave me and see if that gets me anywhere.
>
> -Brian
>
>
> ----- Original Message -----
> From: "Robson Bernard" <rob...@su...>
> To: "Brian Savells" <blu...@at...>
> Sent: Tuesday, March 11, 2003 6:43 PM
> Subject: Re: [Dev-C++] Help with Game Problem
>
>
> > Have you tried allegro game library (compatible with Dev-C++)? With
> allegro
> > you have some great stuff to make games. Try www.talula.demon.co.uk and
> > click the link to allegro library.
> >
> > Below a brief example of how to set interrupt handlers to manage game
> timing
> > with allegro and c++. It makes a very stable timing:
> >
> > Hope it helps!
> >
> >
> > // this boolean variable prevents from jumping for the next game step
> before
> > the time expected;
> > volatile bool doInterrupt;
> >
> >
> >
> > void refresh()
> > {
> > doInterrupt = false;
> > }
> > END_OF_FUNCTION(refresh)
> >
> >
> >
> > void doGame()
> > {
> > do {
> > doInterrupt = true; //sets another step
> >
> > //game stuff
> >
> > while(doInterrupt); //while doInterrup is true, the game
does
> > not advance for the next step.
> > //this interval is set by the
> > argument in the Install_Int funtion (in miliseconds).
> >
> > } while(!key[KEY_ESC]);
> >
> > }
> >
> >
> >
> > // this function sets an interrupt handler calling function 'refresh()'
> > every 50ms.
> > Install_int(refresh, 50);
> >
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by:Crypto Challenge is now open!
> Get cracking and register here for some mind boggling fun and
> the chance of winning an Apple iPod:
> http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|