Re: [Dev-C++] Help with Game Problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Tulius L. <tul...@ho...> - 2003-03-12 03:09:35
|
Brian,
I think you should re-organize your bullet code. Break the upbullet()
function in two: one that setup the bullet, and another one to update the
bullet state.
The first function should have the code that is located before you
do..while loop, and it should be called when you detect the fire key press.
This second function should have the code thats inside your do..while
loop (but not the loop itself), and should be called from within your game
loop (so you won't need the loop and the ship, as well as your other game
entities, will be able to move).
Hope this helps.
Tulius
>From: "Brian Savells" <blu...@at...>
>To: "Allegro Group" <Dev...@li...>
>Subject: Re: [Dev-C++] Help with Game Problem
>Date: Tue, 11 Mar 2003 19:22:34 -0600
>
>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
>
>
>
>-------------------------------------------------------
>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
_________________________________________________________________
MSN Messenger: converse com os seus amigos online.
http://messenger.msn.com.br
|