Sha256: 6711fde963678386f439c4536dc5ce344713816a02f5a71b2c0f37a664ef6109
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
# When hitpoints are at zero or lower, it calls kill! if available, destroy! else. # module Hitpoints extend Trait # TODO def revive! # # Prints an amount of information on these capabilities. # manual <<-MANUAL Defines: hitpoints <some trait> Example: hitpoints 10_000 Call hit(damage = 1) to remove hitpoints. This will call * hit! if hitpoints are still higher than 0. * kill!, and if not available, destroy! if hitpoints are lower than 0. MANUAL def self.included target_class target_class.extend ClassMethods end module ClassMethods # Define the amount of hitpoints of the thing. # def hitpoints amount include InstanceMethods class_inheritable_accessor :prototype_hitpoints self.prototype_hitpoints = amount hook = lambda { self.hitpoints = self.class.prototype_hitpoints } InitializerHooks.register self, &hook end end module InstanceMethods attr_accessor :hitpoints # Override to handle hit! # def hit! end # Hit the thing with that much damage. # # hit!-s if hitpoints higher than 0 # kill!-s if lower, or destroy!-s if kill! # is not available. # def hit damage = 1 self.hitpoints -= damage hit! if hitpoints > 0 respond_to?(:kill!) ? kill! : destroy! if hitpoints == 0 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gosu_extensions-0.2.6 | lib/traits/hitpoints.rb |