moonpxi-nimo 0.1.0

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 (57) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +15 -0
  5. data/Rakefile +47 -0
  6. data/VERSION +1 -0
  7. data/examples/bouncy.rb +101 -0
  8. data/examples/eventy.rb +19 -0
  9. data/examples/images/dg_classm32.png +0 -0
  10. data/examples/images/dg_dungeon32.png +0 -0
  11. data/examples/images/jeeklabs.png +0 -0
  12. data/examples/images/tcheco.png +0 -0
  13. data/examples/imagey.rb +82 -0
  14. data/examples/screeny.rb +80 -0
  15. data/examples/simplest.rb +23 -0
  16. data/examples/sounds/KDE-Sys-Log-Out.ogg +0 -0
  17. data/examples/sounds/k3b_error1.wav +0 -0
  18. data/examples/soundy.rb +40 -0
  19. data/examples/spritey.rb +90 -0
  20. data/lib/nimo.rb +35 -0
  21. data/lib/nimo/behavior/deflector.rb +39 -0
  22. data/lib/nimo/behavior/moveable.rb +33 -0
  23. data/lib/nimo/behavior/projectile.rb +23 -0
  24. data/lib/nimo/behavior/with_velocity.rb +28 -0
  25. data/lib/nimo/game_object.rb +58 -0
  26. data/lib/nimo/game_window.rb +59 -0
  27. data/lib/nimo/listeners/event_listener.rb +27 -0
  28. data/lib/nimo/listeners/input_listener.rb +70 -0
  29. data/lib/nimo/representations/image_representation.rb +18 -0
  30. data/lib/nimo/representations/object_representation.rb +67 -0
  31. data/lib/nimo/representations/quad_representation.rb +23 -0
  32. data/lib/nimo/representations/sprite_representation.rb +78 -0
  33. data/lib/nimo/representations/text_representation.rb +27 -0
  34. data/lib/nimo/screen.rb +103 -0
  35. data/lib/nimo/utils/game.rb +63 -0
  36. data/lib/nimo/utils/intersection.rb +30 -0
  37. data/lib/nimo/utils/object_extension.rb +17 -0
  38. data/lib/nimo/utils/resources.rb +51 -0
  39. data/nimo.gemspec +117 -0
  40. data/spec/nimo/behavior/deflector_spec.rb +51 -0
  41. data/spec/nimo/behavior/moveable_spec.rb +81 -0
  42. data/spec/nimo/behavior/projectile_spec.rb +34 -0
  43. data/spec/nimo/behavior/with_velocity_spec.rb +18 -0
  44. data/spec/nimo/game_object_spec.rb +169 -0
  45. data/spec/nimo/game_window_spec.rb +88 -0
  46. data/spec/nimo/listeners/event_listener_spec.rb +34 -0
  47. data/spec/nimo/listeners/input_listener_spec.rb +87 -0
  48. data/spec/nimo/representations/image_representation_spec.rb +41 -0
  49. data/spec/nimo/representations/object_representation_spec.rb +74 -0
  50. data/spec/nimo/representations/sprite_representation_spec.rb +73 -0
  51. data/spec/nimo/representations/text_representation_spec.rb +21 -0
  52. data/spec/nimo/screen_spec.rb +114 -0
  53. data/spec/nimo/utils/game_spec.rb +44 -0
  54. data/spec/nimo/utils/object_extension_spec.rb +21 -0
  55. data/spec/nimo/utils/resources_spec.rb +59 -0
  56. data/spec/spec_helper.rb +9 -0
  57. metadata +133 -0
data/nimo.gemspec ADDED
@@ -0,0 +1,117 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{nimo}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["moonpxi"]
12
+ s.date = %q{2009-09-17}
13
+ s.email = %q{paulo.schneider@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "examples/bouncy.rb",
26
+ "examples/eventy.rb",
27
+ "examples/images/dg_classm32.png",
28
+ "examples/images/dg_dungeon32.png",
29
+ "examples/images/jeeklabs.png",
30
+ "examples/images/tcheco.png",
31
+ "examples/imagey.rb",
32
+ "examples/screeny.rb",
33
+ "examples/simplest.rb",
34
+ "examples/sounds/KDE-Sys-Log-Out.ogg",
35
+ "examples/sounds/k3b_error1.wav",
36
+ "examples/soundy.rb",
37
+ "examples/spritey.rb",
38
+ "lib/nimo.rb",
39
+ "lib/nimo/behavior/deflector.rb",
40
+ "lib/nimo/behavior/moveable.rb",
41
+ "lib/nimo/behavior/projectile.rb",
42
+ "lib/nimo/behavior/with_velocity.rb",
43
+ "lib/nimo/game_object.rb",
44
+ "lib/nimo/game_window.rb",
45
+ "lib/nimo/listeners/event_listener.rb",
46
+ "lib/nimo/listeners/input_listener.rb",
47
+ "lib/nimo/representations/image_representation.rb",
48
+ "lib/nimo/representations/object_representation.rb",
49
+ "lib/nimo/representations/quad_representation.rb",
50
+ "lib/nimo/representations/sprite_representation.rb",
51
+ "lib/nimo/representations/text_representation.rb",
52
+ "lib/nimo/screen.rb",
53
+ "lib/nimo/utils/game.rb",
54
+ "lib/nimo/utils/intersection.rb",
55
+ "lib/nimo/utils/object_extension.rb",
56
+ "lib/nimo/utils/resources.rb",
57
+ "nimo.gemspec",
58
+ "spec/nimo/behavior/deflector_spec.rb",
59
+ "spec/nimo/behavior/moveable_spec.rb",
60
+ "spec/nimo/behavior/projectile_spec.rb",
61
+ "spec/nimo/behavior/with_velocity_spec.rb",
62
+ "spec/nimo/game_object_spec.rb",
63
+ "spec/nimo/game_window_spec.rb",
64
+ "spec/nimo/listeners/event_listener_spec.rb",
65
+ "spec/nimo/listeners/input_listener_spec.rb",
66
+ "spec/nimo/representations/image_representation_spec.rb",
67
+ "spec/nimo/representations/object_representation_spec.rb",
68
+ "spec/nimo/representations/sprite_representation_spec.rb",
69
+ "spec/nimo/representations/text_representation_spec.rb",
70
+ "spec/nimo/screen_spec.rb",
71
+ "spec/nimo/utils/game_spec.rb",
72
+ "spec/nimo/utils/object_extension_spec.rb",
73
+ "spec/nimo/utils/resources_spec.rb",
74
+ "spec/spec_helper.rb"
75
+ ]
76
+ s.homepage = %q{http://github.com/moonpxi/nimo}
77
+ s.rdoc_options = ["--charset=UTF-8"]
78
+ s.require_paths = ["lib"]
79
+ s.rubygems_version = %q{1.3.4}
80
+ s.summary = %q{Ruby game development library using Gosu.}
81
+ s.test_files = [
82
+ "spec/nimo/behavior/deflector_spec.rb",
83
+ "spec/nimo/behavior/moveable_spec.rb",
84
+ "spec/nimo/behavior/projectile_spec.rb",
85
+ "spec/nimo/behavior/with_velocity_spec.rb",
86
+ "spec/nimo/game_object_spec.rb",
87
+ "spec/nimo/game_window_spec.rb",
88
+ "spec/nimo/listeners/event_listener_spec.rb",
89
+ "spec/nimo/listeners/input_listener_spec.rb",
90
+ "spec/nimo/representations/image_representation_spec.rb",
91
+ "spec/nimo/representations/object_representation_spec.rb",
92
+ "spec/nimo/representations/sprite_representation_spec.rb",
93
+ "spec/nimo/representations/text_representation_spec.rb",
94
+ "spec/nimo/screen_spec.rb",
95
+ "spec/nimo/utils/game_spec.rb",
96
+ "spec/nimo/utils/object_extension_spec.rb",
97
+ "spec/nimo/utils/resources_spec.rb",
98
+ "spec/spec_helper.rb",
99
+ "examples/bouncy.rb",
100
+ "examples/eventy.rb",
101
+ "examples/imagey.rb",
102
+ "examples/screeny.rb",
103
+ "examples/simplest.rb",
104
+ "examples/soundy.rb",
105
+ "examples/spritey.rb"
106
+ ]
107
+
108
+ if s.respond_to? :specification_version then
109
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
110
+ s.specification_version = 3
111
+
112
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
113
+ else
114
+ end
115
+ else
116
+ end
117
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ class StubDeflector < Nimo::GameObject
4
+ include Nimo::Behavior::Deflector
5
+
6
+ def self.for_test
7
+ StubDeflector.new(:x => 100, :y => 100, :width => 20, :height => 5)
8
+ end
9
+ end
10
+
11
+ class StubProjectile < Nimo::GameObject
12
+ include Nimo::Behavior::Projectile
13
+ end
14
+
15
+ describe Nimo::Behavior::Deflector do
16
+
17
+ def new_ball_at(x, y)
18
+ return StubProjectile.new(:x => x, :y => y, :width => 5, :height => 5, :velocity => Nimo::Behavior::Velocity.new(0.2, 0.7))
19
+ end
20
+
21
+ it "should not deflect when deflector does not collide with ball" do
22
+ ball = new_ball_at(0, 0)
23
+ previous_velocity = ball.velocity.clone
24
+
25
+ StubDeflector.for_test.deflect(ball)
26
+
27
+ ball.velocity.x.should == previous_velocity.x
28
+ ball.velocity.y.should == previous_velocity.y
29
+ end
30
+
31
+ it "should deflect vertically when hitted from above/below" do
32
+ ball = new_ball_at(105, 98)
33
+ previous_velocity = ball.velocity.clone
34
+
35
+ StubDeflector.for_test.deflect(ball)
36
+
37
+ ball.velocity.x.should == previous_velocity.x
38
+ ball.velocity.y.should == -previous_velocity.y
39
+ end
40
+
41
+ it "should deflect horizontally when hitted from left/right" do
42
+ ball = new_ball_at(97, 100)
43
+ previous_velocity = ball.velocity.clone
44
+
45
+ StubDeflector.for_test.deflect(ball)
46
+
47
+ ball.velocity.x.should == -previous_velocity.x
48
+ ball.velocity.y.should == previous_velocity.y
49
+ end
50
+
51
+ end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ class StubMoveable < Nimo::GameObject
4
+ include Nimo::Behavior::Moveable
5
+ end
6
+
7
+ describe Nimo::Behavior::Moveable do
8
+
9
+ describe "(moving)" do |variable|
10
+ it "should not move when speed is zero" do
11
+ obj = StubMoveable.new
12
+ obj.move_left
13
+
14
+ obj.x.should == 0
15
+ obj.y.should == 0
16
+ end
17
+
18
+ it "should move left" do
19
+ obj = StubMoveable.new(:speed => 5)
20
+ obj.move_left
21
+
22
+ obj.x.should == -5
23
+ obj.y.should == 0
24
+ end
25
+
26
+ it "should move right" do
27
+ obj = StubMoveable.new(:speed => 5)
28
+ obj.move_right
29
+
30
+ obj.x.should == 5
31
+ obj.y.should == 0
32
+ end
33
+
34
+ it "should move up" do
35
+ obj = StubMoveable.new(:speed => 5)
36
+ obj.move_up
37
+
38
+ obj.x.should == 0
39
+ obj.y.should == -5
40
+ end
41
+
42
+ it "should move down" do
43
+ obj = StubMoveable.new(:speed => 5)
44
+ obj.move_down
45
+
46
+ obj.x.should == 0
47
+ obj.y.should == 5
48
+ end
49
+ end
50
+
51
+ describe "(with boundary)" do
52
+ it "should stop at left boundary" do
53
+ obj = StubMoveable.new(:speed => 5, :boundary => Object.from_hash(:x => -2))
54
+ obj.move_left
55
+
56
+ obj.x.should == -2
57
+ end
58
+
59
+ it "should stop at right boundary" do
60
+ obj = StubMoveable.new(:speed => 5, :boundary => Object.from_hash(:x => 0, :width => 2))
61
+ obj.move_right
62
+
63
+ obj.x.should == 2
64
+ end
65
+
66
+ it "should stop at upper boundary" do
67
+ obj = StubMoveable.new(:speed => 5, :boundary => Object.from_hash(:y => -2))
68
+ obj.move_up
69
+
70
+ obj.y.should == -2
71
+ end
72
+
73
+ it "should stop at bottom boundary" do
74
+ obj = StubMoveable.new(:speed => 5, :boundary => Object.from_hash(:y => 0, :height => 2))
75
+ obj.move_down
76
+
77
+ obj.y.should == 2
78
+ end
79
+ end
80
+
81
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ class StubProjectile < Nimo::GameObject
4
+ include Nimo::Behavior::Projectile
5
+ end
6
+
7
+ class FlipDeflector
8
+ def deflect(projectile)
9
+ projectile.velocity.x = -projectile.velocity.x
10
+ end
11
+ end
12
+
13
+ describe Nimo::Behavior::Projectile do
14
+
15
+ it "should move according to speed and velocity" do
16
+ projectile = StubProjectile.new(:speed => 10, :velocity => Object.from_hash(:x => 0.2, :y => 0.5))
17
+
18
+ projectile.move
19
+
20
+ projectile.x.should == 2
21
+ projectile.y.should == 5
22
+ end
23
+
24
+ it "should be deflected" do
25
+ projectile = StubProjectile.new(:speed => 10, :velocity => Object.from_hash(:x => 0.2, :y => 0.5))
26
+ projectile.with_deflectors(FlipDeflector.new)
27
+
28
+ projectile.move
29
+
30
+ projectile.x.should == -2
31
+ projectile.y.should == 5
32
+ end
33
+
34
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ class StubWithVelocity < Nimo::GameObject
4
+ include Nimo::Behavior::WithVelocity
5
+ end
6
+
7
+ describe Nimo::Behavior::WithVelocity do
8
+
9
+ it "should move according to speed and velocity" do
10
+ obj = StubWithVelocity.new(:speed => 10, :velocity => Object.from_hash(:x => 0.2, :y => 0.5))
11
+
12
+ obj.move
13
+
14
+ obj.x.should == 2
15
+ obj.y.should == 5
16
+ end
17
+
18
+ end
@@ -0,0 +1,169 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Nimo::GameObject do
4
+
5
+ it "should have initial position and dimension values of 0" do
6
+ temp_obj = Nimo::GameObject.new
7
+
8
+ temp_obj.x.should be_zero
9
+ temp_obj.y.should be_zero
10
+ temp_obj.width.should be_zero
11
+ temp_obj.height.should be_zero
12
+ temp_obj.center.x.should be_zero
13
+ temp_obj.center.y.should be_zero
14
+ end
15
+
16
+ it "should override position and dimension values" do
17
+ temp_obj = Nimo::GameObject.new(:x => 10, :y => 20, :width => 30, :height => 40)
18
+
19
+ temp_obj.x.should == 10
20
+ temp_obj.y.should == 20
21
+ temp_obj.width.should == 30
22
+ temp_obj.height.should == 40
23
+ temp_obj.center.x.should == 25
24
+ temp_obj.center.y.should == 40
25
+ end
26
+
27
+ describe "(setting position and dimension)" do
28
+
29
+ it "should set object's position" do
30
+ temp_obj = Nimo::GameObject.new
31
+ temp_obj.at(10, 20)
32
+
33
+ temp_obj.x.should == 10
34
+ temp_obj.y.should == 20
35
+ end
36
+
37
+ it "should set object's dimension" do
38
+ temp_obj = Nimo::GameObject.new
39
+ temp_obj.dimension(10, 20)
40
+
41
+ temp_obj.width.should == 10
42
+ temp_obj.height.should == 20
43
+ end
44
+
45
+ it "should set object's position and dimension through config hash" do
46
+ temp_obj = Nimo::GameObject.new
47
+ temp_obj.configure_with(:x => 10, :y => 20, :width => 30, :height => 40)
48
+
49
+ temp_obj.x.should == 10
50
+ temp_obj.y.should == 20
51
+ temp_obj.width.should == 30
52
+ temp_obj.height.should == 40
53
+ end
54
+
55
+ end
56
+
57
+ describe "(collisions and intersections)" do
58
+
59
+ it "should not collide when not intersecting an object" do
60
+ temp_obj1 = Nimo::GameObject.new(:x => 10, :y => 10, :width => 20, :height => 20)
61
+ temp_obj2 = Nimo::GameObject.new(:x => 100, :y => 100, :width => 20, :height => 20)
62
+
63
+ temp_obj1.collide?(temp_obj2).should be_false
64
+ temp_obj2.collide?(temp_obj1).should be_false
65
+ temp_obj1.intersection(temp_obj2).should be_nil
66
+ temp_obj2.intersection(temp_obj1).should be_nil
67
+ end
68
+
69
+ it "should collide with itself" do
70
+ temp_obj = Nimo::GameObject.new(:x => 10, :y => 10, :width => 20, :height => 20)
71
+
72
+ temp_obj.collide?(temp_obj).should be_true
73
+ assert_intersection(temp_obj.intersection(temp_obj), 10, 10, 20, 20)
74
+ end
75
+
76
+ it "should collide when intersecting through the left/right" do
77
+ temp_obj1 = Nimo::GameObject.new(:x => 10, :y => 10, :width => 20, :height => 20)
78
+ temp_obj2 = Nimo::GameObject.new(:x => 20, :y => 20, :width => 50, :height => 5)
79
+
80
+ temp_obj1.collide?(temp_obj2).should be_true
81
+ temp_obj2.collide?(temp_obj1).should be_true
82
+ assert_intersection(temp_obj1.intersection(temp_obj2), 20, 20, 10, 5)
83
+ assert_intersection(temp_obj2.intersection(temp_obj1), 20, 20, 10, 5)
84
+ end
85
+
86
+ it "should collide when intersecting through the left-top corner/right-bottom corner" do
87
+ temp_obj1 = Nimo::GameObject.new(:x => 10, :y => 10, :width => 20, :height => 20)
88
+ temp_obj2 = Nimo::GameObject.new(:x => 20, :y => 20, :width => 50, :height => 50)
89
+
90
+ temp_obj1.collide?(temp_obj2).should be_true
91
+ temp_obj2.collide?(temp_obj1).should be_true
92
+ assert_intersection(temp_obj1.intersection(temp_obj2), 20, 20, 10, 10)
93
+ assert_intersection(temp_obj2.intersection(temp_obj1), 20, 20, 10, 10)
94
+ end
95
+
96
+ it "should collide when intersecting through the top/bottom" do
97
+ temp_obj1 = Nimo::GameObject.new(:x => 10, :y => 10, :width => 20, :height => 20)
98
+ temp_obj2 = Nimo::GameObject.new(:x => 20, :y => 5, :width => 5, :height => 50)
99
+
100
+ temp_obj1.collide?(temp_obj2).should be_true
101
+ temp_obj2.collide?(temp_obj1).should be_true
102
+ assert_intersection(temp_obj1.intersection(temp_obj2), 20, 10, 5, 20)
103
+ assert_intersection(temp_obj2.intersection(temp_obj1), 20, 10, 5, 20)
104
+ end
105
+
106
+ it "should collide when intersecting through the right-top corner/left-bottom corner" do
107
+ temp_obj1 = Nimo::GameObject.new(:x => 10, :y => 10, :width => 20, :height => 20)
108
+ temp_obj2 = Nimo::GameObject.new(:x => 20, :y => 5, :width => 30, :height => 30)
109
+
110
+ temp_obj1.collide?(temp_obj2).should be_true
111
+ temp_obj2.collide?(temp_obj1).should be_true
112
+ assert_intersection(temp_obj1.intersection(temp_obj2), 20, 10, 10, 20)
113
+ assert_intersection(temp_obj2.intersection(temp_obj1), 20, 10, 10, 20)
114
+ end
115
+
116
+ it "should collide when an object encompasses the other" do
117
+ temp_obj1 = Nimo::GameObject.new(:x => 10, :y => 10, :width => 20, :height => 20)
118
+ temp_obj2 = Nimo::GameObject.new(:x => 5, :y => 5, :width => 100, :height => 100)
119
+
120
+ temp_obj1.collide?(temp_obj2).should be_true
121
+ temp_obj2.collide?(temp_obj1).should be_true
122
+ assert_intersection(temp_obj1.intersection(temp_obj2), 10, 10, 20, 20)
123
+ assert_intersection(temp_obj2.intersection(temp_obj1), 10, 10, 20, 20)
124
+ end
125
+
126
+ def assert_intersection(obj, x, y, width, height)
127
+ obj.x.should == x
128
+ obj.y.should == y
129
+ obj.width.should == width
130
+ obj.height.should == height
131
+ end
132
+ end
133
+
134
+ describe "(event notification)" do
135
+
136
+ it "should notify event to registered listener" do
137
+ mock_listener = mock("listener")
138
+ mock_listener.should_receive(:notify).with(:some_event)
139
+
140
+ obj = Nimo::GameObject.new
141
+ obj.register_listener(:some_event, mock_listener)
142
+ obj.notify(:some_event)
143
+ end
144
+
145
+ it "should notify multiple listeners" do
146
+ mock_listener1 = mock("listener")
147
+ mock_listener2 = mock("listener")
148
+ mock_listener1.should_receive(:notify).with(:some_event)
149
+ mock_listener2.should_receive(:notify).with(:some_event)
150
+
151
+ obj = Nimo::GameObject.new
152
+ obj.register_listener(:some_event, mock_listener1)
153
+ obj.register_listener(:some_event, mock_listener2)
154
+ obj.notify(:some_event)
155
+ end
156
+
157
+ it "should not notify event of different type" do
158
+ mock_listener = mock("listener")
159
+ mock_listener.should_not_receive(:notify).with(:another_event)
160
+ mock_listener.should_not_receive(:notify).with(:some_event)
161
+
162
+ obj = Nimo::GameObject.new
163
+ obj.register_listener(:some_event, mock_listener)
164
+ obj.notify(:another_event)
165
+ end
166
+
167
+ end
168
+
169
+ end