Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Coding a game???

Author
Message
Malo
15
Years of Service
User Offline
Joined: 15th Jan 2009
Location:
Posted: 16th Jan 2009 07:10
I have been working on a 2D game and I got the basic funtions down, like paste an image onto the background and a sprite is animated and can move left and right(thank you forums, you have helped alot).
Now I want to take it further and add things like giving the sprite needs, like hunger and bordom.
But I don't know how to go about doing that. I code in c++ but things like cout or endl don't work. Do I initialize variables for his hunger level and have it decrement based on a rand number generator,than program it if you press a certain button you "feed" the sprite? Sorry there are alot of questions. Then over all, how would I display those stats?
Thanks for any help!
RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 16th Jan 2009 08:20
yeah they are all variables like:

int hungerlevel;
int bordom;

then you will have something like: if (hungerlevel <= 0) kill the sprite;

and if (I click on my sprite to feed it) hungerlevel++;

and to display them, an easy way would be:

before your game loop make a char: char* myinfo = new char[256];
and then to display a var in your loop:

sprintf(myinfo, "Hunger: %d", hungerlevel);
dbText(10,10, myinfo);

sprintf(myinfo, "Bordom: %d", bordom);
dbText(10,20, myinfo);

You need to learn how to make your own functions and stuff. Later you would want to know how to use classes, since it will help you use your code more dynamically where you will have many game characters each with their own set of variables. There are many good web sites that will teach you this quickly.
Look at the www.cplusplus.com tutorials
Malo
15
Years of Service
User Offline
Joined: 15th Jan 2009
Location:
Posted: 18th Jan 2009 03:31
Thank you this has helped alot!
I can code functions and classes but pointers are still new to me so I never would of thought of doing it this way!
Thanks again.
Another question though...
If this code

in the main loop will it constantly be updated?
so lets say hunger starts at 5, that gets displayed than later in the loop it goes up to lets say 6, will it than display 6 instead of 5? does that make sense?
RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 18th Jan 2009 15:51
It will display whatever hunger was before you printed it as text. But is doesnt matter, a loop goes so fast that even if you only called it once at the beginning of a loop, it will still display the most recent value of hunger

well it is good to mess around with classes and stuff, or start with structs. Try getting something done with just variables and your own functions for one character, then move on to putting it all in a class and then use it for more than one character. Remember that your sprites are just representations of what is happening in the background with code.

Login to post a reply

Server time is: 2024-09-30 15:37:38
Your offset time is: 2024-09-30 15:37:38