first post, first game, first problem

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
jaymonster138
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 10
Joined: Wed Nov 25, 2009 10:05 pm

first post, first game, first problem

Post by jaymonster138 »

The idea is when the down key is pressed to display the red bar, when it is released it goes away (i got that to work fine) now i am trying to make the bar change from red to blue each time the space bar is pressed (whether the bar is visible or not). In the code below, the image 2 is red and image 3 is blue. The bar only turns blue when i am holding the down key and press space. When I release the down key the blue bar stays on screen until i press space again. I think when it loops through the main header its setting the count back to zero. i tried initializing count in the main header but gives me the error of "can't find count" how do I make the count public to the whole program and not reset?

Code: Select all

void down()
{
	int x;
	int count = 0;
	if (dbSpaceKey() == 1)
		count++;

	if ((count%2) == 0)
		 x=2;
	else
		 x=3;

	if(dbDownKey() == 1)
		dbSprite(x, 315, 200, x);
	if (dbDownKey() == 0)
		dbDeleteSprite(x);
}
User avatar
animangaman690
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 96
Joined: Mon Feb 02, 2009 8:03 am
Current Project: TDS
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++, C#
Location: Alexander City, AL
Contact:

Re: first post, first game, first problem

Post by animangaman690 »

Try this:

Code: Select all

int count = 0;
int x;
void down();
//What ever any other code that would go here
void down()
{
  if (dbSpaceKey() == 1)
      count++;

   if ((count%2) == 0)
       x=2;
   else
       x=3;

   if(dbDownKey() == 1)
      dbSprite(x, 315, 200, x);
   if (dbDownKey() == 0)
      dbDeleteSprite(x);
}
The prolbem is you can't have int x or int count in your loop or it will start over.
I suggest put the variables in the initialization (for DarkGDK just put the variables before you declare the functions)

I hope this helps. If not, explain to me a bit more what you're trying to do.
jaymonster138
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 10
Joined: Wed Nov 25, 2009 10:05 pm

Re: first post, first game, first problem

Post by jaymonster138 »

That did help! thank you. Don't you hate when someone gives you such a simple fix that you know, just couldn't think of. i haven't programmed in about a half a year so I'm a bit rusty, plus this is my first time using c++, I'm used to java.
But thanks that helped me. It's still not doing exactly what i want but it's closer. I wanna try to figure it out on my own, if i get stuck ill come back and ask. Thanks again
jaymonster138
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 10
Joined: Wed Nov 25, 2009 10:05 pm

Re: first post, first game, first problem

Post by jaymonster138 »

I changed what i was going to do and got it to work. Just in case your curious
now it can only change to blue while your holding the down key and the space bar. i think this may work better with the idea of the game.

Code: Select all

void down()
{
	if(dbDownKey() == 1)
	{
		dbSprite(2, 315, 200, 2);
	       if(dbSpaceKey() == 1)
	       {
		      dbSprite(3, 315, 200, 3);
		      dbDeleteSprite(2);
	        }
	}
	
	if (dbDownKey() == 0)
	{
		dbDeleteSprite(2);
		dbDeleteSprite(3);
	}
}
User avatar
animangaman690
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 96
Joined: Mon Feb 02, 2009 8:03 am
Current Project: TDS
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++, C#
Location: Alexander City, AL
Contact:

Re: first post, first game, first problem

Post by animangaman690 »

I'm glad it helped. What little help it gave.
If you have any more questions regarding DarkGDK, feel free to ask me. I've been using it for quite a while now so I can help you out if you need it.
jaymonster138
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 10
Joined: Wed Nov 25, 2009 10:05 pm

Re: first post, first game, first problem

Post by jaymonster138 »

yeah i will need more help. Is your yahoo i.m. the same as your name on here?
User avatar
animangaman690
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 96
Joined: Mon Feb 02, 2009 8:03 am
Current Project: TDS
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++, C#
Location: Alexander City, AL
Contact:

Re: first post, first game, first problem

Post by animangaman690 »

jaymonster138 wrote:yeah i will need more help. Is your yahoo i.m. the same as your name on here?
no it's 'jchill95' I decided to go with something more professional for my email, but I'm rarely on IM if you email me about your problems I'll tell you the next time I'm on IM.
Post Reply