struct Prism::Clock

Overview

Represents a scalable game clock. With the Clock you can use the concept of 24 hour time in your game in a natural way.

The Clock has a dual purpose. It can represent a point of time or a length of time. This is because all it does is produce a single float value.

Therefore 1:30 could mean one thirty am or one hour and 30 minutes. It all depends on your context.

Defined in:

prism/clock.cr

Constant Summary

REAL_DAY_LENGTH = ((24 * 60) * 60).to_f64

The length of a regular day in seconds

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(hour : Int32 = 0, minute : Int32 = 0, second : Int32 = 0, day_length : Float64 = @@day_length) #

Creates a new Clock instance that corresponds to the given time.

By default the Clock will use a standard day length. Meaning, the clock will use a 24 hour day. You can scale the day down to a smaller time frame by a number of seconds to day_length.

Example

Here we set the day length to 10 seconds. So noon would occur at 5 seconds.

clock = Clock.new(hour: 12, day_length: 10)
clock.real_seconds # => 5

[View source]

Class Method Detail

def self.day_length #

[View source]
def self.day_length=(day_length : Float64) #

[View source]
def self.now(day_length : Float64 = @@day_length) #

Creates a new Clock instance that corresponds to the current game time.


[View source]
def self.set_time(clock : Prism::Clock) #

Changes the current time.


[View source]

Instance Method Detail

def real_seconds : Float64 #

[View source]