ray 0.0.1 → 0.1.0.pre1

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.
Files changed (188) hide show
  1. data/.gemtest +0 -0
  2. data/.yardopts +4 -0
  3. data/README.md +17 -21
  4. data/Rakefile +18 -139
  5. data/VERSION +1 -1
  6. data/ext/audio.cpp +723 -0
  7. data/ext/{color.c → color.cpp} +25 -13
  8. data/ext/drawable.cpp +91 -0
  9. data/ext/event.cpp +460 -0
  10. data/ext/extconf.rb +5 -104
  11. data/ext/font.cpp +190 -0
  12. data/ext/image.cpp +733 -0
  13. data/ext/input.cpp +74 -0
  14. data/ext/ray.cpp +168 -0
  15. data/ext/ray.hpp +356 -0
  16. data/ext/{rect.c → rect.cpp} +51 -37
  17. data/ext/shader.cpp +169 -0
  18. data/ext/shape.cpp +409 -0
  19. data/ext/sprite.cpp +306 -0
  20. data/ext/text.cpp +181 -0
  21. data/ext/vector.cpp +215 -0
  22. data/guide.md +619 -0
  23. data/lib/ray/audio.rb +0 -41
  24. data/lib/ray/color.rb +32 -10
  25. data/lib/ray/drawable.rb +16 -0
  26. data/lib/ray/dsl/event_listener.rb +25 -2
  27. data/lib/ray/dsl/event_runner.rb +33 -5
  28. data/lib/ray/dsl/event_translator.rb +66 -30
  29. data/lib/ray/dsl/handler.rb +3 -2
  30. data/lib/ray/dsl/matcher.rb +58 -14
  31. data/lib/ray/font.rb +38 -96
  32. data/lib/ray/font_set.rb +8 -8
  33. data/lib/ray/game.rb +87 -66
  34. data/lib/ray/helper.rb +105 -10
  35. data/lib/ray/image.rb +150 -24
  36. data/lib/ray/image_set.rb +3 -1
  37. data/lib/ray/input.rb +10 -0
  38. data/lib/ray/music_set.rb +5 -3
  39. data/lib/ray/ray.rb +21 -9
  40. data/lib/ray/rect.rb +48 -7
  41. data/lib/ray/rmagick.rb +41 -0
  42. data/lib/ray/scene.rb +99 -43
  43. data/lib/ray/scene_list.rb +67 -0
  44. data/lib/ray/shape.rb +132 -0
  45. data/lib/ray/sound_set.rb +4 -2
  46. data/lib/ray/sprite.rb +49 -111
  47. data/lib/ray/text.rb +101 -0
  48. data/lib/ray/text_helper.rb +37 -0
  49. data/lib/ray/turtle.rb +215 -0
  50. data/lib/ray/vector.rb +226 -0
  51. data/samples/audio/spacial.rb +44 -0
  52. data/samples/hello_world/hello.rb +9 -13
  53. data/samples/hello_world/hello_dsl.rb +8 -12
  54. data/samples/hello_world/text.rb +15 -0
  55. data/samples/opengl/binding.rb +38 -0
  56. data/samples/opengl/image.rb +32 -0
  57. data/samples/opengl/opengl.rb +34 -0
  58. data/samples/opengl/shader.rb +42 -0
  59. data/samples/pong/pong.rb +14 -10
  60. data/samples/run_scene.rb +53 -0
  61. data/samples/shaders/scene.rb +40 -0
  62. data/samples/shaders/shaders.rb +42 -0
  63. data/samples/shaders/shape.rb +34 -0
  64. data/samples/sokoban/sokoban.rb +18 -18
  65. data/samples/test/actual_scene.rb +41 -0
  66. data/samples/test/scene_riot.rb +39 -0
  67. data/samples/test/scene_spec.rb +32 -0
  68. data/samples/test/scene_test_unit.rb +25 -0
  69. data/samples/turtle/byzantium.rb +45 -0
  70. data/samples/turtle/hilbert.rb +48 -0
  71. data/samples/turtle/koch.rb +55 -0
  72. data/samples/turtle/mandala.rb +61 -0
  73. data/samples/turtle/tree.rb +57 -0
  74. data/test/audio_test.rb +69 -0
  75. data/test/color_test.rb +77 -0
  76. data/test/drawable_test.rb +19 -0
  77. data/test/dsl_test.rb +93 -0
  78. data/test/font_test.rb +57 -0
  79. data/test/helpers.rb +94 -0
  80. data/test/image_test.rb +82 -0
  81. data/test/ray_test.rb +25 -0
  82. data/test/rect_test.rb +121 -0
  83. data/{spec → test}/res/VeraMono.ttf +0 -0
  84. data/{spec → test}/res/aqua.bmp +0 -0
  85. data/{spec → test}/res/aqua.png +0 -0
  86. data/{spec → test}/res/aqua2.bmp +0 -0
  87. data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
  88. data/{spec → test}/res/pop.wav +0 -0
  89. data/test/resource_set_test.rb +99 -0
  90. data/test/run_all.rb +7 -0
  91. data/test/shape_test.rb +101 -0
  92. data/test/sprite_test.rb +89 -0
  93. data/test/text_test.rb +78 -0
  94. data/test/turtle_test.rb +176 -0
  95. data/test/vector_test.rb +111 -0
  96. data/yard_ext.rb +0 -28
  97. metadata +95 -139
  98. data/.gitignore +0 -23
  99. data/.gitmodules +0 -3
  100. data/.rspec +0 -3
  101. data/ext/audio.c +0 -473
  102. data/ext/event.c +0 -557
  103. data/ext/font.c +0 -287
  104. data/ext/image.c +0 -933
  105. data/ext/joystick.c +0 -145
  106. data/ext/ray.c +0 -489
  107. data/ext/ray.h +0 -245
  108. data/ext/ray_osx.m +0 -161
  109. data/lib/ray/joystick.rb +0 -30
  110. data/psp/SDL_psp_main.c +0 -84
  111. data/psp/bigdecimal/README +0 -60
  112. data/psp/bigdecimal/bigdecimal.c +0 -4697
  113. data/psp/bigdecimal/bigdecimal.h +0 -216
  114. data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
  115. data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
  116. data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
  117. data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
  118. data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
  119. data/psp/digest/bubblebabble/bubblebabble.c +0 -142
  120. data/psp/digest/defs.h +0 -20
  121. data/psp/digest/digest.c +0 -643
  122. data/psp/digest/digest.h +0 -32
  123. data/psp/digest/lib/digest.rb +0 -50
  124. data/psp/digest/lib/md5.rb +0 -27
  125. data/psp/digest/lib/sha1.rb +0 -27
  126. data/psp/digest/md5/md5.c +0 -420
  127. data/psp/digest/md5/md5.h +0 -80
  128. data/psp/digest/md5/md5init.c +0 -40
  129. data/psp/digest/rmd160/rmd160.c +0 -457
  130. data/psp/digest/rmd160/rmd160.h +0 -56
  131. data/psp/digest/rmd160/rmd160init.c +0 -40
  132. data/psp/digest/sha1/sha1.c +0 -269
  133. data/psp/digest/sha1/sha1.h +0 -39
  134. data/psp/digest/sha1/sha1init.c +0 -40
  135. data/psp/digest/sha2/lib/sha2.rb +0 -73
  136. data/psp/digest/sha2/sha2.c +0 -919
  137. data/psp/digest/sha2/sha2.h +0 -109
  138. data/psp/digest/sha2/sha2init.c +0 -52
  139. data/psp/enumerator/enumerator.c +0 -298
  140. data/psp/etc/etc.c +0 -559
  141. data/psp/ext.c +0 -289
  142. data/psp/fcntl/fcntl.c +0 -187
  143. data/psp/lib/rbconfig.rb +0 -178
  144. data/psp/nkf/lib/kconv.rb +0 -367
  145. data/psp/nkf/nkf-utf8/config.h +0 -88
  146. data/psp/nkf/nkf-utf8/nkf.c +0 -6040
  147. data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
  148. data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
  149. data/psp/nkf/nkf.c +0 -654
  150. data/psp/socket/addrinfo.h +0 -173
  151. data/psp/socket/getaddrinfo.c +0 -676
  152. data/psp/socket/getnameinfo.c +0 -270
  153. data/psp/socket/pspsocket.c +0 -71
  154. data/psp/socket/pspsocket.h +0 -28
  155. data/psp/socket/socket.c +0 -4662
  156. data/psp/socket/sockport.h +0 -76
  157. data/psp/stringio/stringio.c +0 -1306
  158. data/psp/strscan/strscan.c +0 -1320
  159. data/psp/syck/bytecode.c +0 -1166
  160. data/psp/syck/emitter.c +0 -1242
  161. data/psp/syck/gram.c +0 -1894
  162. data/psp/syck/gram.h +0 -79
  163. data/psp/syck/handler.c +0 -174
  164. data/psp/syck/implicit.c +0 -2990
  165. data/psp/syck/node.c +0 -408
  166. data/psp/syck/rubyext.c +0 -2367
  167. data/psp/syck/syck.c +0 -504
  168. data/psp/syck/syck.h +0 -456
  169. data/psp/syck/token.c +0 -2725
  170. data/psp/syck/yaml2byte.c +0 -257
  171. data/psp/syck/yamlbyte.h +0 -170
  172. data/psp/thread/thread.c +0 -1175
  173. data/psp/zlib/zlib.c +0 -3547
  174. data/script.rb +0 -10
  175. data/spec/ray/audio_spec.rb +0 -146
  176. data/spec/ray/color_spec.rb +0 -57
  177. data/spec/ray/event_spec.rb +0 -80
  178. data/spec/ray/font_spec.rb +0 -93
  179. data/spec/ray/image_set_spec.rb +0 -48
  180. data/spec/ray/image_spec.rb +0 -162
  181. data/spec/ray/joystick_spec.rb +0 -21
  182. data/spec/ray/matcher_spec.rb +0 -50
  183. data/spec/ray/ray_spec.rb +0 -88
  184. data/spec/ray/rect_spec.rb +0 -154
  185. data/spec/ray/resource_set_spec.rb +0 -105
  186. data/spec/ray/sprite_spec.rb +0 -163
  187. data/spec/spec.opts +0 -4
  188. data/spec/spec_helper.rb +0 -8
@@ -1,21 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Ray::Joystick do
4
- describe ".handle_event" do
5
- before :all do
6
- Ray.init
7
- end
8
-
9
- it "can be changed" do
10
- Ray::Joystick.handle_event = true
11
- Ray::Joystick.handle_event.should be_true
12
-
13
- Ray::Joystick.handle_event = false
14
- Ray::Joystick.handle_event.should be_false
15
- end
16
-
17
- after :all do
18
- Ray.init
19
- end
20
- end
21
- end
@@ -1,50 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Ray::Matchers do
4
- it "should add matchers as public methods" do
5
- lambda {
6
- Ray.describe_matcher(:awesome_matcher) do |reg|
7
- lambda { |str| str =~ reg }
8
- end
9
- }.should change {
10
- Ray::Matchers.instance_methods.any? do |i|
11
- i == :awesome_matcher or i == "awesome_matcher"
12
- end
13
- }.from(false).to(true)
14
- end
15
-
16
- it "should return a Ray::DSL::Matchers for defined matchers" do
17
- Ray.describe_matcher(:match) do |reg|
18
- lambda { |str| str =~ reg }
19
- end
20
-
21
- @obj = Object.new
22
- @obj.extend Ray::Matchers
23
-
24
- @obj.instance_eval { match("foo") }.should be_a(Ray::DSL::Matcher)
25
- end
26
-
27
- describe "#where" do
28
- it "should return a matcher matching if the block returns true" do
29
- obj = Object.new
30
- obj.extend Ray::Helper
31
-
32
- res = 0
33
- obj.instance_eval do
34
- self.event_runner = Ray::DSL::EventRunner.new
35
-
36
- on :foo, where { |x| x > 10 } do |x|
37
- x.should > 10
38
- res += 1
39
- end
40
-
41
- raise_event(:foo, 10)
42
- raise_event(:foo, 15)
43
-
44
- listener_runner.run
45
- end
46
-
47
- res.should == 1
48
- end
49
- end
50
- end
@@ -1,88 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'rbconfig'
3
-
4
- describe Ray do
5
- describe ".create_window" do
6
- it "should raise runtime error for invalid configurations" do
7
- Ray.init
8
-
9
- lambda {
10
- Ray.create_window(:w => 100, :h => 100, :bpp => 1)
11
- }.should raise_exception(RuntimeError)
12
-
13
- Ray.stop
14
- end
15
-
16
- it "should create a window of the expected size for valid configurations" do
17
- Ray.init
18
-
19
- win = Ray.create_window(:w => 100, :h => 50)
20
- win.width.should == 100
21
- win.height.should == 50
22
-
23
- win = Ray.create_window(:width => 50, :height => 100)
24
- win.width.should == 50
25
- win.height.should == 100
26
-
27
- Ray.stop
28
- end
29
- end
30
-
31
- describe ".can_use_mode?" do
32
- it "should return false for invalid configurations" do
33
- Ray.init
34
- Ray.can_use_mode?(:w => 100, :h => 100, :bpp => 1).should be_false
35
- Ray.stop
36
- end
37
-
38
- it "should return true for valid configurations" do
39
- Ray.init
40
- Ray.can_use_mode?(:w => 480, :h => 272).should be_true
41
- Ray.stop
42
- end
43
- end
44
-
45
- context "after being initialized" do
46
- before :all do Ray.init end
47
-
48
- subject { Ray }
49
-
50
- its(:window_title) { should be_nil }
51
- its(:text_icon) { should be_nil }
52
-
53
- its(:grab_input) { should be_false }
54
-
55
- after :all do Ray.stop end
56
- end
57
-
58
- context "after changing the title" do
59
- before :all do Ray.init end
60
-
61
- it "should change the window title and text icon and grab the input" do
62
- Ray.text_icon = "foo"
63
- Ray.text_icon.should == "foo"
64
-
65
- Ray.window_title = "bar"
66
- Ray.window_title == "bar"
67
-
68
- unless RbConfig::CONFIG["target_vendor"] == "psp"
69
- Ray.grab_input = false
70
- Ray.grab_input.should be_false
71
-
72
- Ray.grab_input = true
73
- Ray.grab_input.should be_true
74
- end
75
- end
76
-
77
- after :all do Ray.stop end
78
- end
79
-
80
- describe ".init" do
81
- it "should allow to pass a hash to add options" do
82
- lambda {
83
- Ray.init({})
84
- Ray.stop
85
- }.should_not raise_exception
86
- end
87
- end
88
- end
@@ -1,154 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Ray::Rect do
4
- [:x, :y, :width, :height].each do |meth|
5
- describe "##{meth}=" do
6
- it "should set a new value to #{meth}" do
7
- rect = Ray::Rect.new(0, 0)
8
- lambda {
9
- rect.send("#{meth}=", 30)
10
- }.should change(rect, meth).from(0).to(30)
11
- end
12
-
13
- it "should only allow numerics" do
14
- rect = Ray::Rect.new(0, 0)
15
-
16
- ["1.0", "5.d", Ray, Ray::Rect, rect].each do |obj|
17
- lambda {
18
- rect.send("#{meth}=", obj)
19
- }.should raise_exception(TypeError)
20
- end
21
- end
22
- end
23
- end
24
-
25
- describe "#initialize" do
26
- context "with a hash" do
27
- it "should not allow to pass x but not y" do
28
- lambda {
29
- Ray::Rect.new(:x => 10)
30
- }.should raise_exception(ArgumentError)
31
- end
32
-
33
- it "should not allow to pass width but not height" do
34
- lambda {
35
- Ray::Rect.new(:x => 10, :y => 200, :width => 300)
36
- }.should raise_exception(ArgumentError)
37
- end
38
-
39
- it "should require x and y to be present" do
40
- lambda {
41
- Ray::Rect.new(:width => 400, :height => 300)
42
- }.should raise_exception(ArgumentError)
43
- end
44
-
45
- it "should only work with numerics" do
46
- ["1.0", "5.d", Ray, Ray::Rect].each do |obj|
47
- lambda {
48
- Ray::Rect.new(:x => obj, :y => 30)
49
- }.should raise_exception(TypeError)
50
- end
51
- end
52
- end
53
-
54
- context "with separated arguments" do
55
- it "should not work with one integer" do
56
- lambda {
57
- Ray::Rect.new(10)
58
- }.should raise_exception(ArgumentError)
59
- end
60
-
61
- it "should not work with 3 integers" do
62
- lambda {
63
- Ray::Rect.new(10, 30, 40)
64
- }.should raise_exception(ArgumentError)
65
- end
66
-
67
- it "should only work with numerics" do
68
- ["1.0", "5.d", Ray, Ray::Rect].each do |obj|
69
- lambda {
70
- Ray::Rect.new(obj, 30)
71
- }.should raise_exception(TypeError)
72
- end
73
- end
74
- end
75
- end
76
-
77
- describe "#inside?" do
78
- it "should return true if the rect is the receiver itself" do
79
- rect = Ray::Rect.new(10, 15, 20, 30)
80
- rect.should be_inside(rect)
81
- end
82
-
83
- it "should return true if the rect inside the receiver" do
84
- rect = Ray::Rect.new(10, 15, 30, 40)
85
- Ray::Rect.new(13, 17, 10, 20).should be_inside(rect)
86
- end
87
-
88
- it "should return false if the rect only collides with the receiver" do
89
- rect = Ray::Rect.new(10, 15, 30, 40)
90
-
91
- Ray::Rect.new(5, 10, 20, 20).should_not be_inside(rect)
92
- Ray::Rect.new(11, 16, 40, 50).should_not be_inside(rect)
93
- end
94
-
95
- it "should return false if the rect is outside the receiver" do
96
- rect = Ray::Rect.new(10, 15, 20, 30)
97
-
98
- Ray::Rect.new(1, 2, 3, 5).should_not be_inside(rect)
99
- Ray::Rect.new(100, 150, 350, 450).should_not be_inside(rect)
100
- end
101
- end
102
-
103
- describe "#outside?" do
104
- it "should return false if the rect is the receiver itself" do
105
- rect = Ray::Rect.new(10, 15, 20, 30)
106
- rect.should_not be_outside(rect)
107
- end
108
-
109
- it "should return true if the rect is outside the receiver" do
110
- rect = Ray::Rect.new(10, 15, 20, 30)
111
-
112
- Ray::Rect.new(1, 2, 3, 5).should be_outside(rect)
113
- Ray::Rect.new(100, 150, 350, 450).should be_outside(rect)
114
- end
115
-
116
- it "should return false if the rect is inside the receiver" do
117
- rect = Ray::Rect.new(10, 15, 30, 40)
118
- Ray::Rect.new(13, 17, 10, 20).should_not be_outside(rect)
119
- end
120
-
121
- it "should return false if the rect collides with the receiver" do
122
- rect = Ray::Rect.new(10, 15, 30, 40)
123
-
124
- Ray::Rect.new(5, 10, 20, 20).should_not be_outside(rect)
125
- Ray::Rect.new(11, 16, 40, 50).should_not be_outside(rect)
126
- end
127
- end
128
-
129
- describe "#colllide?" do
130
- it "should return true if the rect is the receiver itself" do
131
- rect = Ray::Rect.new(10, 15, 20, 30)
132
- rect.collide?(rect).should be_true
133
- end
134
-
135
- it "should return false if the rect is outside the receiver" do
136
- rect = Ray::Rect.new(10, 15, 20, 30)
137
-
138
- Ray::Rect.new(1, 2, 3, 5).collide?(rect).should_not be_true
139
- Ray::Rect.new(100, 150, 350, 450).collide?(rect).should_not be_true
140
- end
141
-
142
- it "should return true if the rect is inside the receiver" do
143
- rect = Ray::Rect.new(10, 15, 30, 40)
144
- Ray::Rect.new(13, 17, 10, 20).collide?(rect).should be_true
145
- end
146
-
147
- it "should return true if the rect collides with the receiver" do
148
- rect = Ray::Rect.new(10, 15, 30, 40)
149
-
150
- Ray::Rect.new(5, 10, 20, 20).collide?(rect).should be_true
151
- Ray::Rect.new(11, 16, 40, 50).collide?(rect).should be_true
152
- end
153
- end
154
- end
@@ -1,105 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- module TestSet
4
- extend Ray::ResourceSet
5
-
6
- def self.missing_pattern(string)
7
- "unknown"
8
- end
9
-
10
- add_set(/^string:(.+)$/) do |str|
11
- str
12
- end
13
- end
14
-
15
- module DefaultMissingPattern
16
- extend Ray::ResourceSet
17
- end
18
-
19
- module MultipleArgumentsSet
20
- extend Ray::ResourceSet
21
-
22
- need_argument_count 1
23
-
24
- add_set(/^string:(.+)$/) do |str, times|
25
- str * times
26
- end
27
-
28
- def self.missing_pattern(*args)
29
- args
30
- end
31
- end
32
-
33
- module CacheTestSet
34
- extend Ray::ResourceSet
35
-
36
- add_set(/(.+)/) { |str| str }
37
- end
38
-
39
- describe Ray::ResourceSet do
40
- it "should use the block we passed to create a string" do
41
- TestSet["string:test"].should == "test"
42
- end
43
-
44
- it "should always return the same object for the same key" do
45
- str = TestSet["string:my string"]
46
- str.object_id.should == TestSet["string:my string"].object_id
47
- end
48
-
49
- it "should call the missing_pattern method when a string isn't matched" do
50
- TestSet["Hello world"].should == "unknown"
51
- end
52
-
53
- it "should raise NoPatternError for unmatched string by default" do
54
- lambda {
55
- DefaultMissingPattern["unknown"]
56
- }.should raise_exception(Ray::NoPatternError)
57
- end
58
-
59
- it "should allow more arguments in []" do
60
- lambda {
61
- MultipleArgumentsSet["string:test", 3]
62
- }.should_not raise_exception
63
- end
64
-
65
- it "should raise an error when using an invalid argument count" do
66
- lambda {
67
- TestSet["string:foo", 3]
68
- }.should raise_exception
69
- end
70
-
71
- it "should provide user arguments at the end" do
72
- MultipleArgumentsSet.add_set(/my_(.)/) do |char, times|
73
- char.should == "a"
74
- times.should == 3
75
-
76
- true
77
- end
78
-
79
- MultipleArgumentsSet["my_a", 3]
80
- end
81
-
82
- it "should be able to select objects from the cache" do
83
- first = CacheTestSet["first"]
84
- sec = CacheTestSet["sec"]
85
-
86
- CacheTestSet.select! { |key, val| key == "first" }
87
-
88
- first.object_id.should == CacheTestSet["first"].object_id
89
- sec.object_id.should_not == CacheTestSet["sec"].object_id
90
- end
91
-
92
- it "should be able to reject objects from the cache" do
93
- first = CacheTestSet["first"]
94
- sec = CacheTestSet["sec"]
95
-
96
- CacheTestSet.reject! { |key, val| key == "first" }
97
-
98
- first.object_id.should_not == CacheTestSet["first"].object_id
99
- sec.object_id.should == CacheTestSet["sec"].object_id
100
- end
101
-
102
- it "should pass all the arguments to missing_pattern" do
103
- MultipleArgumentsSet["a", 3].should == ["a", 3]
104
- end
105
- end
@@ -1,163 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Ray::Sprite do
4
- before :all do
5
- Ray.init
6
- @win = Ray.create_window(:w => 100, :h => 100)
7
- end
8
-
9
- it "should wrap an image" do
10
- image = Ray::Image.new(:w => 10, :h => 10)
11
-
12
- sprite = Ray::Sprite.new(image)
13
- sprite.image.should == image
14
- end
15
-
16
- it "should convert strings to images" do
17
- image = Ray::ImageSet[path_of("aqua.bmp")]
18
-
19
- sprite = Ray::Sprite.new(path_of("aqua.bmp"))
20
- sprite.image.should == image
21
- end
22
-
23
- it "should blit its image when drawn" do
24
- image = mock("image")
25
- image.stub!(:to_image).and_return(image)
26
- image.stub!(:is_a?).and_return(true)
27
- image.should_receive(:blit).and_return(@win)
28
-
29
- sprite = Ray::Sprite.new(image)
30
- sprite.draw_on(@win)
31
- end
32
-
33
- it "should draw on the screen by default" do
34
- image = mock("image")
35
- image.stub!(:to_image).and_return(image)
36
- image.stub!(:is_a?).and_return(true)
37
- image.should_receive(:blit).with(hash_including(:on => @win)).and_return(@win)
38
-
39
- sprite = Ray::Sprite.new(image)
40
- sprite.draw
41
- end
42
-
43
- it "should have a position" do
44
- sprite = Ray::Sprite.new(@win, :at => [10, 15])
45
- sprite.is_at?(10, 15).should be_true
46
- end
47
-
48
- it "should not be at a position it wan't assigned to" do
49
- sprite = Ray::Sprite.new(@win, :at => [13, 20])
50
- sprite.is_at?(10, 15).should be_false
51
- end
52
-
53
- it "should be at (0, 0) by default" do
54
- sprite = Ray::Sprite.new(@win)
55
- sprite.is_at?(0, 0).should be_true
56
- end
57
-
58
- it "should draw the image at its position" do
59
- image = mock("image")
60
- image.stub!(:to_image).and_return(image)
61
- image.stub!(:is_a?).and_return(true)
62
- image.should_receive(:blit).with(hash_including(:at => [10, 15])).
63
- and_return(@win)
64
-
65
- sprite = Ray::Sprite.new(image, :at => [10, 15])
66
- sprite.draw
67
- end
68
-
69
- it "should allow to draw only a small rect of the image" do
70
- image = mock("image")
71
- image.stub!(:to_image).and_return(image)
72
- image.stub!(:is_a?).and_return(true)
73
- rect = Ray::Rect.new(50, 30, 100, 120)
74
- image.should_receive(:blit).with(hash_including(:rect => rect)).
75
- and_return(@win)
76
-
77
- sprite = Ray::Sprite.new(image, :rect => [50, 30, 100, 120])
78
- sprite.draw
79
- end
80
-
81
- it "should default to an empty rect" do
82
- sprite = Ray::Sprite.new(@win)
83
- sprite.from_rect.should == Ray::Rect.new(0, 0, 0, 0)
84
- end
85
-
86
- describe "#rect" do
87
- it "should return the rect where the image will be drawn" do
88
- sprite = Ray::Sprite.new(@win, :rect => [70, 80, 80, 80],
89
- :at => [50, 30])
90
- sprite.rect.should == Ray::Rect.new(50, 30, 80, 80)
91
- end
92
-
93
- it "should return the image size if the rect is not set" do
94
- sprite = Ray::Sprite.new(@win)
95
- sprite.rect.should == Ray::Rect.new(0, 0, 100, 100)
96
- end
97
- end
98
-
99
- it "should allow to set an angle" do
100
- sprite = Ray::Sprite.new(@win, :angle => 30)
101
- sprite.angle.should == 30
102
- end
103
-
104
- it "should draw using its angle" do
105
- image = mock("image")
106
- image.stub!(:to_image).and_return(image)
107
- image.stub!(:is_a?).and_return(true)
108
- image.should_receive(:blit).with(hash_including(:angle => 40))
109
-
110
- sprite = Ray::Sprite.new(image, :angle => 40)
111
- sprite.draw
112
- end
113
-
114
- it "should allow to zoom" do
115
- sprite = Ray::Sprite.new(@win, :zoom => 3)
116
- sprite.zoom.should == 3
117
- end
118
-
119
- it "should draw using its zoom level" do
120
- image = mock("image")
121
- image.stub!(:to_image).and_return(image)
122
- image.stub!(:is_a?).and_return(true)
123
- image.should_receive(:blit).with(hash_including(:zoom => 3))
124
-
125
- sprite = Ray::Sprite.new(image, :zoom => 3)
126
- sprite.draw
127
- end
128
-
129
- it "should allow to set its position using an array" do
130
- sprite = Ray::Sprite.new(@win)
131
- sprite.pos = [10, 15]
132
- sprite.pos.to_rect.should == Ray::Rect.new(10, 15)
133
- end
134
-
135
- it "should allow to use a sprite sheet" do
136
- sprite = Ray::Sprite.new(@win)
137
- sprite.sheet_size = [10, 10]
138
-
139
- sprite.rect.w.should == (@win.w / 10)
140
- sprite.rect.h.should == (@win.h / 10)
141
- end
142
-
143
- it "should allow to change the cell which will be drawn" do
144
- sprite = Ray::Sprite.new(@win)
145
- sprite.sheet_size = [10, 10]
146
- sprite.sheet_pos = [3, 6]
147
-
148
- sprite.from_rect.should == Ray::Rect.new((@win.w / 10) * 3,
149
- (@win.h / 10) * 6,
150
- @win.w / 10, @win.h / 10)
151
- end
152
-
153
- it "should allow to disable the use of a sprite sheet" do
154
- sprite = Ray::Sprite.new(@win)
155
- sprite.sheet_size = [10, 10]
156
- sprite.disable_sprite_sheet
157
- sprite.from_rect.should == Ray::Rect.new(0, 0, @win.w, @win.h)
158
- end
159
-
160
- after :all do
161
- Ray.stop
162
- end
163
- end