lib/traits/shooter.rb in gosu_extensions-0.2.7 vs lib/traits/shooter.rb in gosu_extensions-0.2.8

- old
+ new

@@ -1,7 +1,34 @@ module Shooter extend Trait + module Position + def self.front x, y = nil + # y || (y, x = x, 0) + y ||= 0 + relative x, y + end + def self.relative x, y + relative_position = CP::Vec2.new x, y + relative_length = relative_position.length + relative_rotation = relative_position.to_angle + lambda { self.position + (self.rotation - relative_rotation).radians_to_vec2*relative_length } + end + end + module Velocity + def self.front initial_speed + lambda { |_| self.rotation_vector*initial_speed } + end + end + module Rotation + def self.custom rotation; lambda { |_| rotation } end + Frontal = lambda { |_| self.rotation } + Right = lambda { |_| self.rotation + Rotation::Half } + Backwards = lambda { |_| -self.rotation } + Left = lambda { |_| self.rotation - Rotation::Half } + Default = Frontal + end + Shoot = :shoot manual <<-MANUAL Defines: range <some range> # This is only needed for targeted shooting, e.g. automatic cannons @@ -49,20 +76,23 @@ def shoots type InitializerHooks.register self do self.shot_type = type end end - def muzzle_position &block + def muzzle_position lam = nil, &block + block ||= lam InitializerHooks.register self do muzzle_position_func &block end end - def muzzle_velocity &block + def muzzle_velocity lam = nil, &block + block ||= lam InitializerHooks.register self do muzzle_velocity_func &block end end - def muzzle_rotation &block + def muzzle_rotation lam = nil, &block + block ||= lam InitializerHooks.register self do muzzle_rotation_func &block end end end \ No newline at end of file