Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 28, 2009, 12:27 AM   #1
Branskins
macrumors 6502a
 
Join Date: Dec 2008
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?
Branskins is offline   0 Reply With Quote
Old Jul 28, 2009, 09:36 AM   #2
m3kilpat
macrumors regular
 
Join Date: Jul 2009
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.

Code:
#include <time.h>

clock_t start, end;
double elapsed;

start = clock();
/* Do stuff */
end = clock();
elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
So you can subtract health something like every 30 seconds by putting the above code into a while loop and when elapsed = 30 then subtract from health.

Last edited by kainjow; Jul 28, 2009 at 10:34 AM. Reason: removed quote
m3kilpat is offline   0 Reply With Quote
Old Jul 28, 2009, 04:13 PM   #3
Branskins
Thread Starter
macrumors 6502a
 
Join Date: Dec 2008
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!
Branskins is offline   0 Reply With Quote
Old Jul 29, 2009, 08:30 AM   #4
m3kilpat
macrumors regular
 
Join Date: Jul 2009
Quote:
Originally Posted by Branskins View Post
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!
Check out this page.

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.
m3kilpat is offline   0 Reply With Quote
Old Jul 29, 2009, 01:16 PM   #5
Branskins
Thread Starter
macrumors 6502a
 
Join Date: Dec 2008
Thanks! This should work
Branskins is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
MyWi (4.51.1) Status Bar Icon galanoth Jailbreaks and iOS Hacks 1 Feb 11, 2011 10:28 PM
Weird icon in status bar on my iPhone 3G - I have no clue what it is! kidpaul1 iPhone Tips, Help and Troubleshooting 2 Nov 3, 2010 05:29 PM
Need help identifying strange status bar icon on JB iPhone 3G Snide iPhone 8 Apr 1, 2009 02:26 PM
Help wanted - mailto: and status bar message stevep Web Design and Development 0 Feb 17, 2006 12:33 PM
I cant find the bluetooth status bar! Please help! kingcrosscutie Mac Basics and Help 4 Jan 19, 2006 08:07 PM


All times are GMT -5. The time now is 01:22 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC