gosu_extensions 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/core/game_window.rb +19 -0
- data/lib/core/layer.rb +1 -1
- data/lib/extensions/circle.rb +22 -0
- data/lib/extensions/poly.rb +24 -0
- data/lib/gosu_extensions.rb +2 -0
- data/lib/traits/imageable.rb +14 -4
- data/lib/traits/shooter.rb +2 -2
- data/lib/units/sprite.rb +0 -1
- data/lib/units/thing.rb +4 -0
- data/spec/lib/core/layer_spec.rb +3 -0
- data/spec/lib/traits/shooter_spec.rb +2 -2
- data/spec/lib/units/thing_spec.rb +11 -3
- metadata +4 -2
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.3. | 
| 1 | 
            +
            0.3.2
         | 
    
        data/lib/core/game_window.rb
    CHANGED
    
    | @@ -37,6 +37,15 @@ class GameWindow < Gosu::Window | |
| 37 37 | 
             
                            :proceed_condition,
         | 
| 38 38 | 
             
                            :collisions
         | 
| 39 39 |  | 
| 40 | 
            +
              # TODO Move to Debug Module
         | 
| 41 | 
            +
              #
         | 
| 42 | 
            +
              def draw_circle x, y, r, color
         | 
| 43 | 
            +
                0.step(360, 10) { |a1|
         | 
| 44 | 
            +
                  a2 = a1 + 10
         | 
| 45 | 
            +
                  draw_line x + Gosu.offset_x(a1, r), y + Gosu.offset_y(a1, r), color, x + Gosu.offset_x(a2, r), y + Gosu.offset_y(a2, r), color, 0
         | 
| 46 | 
            +
                }
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
              
         | 
| 40 49 | 
             
              def initialize
         | 
| 41 50 | 
             
                setup_window
         | 
| 42 51 |  | 
| @@ -127,8 +136,18 @@ class GameWindow < Gosu::Window | |
| 127 136 | 
             
                # default is no background
         | 
| 128 137 | 
             
              end
         | 
| 129 138 |  | 
| 139 | 
            +
              def debug?
         | 
| 140 | 
            +
                @debug
         | 
| 141 | 
            +
              end
         | 
| 142 | 
            +
              
         | 
| 130 143 | 
             
              class << self
         | 
| 131 144 |  | 
| 145 | 
            +
                def debug
         | 
| 146 | 
            +
                  InitializerHooks.register self do
         | 
| 147 | 
            +
                    @debug = true
         | 
| 148 | 
            +
                  end
         | 
| 149 | 
            +
                end
         | 
| 150 | 
            +
                
         | 
| 132 151 | 
             
                # Sets the Esc button to close the window.
         | 
| 133 152 | 
             
                #
         | 
| 134 153 | 
             
                def default_controls
         | 
    
        data/lib/core/layer.rb
    CHANGED
    
    
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            module CP
         | 
| 2 | 
            +
              module Shape
         | 
| 3 | 
            +
                
         | 
| 4 | 
            +
                class Circle
         | 
| 5 | 
            +
                  
         | 
| 6 | 
            +
                  attr_reader :radius, :center
         | 
| 7 | 
            +
                  
         | 
| 8 | 
            +
                  def initialize_with_radius body, radius, center
         | 
| 9 | 
            +
                    @radius, @center = radius, center
         | 
| 10 | 
            +
                    initialize_without_radius body, radius, center
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                  alias_method_chain :initialize, :radius
         | 
| 13 | 
            +
                  
         | 
| 14 | 
            +
                  
         | 
| 15 | 
            +
                  def debug window, _
         | 
| 16 | 
            +
                    window.draw_circle body.p.x, body.p.y, radius, Gosu::Color::RED
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                  
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
                
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            module CP
         | 
| 2 | 
            +
              module Shape
         | 
| 3 | 
            +
                
         | 
| 4 | 
            +
                class Poly
         | 
| 5 | 
            +
                  
         | 
| 6 | 
            +
                  attr_reader :verts, :offset
         | 
| 7 | 
            +
                  
         | 
| 8 | 
            +
                  def initialize_with_verts body, verts, offset
         | 
| 9 | 
            +
                    @verts, @offset = verts, offset
         | 
| 10 | 
            +
                    initialize_without_verts body, verts, offset
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                  alias_method_chain :initialize, :verts
         | 
| 13 | 
            +
                  
         | 
| 14 | 
            +
                  def debug window, thing
         | 
| 15 | 
            +
                    colors = [Gosu::Color::RED]*verts.size
         | 
| 16 | 
            +
                    points = verts.map{ |vert| vert = vert.rotate(body.a.radians_to_vec2); vert += body.p; [vert.x, vert.y] }.zip(colors).flatten
         | 
| 17 | 
            +
                    points << 0 << :default
         | 
| 18 | 
            +
                    window.draw_quad *points
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                  
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
                
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
    
        data/lib/gosu_extensions.rb
    CHANGED
    
    
    
        data/lib/traits/imageable.rb
    CHANGED
    
    | @@ -40,22 +40,32 @@ module Imageable extend Trait | |
| 40 40 | 
             
              def image
         | 
| 41 41 | 
             
                @image || raise(ImageMissingError.new)
         | 
| 42 42 | 
             
              end
         | 
| 43 | 
            +
              # Set this thing's image using a path.
         | 
| 44 | 
            +
              #
         | 
| 45 | 
            +
              def image_from path, *args
         | 
| 46 | 
            +
                self.image = Gosu::Image.new self.window, File.join(Resources.root, path), *args
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
              # Set this thing's image in the form of a sequenced image.
         | 
| 49 | 
            +
              #
         | 
| 50 | 
            +
              def sequenced_image_from path, width, height, frequency = 10, &block
         | 
| 51 | 
            +
                @image_sequence_started = Time.now
         | 
| 52 | 
            +
                self.image = Gosu::Image::load_tiles self.window, File.join(Resources.root, path), width, height, false
         | 
| 53 | 
            +
              end
         | 
| 43 54 |  | 
| 44 55 | 
             
              module ClassMethods
         | 
| 45 56 |  | 
| 46 57 | 
             
                def image path, *args
         | 
| 47 58 | 
             
                  InitializerHooks.register self do
         | 
| 48 | 
            -
                     | 
| 59 | 
            +
                    image_from path, *args
         | 
| 49 60 | 
             
                  end
         | 
| 50 61 | 
             
                end
         | 
| 51 62 |  | 
| 52 63 | 
             
                def sequenced_image path, width, height, frequency = 10, &block
         | 
| 53 64 | 
             
                  InitializerHooks.register self do
         | 
| 54 | 
            -
                     | 
| 55 | 
            -
                    self.image = Gosu::Image::load_tiles self.window, File.join(Resources.root, path), width, height, false
         | 
| 65 | 
            +
                    sequenced_image_from path, width, height, frequency, &block
         | 
| 56 66 | 
             
                  end
         | 
| 57 67 | 
             
                  # divider = 1000 / frequency
         | 
| 58 | 
            -
             | 
| 68 | 
            +
                  
         | 
| 59 69 | 
             
                  # Override image.
         | 
| 60 70 | 
             
                  #
         | 
| 61 71 | 
             
                  define_method :image do
         | 
    
        data/lib/traits/shooter.rb
    CHANGED
    
    | @@ -102,8 +102,8 @@ module Shooter extend Trait | |
| 102 102 | 
             
                self.shot_type.new @window
         | 
| 103 103 | 
             
              end
         | 
| 104 104 |  | 
| 105 | 
            -
              def muzzle_position
         | 
| 106 | 
            -
                instance_eval &(@muzzle_position || @muzzle_position = lambda { |*| self.position + self.rotation_vector* | 
| 105 | 
            +
              def muzzle_position distance = 10
         | 
| 106 | 
            +
                instance_eval &(@muzzle_position || @muzzle_position = lambda { |*| self.position + self.rotation_vector * distance })
         | 
| 107 107 | 
             
              end
         | 
| 108 108 | 
             
              def muzzle_velocity target = nil
         | 
| 109 109 | 
             
                instance_eval &(@muzzle_velocity || @muzzle_velocity = lambda { |*| self.rotation_vector })
         | 
    
        data/lib/units/sprite.rb
    CHANGED
    
    | @@ -144,7 +144,6 @@ class Sprite | |
| 144 144 | 
             
              # Draws its image.
         | 
| 145 145 | 
             
              #
         | 
| 146 146 | 
             
              def draw
         | 
| 147 | 
            -
                # p [self.class, self.layer, self.drawing_rotation, 0.5, 0.5, *self.current_size] unless self.position
         | 
| 148 147 | 
             
                self.image.draw_rot self.position.x, self.position.y, self.layer, self.drawing_rotation, 0.5, 0.5, *self.current_size
         | 
| 149 148 | 
             
              end
         | 
| 150 149 | 
             
              def current_size
         | 
    
        data/lib/units/thing.rb
    CHANGED
    
    
    
        data/spec/lib/core/layer_spec.rb
    CHANGED
    
    
| @@ -126,9 +126,9 @@ describe Shooter do | |
| 126 126 | 
             
              describe 'muzzle_position' do
         | 
| 127 127 | 
             
                context 'default' do
         | 
| 128 128 | 
             
                  it 'should use the default calculation' do
         | 
| 129 | 
            -
                    @shooter.stub! :position => "position + ", :rotation_vector => "rotation" | 
| 129 | 
            +
                    @shooter.stub! :position => "position + ", :rotation_vector => "rotation"
         | 
| 130 130 |  | 
| 131 | 
            -
                    @shooter.muzzle_position.should == "position +  | 
| 131 | 
            +
                    @shooter.muzzle_position.should == "position + rotationrotationrotationrotationrotationrotationrotationrotationrotationrotation"
         | 
| 132 132 | 
             
                  end
         | 
| 133 133 | 
             
                end
         | 
| 134 134 | 
             
                context 'non-default' do
         | 
| @@ -35,10 +35,18 @@ describe Thing do | |
| 35 35 | 
             
                               :drawing_rotation => :some_drawing_rotation,
         | 
| 36 36 | 
             
                               :current_size     => [:size_x, :size_y]
         | 
| 37 37 | 
             
                end
         | 
| 38 | 
            -
                 | 
| 39 | 
            -
                  @image.should_receive(:draw_rot).once.with :some_x, :some_y, :some_layer, :some_drawing_rotation, 0.5, 0.5, :size_x, :size_y
         | 
| 38 | 
            +
                context 'debug on' do
         | 
| 40 39 |  | 
| 41 | 
            -
             | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
                context 'debug off' do
         | 
| 42 | 
            +
                  before(:each) do
         | 
| 43 | 
            +
                    @window.stub! :debug? => false
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                  it "should delegate to the image" do
         | 
| 46 | 
            +
                    @image.should_receive(:draw_rot).once.with :some_x, :some_y, :some_layer, :some_drawing_rotation, 0.5, 0.5, :size_x, :size_y
         | 
| 47 | 
            +
                    
         | 
| 48 | 
            +
                    @thing.draw
         | 
| 49 | 
            +
                  end
         | 
| 42 50 | 
             
                end
         | 
| 43 51 | 
             
              end
         | 
| 44 52 |  | 
    
        metadata
    CHANGED
    
    | @@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version | |
| 5 5 | 
             
              segments: 
         | 
| 6 6 | 
             
              - 0
         | 
| 7 7 | 
             
              - 3
         | 
| 8 | 
            -
              -  | 
| 9 | 
            -
              version: 0.3. | 
| 8 | 
            +
              - 2
         | 
| 9 | 
            +
              version: 0.3.2
         | 
| 10 10 | 
             
            platform: ruby
         | 
| 11 11 | 
             
            authors: 
         | 
| 12 12 | 
             
            - Florian Hanke
         | 
| @@ -74,9 +74,11 @@ files: | |
| 74 74 | 
             
            - lib/core/vector_utilities.rb
         | 
| 75 75 | 
             
            - lib/core/wave.rb
         | 
| 76 76 | 
             
            - lib/core/waves.rb
         | 
| 77 | 
            +
            - lib/extensions/circle.rb
         | 
| 77 78 | 
             
            - lib/extensions/math.rb
         | 
| 78 79 | 
             
            - lib/extensions/module.rb
         | 
| 79 80 | 
             
            - lib/extensions/numeric.rb
         | 
| 81 | 
            +
            - lib/extensions/poly.rb
         | 
| 80 82 | 
             
            - lib/gosu_extensions.rb
         | 
| 81 83 | 
             
            - lib/traits/attachable.rb
         | 
| 82 84 | 
             
            - lib/traits/controllable.rb
         |