Class: ShatteredPack::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/shattered_pack/base.rb

Direct Known Subclasses

ShatteredModel::Base, ShatteredState::Base

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#time_elapsedObject Also known as: per_second

Returns the value of attribute time_elapsed.



12
13
14
# File 'lib/shattered_pack/base.rb', line 12

def time_elapsed
  @time_elapsed
end

Class Method Details

.new(options = {}) ⇒ Object

This is overwritten to allow for a pre_initialize before initialize



16
17
18
19
20
21
# File 'lib/shattered_pack/base.rb', line 16

def self.new(options={}) #:nodoc
  new_base = allocate
  new_base.pre_initialize(options)
  new_base.send(:initialize)
  return new_base
end

Instance Method Details

#attr_accessor(*args) ⇒ Object

attr helpers. These are instance level attr_* functions.

attr_accessor accepts a value as the second argument



79
80
81
82
# File 'lib/shattered_pack/base.rb', line 79

def attr_accessor(*args)
  name, value = args
  attr_define(:accessor, name, value)
end

#attr_reader(*args) ⇒ Object

attr helpers. These are instance level attr_* functions.



65
66
67
68
# File 'lib/shattered_pack/base.rb', line 65

def attr_reader(*args)
  name, value = args
  attr_define(:reader, name, value)
end

#attr_writer(*args) ⇒ Object

attr helpers. These are instance level attr_* functions.

attr_writer accepts a value as the second argument



72
73
74
75
# File 'lib/shattered_pack/base.rb', line 72

def attr_writer(*args)
  name, value = args
  attr_define(:writer, name, value)
end

#remove_dead_actorsObject

TODO outdated?



49
50
51
52
53
# File 'lib/shattered_pack/base.rb', line 49

def remove_dead_actors #:nodoc:
  actors.each do |actor|
    remove_from_scene actor if actor.remove_from_scene?
  end
end

#remove_from_scene(actor) ⇒ Object

TODO outdated?



56
57
58
59
# File 'lib/shattered_pack/base.rb', line 56

def remove_from_scene(actor)
  actors.delete actor
  actor.unload!
end

#remove_from_scene?Boolean

remove_from_scene? should just be defined in model. Refactor? TODO

Returns:

  • (Boolean)


38
39
40
# File 'lib/shattered_pack/base.rb', line 38

def remove_from_scene? #:nodoc:
  return false
end

#stateObject

Retrieve the current state



24
25
26
# File 'lib/shattered_pack/base.rb', line 24

def state 
  Shatter::GameLoader.instance.current_state
end

#update_actors(time_elapsed) ⇒ Object

TODO outdated?



43
44
45
46
# File 'lib/shattered_pack/base.rb', line 43

def update_actors(time_elapsed) #:nodoc:
  update_event time_elapsed
  remove_dead_actors
end

#update_event(time_elapsed) ⇒ Object

TODO - is this called anymore?



29
30
31
32
33
34
# File 'lib/shattered_pack/base.rb', line 29

def update_event(time_elapsed) #:nodoc:
  actors.each do |actor|
    actor.update_actors(time_elapsed)
    actor.update(time_elapsed)
  end
end

#when_unloaded(&block) ⇒ Object

Define a block to execute when an object is unloaded.



85
86
87
88
# File 'lib/shattered_pack/base.rb', line 85

def when_unloaded(&block)
  @unloaded_events ||= []
  @unloaded_events << block
end