|Jul 28, 2009, 01:27 AM||#1|
Helping programming a status bars
I am learning C++ at the same as I am programming a simple game. I am stuck on programming the health bar. I want it to decay over time, only to be increased by using a heal pot.
I thought it would be simple, which I still think it probably is, but what is the best way to go about doing this?
|Jul 28, 2009, 10:36 AM||#2|
Is this a command line based game? You could use the clock command to figure out elapsed time to subtract from the health and simply add to the health when a "pot" is used.
#include <time.h> clock_t start, end; double elapsed; start = clock(); /* Do stuff */ end = clock(); elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
Last edited by kainjow; Jul 28, 2009 at 11:34 AM. Reason: removed quote
|Jul 28, 2009, 05:13 PM||#3|
Okay thank you! Now let's say your health decays every 8 hours and you don't login for 1 day. How would it record this difference? Basically, what is the best way to save logout time and then compare it to login time?
Sorry for these trivial questions!
|Jul 29, 2009, 09:30 AM||#4|
That may or may not work. It depends on if you're programming for windows or unix because there is no default C++ time function. Time is a system library, so POSIX and windows each have their own. You can easily find what you're looking for with a quick google search.
But if the above link does work...You will get the number of seconds since the epoch when calling time. So save this number upon the user exiting. Once they load up again call time again and subtract the saved time from this new time to get the difference and then calculate number of hours and subtract health accordingly.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Mac programming should be more like iOS programming.||moonman239||Mac Programming||13||Feb 17, 2014 02:37 PM|
|iPhone: 2 Status Bars wtf||darkmau2013||iOS 7||7||Nov 30, 2013 11:17 AM|
|iPhone: transparent status bars||DatRippelEffect||Jailbreaks and iOS Hacks||0||Mar 5, 2013 09:43 AM|
|iphone white bars/black bars?||duhyes||iPhone||7||Jan 7, 2013 07:07 AM|
|Iphone 5 signal dropping from full bars to 3 bars every 24 hours||onearsenewenger||iPhone||4||Oct 14, 2012 08:44 PM|
All times are GMT -5. The time now is 05:30 PM.