Module: GameboxDSL

Included in:
Gamebox
Defined in:
lib/gamebox/core/gamebox_dsl.rb

Instance Method Summary collapse

Instance Method Details

#define_actor(name, &blk) ⇒ Object

Defines an actor type, (ie :plumber). Optionally adding attributes, behaviors and a view.

Raises an erorr if the actor already exists

define_actor :plumber do

define default attributes and values

has_attribute(s) x: 7, y: 12

# define default behaviors and their options options can be
#   - list of behavior names
#   - hash of behavior names to options for each behavior
#   - block form
has_behavior :postitioned
has_behaviors do
 jumper max: 12, double: true
end

# Allows the inlining of one behavior in this actor.
# It is equivalent to creating a behavior with the same name as the actor,
# and adding it to the actor.
#
# The block works the same as calling #define_behavior.
behavior
 
# Allows the inline of a view in this actor
# It is equivalent to creating an actor view with the same name as the actor.
# 
# The block works the same as calling #define_actor_view.
view

end



101
102
103
# File 'lib/gamebox/core/gamebox_dsl.rb', line 101

def define_actor(name, &blk)
  Actor.define name, &blk
end

#define_actor_view(name, &blk) ⇒ Object

Defines an actor view type. (ie :plumber_view). Constructed when any actor with matching name is created ie: :ship_view will be created and shown for any actor :ship that is created

Raises an erorr if the actor view already exists

define_actor :plumber_view do

injects your dependencies; will construct if needed

requires :input_manager, :customer_monkey_factory

# callback when your view is created
# #actor will be available at this time
setup &block

# define any helper methods and include any needed modules
helpers &block

end



126
127
128
# File 'lib/gamebox/core/gamebox_dsl.rb', line 126

def define_actor_view(name, &blk)
  ActorView.define name, &blk
end

#define_behavior(name, &blk) ⇒ Object

Defines a behavior type. (ie :jumper or :shooter)

Raises an erorr if the behavior already exists

define_behavior :jumper do

injects your dependencies; will construct if needed

requires :input_manager, :timer_manager, :stage

# adds the required behaviors to your actor if not present
# NOTE: no options can be passed to the added behavior
required_behaviors :positioned

# callback when your behavior has been added to an actor
# #opts will be populated with any args that were specified on behavior
# addition 
setup &block

# callback when your behavior has been removed from an actor
remove &block

# define a custom handler for reacting to your actor's messages
# @see Behavior#reacts_with for recommended message dispatch
react_to &block

# define any helper methods and include any needed modules
helpers &block

end



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

def define_behavior(name, &blk)
  Behavior.define name, &blk
end

#define_stage(name, &blk) ⇒ Object

Defines a stage; a stage is a game mode. (ie :main_menu, :play, or :credits)

Raises an erorr if the stage already exists

define_stage :main_menu do

injects your dependencies; will construct if needed

requires :input_manager, :customer_monkey_factory

# callback for stage setup
curtain_up &block

# callback for stage teardown
curtain_down &block

# redefine the renderer for this stage, Gamebox has a default Renderer
# if unspecified 
render_with :my_custom_renderer

# define any helper methods and include any needed modules
helpers &block

end



28
29
30
# File 'lib/gamebox/core/gamebox_dsl.rb', line 28

def define_stage(name, &blk)
  Stage.define name, &blk
end