Class: Slickr::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/slickr/entity.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEntity

Returns a new instance of Entity.



42
43
44
# File 'lib/slickr/entity.rb', line 42

def initialize
  behaviors.each { |behavior, options| behave_like(behavior, options) }
end

Class Attribute Details

.behaviorsObject



34
35
36
# File 'lib/slickr/entity.rb', line 34

def self.behaviors
  @behaviors ||= []
end

Class Method Details

.resetObject



38
39
40
# File 'lib/slickr/entity.rb', line 38

def self.reset
  @behaviors = []
end

.use(behavior, options = {}) ⇒ Object

Specify that an Entity should behave a certain way.

Different Behaviors will allow you to specify different default values. For example, a Spatiality behavior that allows an Entity to move about the world, may take a default x and y value. The Entity will be placed at that location when the scene is first loaded.

Examples:

A Hero can move about the world.


class Hero < Slickr::Entity
  use Spatiality
end

A Hero starting at a specific location.


class Hero < Slickr::Entity
  use Spatiality, x: 100, y: 100
end

Parameters:

  • behavior (Slickr::Behavior)

    The behavior to use.

  • options (Hash) (defaults to: {})

    Default behavior values.



30
31
32
# File 'lib/slickr/entity.rb', line 30

def self.use(behavior, options={})
  behaviors << [behavior, options]
end

Instance Method Details

#behaviorsObject



46
47
48
# File 'lib/slickr/entity.rb', line 46

def behaviors
  self.class.behaviors
end