gosu_extensions 0.1.10 → 0.1.11

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.10
1
+ 0.1.11
@@ -49,6 +49,6 @@ require 'scheduling'
49
49
  require 'waves'
50
50
  require 'layer'
51
51
 
52
- DEFAULT_SCREEN_WIDTH = 1200
53
- DEFAULT_SCREEN_HEIGHT = 700
54
- SUBSTEPS = 10
52
+ DEFAULT_SCREEN_WIDTH = 1200 unless defined?(DEFAULT_SCREEN_WIDTH)
53
+ DEFAULT_SCREEN_HEIGHT = 700 unless defined?(DEFAULT_SCREEN_HEIGHT)
54
+ SUBSTEPS = 10 unless defined?(SUBSTEPS)
@@ -2,16 +2,50 @@
2
2
  #
3
3
  # Example:
4
4
  # class Rocket
5
- # it_is ShortLived
6
5
  # it_is Damaging
6
+ #
7
+ # damage { rand(10) + 5 }
8
+ # end
9
+ #
10
+ # OR
11
+ # class Rocket
12
+ # it_is Damaging
13
+ #
14
+ # damage 15
15
+ # end
16
+ #
17
+ # OR
18
+ #
19
+ # class Rocket
20
+ # it_is Damaging
21
+ #
22
+ # def damage
23
+ # # Define your own damage method.
24
+ # end
7
25
  # end
8
26
  #
9
27
  module Damaging
10
28
 
11
- mattr_accessor :damage
29
+ # TODO Explain better what to do.
30
+ #
31
+ class DamageMissingError < StandardError; end
32
+
33
+ def self.included klass
34
+ klass.extend ClassMethods
35
+ end
36
+
37
+ def initialize window
38
+ raise DamageMissingError.new unless self.respond_to? :damage
39
+ super window
40
+ end
12
41
 
13
- def damage
14
- @@damage
42
+ module ClassMethods
43
+
44
+ def damage damage = nil, &block
45
+ block = lambda { damage } unless block_given?
46
+ define_method :damage, &block
47
+ end
48
+
15
49
  end
16
50
 
17
51
  end
@@ -9,9 +9,8 @@ module ShortLived
9
9
  end
10
10
 
11
11
  def initialize window
12
+ raise LifetimeMissingError.new unless self.respond_to? :lifetime
12
13
  super window
13
-
14
- raise ShortLived::LifetimeMissingError.new unless self.respond_to? :lifetime
15
14
  threaded self.lifetime do
16
15
  self.destroy!
17
16
  end
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), '/../../spec_helper')
2
+
3
+ describe Attachable do
4
+
5
+ before(:each) do
6
+ @attachable = test_class_with(Attachable).new stub(:window)
7
+ end
8
+
9
+ describe "move_relative" do
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
13
+ end
14
+ 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
+
17
+ @attachable.move_relative @pod
18
+ end
19
+ it "should set the rotation to the pod's rotation" do
20
+ @attachable.should_receive(:rotation=).once.with :some_rotation
21
+
22
+ @attachable.move_relative @pod
23
+ end
24
+ end
25
+
26
+ describe "relative_position" do
27
+ it "should be a writer" do
28
+ lambda { @attachable.relative_position = :some_position }.should_not raise_error
29
+ end
30
+ it "should have a reader" do
31
+ lambda { @attachable.relative_position }.should_not raise_error
32
+ end
33
+ it "should read what is written" do
34
+ @attachable.relative_position = :some_position
35
+ @attachable.relative_position.should == :some_position
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), '/../../spec_helper')
2
+
3
+ describe Damaging do
4
+
5
+ before(:each) do
6
+ @window = stub :window
7
+ end
8
+
9
+ context 'damage given as block' do
10
+ before(:each) do
11
+ @damaging = test_class_with(Damaging) do
12
+ damage { 10 + 10 }
13
+ end.new @window
14
+ end
15
+ it "should define a method lifetime which returns the result of the block" do
16
+ @damaging.damage.should == 20
17
+ end
18
+ end
19
+ context 'damage given normally' do
20
+ before(:each) do
21
+ @damaging = test_class_with(Damaging) do
22
+ damage 30
23
+ end.new @window
24
+ end
25
+ it "should define a method damage which returns the set value" do
26
+ @damaging.damage.should == 30
27
+ end
28
+ end
29
+ context 'no damage given – what now?' do
30
+ before(:each) do
31
+ @damaging_class = test_class_with Damaging
32
+ end
33
+ it "should raise a DamageMissingError" do
34
+ lambda { @damaging_class.new(@window) }.should raise_error(Damaging::DamageMissingError)
35
+ end
36
+ end
37
+
38
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 10
9
- version: 0.1.10
8
+ - 11
9
+ version: 0.1.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-04 00:00:00 +02:00
17
+ date: 2010-04-05 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -114,6 +114,8 @@ specification_version: 3
114
114
  summary: Default extensions built onto the popular Gosu Framework. Uses Chipmunk for game physics. That's it for now. I'm working on them. Anyway, GAME ON!
115
115
  test_files:
116
116
  - spec/lib/extensions/numeric_spec.rb
117
+ - spec/lib/traits/attachable_spec.rb
118
+ - spec/lib/traits/damaging_spec.rb
117
119
  - spec/lib/traits/shooter_spec.rb
118
120
  - spec/lib/traits/short_lived_spec.rb
119
121
  - spec/lib/traits/shot_spec.rb