Sha256: 1ee1070ab80cb2f7af2eb4147c55f3f58d2609cb43a4a4393d6146601fd48c50

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

# A thing is destroyed if a number of lives has been passed.
#
module Lives
  
  # TODO def revive!
  #
  
  # Prints an amount of information on these capabilities.
  #
  manual <<-MANUAL
    Defines:
      lives <some trait>
    
    Example:
      lives 10
    
    Call kill! to remove a live. Override killed! to exhibit behaviour.
  MANUAL
  
  def self.included target_class
    target_class.extend IncludeMethods
  end
  
  module IncludeMethods
    
    # Define the amount of lives in the class.
    #
    def lives amount
      include InstanceMethods
      class_inheritable_accessor :prototype_lives
      self.prototype_lives = amount
      
      hook = lambda { self.lives = self.class.prototype_lives }
      InitializerHooks.register self, &hook
    end
    
  end
  
  module InstanceMethods
    
    attr_accessor :lives
    
    # Does three things:
    # * Deduct 1 live.
    # * Check to see if the amount is 0.
    # * Calls #destroy! if yes.
    #
    def killed!
      
    end
    def kill!
      self.lives -= 1
      killed!
      destroy! if self.lives == 0
    end
    
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gosu_extensions-0.1.5 lib/traits/lives.rb
gosu_extensions-0.1.4 lib/traits/lives.rb
gosu_extensions-0.1.3 lib/traits/lives.rb
gosu_extensions-0.1.2 lib/traits/lives.rb
gosu_extensions-0.1.1 lib/traits/lives.rb
gosu_extensions-0.1.0 lib/traits/lives.rb