Class: Chronus::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/chronus/timer.rb

Instance Method Summary collapse

Constructor Details

#initializeTimer

Returns a new instance of Timer.



6
7
8
9
10
11
# File 'lib/chronus/timer.rb', line 6

def initialize
  @start_ticks = 0
  @paused_ticks = 0
  @paused = false
  @started = false
end

Instance Method Details

#pauseObject

Pause counter timer



27
28
29
30
31
32
# File 'lib/chronus/timer.rb', line 27

def pause
  if @started == true && @paused == false
    @paused = true
    @paused_ticks = SDL.get_ticks - @start_ticks
  end
end

#paused?Boolean

Return true if paused == true

Returns:

  • (Boolean)


62
63
64
# File 'lib/chronus/timer.rb', line 62

def paused?
  @paused
end

#resumeObject

Resume counter timer



35
36
37
38
39
40
41
# File 'lib/chronus/timer.rb', line 35

def resume
  if @paused == true
    @paused = false
    @start_ticks = SDL.get_ticks - @paused_ticks
    @paused_ticks = 0
  end
end

#startObject

Start counter timer



14
15
16
17
18
# File 'lib/chronus/timer.rb', line 14

def start
  @started = true
  @paused = false
  @start_ticks = SDL.get_ticks
end

#started?Boolean

Return true if started == true

Returns:

  • (Boolean)


57
58
59
# File 'lib/chronus/timer.rb', line 57

def started?
  @started
end

#stopObject

Stop counter timer



21
22
23
24
# File 'lib/chronus/timer.rb', line 21

def stop
  @started = false
  @paused = false
end

#ticksObject

Return current tick



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chronus/timer.rb', line 44

def ticks
  t = 0
  if @started == true
    if @paused == true
      t = @paused_ticks
    else
      t = SDL.get_ticks - @start_ticks
    end
  end
  t
end