Class: Stage
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
#aabb_tree, #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
#backstage ⇒ Object
Returns the value of attribute backstage.
12
13
14
|
# File 'lib/gamebox/core/stage.rb', line 12
def backstage
@backstage
end
|
Returns the value of attribute opts.
12
13
14
|
# File 'lib/gamebox/core/stage.rb', line 12
def opts
@opts
end
|
Class Method Details
.define(stage_name, opts = {}, &blk) ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/gamebox/core/stage.rb', line 101
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
|
.definitions ⇒ Object
111
112
113
|
# File 'lib/gamebox/core/stage.rb', line 111
def definitions
@definitions ||= {}
end
|
Instance Method Details
14
15
16
17
18
19
20
|
# File 'lib/gamebox/core/stage.rb', line 14
def configure(backstage, opts)
viewport.reset
@backstage = backstage
@opts = opts
renderer.clear_drawables
end
|
#create_actor(type, args = {}) ⇒ Object
Also known as:
spawn
22
23
24
|
# File 'lib/gamebox/core/stage.rb', line 22
def create_actor(type, args={})
actor_factory.build type, args
end
|
#curtain_down(*args) ⇒ Object
41
42
|
# File 'lib/gamebox/core/stage.rb', line 41
def curtain_down(*args)
end
|
#curtain_up(*args) ⇒ Object
38
39
|
# File 'lib/gamebox/core/stage.rb', line 38
def curtain_up(*args)
end
|
#draw(target) ⇒ Object
27
28
29
|
# File 'lib/gamebox/core/stage.rb', line 27
def draw(target)
renderer.draw target
end
|
#modal_actor(*args) ⇒ Object
pauses the current stage, creates an actor using args, unpauses on actor death
Example:
modal_actor :dialog, x: 40, y: 50, message: "WOW"
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/gamebox/core/stage.rb', line 84
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
|
#on_pause(&block) ⇒ Object
44
45
46
47
|
# File 'lib/gamebox/core/stage.rb', line 44
def on_pause(&block)
@pause_listeners ||= []
@pause_listeners << block if block_given?
end
|
#on_unpause(&block) ⇒ Object
49
50
51
52
|
# File 'lib/gamebox/core/stage.rb', line 49
def on_unpause(&block)
@unpause_listeners ||= []
@unpause_listeners << block if block_given?
end
|
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/gamebox/core/stage.rb', line 58
def pause
@pause_listeners ||= []
@paused = true
director.pause
timer_manager.pause
input_manager.pause
@pause_listeners.each do |listener|
listener.call
end
end
|
#paused? ⇒ Boolean
54
55
56
|
# File 'lib/gamebox/core/stage.rb', line 54
def paused?
@pause
end
|
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/gamebox/core/stage.rb', line 69
def unpause
@unpause_listeners ||= []
director.unpause
input_manager.unpause
timer_manager.unpause
@unpause_listeners.each do |listener|
listener.call
end
@paused = true
end
|
#update(time) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/gamebox/core/stage.rb', line 31
def update(time)
director.update time
viewport.update time
find_collisions
timer_manager.update time
end
|