- A game template for building and distributing Gosu games.
- Quickly generate a game and have it up and running.
- Provide conventions and DSL for building your game.
- Facilitate quickly building distributable artifacts.
- see gamebox on rubygems.org for the list of requirements
Getting started with Gamebox
Why use Gamebox? Gamebox was designed to spring board game development. It allows the developer to define business rules about a game very quickly without having to worry about resource loading, sound/music management, creating windows, or messing with viewports. Gamebox allows you to define a game's business rules within minutes, using the metaphor of a 5th grade play.
The driving idea behind Gamebox is to provide the ability to have as many of the basic common pieces of a 2D game at the developers disposal from the beginning.
The reason I wrote Gamebox is twofold: first, to aid in 48 hour game writing competitions and second, to allow me to write simple educational games for my kids.
- gem install gamebox
- or tar
git clone git://github.com/shawn42/gamebox.git && bundle && rake install
- gamebox new zapper
this will create the directory structure and needed files to get a basic actor up on the screen:
zapper ├── Gemfile ├── README.rdoc ├── Rakefile ├── config │ ├── boot.rb │ ├── environment.rb │ └── game.yml ├── data │ ├── fonts │ ├── graphics │ ├── music │ └── sounds ├── spec │ └── helper.rb └── src ├── actors │ └── player.rb ├── app.rb └── demo_stage.rb
you now have a runnable Gamebox game
cd zapper bundle rake
A stage is where all the magic happens. Each new play type in your game will use a different stage. An example game may have a number of stages such as:
demo_stage.rb is created for you by using the
gamebox new command.
define_stage :demo do curtain_up do ... end end
Actors are the basic building blocks of games in Gamebox. Everything in the game is an actor: the player, an alien, the bullet, even the score on the screen. Internally, actors are just named collections of behaviors and observable attributes.
define_actor :player do has_behaviors do shooter recharge_time: 4_000, shot_power: 15, kickback: 0.7 shielded bomber kickback: 5 die_by_sword die_by_bullet die_by_bomb blasted_by_bomb jumper end end
Behaviors are what bring life to actors. They interact interact with the actor's internal data, input, audio, etc.
define_behavior :projectile do requires :director requires_behaviors :positioned setup do actor.has_attributes vel_x: 0, vel_y: 0 director.when :update do |delta_ms, delta_secs| actor.x += (actor.vel_x * delta_secs) actor.y += (actor.vel_y * delta_secs) end end end
Actor views are the mechanism for drawing an actor in Gamebox. When an actor is created, Gamebox will see if there is a matching actor view by name. It will register the view to be drawn by the renderer. The draw callback is called with the rendering target, the x and y offsets based on the viewport, and the z layer to be used for drawing this actor (see the section on parallax layers for more on z layers).
define_actor_view :label_view do draw do |target, x_off, y_off, z| target.print actor.text, actor.x, actor.y, z, actor.font_style end end
Getting actors on stage
To get an actor on the stage, use the
create_actor method on stage. This can be done directly from a stage or from a behavior that has required stage via
curtain_up do @player = create_actor :label, x: 20, y: 30, text: "Hello World!" end # or stage.create_actor ..
Input comes from the InputManager. The stage has direct access via the
input_manager method. Behaviors can request that they get the
requires :input_manager. The preferred way of getting input to your actors is via the actor's
input method. It returns an InputMapper that can be built with a hash of events. Behaviors then subscribe for those events from the actor's input, or ask for it during updates.
actor.input.map_input '+space' => :shoot, '+w' => :jump, '+a' => :walk_left '+s' => :duck '+d' => :walk_right actor.input.when :shoot do # shoot code end # or if actor.input.walk_left? # walk left end
Updates all come from the Director. Again, the stage has direct access via
director and behaviors must
director.when :update do |t_ms, t_sec| # update something end
Sound and Music
SoundManager handles the autoloading of sounds from
data/music. The stage has direct access via
sound_manager. To allow an actor to emit sounds or music, give them the
audible behavior. See Reactions below for usage from actors.
# music sound_manager.play_music :overworld # sounds sound_manager.play_sound :death
To ask to react to something we use the
react_to method. It sends your message to all of the actors behaviors, giving them a chance to (you guessed it), react.
actor.react_to :play_sound, :jump
If the actor has an audible behavior listening, he'll play the jump sound. But what if something else wants to know about playing sounds. Maybe the actor triggers an effect by making sound. If the actor had a
noise_alert behavior, it too would be notified of the
define_behavior :noise_alert do setup do reacts_with :play_sound end helpers do def play_sound(*args) # react here end end end
reacts_with helper takes a list of events that your behavior is interested in, and maps them to helper methods.
- load paths
- graphics (caching)
- configuring stages
- changing stages
Copyright © 2012 Shawn Anderson