Sha256: 681410157f56e21db32c395510bbd1debe1ff6e3c94f2986b51b34f26aee964f
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
# A thing is destroyed if a number of lives has been passed. # module Lives extend Trait # 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 target_class.send :include, InstanceMethods end module IncludeMethods # Define the amount of lives in the class. # def lives amount InitializerHooks.register self do self.lives = amount end attr_reader :lives # override the default end end module InstanceMethods attr_writer :lives def lives 3 end # Override to handle killed! # def killed! end # Does three things: # * Deduct 1 live. # * Check to see if the amount is 0. # * Calls #destroy! if yes. # def kill! self.lives -= 1 killed! if self.lives > 0 destroy! if self.lives == 0 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gosu_extensions-0.2.6 | lib/traits/lives.rb |