Calculate Time

3 replies to this topic

#1 Pythondesigns

Pythondesigns
• Members
• Member
• 17 posts

Posted 18 September 2006 - 09:29 PM

This is quite an odd question which I havent found it being asked anywhere else.

Basically Im working on an online web based RPG game. Now I want there to be an in-game time. This in-game time runs a lot faster than real time. I want it so that 1 day real time means 7 days in game time. So what I need to know is how I can display the in-game time on my site.

Eventually I will use AJAX to display a more dynamic/live version of it but for now is there a way which I can just perhaps store the game time in a text file.

Let me know.

Thanks

#2 btherl

btherl
• Staff Alumni
• Advanced Member
• 3,893 posts
• LocationAustralia

Posted 19 September 2006 - 01:01 AM

Do you want in-game time to follow real time, but at a faster rate?  If so, it's probably easier if you calculate game time from real time each time rather than storing it.

#3 obsidian

obsidian
• Staff Alumni
• Advanced Member
• 3,202 posts
• LocationSeattle, WA

Posted 19 September 2006 - 01:14 AM

i'm with btherl on this one. you need to come up with an algorithm to allow you to calculate your exact time based on current time of the day rather than trying to store the time. for one thing, with time moving that quickly, you'll never have your time very accurate if you keep having to update a text file, but in addition to that, if you're calculating the time, you can actually allow people to have their time reflect their own timezones, too. since you're talking about exactly 1 week (168 game hours) each day, you'll be having 7 gameplay hours pass for every 1 hour in real time. with that in the back of your mind, you should be able to write a function to pretty successfully calculate the gametime at any given moment. for instance:
```<?php
// i know that 1 day = 168 gameplay hours = 7 gameplay days
// 1 hour = 7 gameplay hours
// 3 hours 25 minutes ~ is about 1 gameplay day
// about 8.5 minutes = 1 gameplay hour

// get current hour and minute
list(\$hour, \$min) = explode(':', date('h:i'));

// figure out where in the gameplay week for today you are:
\$gpHours = \$hour * 7;
\$gpMins  = \$min * 8.49;

// increment \$gpHours 1 for each gamplay hour the minutes represent
\$gpHours += floor(\$gpMins / 60);

// gamplay days is equivalent to how many hours have passed
\$gpDays = floor(\$gpHours / 24);

// gamplay hours are the balance
\$gpHours = \$gpHours % 24;

// \$gpMins = the remainder of the above calculation
\$gpMins  = \$gpMins % 60;

echo "Today is the \$gpDays of the week. The time is {\$gpHours}:{\$gpMins}.";
?>
```

obviously, this is very rudimentary code, and you'll need to modify it to fit your needs, but i think you'll get a good feel for how it can work.

good luck
You can't win, you can't lose, you can't break even... you can't even get out of the game.

```<?php
while (count(\$life->getQuestions()) > 0)
{   \$life->study(); } ?>```
LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 Pythondesigns

Pythondesigns
• Members
• Member
• 17 posts

Posted 20 September 2006 - 08:52 PM

Ok,

The way I have done it was...

I found out the time difference in seconds from a set date & time (which wont change) and the current time. Then I multiplied this by 7 and added it onto the current time.

So now I have the variable \$gametime which equals the in game time which is 7 times faster than real time.

The next thing I would like to do is construct some sort of basic calendar based off this speeded up date/time.

If someone could show me how I could just view the current month in a day by day view and then I will modify and expand to allow more months to be viewed.

Thanks

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users