Gamefic

Adventure Games and Interactive Fiction

Building Your Game World

Authors use seeds to populate their game worlds with entities.

The make method

Seed blocks provide a make method for creating entities from a class and a list of attributes.

Mygame::Plot.seed do
  @room = make Room, name: 'living room'

  make Item, name: 'plate', parent: @room
  make Fixture, name: 'mirror', parent: @room
  make Supporter, name: 'table', parent: @room
end

Note that we can use the parent attribute to put entities inside of other entities.

Instance Variables

Assigning an entity to an instance variable is the easiest way to make it accessible to other code.

Mygame::Plot.seed do
  @room = make Room, name: 'living room'
end

Mygame::Plot.script do
  introduction do |actor|
    actor.parent = @room
    actor.tell "You're in your living room."
  end
end

You can also define plain old Ruby instance methods instead of using seeds.

class Mygame::Plot < Gamefic::Plot
  include Gamefic::Standard

  def office
    @office ||= make Room, name: 'office'
  end

  def intro_text
    @intro_text ||= 'Hello, world!'
  end

  script do
    introduction do |actor|
      actor.parent = office
      actor.tell intro_text
    end
  end
end

Next: More about scripts