gosu_extensions 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/gogogosu +33 -0
- data/lib/traits/imageable.rb +25 -8
- data/lib/traits/shooter.rb +2 -2
- data/lib/units/thing.rb +1 -3
- data/spec/lib/traits/imageable_spec.rb +21 -6
- data/spec/lib/units/thing_spec.rb +12 -0
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/bin/gogogosu
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
# TODO remove
|
3
|
+
|
4
|
+
Signal.trap("INT") { puts; exit } # CTRL-C
|
5
|
+
|
6
|
+
File.open(File.join(File.dirname(__FILE__), '../VERSION')) do |f|
|
7
|
+
puts "Gosu Extensions #{f.read}"
|
8
|
+
end
|
9
|
+
|
10
|
+
application = ARGV.first
|
11
|
+
|
12
|
+
puts "Usage: gogogosu <application_name>" and exit(1) unless application
|
13
|
+
|
14
|
+
require File.dirname(__FILE__) + '/../generator/gogogosu'
|
15
|
+
|
16
|
+
generator = Generator::Gogogosu.new
|
17
|
+
|
18
|
+
generator.dir application do
|
19
|
+
generator.dir 'lib' do
|
20
|
+
|
21
|
+
end
|
22
|
+
generator.dir 'media' do
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
puts <<-START
|
28
|
+
Great!
|
29
|
+
|
30
|
+
Now proceed as follows:
|
31
|
+
1. cd #{application}
|
32
|
+
2.
|
33
|
+
START
|
data/lib/traits/imageable.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# In an Imageable, you either need to define method
|
2
|
+
# image path, *args
|
3
|
+
# for an unchanging image
|
4
|
+
# or
|
5
|
+
# sequenced_image path, width, height, frequency = 10, &block
|
6
|
+
# for a sprite sequence.
|
7
|
+
# Or override
|
8
|
+
# method image
|
9
|
+
# or set an image dynamically.
|
10
|
+
#
|
1
11
|
module Imageable extend Trait
|
2
12
|
|
3
13
|
class ImageMissingError < RuntimeError
|
@@ -10,6 +20,9 @@ module Imageable extend Trait
|
|
10
20
|
or
|
11
21
|
sequenced_image path, width, height, frequency = 10, &block
|
12
22
|
for a sprite sequence.
|
23
|
+
Or override
|
24
|
+
method image
|
25
|
+
or set an image dynamically.
|
13
26
|
|
14
27
|
MESSAGE
|
15
28
|
end
|
@@ -19,28 +32,32 @@ module Imageable extend Trait
|
|
19
32
|
klass.extend ClassMethods
|
20
33
|
end
|
21
34
|
|
22
|
-
def initialize
|
23
|
-
|
24
|
-
|
35
|
+
def initialize *args
|
36
|
+
super *args
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_writer :image
|
40
|
+
def image
|
41
|
+
@image || raise(ImageMissingError.new)
|
25
42
|
end
|
26
43
|
|
27
44
|
module ClassMethods
|
28
45
|
|
29
46
|
def image path, *args
|
30
47
|
InitializerHooks.register self do
|
31
|
-
|
32
|
-
end
|
33
|
-
define_method :image do
|
34
|
-
@image
|
48
|
+
self.image = Gosu::Image.new self.window, File.join(Resources.root, path), *args
|
35
49
|
end
|
36
50
|
end
|
37
51
|
|
38
52
|
def sequenced_image path, width, height, frequency = 10, &block
|
39
53
|
InitializerHooks.register self do
|
40
54
|
@image_sequence_started = Time.now
|
41
|
-
|
55
|
+
self.image = Gosu::Image::load_tiles self.window, File.join(Resources.root, path), width, height, false
|
42
56
|
end
|
43
57
|
# divider = 1000 / frequency
|
58
|
+
|
59
|
+
# Override image.
|
60
|
+
#
|
44
61
|
define_method :image do
|
45
62
|
@image[(block ? block : lambda { (Time.now - @image_sequence_started)*frequency % @image.size })[]]
|
46
63
|
end
|
data/lib/traits/shooter.rb
CHANGED
@@ -41,8 +41,8 @@ module Shooter extend Trait
|
|
41
41
|
Example:
|
42
42
|
frequency 20
|
43
43
|
shoots Bullet
|
44
|
-
muzzle_position { self.position + self.rotation_vector.normalize*
|
45
|
-
muzzle_velocity { |_| self.rotation_vector.normalize }
|
44
|
+
muzzle_position { self.position + self.rotation_vector.normalize*20 } # Or: Shooter::Position.front(20)
|
45
|
+
muzzle_velocity { |_| self.rotation_vector.normalize } # Or: Shooter::Velocity.front(1)
|
46
46
|
muzzle_rotation { |_| self.rotation }
|
47
47
|
MANUAL
|
48
48
|
|
data/lib/units/thing.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
class Thing < Sprite
|
4
4
|
|
5
5
|
attr_reader :shape
|
6
|
+
delegate :collision_type, :to => :shape
|
6
7
|
|
7
8
|
def mass
|
8
9
|
0.1
|
@@ -27,9 +28,6 @@ class Thing < Sprite
|
|
27
28
|
}
|
28
29
|
def shape form, *args
|
29
30
|
form_shape_class_mapping = @@form_shape_class_mapping
|
30
|
-
define_method :radius do
|
31
|
-
args.first # TODO fix!
|
32
|
-
end
|
33
31
|
InitializerHooks.prepend self do
|
34
32
|
shape_class = form_shape_class_mapping[form]
|
35
33
|
raise "Shape #{form} does not exist." unless shape_class
|
@@ -7,6 +7,20 @@ describe Imageable do
|
|
7
7
|
Resources.stub! :root => 'some/root'
|
8
8
|
end
|
9
9
|
|
10
|
+
describe 'image=' do
|
11
|
+
before(:each) do
|
12
|
+
@imageable = test_class_with(Imageable).new @window
|
13
|
+
end
|
14
|
+
it 'should set the image' do
|
15
|
+
lambda { @imageable.image = :some_image }.should_not raise_error
|
16
|
+
end
|
17
|
+
it 'should return that image' do
|
18
|
+
@imageable.image = :some_image
|
19
|
+
|
20
|
+
@imageable.image.should == :some_image
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
10
24
|
context 'image defined on class' do
|
11
25
|
before(:each) do
|
12
26
|
@imageable_class = test_class_with(Imageable) do
|
@@ -25,7 +39,7 @@ describe Imageable do
|
|
25
39
|
sequenced_image 'some/path', :some_width, :some_height, 10.0
|
26
40
|
end
|
27
41
|
end
|
28
|
-
it "should define a method
|
42
|
+
it "should define a method image" do
|
29
43
|
image = stub :image
|
30
44
|
sequenced_image = stub :image, :size => 10, :[] => image
|
31
45
|
|
@@ -36,15 +50,13 @@ describe Imageable do
|
|
36
50
|
end
|
37
51
|
context 'no image given – what now?' do
|
38
52
|
before(:each) do
|
39
|
-
@imageable_class =
|
40
|
-
include Imageable
|
41
|
-
end
|
53
|
+
@imageable_class = test_class_with Imageable
|
42
54
|
end
|
43
55
|
it "should raise a ImageMissingError" do
|
44
|
-
lambda { @imageable_class.new(@window) }.should raise_error(Imageable::ImageMissingError)
|
56
|
+
lambda { @imageable_class.new(@window).image }.should raise_error(Imageable::ImageMissingError)
|
45
57
|
end
|
46
58
|
it "should raise with the right message" do
|
47
|
-
lambda { @imageable_class.new(@window) }.should raise_error(Imageable::ImageMissingError, <<-MESSAGE
|
59
|
+
lambda { @imageable_class.new(@window).image }.should raise_error(Imageable::ImageMissingError, <<-MESSAGE
|
48
60
|
|
49
61
|
In an Imageable, you either need to define method
|
50
62
|
image path, *args
|
@@ -52,6 +64,9 @@ describe Imageable do
|
|
52
64
|
or
|
53
65
|
sequenced_image path, width, height, frequency = 10, &block
|
54
66
|
for a sprite sequence.
|
67
|
+
Or override
|
68
|
+
method image
|
69
|
+
or set an image dynamically.
|
55
70
|
|
56
71
|
MESSAGE
|
57
72
|
)
|
@@ -8,6 +8,18 @@ describe Thing do
|
|
8
8
|
@thing = Thing.new @window
|
9
9
|
end
|
10
10
|
|
11
|
+
describe 'collision_type=' do
|
12
|
+
before(:each) do
|
13
|
+
@shape = stub :shape
|
14
|
+
@thing.stub! :shape => @shape
|
15
|
+
end
|
16
|
+
it 'should delegate to the shape' do
|
17
|
+
@shape.should_receive(:collision_type).once.with :some_collision_type
|
18
|
+
|
19
|
+
@thing.collision_type :some_collision_type
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
describe "current_size" do
|
12
24
|
it "should return [1.0, 1.0] by default" do
|
13
25
|
@thing.current_size.should == [1.0, 1.0]
|
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
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
@@ -16,7 +16,7 @@ bindir: bin
|
|
16
16
|
cert_chain: []
|
17
17
|
|
18
18
|
date: 2010-04-15 00:00:00 +02:00
|
19
|
-
default_executable:
|
19
|
+
default_executable: gogogosu
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: gosu
|
@@ -44,8 +44,8 @@ dependencies:
|
|
44
44
|
version_requirements: *id002
|
45
45
|
description: ""
|
46
46
|
email: florian.hanke@gmail.com
|
47
|
-
executables:
|
48
|
-
|
47
|
+
executables:
|
48
|
+
- gogogosu
|
49
49
|
extensions: []
|
50
50
|
|
51
51
|
extra_rdoc_files: []
|