Class: StageManager

Inherits:
Object show all
Defined in:
lib/gamebox/core/stage_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStageManager

Returns a new instance of StageManager.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gamebox/core/stage_manager.rb', line 8

def initialize
  @stages = {}

  stages = Gamebox.configuration.stages

  @stage_names = []
  @stage_opts = []
  stages.each do |stage|
    if stage.is_a? Hash
      stage_name = stage.keys.first
      opts = stage.values.first
      @stage_names << stage_name
      opts ||= {}
      @stage_opts << opts
    else
      @stage_names << stage
      @stage_opts << {}
    end
  end
end

Instance Attribute Details

#stage_namesObject (readonly)

Returns the value of attribute stage_names.



6
7
8
# File 'lib/gamebox/core/stage_manager.rb', line 6

def stage_names
  @stage_names
end

#stage_optsObject (readonly)

Returns the value of attribute stage_opts.



6
7
8
# File 'lib/gamebox/core/stage_manager.rb', line 6

def stage_opts
  @stage_opts
end

Instance Method Details

#current_stageObject



63
64
65
# File 'lib/gamebox/core/stage_manager.rb', line 63

def current_stage
  @stages[@stage]
end

#default_stageObject



29
30
31
# File 'lib/gamebox/core/stage_manager.rb', line 29

def default_stage
  @stage_names.first
end

#draw(target) ⇒ Object



71
72
73
# File 'lib/gamebox/core/stage_manager.rb', line 71

def draw(target)
  @stages[@stage].draw target unless @stages[@stage].nil?
end

#next_stage(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/gamebox/core/stage_manager.rb', line 33

def next_stage(*args)
  index = @stage_names.index @stage
  if index == @stage_names.size-1
    log "last stage, exiting"
    exit
  end

  switch_to_stage @stage_names[index+1], *args
end

#prev_stage(*args) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/gamebox/core/stage_manager.rb', line 43

def prev_stage(*args)
  index = @stage_names.index @stage
  if index == 0
    log "first stage, exiting"
    exit
  end

  switch_to_stage @stage_names[index-1], *args
end

#restart_stage(*args) ⇒ Object



53
54
55
# File 'lib/gamebox/core/stage_manager.rb', line 53

def restart_stage(*args)
  switch_to_stage @stage, *args
end

#switch_to_stage(stage_name, *args) ⇒ Object Also known as: change_stage_to



57
58
59
60
# File 'lib/gamebox/core/stage_manager.rb', line 57

def switch_to_stage(stage_name, *args)
  shutdown_current_stage *args
  activate_new_stage stage_name, *args
end

#update(time) ⇒ Object



67
68
69
# File 'lib/gamebox/core/stage_manager.rb', line 67

def update(time)
  @stages[@stage].update time unless @stages[@stage].nil?
end