Sha256: 440376df768a7d1b92d64967f840be9c57539c9adce998e5ae108616545a2b9f

Contents?: true

Size: 587 Bytes

Versions: 4

Compression:

Stored size: 587 Bytes

Contents

define_behavior :score_keeper do
  requires :stage

  setup do
    # TODO helper for "attached subactor"
    label = stage.create_actor(:label, actor.attributes)
    actor.has_attributes label: label, score: 0
    actor.when :position_changed do
      actor.label.x = actor.x
      actor.label.y = actor.y
    end
    actor.when(:remove_me) { label.remove }
    actor.when(:score_changed) { update_text }
    update_text
  end

  helpers do
    def update_text
      actor.label.text = actor.score
    end
  end
end

define_actor :score do
  has_behavior :score_keeper, layered: 999
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gamebox-0.5.5 lib/gamebox/actors/score.rb
gamebox-0.5.4 lib/gamebox/actors/score.rb
gamebox-0.5.2 lib/gamebox/actors/score.rb
gamebox-0.5.1 lib/gamebox/actors/score.rb