• Stars
    star
    266
  • Rank 148,523 (Top 4 %)
  • Language
    Ruby
  • Created about 15 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A game template for building and distributing Gosu apps.

Gamebox

Gem Version Gamebox Build Status Code Climate

  • 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.
  • http://gamebox.io/
  • see gamebox on rubygems.org for the list of requirements

Getting started with Gamebox

Purpose

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.

Installation

  • gem install gamebox
  • git clone git://github.com/shawn42/gamebox.git && cd gamebox && bundle && rake install

Game Creation

To create a new Gamebox project run:

$ 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

To run your game:

$ cd zapper
$ bundle
$ rake

Stages

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: main_menu, play, or credits. A demo_stage.rb is created for you by using the gamebox new command.

define_stage :demo do
  curtain_up do
   ...
  end
end

Actors

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

Behaviors are what bring life to actors. They 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

Views

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 requires :stage.

curtain_up do
  @player = create_actor :label, x: 20, y: 30, text: "Hello World!"
end

# or
stage.create_actor ..

Input

Input comes from the InputManager. The stage has direct access via the input_manager method. Behaviors can request that they get the input_manager via 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

Updates all come from the Director. Again, the stage has direct access via director and behaviors must requires :director.

director.when :update do |t_ms, t_sec|
  # update something
end

Sound and Music

SoundManager handles the autoloading of sounds from data/sounds and 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

Reactions

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 :play_sound event.

define_behavior :noise_alert do
  setup do
    reacts_with :play_sound
  end

  helpers do
    def play_sound(*args)
      # react here
    end
  end
end

The reacts_with helper takes a list of events that your behavior is interested in, and maps them to helper methods.

TODO

Configuration

  1. Gamebox.configuration

Resources

  1. load paths
  2. fonts
  3. graphics (caching)
  4. sounds

Stages

  1. configuring stages
  2. changing stages

Physics

Links

Frequently Asked Questions

License

The MIT License (MIT)

Copyright © 2012 Shawn Anderson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

hinas_journey

Procedural universe space exploration game (prototype).
Ruby
46
star
2

garden_pi_waterer

Autowatering of my garden via Raspberry Pi
Ruby
31
star
3

tmx

Tmx loader for loading Tiled maps into a basic data structure in Ruby.
Ruby
28
star
4

polaris

A* pathfinding in Ruby
Ruby
19
star
5

xamarin-web-sample

Sample project using Xamarin as a Cordova / Phonegap replacement.
C#
18
star
6

killbox

Multiplayer same-screen action shooter.
Ruby
15
star
7

snelps

Snelps is a RTS written in Rubygame
Ruby
14
star
8

cold-season

Cold Season is a simple arcade type game using Gamebox.
Ruby
9
star
9

netz

p2p network layer
Ruby
8
star
10

rubygoo

GUI library for working with Gosu and Rubygame
Ruby
8
star
11

pixel_monster

PixelMonster (originally for LD33)
Ruby
6
star
12

omg_aliens

Space Invaders Clone using the Gamebox framework
Ruby
6
star
13

pisces_dentata

LD18 Entry
ActionScript
5
star
14

game_ecs

ECS framework for writing games in Ruby
Ruby
4
star
15

kvo

KVO in Ruby
Ruby
4
star
16

theft

Property based testing in Ruby based on the theft C library.
Ruby
3
star
17

garden_know_ems

BLE Garden Sensor built on Nordic NRF51822
C
3
star
18

game_dev_workshop

Materials for my workshop at Scale12x; please come to the workshop with an up to date version of this repo
Ruby
3
star
19

gamebox_website

Gamebox website
CSS
2
star
20

ludum_dare_22

Ludum Dare Jam Entry
Ruby
2
star
21

joy_garden

Joy Garden: game written in Ruby with custom ECS
Ruby
2
star
22

free-radicals

Free Radicals is a Gamebox game, for RubyWeekend #3 "A tiny world"
Ruby
2
star
23

showoff-pew-pew-games-in-ruby

Presentation on writing games in ruby.
Ruby
2
star
24

seed_life

Little simulation toy for LD 26
Ruby
2
star
25

ld38

Lua
2
star
26

showoff-gamebox-workshop

Getting started with Gamebox workshop at SCaLE 12x
CSS
1
star
27

ffi-allegro

A ruby binding to the allegro graphic library.
Ruby
1
star
28

puddle

Simple Object Pooling in Ruby
Ruby
1
star
29

island_hopping

LD17 entry for the Island theme
Ruby
1
star
30

eve_path

Path Finding Eve Solar Systems in Ruby
Ruby
1
star
31

ao-rts-clients

My client repo mirror for Atomic Games
Ruby
1
star
32

chessbox

Networked chess game built with Gamebox
Ruby
1
star
33

FreeRadicals

FreeRadicals iOS
Objective-C
1
star
34

floopy_bird

flappy bird clone for scale 12x workshop
Ruby
1
star
35

shawn42.github.com

me
1
star
36

Cradiator-TeamCity-Plugin

This is a plugin for TeamCity for use with Cradiator (http://cradiator.codeplex.com/)
Java
1
star
37

key_masher

Game for toddlers to bash on keyboard using Gamebox
Ruby
1
star
38

props_rb

Ember style properties in Ruby
Ruby
1
star
39

venture_serve

Server for Venture
Ruby
1
star