Class: Stage

Inherits:
Object show all
Extended by:
Publisher
Includes:
Arbiter
Defined in:
lib/gamebox/core/stage.rb

Overview

Stage is a state that the game is in. (ie intro stage, multiplayer stage, single player stage).

Instance Attribute Summary (collapse)

Attributes included from Arbiter

#checks, #collisions

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Arbiter

#circle_interval, #collide?, #collide_circle_circle?, #collide_circle_polygon?, #collide_polygon_circle?, #collide_polygon_polygon?, #find_collisions, #interested_in_collision_of?, #on_collision_of, #polygon_interval, #project_and_detect, #register_collidable, #run_callbacks, #unregister_collidable

Instance Attribute Details

- (Object) backstage

Returns the value of attribute backstage



12
13
14
# File 'lib/gamebox/core/stage.rb', line 12

def backstage
  @backstage
end

- (Object) opts

Returns the value of attribute opts



12
13
14
# File 'lib/gamebox/core/stage.rb', line 12

def opts
  @opts
end

Class Method Details

+ (Object) define(stage_name, opts = {}, &blk)



140
141
142
143
144
145
146
147
148
# File 'lib/gamebox/core/stage.rb', line 140

def define(stage_name, opts={}, &blk)
  @definitions ||= {}
  raise "Stage [#{stage_name}] already defined at #{@definitions[stage_name].source}" if @definitions[stage_name]

  definition = StageDefinition.new
  definition.source = caller.detect{|c|!c.match /core/}
  definition.instance_eval &blk if block_given?
  @definitions[stage_name] = definition
end

+ (Object) definitions



150
151
152
# File 'lib/gamebox/core/stage.rb', line 150

def definitions
  @definitions ||= {}
end

Instance Method Details

- (Object) configure(backstage, opts)



14
15
16
17
18
19
20
21
# File 'lib/gamebox/core/stage.rb', line 14

def configure(backstage, opts)
  viewport.reset

  @stagehands = {}
  @backstage = backstage
  @opts = opts
  renderer.clear_drawables
end

- (Object) create_actor(type, args = {}) Also known as: spawn



23
24
25
# File 'lib/gamebox/core/stage.rb', line 23

def create_actor(type, args={})
  actor_factory.build type, args
end

- (Object) create_actors_from_svg(svg_doc)

extract all the params from a node that are needed to construct an actor



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gamebox/core/stage.rb', line 29

def create_actors_from_svg svg_doc
  float_keys = ["x","y"]
  dynamic_actors ||= {}
  layer = svg_doc.find_group_by_label("actors")

  unless layer.nil?
    # each image in the layer is an actor
    layer.images.each do |actor_def|
      klass = actor_def.game_class.to_sym
      handle = actor_def.game_handle
      new_opts = {}
      actor_def.node.attributes.each do |k,v|
        v = v.to_f if float_keys.include? k
        new_opts[k.to_sym] = v
      end

      actor = create_actor klass, new_opts
      dynamic_actors[handle.to_sym] = actor if handle
    end
  end
  alias :spawn_from_svg :create_actors_from_svg

  dynamic_actors
end

- (Object) curtain_down(*args)



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

def curtain_down(*args)
end

- (Object) curtain_up(*args)



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

def curtain_up(*args)
end

- (Object) draw(target)



54
55
56
# File 'lib/gamebox/core/stage.rb', line 54

def draw(target)
  renderer.draw target
end

pauses the current stage, creates an actor using args, unpauses on actor death

Example:

modal_actor :dialog, x: 40, y: 50, message: "WOW"


118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/gamebox/core/stage.rb', line 118

def modal_actor(*args)
  on_pause do
    pause_actor = create_actor *args
    pause_actor.when :remove_me do
      @pause_listeners = nil
      unpause
      yield if block_given?
    end
  end
  pause

end

- (Object) on_pause(&block)



74
75
76
77
# File 'lib/gamebox/core/stage.rb', line 74

def on_pause(&block)
  @pause_listeners ||= []
  @pause_listeners << block if block_given?
end

- (Object) on_unpause(&block)



79
80
81
82
# File 'lib/gamebox/core/stage.rb', line 79

def on_unpause(&block)
  @unpause_listeners ||= []
  @unpause_listeners << block if block_given?
end

- (Object) pause



88
89
90
91
92
93
94
95
96
97
# File 'lib/gamebox/core/stage.rb', line 88

def pause
  @pause_listeners ||= []
  @paused = true
  director.pause
  timer_manager.pause
  input_manager.pause
  @pause_listeners.each do |listener|
    listener.call
  end
end

- (Boolean) paused?

Returns:

  • (Boolean)


84
85
86
# File 'lib/gamebox/core/stage.rb', line 84

def paused?
  @pause
end

- (Object) stagehand(stagehand_sym, opts = {})



110
111
112
# File 'lib/gamebox/core/stage.rb', line 110

def stagehand(stagehand_sym, opts={})
  @stagehands[stagehand_sym] ||= create_stagehand(stagehand_sym, opts)
end

- (Object) unpause



99
100
101
102
103
104
105
106
107
108
# File 'lib/gamebox/core/stage.rb', line 99

def unpause
  @unpause_listeners ||= []
  director.unpause
  input_manager.unpause
  timer_manager.unpause
  @unpause_listeners.each do |listener|
    listener.call
  end
  @paused = true
end

- (Object) update(time)



58
59
60
61
62
63
64
65
66
# File 'lib/gamebox/core/stage.rb', line 58

def update(time)
  director.update time
  viewport.update time
  @stagehands.each do |name, stagehand|
    stagehand.update time 
  end
  find_collisions
  timer_manager.update time
end