lib/units/thing.rb in gosu_extensions-0.1.28 vs lib/units/thing.rb in gosu_extensions-0.2.0

- old
+ new

@@ -29,32 +29,48 @@ end def layer @layer || Layer::Players end + def mass + 0.1 + end + def moment + 0.1 + end + class << self - @@form_shape_class_mapping = { :circle => CP::Shape::Circle } - def shape form + @@form_shape_class_mapping = { + :circle => CP::Shape::Circle, # :circle, radius + :poly => CP::Shape::Poly, # :poly, CP::Vec2.new(-22, -18), CP::Vec2.new(-22, -10), etc. + :segment => CP::Shape::Segment # :segment, ... + # TODO :image => # Special, just traces the extent of the image. + } + def shape form, *args form_shape_class_mapping = @@form_shape_class_mapping + define_method :radius do + args.first # TODO fix! + end InitializerHooks.append self do shape_class = form_shape_class_mapping[form] raise "Shape #{form} does not exist." unless shape_class - @shape = shape_class.new(CP::Body.new(self.mass, self.moment), self.radius, CP::Vec2.new(0.0, 0.0)) + + params = [] + params << CP::Body.new(self.mass, self.moment) + params += args + params << CP::Vec2.new(0.0, 0.0) + + @shape = shape_class.new *params end end def mass amount define_method :mass do - amount || 1.0 + amount end end def moment amount define_method :moment do - amount || 1.0 - end - end - def radius amount - define_method :radius do - amount || 10.0 + amount end end def collision_type type to_execute = lambda do |shape| \ No newline at end of file