gosu_extensions 0.1.24 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.24
1
+ 0.1.25
data/lib/core/wave.rb CHANGED
@@ -4,11 +4,23 @@ class Wave
4
4
 
5
5
  attr_reader :generated_type, :execution_amount, :positioning_function
6
6
 
7
- UniformRandom = lambda { |window, instance| instance.warp_to *window.uniform_random_position }
8
- TopBorder = lambda { |window, instance| instance.warp_to rand(window.width), 0 }
9
- RightBorder = lambda { |window, instance| instance.warp_to window.width, rand(window.height) }
10
- BottomBorder = lambda { |window, instance| instance.warp_to rand(window.width), window.height }
11
- LeftBorder = lambda { |window, instance| instance.warp_to 0, rand(window.height) }
7
+ class << self
8
+ def uniform_random
9
+ lambda { |window, instance| instance.warp_to *window.uniform_random_position }
10
+ end
11
+ def top_border offset = 0
12
+ lambda { |window, instance| instance.warp_to rand(window.width), -offset }
13
+ end
14
+ def right_border offset = 0
15
+ lambda { |window, instance| instance.warp_to window.width+offset, rand(window.height) }
16
+ end
17
+ def bottom_border offset = 0
18
+ lambda { |window, instance| instance.warp_to rand(window.width), window.height+offset }
19
+ end
20
+ def left_border offset = 0
21
+ lambda { |window, instance| instance.warp_to -offset, rand(window.height) }
22
+ end
23
+ end
12
24
 
13
25
  #
14
26
  #
@@ -17,7 +29,7 @@ class Wave
17
29
  def initialize generated_type, execution_amount = 1, &positioning_function
18
30
  @generated_type = generated_type
19
31
  @execution_amount = execution_amount
20
- @positioning_function = positioning_function || UniformRandom
32
+ @positioning_function = positioning_function || Wave.uniform_random
21
33
  end
22
34
 
23
35
  #
@@ -5,7 +5,7 @@ module Attachable extend Trait
5
5
  attr_accessor :relative_position
6
6
 
7
7
  def move_relative pod
8
- self.position = pod.position + relative_position # pod.rotation
8
+ self.position = pod.relative_position self
9
9
  self.rotation = pod.rotation
10
10
  end
11
11
 
data/lib/traits/pod.rb CHANGED
@@ -15,25 +15,17 @@ module Pod extend Trait
15
15
  MANUAL
16
16
 
17
17
  def self.included target_class
18
- target_class.extend IncludeMethods
18
+ target_class.extend ClassMethods
19
19
  target_class.holds_attachments
20
+ target_class.send :include, InstanceMethods
20
21
  end
21
22
 
22
- # TODO is_a Rack
23
23
  #
24
- # TODO Maybe
25
- # is_a Rack.
26
- # with(Cannon, 10, 10).
27
- # with(Cannon, 20, 10)
28
24
  #
29
- module IncludeMethods
25
+ module ClassMethods
30
26
 
31
27
  def holds_attachments
32
- include InstanceMethods
33
- alias_method_chain :move, :attachments
34
-
35
28
  class_inheritable_accessor :prototype_attachments
36
- extend ClassMethods
37
29
  hook = lambda do
38
30
  self.class.prototype_attachments.each do |type, x, y|
39
31
  attach type.new(self.window), x, y
@@ -42,10 +34,6 @@ module Pod extend Trait
42
34
  InitializerHooks.append self, &hook
43
35
  end
44
36
 
45
- end
46
-
47
- module ClassMethods
48
-
49
37
  # Example:
50
38
  # class MotherShip
51
39
  # is_a Pod
@@ -62,17 +50,26 @@ module Pod extend Trait
62
50
 
63
51
  module InstanceMethods
64
52
 
65
- attr_accessor :attachments
53
+ def materialize attachment
54
+ attachment.extend Attachable # This is where Ruby shines.
55
+ window.register attachment
56
+ end
57
+
58
+ #
59
+ #
60
+ def attachments
61
+ @attachments || @attachments = []
62
+ end
66
63
 
67
64
  #
68
65
  #
69
66
  def attach attachment, x, y
70
- self.attachments ||= []
71
- attachment.extend Attachable # This is where Ruby shines.
72
- window.register attachment
73
- # attachment.rotation = self.rotation
67
+ # TODO Move to better place.
68
+ self.class.alias_method_chain :move, :attachments unless respond_to?(:move_without_attachments)
69
+ #
70
+ materialize attachment
74
71
  attachment.relative_position = CP::Vec2.new x, y
75
- self.attachments << attachment
72
+ attachments << attachment
76
73
  end
77
74
 
78
75
  #
@@ -89,12 +86,19 @@ module Pod extend Trait
89
86
  end
90
87
  end
91
88
 
89
+ #
90
+ #
91
+ def relative_position attachment
92
+ self.position + attachment.relative_position.rotate(self.rotation_vector)
93
+ end
94
+
92
95
  #
93
96
  #
94
97
  def move_with_attachments
95
98
  move_attachments
96
99
  move_without_attachments
97
100
  end
101
+ # alias_method_chain :move, :attachments
98
102
 
99
103
  end
100
104
 
@@ -8,11 +8,12 @@ describe Attachable do
8
8
 
9
9
  describe "move_relative" do
10
10
  before(:each) do
11
- @attachable.stub! :relative_position => "+ attachable position", :position= => nil, :rotation= => nil
12
- @pod = stub :pod, :position => "pod position ", :rotation => :some_rotation
11
+ @attachable.stub! :position= => nil, :rotation= => nil
12
+
13
+ @pod = stub :pod, :relative_position => :relative_position, :rotation => :some_rotation
13
14
  end
14
15
  it "should set the position to the pod's position plus the relative position" do
15
- @attachable.should_receive(:position=).once.with "pod position + attachable position"
16
+ @attachable.should_receive(:position=).once.with :relative_position
16
17
 
17
18
  @attachable.move_relative @pod
18
19
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 24
9
- version: 0.1.24
8
+ - 25
9
+ version: 0.1.25
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke