Jump to content

Calculate Time


Pythondesigns

Recommended Posts

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
Link to comment
Share on other sites

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:
[code]
<?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}.";
?>
[/code]

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.