yeah 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +51 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +7 -0
- data/README.md +99 -0
- data/lib/yeah/entity.rb +31 -0
- data/lib/yeah/game.rb +11 -0
- data/lib/yeah/vector.rb +130 -0
- data/lib/yeah.rb +7 -0
- data/spec/entity_spec.rb +48 -0
- data/spec/game_spec.rb +32 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/vector_spec.rb +197 -0
- data/spec/yeah_spec.rb +14 -0
- data/tmp/rspec_guard_result +1 -0
- data/yeah-0.0.2.gem +0 -0
- data/yeah.gemspec +18 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f0c6e5215bc7f40ed78d1fba8db16ff7b0adf9d3
|
4
|
+
data.tar.gz: ddc2c5ebf36519ba42d7ddffd788dc4d20092534
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00dcbd4572d660d377624cc12b49412ef26b56844734c3bd43fe93fb24049179531fd956ed63aef47e584b48accbe465239cf5747663ab98db2a9d2773ab206e
|
7
|
+
data.tar.gz: 50f5ad56743ee6291682f66302cdddb75931502f2a205926dce1041b3012ee6df461453d5f9bbcd00c8d22f71e04f996b4202bf0cf7a12ee0cf83804ee44f30c
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.0.9)
|
5
|
+
diff-lcs (1.2.4)
|
6
|
+
ffi (1.9.0)
|
7
|
+
formatador (0.2.4)
|
8
|
+
guard (1.8.1)
|
9
|
+
formatador (>= 0.2.4)
|
10
|
+
listen (>= 1.0.0)
|
11
|
+
lumberjack (>= 1.0.2)
|
12
|
+
pry (>= 0.9.10)
|
13
|
+
thor (>= 0.14.6)
|
14
|
+
guard-rspec (3.0.2)
|
15
|
+
guard (>= 1.8)
|
16
|
+
rspec (~> 2.13)
|
17
|
+
libnotify (0.8.1)
|
18
|
+
ffi (>= 1.0.11)
|
19
|
+
listen (1.2.2)
|
20
|
+
rb-fsevent (>= 0.9.3)
|
21
|
+
rb-inotify (>= 0.9)
|
22
|
+
rb-kqueue (>= 0.2)
|
23
|
+
lumberjack (1.0.4)
|
24
|
+
method_source (0.8.1)
|
25
|
+
pry (0.9.12.2)
|
26
|
+
coderay (~> 1.0.5)
|
27
|
+
method_source (~> 0.8)
|
28
|
+
slop (~> 3.4)
|
29
|
+
rb-fsevent (0.9.3)
|
30
|
+
rb-inotify (0.9.0)
|
31
|
+
ffi (>= 0.5.0)
|
32
|
+
rb-kqueue (0.2.0)
|
33
|
+
ffi (>= 0.5.0)
|
34
|
+
rspec (2.14.1)
|
35
|
+
rspec-core (~> 2.14.0)
|
36
|
+
rspec-expectations (~> 2.14.0)
|
37
|
+
rspec-mocks (~> 2.14.0)
|
38
|
+
rspec-core (2.14.5)
|
39
|
+
rspec-expectations (2.14.2)
|
40
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
41
|
+
rspec-mocks (2.14.3)
|
42
|
+
slop (3.4.5)
|
43
|
+
thor (0.18.1)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
guard-rspec
|
50
|
+
libnotify
|
51
|
+
rspec
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2013 Artur Ostrega
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
Yeah
|
2
|
+
====
|
3
|
+
The positive video game framework
|
4
|
+
|
5
|
+
Ruby is a good fit for game development for the following reasons:
|
6
|
+
* Ruby is optimized for developer happiness, and this framework is, too. A happy developer is a productive developer, which translates into more games made and with greater passion.
|
7
|
+
* Ruby has great object-oriented syntax that makes a lot of sense for game constructs.
|
8
|
+
* Ruby's expressiveness reduces development time and makes it easier to experiment.
|
9
|
+
* Ruby supports operator overloading, which is very handy for the linear algebra that is typically abundant in game code.
|
10
|
+
* Code testing is wonderful and ubiquitous in the Ruby community, but the game development community has not embraced it. I hope this framework will help change that.
|
11
|
+
* [Rubygame](https://github.com/rubygame/rubygame/), [Opal](https://github.com/opal/opal), [Ruboto](https://github.com/ruboto/ruboto) and [MobiRuby](https://github.com/mobiruby/mobiruby-ios) would allow games to target the desktop, web, and mobile using the same codebase.
|
12
|
+
* The Ruby and game development communities are both particularly artistic as far as software development communities go.
|
13
|
+
|
14
|
+
So here's the plan
|
15
|
+
------------------
|
16
|
+
|
17
|
+
### Vector
|
18
|
+
`Vector` instances represent position, distance, velocity, etc. For the sake of simplicity, all `Vector` instances are three-dimensional and missing components default to 0. This is not problematic for 2D game development because one can treat a three-dimensional vector with a third component of 0 as a two-dimensional vector in practice. `Vector` has method aliases for various synonyms and contexts.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
Vector[] #=> Vector[0, 0, 0]
|
22
|
+
v1 = Vector[2, 4, 16] #=> Vector[2, 4, 16]
|
23
|
+
v1[0] #=> 2
|
24
|
+
v1.height #=> 4
|
25
|
+
v1.z #=> 16
|
26
|
+
v2 = Vector[1.5, 2] * 2 #=> Vector[3, 4, 0]
|
27
|
+
v2.norm #=> 5
|
28
|
+
v2.magnitude #=> 5
|
29
|
+
v2.length #=> 5
|
30
|
+
v2.distance #=> 5
|
31
|
+
v2.speed #=> 5
|
32
|
+
```
|
33
|
+
|
34
|
+
### Entity
|
35
|
+
`Entity` instances are objects that behave in the context of a `Game` instance. Each has a `Vector` `position`, and may have a `Vector` `size` and `Visual` `visual`. An `Entity` instance has an `update` method which is continuously called by its `Game` instance. `Entity` is meant to be built upon.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class Paddle < Entity
|
39
|
+
def initialize(*args)
|
40
|
+
super(*args) # attach to Game instance and set up position
|
41
|
+
@visual = Image.new("gfx/paddle.png")
|
42
|
+
@speed = 5
|
43
|
+
@velocity = Vector[]
|
44
|
+
end
|
45
|
+
|
46
|
+
def update
|
47
|
+
@velocity.reset # same as `@velocity = Vector[0, 0, 0]`
|
48
|
+
|
49
|
+
if pressing? :left || pressing? :a # if the left arrow key or A key is pressed...
|
50
|
+
@velocity.x -= @speed # increase @velocity to the left
|
51
|
+
end
|
52
|
+
|
53
|
+
if pressing? :right || pressing? :d # if right arrow or D is pressed...
|
54
|
+
@velocity.x += @speed # increase @velocity to the right
|
55
|
+
end
|
56
|
+
|
57
|
+
if touching? Wall # if next to or intersecting a Wall...
|
58
|
+
unintersect Wall # fancy function to unintersect from any Wall
|
59
|
+
@velocity.reset # all of our previous button pressing was for naught
|
60
|
+
end
|
61
|
+
|
62
|
+
@position += @velocity # move (or perhaps not)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
p = Paddle.new(20, 30) #=> Paddle at (20, 30, 0)
|
67
|
+
p.position #=> Vector[20, 30, 0]
|
68
|
+
p.y #=> 30 # method alias!
|
69
|
+
```
|
70
|
+
|
71
|
+
### Map
|
72
|
+
Maps are Ruby hashes that can be parsed from JSON. Upon loading a map into a `Game` instance, the game looks for an `entities` key with a value of a hash with keys that correspond to `Entity` subclass names. Each of these keys have a value that is an array of up to 3 numeric elements or an array of said arrays. These numeric arrays represent coordinates at which to instantiate said `Entity` subclasses. Maps can also contain arbitrary data.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
level4 = {
|
76
|
+
entities: {
|
77
|
+
Teal: [10, 10], # instantiate Entity subclass Teal at (10, 10, 0)
|
78
|
+
Behemoth: [ # instantiate Behemoth at three different coordinates
|
79
|
+
[50, 10],
|
80
|
+
[100, 10],
|
81
|
+
[150, 10]
|
82
|
+
]
|
83
|
+
},
|
84
|
+
name: "Level 4", # arbitrary data
|
85
|
+
time_limit: 300 # this too
|
86
|
+
}
|
87
|
+
```
|
88
|
+
|
89
|
+
### Game
|
90
|
+
A `Game` instance holds `Entity` instances in an `entities` array and runs their `update` methods on each frame. Assigning a map to `map` replaces `entities` with an array of new instances according to the map.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
g = Game.new #=> Game
|
94
|
+
g.entities #=> []
|
95
|
+
g.entities << Paddle.new #=> [Paddle]
|
96
|
+
g.entities #=> [Paddle]
|
97
|
+
g.map = level4
|
98
|
+
g.entities #=> [Teal, Behemoth, Behemoth, Behemoth]
|
99
|
+
```
|
data/lib/yeah/entity.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Yeah::Entity
|
2
|
+
attr_accessor :position
|
3
|
+
|
4
|
+
def initialize(*position)
|
5
|
+
@position = Yeah::Vector[*position]
|
6
|
+
end
|
7
|
+
|
8
|
+
def x
|
9
|
+
@position.x
|
10
|
+
end
|
11
|
+
|
12
|
+
def x=(value)
|
13
|
+
@position.x = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def y
|
17
|
+
@position.y
|
18
|
+
end
|
19
|
+
|
20
|
+
def y=(value)
|
21
|
+
@position.y = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def z
|
25
|
+
@position.z
|
26
|
+
end
|
27
|
+
|
28
|
+
def z=(value)
|
29
|
+
@position.z = value
|
30
|
+
end
|
31
|
+
end
|
data/lib/yeah/game.rb
ADDED
data/lib/yeah/vector.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
class Yeah::Vector
|
2
|
+
class << self
|
3
|
+
alias_method :[], :new
|
4
|
+
end
|
5
|
+
|
6
|
+
def initialize(*components)
|
7
|
+
if components.size > 3
|
8
|
+
error_message = "too many arguments (#{components.size} for up to 3)"
|
9
|
+
raise ArgumentError, error_message
|
10
|
+
end
|
11
|
+
|
12
|
+
self.components = components
|
13
|
+
end
|
14
|
+
|
15
|
+
def components
|
16
|
+
@components
|
17
|
+
end
|
18
|
+
|
19
|
+
def components=(values)
|
20
|
+
if values.size > 3
|
21
|
+
error_message = "too many elements (#{values.size} for up to 3)"
|
22
|
+
raise ArgumentError, error_message
|
23
|
+
end
|
24
|
+
|
25
|
+
@components = values + [0] * (3 - values.size)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(other)
|
29
|
+
other.class == self.class && @components == other.components ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](index)
|
33
|
+
@components[index]
|
34
|
+
end
|
35
|
+
|
36
|
+
def []=(index, value)
|
37
|
+
@components[index] = value
|
38
|
+
end
|
39
|
+
|
40
|
+
def +(addend)
|
41
|
+
case addend
|
42
|
+
when self.class
|
43
|
+
comp_addends = addend.components
|
44
|
+
when Numeric
|
45
|
+
comp_addends = [addend] * 3
|
46
|
+
end
|
47
|
+
components = @components.zip(comp_addends).map { |c| c.reduce(:+) }
|
48
|
+
|
49
|
+
self.class[*components]
|
50
|
+
end
|
51
|
+
|
52
|
+
def -(subtrahend)
|
53
|
+
case subtrahend
|
54
|
+
when self.class
|
55
|
+
comp_subtrahends = subtrahend.components
|
56
|
+
when Numeric
|
57
|
+
comp_subtrahends = [subtrahend] * 3
|
58
|
+
end
|
59
|
+
components = @components.zip(comp_subtrahends).map { |c| c.reduce(:-)}
|
60
|
+
|
61
|
+
self.class[*components]
|
62
|
+
end
|
63
|
+
|
64
|
+
def *(multiple)
|
65
|
+
case multiple
|
66
|
+
when self.class
|
67
|
+
comp_multiples = multiple.components
|
68
|
+
when Numeric
|
69
|
+
comp_multiples = [multiple] * 3
|
70
|
+
end
|
71
|
+
|
72
|
+
components = @components.zip(comp_multiples).map { |c| c.reduce(:*) }
|
73
|
+
self.class[*components]
|
74
|
+
end
|
75
|
+
|
76
|
+
def /(divisor)
|
77
|
+
case divisor
|
78
|
+
when self.class
|
79
|
+
comp_divisors = divisor.components
|
80
|
+
when Numeric
|
81
|
+
comp_divisors = [divisor] * 3
|
82
|
+
end
|
83
|
+
|
84
|
+
components = @components.zip(comp_divisors).map { |c| c.reduce(:/) }
|
85
|
+
self.class[*components]
|
86
|
+
end
|
87
|
+
|
88
|
+
def x
|
89
|
+
@components[0]
|
90
|
+
end
|
91
|
+
alias_method :width, :x
|
92
|
+
|
93
|
+
def y
|
94
|
+
@components[1]
|
95
|
+
end
|
96
|
+
alias_method :height, :y
|
97
|
+
|
98
|
+
def z
|
99
|
+
@components[2]
|
100
|
+
end
|
101
|
+
alias_method :depth, :z
|
102
|
+
|
103
|
+
def x=(value)
|
104
|
+
@components[0] = value
|
105
|
+
end
|
106
|
+
alias_method :width=, :x=
|
107
|
+
|
108
|
+
def y=(value)
|
109
|
+
@components[1] = value
|
110
|
+
end
|
111
|
+
alias_method :height=, :y=
|
112
|
+
|
113
|
+
def z=(value)
|
114
|
+
@components[2] = value
|
115
|
+
end
|
116
|
+
alias_method :depth=, :z=
|
117
|
+
|
118
|
+
def norm
|
119
|
+
Math.sqrt(@components.reduce(0) { |m, c| m + c*c })
|
120
|
+
end
|
121
|
+
alias_method :magnitude, :norm
|
122
|
+
alias_method :length, :norm
|
123
|
+
alias_method :distance, :norm
|
124
|
+
alias_method :speed, :norm
|
125
|
+
|
126
|
+
def reset
|
127
|
+
@components = [0, 0, 0]
|
128
|
+
self
|
129
|
+
end
|
130
|
+
end
|
data/lib/yeah.rb
ADDED
data/spec/entity_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yeah::Entity do
|
4
|
+
let(:klass) { Yeah::Entity }
|
5
|
+
let(:instance) { klass.new }
|
6
|
+
|
7
|
+
it { klass.should be_instance_of Class }
|
8
|
+
|
9
|
+
describe '::new' do
|
10
|
+
subject(:method) { klass.method(:new) }
|
11
|
+
|
12
|
+
it { method.call.should be_instance_of klass }
|
13
|
+
it { method.call.position.should eq Yeah::Vector[0, 0, 0] }
|
14
|
+
it { method.call(2, 4, 8).position.should eq Yeah::Vector[2, 4, 8] }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#position' do
|
18
|
+
subject(:position) { instance.position }
|
19
|
+
|
20
|
+
it { should be_instance_of Yeah::Vector }
|
21
|
+
it { position.components.should eq [0, 0, 0] }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#position=' do
|
25
|
+
it "assigns position" do
|
26
|
+
vector = Yeah::Vector[Random.rand(100)]
|
27
|
+
instance.position = vector
|
28
|
+
instance.position.should eq vector
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
[:x, :y, :z].each do |method_name|
|
33
|
+
describe "##{method_name}" do
|
34
|
+
it "is #position.#{method_name}" do
|
35
|
+
instance.position.send("#{method_name}=", Random.rand(100))
|
36
|
+
instance.send(method_name).should eq instance.position.send(method_name)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "##{method_name}=" do
|
41
|
+
it "assigns #position.#{method_name}" do
|
42
|
+
value = Random.rand(100)
|
43
|
+
instance.send("#{method_name}=", value)
|
44
|
+
instance.position.send(method_name).should eq value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/game_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yeah::Game do
|
4
|
+
let(:klass) { Yeah::Game }
|
5
|
+
let(:instance) { klass.new }
|
6
|
+
|
7
|
+
it { klass.should be_instance_of Class }
|
8
|
+
|
9
|
+
describe '#entities' do
|
10
|
+
subject(:entities) { instance.entities }
|
11
|
+
|
12
|
+
it { should eq [] }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#entities=' do
|
16
|
+
it "assigns #entities" do
|
17
|
+
value = [Yeah::Entity.new(Random.rand(100))]
|
18
|
+
instance.entities = value
|
19
|
+
instance.entities.should eq value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#update' do
|
24
|
+
it "calls #update of each element in #entities" do
|
25
|
+
instance.entities = (1..3).map { DummyEntity.new }
|
26
|
+
update_count = Random.rand(5)
|
27
|
+
update_count.times { instance.update }
|
28
|
+
|
29
|
+
instance.entities.each { |e| e.update_count.should eq update_count }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/vector_spec.rb
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yeah::Vector do
|
4
|
+
let(:klass) { Yeah::Vector }
|
5
|
+
let(:arguments) { (1..3).map { Random.rand(100) } }
|
6
|
+
let(:instance) { klass.new(*arguments) }
|
7
|
+
|
8
|
+
it { klass.should be_instance_of Class }
|
9
|
+
|
10
|
+
[:new, :[]].each do |method_name|
|
11
|
+
describe "::#{method_name}" do
|
12
|
+
subject(:method) { klass.method(method_name) }
|
13
|
+
|
14
|
+
it { method.call.should be_instance_of klass }
|
15
|
+
it { method.call.components.should eq [0, 0, 0] }
|
16
|
+
it { method.call(4, 5, 6).components.should eq [4, 5, 6] }
|
17
|
+
it { method.call(8, 9).components.should eq [8, 9, 0] }
|
18
|
+
it { method.call(7).components.should eq [7, 0, 0] }
|
19
|
+
|
20
|
+
it "complains with 4 arguments" do
|
21
|
+
expect { method.call(7, 8, 9, 10) }.
|
22
|
+
to raise_error ArgumentError, /too many arguments/
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#components' do
|
28
|
+
subject(:components) { instance.components }
|
29
|
+
|
30
|
+
it { should be_instance_of Array }
|
31
|
+
it { should have(3).elements }
|
32
|
+
it { components.each { |c| c.should be_kind_of Numeric } }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#components=' do
|
36
|
+
it "assigns array of up to 3 elements and uses 0 for missing elements" do
|
37
|
+
instance.components = [4, 5, 6]
|
38
|
+
instance.components.should eq [4, 5, 6]
|
39
|
+
|
40
|
+
instance.components = [8, 9]
|
41
|
+
instance.components.should eq [8, 9, 0]
|
42
|
+
|
43
|
+
instance.components = []
|
44
|
+
instance.components.should eq [0, 0, 0]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "complains with 4-element array" do
|
48
|
+
expect { instance.components = [7, 8, 9, 10] }.
|
49
|
+
to raise_error ArgumentError, /too many elements/
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#==' do
|
54
|
+
it { (instance == klass[*instance.components]).should eq true }
|
55
|
+
it { (instance == klass[*instance.components.reverse]).should eq false }
|
56
|
+
it { (instance == nil).should eq false }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#[]' do
|
60
|
+
it { instance[0].should eq arguments[0] }
|
61
|
+
it { instance[1].should eq arguments[1] }
|
62
|
+
it { instance[2].should eq arguments[2] }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#[]=' do
|
66
|
+
it "assigns n component" do
|
67
|
+
3.times do |i|
|
68
|
+
instance[i] = instance[i] + 5
|
69
|
+
instance[i].should eq arguments[i] + 5
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#+' do
|
75
|
+
it "adds Vector" do
|
76
|
+
sum = instance + instance
|
77
|
+
sum.components.each_with_index do |component, i|
|
78
|
+
component.should eq instance.components[i] * 2
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "adds Numeric" do
|
83
|
+
addend = Random.rand(100)
|
84
|
+
sum = instance + addend
|
85
|
+
|
86
|
+
sum.components.each_with_index do |component, i|
|
87
|
+
component.should eq instance.components[i] + addend
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#-' do
|
93
|
+
it "subtracts Vector" do
|
94
|
+
difference = instance - instance
|
95
|
+
difference.components.each do |component|
|
96
|
+
component.should eq 0
|
97
|
+
end
|
98
|
+
|
99
|
+
difference2 = difference - instance
|
100
|
+
difference2.components.each_with_index do |component, i|
|
101
|
+
component.should eq -instance.components[i]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "subtracts Numeric" do
|
106
|
+
subtrahend = Random.rand(100)
|
107
|
+
difference = instance + subtrahend
|
108
|
+
|
109
|
+
difference.components.each_with_index do |component, i|
|
110
|
+
component.should eq instance.components[i] + subtrahend
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#*' do
|
116
|
+
it "multiplies by Vector" do
|
117
|
+
product = instance * instance
|
118
|
+
product.components.each_with_index do |component, i|
|
119
|
+
component.should eq instance.components[i] ** 2
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it "multiplies by Numeric" do
|
124
|
+
multiple = Random.rand(100)
|
125
|
+
product = instance * multiple
|
126
|
+
|
127
|
+
product.components.each_with_index do |component, i|
|
128
|
+
component.should eq instance.components[i] * multiple
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#/' do
|
134
|
+
it "divides by Vector" do
|
135
|
+
quotient = instance / instance
|
136
|
+
quotient.components.each do |component|
|
137
|
+
component.should eq 1
|
138
|
+
end
|
139
|
+
|
140
|
+
quotient2 = instance / quotient
|
141
|
+
quotient2.components.each_with_index do |component, i|
|
142
|
+
component.should eq instance.components[i]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "divides by Numeric" do
|
147
|
+
divisor = Random.rand(100)
|
148
|
+
quotient = instance / divisor
|
149
|
+
|
150
|
+
quotient.components.each_with_index do |component, i|
|
151
|
+
component.should eq instance.components[i] / divisor
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
[
|
157
|
+
[:x, :width],
|
158
|
+
[:y, :height],
|
159
|
+
[:z, :depth]
|
160
|
+
].each_with_index do |method_name_set, i|
|
161
|
+
method_name_set.each do |method_name|
|
162
|
+
describe "##{method_name}" do
|
163
|
+
subject(:method) { instance.method(method_name) }
|
164
|
+
|
165
|
+
it { method.call.should eq instance[i] }
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "#{method_name}=" do
|
169
|
+
subject(:method) { instance.method("#{method_name}=") }
|
170
|
+
|
171
|
+
it "assigns value" do
|
172
|
+
value = Random.rand(100)
|
173
|
+
method.call(value)
|
174
|
+
instance[i].should eq value
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
[:norm, :magnitude, :length, :distance, :speed].each do |method_name|
|
181
|
+
describe "##{method_name}" do
|
182
|
+
it { klass.new(3, 4).method(method_name).call.should eq 5 }
|
183
|
+
it { klass.new(6, 8).method(method_name).call.should eq 10 }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe '#reset' do
|
188
|
+
it "sets components to 0" do
|
189
|
+
instance.reset
|
190
|
+
instance.components.should eq [0, 0, 0]
|
191
|
+
end
|
192
|
+
|
193
|
+
it "returns itself" do
|
194
|
+
instance.reset.should eq instance
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
data/spec/yeah_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yeah do
|
4
|
+
it "is a Module" do
|
5
|
+
Yeah.should be_instance_of Module
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '::VERSION' do
|
9
|
+
subject { Yeah::VERSION }
|
10
|
+
|
11
|
+
it { should be_instance_of String }
|
12
|
+
it { should match /[0-9]+\.[0-9]+\.[0-9]+/ }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/yeah-0.0.2.gem
ADDED
Binary file
|
data/yeah.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib/', __FILE__)
|
4
|
+
$:.unshift lib unless $:.include?(lib)
|
5
|
+
|
6
|
+
require 'yeah'
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = 'yeah'
|
10
|
+
s.version = Yeah::VERSION
|
11
|
+
s.summary = "The positive video game framework"
|
12
|
+
s.description = "Programming video games should have a positive impact on your health!"
|
13
|
+
s.authors = ["Artur Ostrega"]
|
14
|
+
s.email = 'skoofoo@gmail.com'
|
15
|
+
s.files = Dir.glob('**/*')
|
16
|
+
s.license = 'MIT'
|
17
|
+
s.homepage = 'https://github.com/skofo/yeah'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yeah
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Artur Ostrega
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Programming video games should have a positive impact on your health!
|
14
|
+
email: skoofoo@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- Gemfile
|
20
|
+
- Guardfile
|
21
|
+
- lib/yeah/game.rb
|
22
|
+
- lib/yeah/vector.rb
|
23
|
+
- lib/yeah/entity.rb
|
24
|
+
- lib/yeah.rb
|
25
|
+
- README.md
|
26
|
+
- yeah-0.0.2.gem
|
27
|
+
- tmp/rspec_guard_result
|
28
|
+
- Gemfile.lock
|
29
|
+
- yeah.gemspec
|
30
|
+
- LICENSE.txt
|
31
|
+
- spec/yeah_spec.rb
|
32
|
+
- spec/game_spec.rb
|
33
|
+
- spec/spec_helper.rb
|
34
|
+
- spec/entity_spec.rb
|
35
|
+
- spec/vector_spec.rb
|
36
|
+
homepage: https://github.com/skofo/yeah
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.0.5
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: The positive video game framework
|
60
|
+
test_files: []
|