Class: Core::Game::CompositeGoal

Inherits:
Array show all
Defined in:
lib/game/npc/goal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#to_color, #x, #y

Constructor Details

#initialize(policy = :abort) ⇒ CompositeGoal

Returns a new instance of CompositeGoal.



39
40
41
42
43
44
# File 'lib/game/npc/goal.rb', line 39

def initialize(policy=:abort)
  super()
  @current = 0
  @policy = policy
  @state = :progress
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



38
39
40
# File 'lib/game/npc/goal.rb', line 38

def state
  @state
end

Instance Method Details

#advanceObject



73
74
75
76
77
78
79
# File 'lib/game/npc/goal.rb', line 73

def advance
  @current += 1
  if @current == self.size
    @state = :finished
    @current = 0
  end
end

#currentObject



53
54
55
# File 'lib/game/npc/goal.rb', line 53

def current
  return self[@current]
end

#resetObject



45
46
47
48
49
# File 'lib/game/npc/goal.rb', line 45

def reset
  self.clear
  @current = 0
  @state = :reset
end

#startObject



50
51
52
# File 'lib/game/npc/goal.rb', line 50

def start
  @state = :progress
end

#updateObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/game/npc/goal.rb', line 56

def update
  if @state == :progress
    awesome_print(self) if !current
    case current.state
    when :before
      if current.class != MotionGoal
        current.setup
      end
    when :progress
      return
    when :failed
      handle_failed
    when :finished
      advance
    end
  end
end