yeah 0.3.5 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/README.md +17 -9
- data/lib/yeah/_platform/class_methods.rb +9 -0
- data/lib/yeah/_platform/display.rb +112 -44
- data/lib/yeah/_platform/font.rb +10 -0
- data/lib/yeah/_template/Gemfile +3 -3
- data/lib/yeah/_template/code/config.rb +4 -0
- data/lib/yeah/constants.rb +1 -2
- data/lib/yeah/game.rb +4 -23
- data/lib/yeah/vector.rb +61 -12
- data/lib/yeah/version.rb +1 -1
- data/lib/yeah/web/builder.rb +8 -4
- data/lib/yeah/web/runner.html.erb +33 -17
- data/lib/yeah/web/server.rb +4 -0
- data/lib/yeah/web/setup.rb +1 -0
- data/opal/yeah/web.rb +4 -0
- data/opal/yeah/web/class_methods.opal +14 -0
- data/opal/yeah/web/display.opal +94 -15
- data/opal/yeah/web/font.opal +6 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9358d3033c95b213ffc6f6b8e34880d247aa8a34
|
4
|
+
data.tar.gz: 636ce5c237cc12d40f0f1fc832e5433df6d92182
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3115c006cadf70c7e3052cb4cb6937e17a3be3b0389791e61ec2103581d73a197fbc4dcfa1e1ebc34501b789ffa2af0914a2e88fc6363db4a45f3697d55a145d
|
7
|
+
data.tar.gz: 481caa7ec53564160a1ac3edb80f052a4a115c5b9ff2d83fd13071dbd4cda26bf629600dda30669ab227e824aa521c80e1060e422ad0d03928cf7a95994cdec0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
0.4.2 (2014-09-14)
|
2
|
+
------------------
|
3
|
+
* Need sleep.
|
4
|
+
|
5
|
+
0.4.1 (2014-09-14)
|
6
|
+
------------------
|
7
|
+
* Fixed `yeah build`.
|
8
|
+
|
9
|
+
0.4.0 (2014-09-14)
|
10
|
+
------------------
|
11
|
+
* New `Font` class
|
12
|
+
* `Web` runner scales game display to use all available space
|
13
|
+
* New configuration system; title and factorial scaling configuration
|
14
|
+
* `Display` replaced `#font_family` & `#font_size` with `#text_font` & `#text_size`
|
15
|
+
* `Vector` added `#==`, `#add[!]`, `#subtract[!]`, `#multiply[!]`, `#divide[!]`
|
16
|
+
* `Vector#toward[!]` works in 3 dimensions
|
17
|
+
* `Display#rotate` takes `Vector` instead of `Numeric`
|
18
|
+
* `Display#[translate|scale|rotate]_[x|y|z]` added
|
19
|
+
* `Display` added `#stroke_curve` and `#stroke_curve2`
|
20
|
+
* `Display#transformation` removed
|
21
|
+
* `Game::config` removed
|
22
|
+
* `yeah build` builds to `builds`
|
23
|
+
* Secure Rubygems for Gemfile in game projects (thanks cokernel)
|
24
|
+
* Tests made platform-agnostic
|
25
|
+
* Interface tests for most classes, some `Display` draw tests, some `Color` initialization tests
|
26
|
+
* Benchmarks made more consistent
|
27
|
+
* Various bug fixes
|
28
|
+
* Documentation cleanup
|
29
|
+
|
1
30
|
0.3.5 (2014-08-24)
|
2
31
|
------------------
|
3
32
|
* Updated project structure; new entrypoint is `code/game.rb`
|
data/README.md
CHANGED
@@ -16,16 +16,15 @@ Practical Ruby video game framework, alpha stage
|
|
16
16
|
|
17
17
|
## Examples
|
18
18
|
|
19
|
-
[Code for all examples]
|
19
|
+
[Code for all examples][Example code]
|
20
20
|
|
21
|
-
[![Asteroids](https://cdn.mediacru.sh/IkYZP46TmCsd.png)]
|
21
|
+
[![Asteroids](https://cdn.mediacru.sh/IkYZP46TmCsd.png)][Asteroids example]
|
22
22
|
|
23
|
-
[*Asteroids*]
|
23
|
+
[*Asteroids*][Asteroids example]
|
24
24
|
|
25
|
-
[![Random](https://cdn.mediacru.sh/KW9M6TndLry0.png)]
|
26
|
-
|
27
|
-
[*Random*](https://yeahrb.github.io/examples/random/runner.html)
|
25
|
+
[![Random](https://cdn.mediacru.sh/KW9M6TndLry0.png)][Random example]
|
28
26
|
|
27
|
+
[*Random*][Random example]
|
29
28
|
|
30
29
|
## Usage
|
31
30
|
|
@@ -40,17 +39,26 @@ NOTE: This is alpha-stage software, expect changes!
|
|
40
39
|
### Making a game
|
41
40
|
|
42
41
|
1. In a command line, enter `yeah new` to generate a new game project.
|
43
|
-
2. Change into the new
|
44
|
-
3. Add game code to `code/game.rb`. No tutorials yet; please take a look at the [example code]
|
42
|
+
2. Change into the new project directory, then enter `bundle install`.
|
43
|
+
3. Add game code to `code/game.rb`. No tutorials yet; please take a look at the [example code][Example code] and [API reference][0.4.2 API].
|
45
44
|
4. Enter `yeah serve` and visit [http://localhost:1234](http://localhost:1234) to try the game.
|
46
45
|
|
47
46
|
|
48
47
|
## Links
|
49
48
|
|
50
|
-
[0.
|
49
|
+
API reference: [0.4.2][0.4.2 API], [0.3.5][0.3.5 API]
|
50
|
+
|
51
|
+
[Version upgrade notes](https://github.com/yeahrb/yeah/blob/master/UPGRADING.md)
|
51
52
|
|
52
53
|
[Issue & feature tracker](https://github.com/yeahrb/yeah/issues)
|
53
54
|
|
54
55
|
[Discussion via Gitter](https://gitter.im/yeahrb/yeah)
|
55
56
|
|
56
57
|
[Author's email](mailto:skoofoo@gmail.com)
|
58
|
+
|
59
|
+
|
60
|
+
[0.4.2 API]: http://rdoc.info/github/yeahrb/yeah/32a50f5/frames
|
61
|
+
[0.3.5 API]: http://rdoc.info/github/yeahrb/yeah/5efbbc9/frames
|
62
|
+
[Example code]: https://github.com/yeahrb/examples
|
63
|
+
[Asteroids example]: https://yeahrb.github.io/examples/asteroids/runner.html
|
64
|
+
[Random example]: https://yeahrb.github.io/examples/random/runner.html
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Yeah
|
2
|
+
# @!method self.configure
|
3
|
+
# @abstract Provided by a `Platform`.
|
4
|
+
# @yield [config] configuration block
|
5
|
+
# @yieldparam [Struct] configuration
|
6
|
+
# @note Configuration struct attributes: `title` (String),
|
7
|
+
# `factorial_scaling` (Boolean)
|
8
|
+
# @return [nil]
|
9
|
+
end
|
@@ -7,22 +7,22 @@ class Display
|
|
7
7
|
# @param [Hash] options for new object
|
8
8
|
# @option options [Vector] :size (V[1280, 720]) of display
|
9
9
|
# @option options [String] :canvas_selector ('canvas') for canvas HTML
|
10
|
-
# element (
|
10
|
+
# element (applies only to `Web::Display`)
|
11
11
|
def initialize(options = {})
|
12
12
|
raise NotImplementedError
|
13
13
|
end
|
14
14
|
|
15
15
|
# @!attribute size
|
16
|
-
# @param [Vector] size to make display
|
17
|
-
# @return [Vector] size of display
|
16
|
+
# @param [Vector] size to make display in pixels
|
17
|
+
# @return [Vector] size of display in pixels
|
18
18
|
|
19
19
|
# @!attribute width
|
20
|
-
# @param [
|
21
|
-
# @return [
|
20
|
+
# @param [Integer] width to make display in pixels
|
21
|
+
# @return [Integer] width of display in pixels
|
22
22
|
|
23
23
|
# @!attribute height
|
24
|
-
# @param [
|
25
|
-
# @return [
|
24
|
+
# @param [Integer] height to make display in pixels
|
25
|
+
# @return [Integer] height of display in pixels
|
26
26
|
|
27
27
|
# @!attribute fill_color
|
28
28
|
# @param [Color] color for fill
|
@@ -33,78 +33,146 @@ class Display
|
|
33
33
|
# @return [Color] color for stroke
|
34
34
|
|
35
35
|
# @!attribute stroke_width
|
36
|
-
# @param [Numeric] width for stroke
|
37
|
-
# @return [Numeric] width for stroke
|
36
|
+
# @param [Numeric] width for stroke in pixels
|
37
|
+
# @return [Numeric] width for stroke in pixels
|
38
38
|
|
39
|
-
# @!attribute
|
40
|
-
# @param [
|
41
|
-
# @return [
|
39
|
+
# @!attribute text_font
|
40
|
+
# @param [Font] font for text
|
41
|
+
# @return [Font] font for text
|
42
42
|
|
43
|
-
# @!attribute
|
44
|
-
# @param [
|
45
|
-
# @return [
|
43
|
+
# @!attribute text_size
|
44
|
+
# @param [Integer] size for text in pixels
|
45
|
+
# @return [Integer] size for text in pixels
|
46
46
|
|
47
47
|
# @!method color_at(position)
|
48
48
|
# @param [Vector] position of pixel from which to get color
|
49
49
|
# @return [Color] color of pixel
|
50
50
|
|
51
|
-
# @!attribute [r] transformation
|
52
|
-
# @return [Array] transformation matrix
|
53
|
-
|
54
51
|
# @!method translate(displacement)
|
55
|
-
# @param [Vector] displacement
|
52
|
+
# @param [Vector] displacement
|
53
|
+
# @return [nil]
|
54
|
+
# @note `Web::Display#translate` is currently 2D (only X and Y apply).
|
55
|
+
# Move the transformation by a vector displacement.
|
56
|
+
|
57
|
+
# @!method translate_x(displacement)
|
58
|
+
# @param [Numeric] displacement
|
59
|
+
# @return [nil]
|
60
|
+
# Move the transformation by a displacement on the X axis.
|
61
|
+
|
62
|
+
# @!method translate_y(displacement)
|
63
|
+
# @param [Numeric] displacement
|
64
|
+
# @return [nil]
|
65
|
+
# Move the transformation by a displacement on the Y axis.
|
66
|
+
|
67
|
+
# @!method translate_z(displacement)
|
68
|
+
# @param [Numeric] displacement
|
56
69
|
# @return [nil]
|
57
|
-
# @
|
58
|
-
# Move the transformation by a
|
70
|
+
# @note No-op in `Web::Display`, which is currently 2D.
|
71
|
+
# Move the transformation by a displacement on the Z axis.
|
59
72
|
|
60
73
|
# @!method scale(multiplier)
|
61
|
-
# @param [Vector] multiplier
|
74
|
+
# @param [Vector] multiplier
|
62
75
|
# @return [nil]
|
63
|
-
# @
|
64
|
-
# Scale the transformation by a
|
76
|
+
# @note `Web::Display#scale` is currently 2D (only X and Y apply).
|
77
|
+
# Scale the transformation by a vector multiplier.
|
78
|
+
|
79
|
+
# @!method scale_x(multiplier)
|
80
|
+
# @param [Numeric] multiplier
|
81
|
+
# @return [nil]
|
82
|
+
# Scale the transformation by a multiplier on the X axis.
|
83
|
+
|
84
|
+
# @!method scale_y(multiplier)
|
85
|
+
# @param [Numeric] multiplier
|
86
|
+
# @return [nil]
|
87
|
+
# Scale the transformation by a multiplier on the Y axis.
|
88
|
+
|
89
|
+
# @!method scale_z(multiplier)
|
90
|
+
# @param [Numeric] multiplier
|
91
|
+
# @return [nil]
|
92
|
+
# @note No-op in `Web::Display`, which is currently 2D.
|
93
|
+
# Scale the transformation by a multiplier on the Z axis.
|
65
94
|
|
66
95
|
# @!method rotate(radians)
|
67
|
-
# @param [
|
96
|
+
# @param [Vector] radians
|
97
|
+
# @return [nil]
|
98
|
+
# @note `Web::Display#rotate` is currently 2D (only Z applies).
|
99
|
+
# Rotate the transformation by vector radians.
|
100
|
+
|
101
|
+
# @!method rotate_x(radians)
|
102
|
+
# @param [Numeric] radians
|
103
|
+
# @return [nil]
|
104
|
+
# @note No-op in `Web::Display`, which is currently 2D.
|
105
|
+
# Rotate the transformation by radians on the X axis.
|
106
|
+
|
107
|
+
# @!method rotate_y(radians)
|
108
|
+
# @param [Numeric] radians
|
68
109
|
# @return [nil]
|
69
|
-
# @
|
70
|
-
# Rotate the transformation by radians.
|
110
|
+
# @note No-op in `Web::Display`, which is currently 2D.
|
111
|
+
# Rotate the transformation by radians on the Y axis.
|
112
|
+
|
113
|
+
# @!method rotate_z(radians)
|
114
|
+
# @param [Numeric] radians
|
115
|
+
# @return [nil]
|
116
|
+
# Rotate the transformation by radians on the Z axis.
|
71
117
|
|
72
118
|
# @!method push
|
73
119
|
# @return [nil]
|
74
|
-
# Push transformation to the transformation stack.
|
120
|
+
# Push current transformation to the transformation stack.
|
75
121
|
|
76
122
|
# @!method pop
|
77
123
|
# @return [nil]
|
78
|
-
# Pop a transformation off the transformation stack.
|
124
|
+
# Pop a transformation off the transformation stack and use it.
|
79
125
|
|
80
126
|
# @!method stroke_line(start_pos, end_pos)
|
81
|
-
# @param [Vector] start position
|
82
|
-
# @param [Vector] end position
|
127
|
+
# @param [Vector] start position
|
128
|
+
# @param [Vector] end position
|
83
129
|
# @return [nil]
|
130
|
+
# @note `Web::Display#stroke_line` is currently 2D (only X and Y apply).
|
84
131
|
# Stroke a line between two positions.
|
85
132
|
|
133
|
+
# @!method stroke_curve(start_pos, end_pos, control)
|
134
|
+
# @param [Vector] start position
|
135
|
+
# @param [Vector] end position
|
136
|
+
# @param [Vector] control point position
|
137
|
+
# @return [nil]
|
138
|
+
# @note `Web::Display#stroke_curve` is currently 2D (only X and Y apply).
|
139
|
+
# Stroke curve with a control point between two positions.
|
140
|
+
|
141
|
+
# @!method stroke_curve2(start_pos, end_pos, control1, control2)
|
142
|
+
# @param [Vector] start position
|
143
|
+
# @param [Vector] end position
|
144
|
+
# @param [Vector] first control point position
|
145
|
+
# @param [Vector] second control point position
|
146
|
+
# @return [nil]
|
147
|
+
# @note `Web::Display#stroke_curve2` is currently 2D (only X and Y apply).
|
148
|
+
# Stroke curve with 2 control points between two positions.
|
149
|
+
|
86
150
|
# @!method stroke_rectangle(position, size)
|
87
|
-
# @param [Vector] position
|
88
|
-
# @param [Vector] size
|
151
|
+
# @param [Vector] position
|
152
|
+
# @param [Vector] size
|
89
153
|
# @return [nil]
|
154
|
+
# @note `Web::Display#stroke_rectangle` is currently 2D (only X and Y apply).
|
90
155
|
# Stroke a rectangle at a position and size.
|
91
156
|
|
92
157
|
# @!method fill_rectangle(position, size)
|
93
|
-
# @param [Vector] position
|
94
|
-
# @param [Vector] size
|
158
|
+
# @param [Vector] position
|
159
|
+
# @param [Vector] size
|
95
160
|
# @return [nil]
|
161
|
+
# @note `Web::Display#fill_rectangle` is currently 2D (only X and Y apply).
|
96
162
|
# Fill a rectangle at a position and size.
|
97
163
|
|
98
164
|
# @!method stroke_ellipse(center, radius)
|
99
|
-
# @param [Vector] center position
|
100
|
-
# @param [Vector] radius in 2D
|
165
|
+
# @param [Vector] center position
|
166
|
+
# @param [Vector] radius in pixels in 2D
|
101
167
|
# @return [nil]
|
168
|
+
# @note `Web::Display#stroke_ellipse` is currently 2D (only X and Y apply).
|
102
169
|
# Stroke an ellipse at a center position and 2D radius.
|
103
170
|
|
104
171
|
# @!method fill_ellipse(center, radius)
|
105
|
-
# @param [Vector] center position
|
106
|
-
# @param [Vector] radius in 2D
|
172
|
+
# @param [Vector] center position
|
173
|
+
# @param [Vector] radius in pixels in 2D
|
107
174
|
# @return [nil]
|
175
|
+
# @note `Web::Display#fill_ellipse` is currently 2D (only X and Y apply).
|
108
176
|
# Fill an ellipse at a center position and 2D radius.
|
109
177
|
|
110
178
|
# @!method clear
|
@@ -127,20 +195,20 @@ class Display
|
|
127
195
|
# @!method line_to(position)
|
128
196
|
# @param [Vector] position
|
129
197
|
# @return [nil]
|
130
|
-
#
|
198
|
+
# Trace line to position as part of shape.
|
131
199
|
|
132
200
|
# @!method curve_to(position, control)
|
133
201
|
# @param [Vector] position
|
134
202
|
# @param [Vector] control point position
|
135
203
|
# @return [nil]
|
136
|
-
#
|
204
|
+
# Trace curve with a control point to position as part of shape.
|
137
205
|
|
138
206
|
# @!method curve2_to(position, control1, control2)
|
139
207
|
# @param [Vector] position
|
140
208
|
# @param [Vector] first control point position
|
141
209
|
# @param [Vector] second control point position
|
142
210
|
# @return [nil]
|
143
|
-
#
|
211
|
+
# Trace curve with 2 control points to position as part of shape.
|
144
212
|
|
145
213
|
# @!method stroke_shape
|
146
214
|
# @return [nil]
|
@@ -155,13 +223,13 @@ class Display
|
|
155
223
|
# @param [Vector] position
|
156
224
|
# @return [nil]
|
157
225
|
# @example Draw a duck within a game
|
158
|
-
# display.image
|
226
|
+
# display.image(Image['images/duck.png'], V[80, 80])
|
159
227
|
# Draw an image at a position.
|
160
228
|
|
161
229
|
# @!method image_cropped(image, position, crop_position, crop_size)
|
162
230
|
# @param [Image] image to draw
|
163
231
|
# @param [Vector] position
|
164
|
-
# @param [Vector] start
|
232
|
+
# @param [Vector] start position of crop
|
165
233
|
# @param [Vector] size of crop
|
166
234
|
# @return [nil]
|
167
235
|
# Draw a cropped image at a position.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Yeah
|
2
|
+
|
3
|
+
# A `Font` is an asset that is used to set `Display#text_font` in order to be
|
4
|
+
# drawn using `Display#fill_text` and `Display#stroke_text`.
|
5
|
+
# @abstract Provided by a `Platform`.
|
6
|
+
# @see Yeah::Display#text_font
|
7
|
+
class Font < Asset
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
data/lib/yeah/_template/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source '
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'yeah', '~> 0.
|
4
|
-
gem 'opal', github: 'opal/opal', ref: '
|
3
|
+
gem 'yeah', '~> 0.4.2'
|
4
|
+
gem 'opal', github: 'opal/opal', ref: '78b4fb9'
|
data/lib/yeah/constants.rb
CHANGED
data/lib/yeah/game.rb
CHANGED
@@ -9,21 +9,6 @@ module Yeah
|
|
9
9
|
# @abstract Subclass this to make a game.
|
10
10
|
class Game
|
11
11
|
class << self
|
12
|
-
# @param [Hash] configuration used for new game instances
|
13
|
-
# @option configuration [Hash] :ticker options
|
14
|
-
# @option configuration [Hash] :display options
|
15
|
-
# @option configuration [Hash] :keyboard options
|
16
|
-
# @option configuration [Hash] :mouse options
|
17
|
-
# @return [Hash] configuration for new game instances
|
18
|
-
def config
|
19
|
-
@config ||= {
|
20
|
-
ticker: {},
|
21
|
-
display: {},
|
22
|
-
keyboard: {},
|
23
|
-
mouse: {}
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
12
|
# @return [Game] default subclass (i.e. project game)
|
28
13
|
def default
|
29
14
|
subclasses.last
|
@@ -84,18 +69,14 @@ class Game
|
|
84
69
|
|
85
70
|
private
|
86
71
|
|
87
|
-
def config
|
88
|
-
self.class.config
|
89
|
-
end
|
90
|
-
|
91
72
|
def defaults
|
92
|
-
ticker = Ticker.new
|
73
|
+
ticker = Ticker.new
|
93
74
|
|
94
75
|
{
|
95
76
|
ticker: ticker,
|
96
|
-
display: Display.new
|
97
|
-
keyboard: Keyboard.new(
|
98
|
-
mouse: Mouse.new(
|
77
|
+
display: Display.new,
|
78
|
+
keyboard: Keyboard.new(ticker: ticker),
|
79
|
+
mouse: Mouse.new(ticker: ticker)
|
99
80
|
}
|
100
81
|
end
|
101
82
|
end
|
data/lib/yeah/vector.rb
CHANGED
@@ -74,6 +74,12 @@ class Vector
|
|
74
74
|
|
75
75
|
alias :unit :normalize
|
76
76
|
|
77
|
+
# @param [Vector] vector to equate
|
78
|
+
# @return [Boolean] whether self equals vector
|
79
|
+
def ==(other)
|
80
|
+
@components == other.components
|
81
|
+
end
|
82
|
+
|
77
83
|
# @param [Vector] vector to add
|
78
84
|
# @return [Vector] vector sum
|
79
85
|
def +(vector)
|
@@ -106,11 +112,56 @@ class Vector
|
|
106
112
|
@components[2] / numeric)
|
107
113
|
end
|
108
114
|
|
109
|
-
|
110
|
-
|
111
|
-
|
115
|
+
alias :add :+
|
116
|
+
|
117
|
+
alias :subtract :-
|
118
|
+
|
119
|
+
alias :multiply :*
|
120
|
+
|
121
|
+
alias :divide :/
|
122
|
+
|
123
|
+
# @param (see #add)
|
124
|
+
# @return [Vector] self after adding vector
|
125
|
+
def add!(vector)
|
126
|
+
@components[0] += vector.components[0]
|
127
|
+
@components[1] += vector.components[1]
|
128
|
+
@components[2] += vector.components[2]
|
129
|
+
|
130
|
+
self
|
112
131
|
end
|
113
132
|
|
133
|
+
# @param (see #subtract)
|
134
|
+
# @return [Vector] self after subtracting vector
|
135
|
+
def subtract!(vector)
|
136
|
+
@components[0] -= vector.components[0]
|
137
|
+
@components[1] -= vector.components[1]
|
138
|
+
@components[2] -= vector.components[2]
|
139
|
+
|
140
|
+
self
|
141
|
+
end
|
142
|
+
|
143
|
+
# @param (see #multiply)
|
144
|
+
# @return [Vector] self after multiplying by numeric
|
145
|
+
def multiply!(numeric)
|
146
|
+
@components[0] *= numeric
|
147
|
+
@components[1] *= numeric
|
148
|
+
@components[2] *= numeric
|
149
|
+
|
150
|
+
self
|
151
|
+
end
|
152
|
+
|
153
|
+
# @param (see #divide)
|
154
|
+
# @return [Vector] self after dividing by numeric
|
155
|
+
def divide!(numeric)
|
156
|
+
@components[0] /= numeric
|
157
|
+
@components[1] /= numeric
|
158
|
+
@components[2] /= numeric
|
159
|
+
|
160
|
+
self
|
161
|
+
end
|
162
|
+
|
163
|
+
alias :+@ :dup
|
164
|
+
|
114
165
|
# @return [Vector] negative vector
|
115
166
|
def -@
|
116
167
|
self.class.new(-@components[0],
|
@@ -138,7 +189,8 @@ class Vector
|
|
138
189
|
# @return [Vector] position moved along an angle for a distance in 2D
|
139
190
|
def along(angle, distance)
|
140
191
|
self.class.new(@components[0] + Math.cos(angle) * distance,
|
141
|
-
@components[1] + Math.sin(angle) * distance
|
192
|
+
@components[1] + Math.sin(angle) * distance,
|
193
|
+
@components[2])
|
142
194
|
end
|
143
195
|
|
144
196
|
# @param (see #along)
|
@@ -152,18 +204,15 @@ class Vector
|
|
152
204
|
|
153
205
|
# @param [Vector] position to move to
|
154
206
|
# @param [Vector] distance to move
|
155
|
-
# @return [Vector] position moved toward other position for a distance
|
156
|
-
# @todo Make work in 3D.
|
207
|
+
# @return [Vector] position moved toward other position for a distance
|
157
208
|
def toward(position, distance)
|
158
|
-
|
209
|
+
self + (position - self).unit * distance
|
159
210
|
end
|
160
211
|
|
161
212
|
# @param (see #toward)
|
162
|
-
# @return [Vector] self after moving toward other position for a distance
|
163
|
-
|
164
|
-
|
165
|
-
def toward!(position, amount)
|
166
|
-
along! angle_to(position), amount
|
213
|
+
# @return [Vector] self after moving toward other position for a distance
|
214
|
+
def toward!(position, distance)
|
215
|
+
self.add! (position - self).unit * distance
|
167
216
|
end
|
168
217
|
end
|
169
218
|
end
|
data/lib/yeah/version.rb
CHANGED
data/lib/yeah/web/builder.rb
CHANGED
@@ -18,14 +18,14 @@ class Builder
|
|
18
18
|
setup_compiler
|
19
19
|
compile
|
20
20
|
|
21
|
-
puts "Built game package to `
|
21
|
+
puts "Built game package to `builds/web`."
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def make_build_dirs
|
27
27
|
# Make build directories.
|
28
|
-
FileUtils.mkpath '
|
28
|
+
FileUtils.mkpath 'builds/web/assets/yeah/web'
|
29
29
|
end
|
30
30
|
|
31
31
|
def setup_compiler
|
@@ -46,7 +46,7 @@ class Builder
|
|
46
46
|
def compile
|
47
47
|
runner_path = Pathname.new(__FILE__).join('..', 'runner.html.erb')
|
48
48
|
html = ERB.new(File.read(runner_path)).result(binding)
|
49
|
-
File.write('
|
49
|
+
File.write('builds/web/runner.html', html)
|
50
50
|
end
|
51
51
|
|
52
52
|
def asset_include_tags
|
@@ -58,6 +58,10 @@ class Builder
|
|
58
58
|
case path
|
59
59
|
when /\.(ogg|wav|mp3)$/
|
60
60
|
"<audio src=\"./#{path}\"></audio>"
|
61
|
+
when /\.(otf|ttf|woff)$/
|
62
|
+
"<style>" +
|
63
|
+
"@font-face { font-family: \"#{path[7..-1]}\"; src: url(#{path}) }" +
|
64
|
+
"</style>"
|
61
65
|
else
|
62
66
|
"<img src=\"./#{path}\" />"
|
63
67
|
end
|
@@ -81,7 +85,7 @@ class Builder
|
|
81
85
|
end
|
82
86
|
|
83
87
|
def build_path
|
84
|
-
@build_path ||= Pathname.new("
|
88
|
+
@build_path ||= Pathname.new("builds/web")
|
85
89
|
end
|
86
90
|
|
87
91
|
def gem_path
|
@@ -1,49 +1,62 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title>Game</title>
|
4
|
+
<title>Game</title>
|
5
5
|
|
6
6
|
<style>
|
7
|
+
html, body {
|
8
|
+
overflow: hidden;
|
9
|
+
height: 100%;
|
10
|
+
margin: 0;
|
11
|
+
}
|
12
|
+
|
7
13
|
body {
|
8
14
|
background: black;
|
9
|
-
margin: 0;
|
10
15
|
}
|
11
16
|
|
12
17
|
.center-content {
|
13
|
-
/* Internet Explorer 10 */
|
14
18
|
display: -ms-flexbox;
|
15
19
|
-ms-flex-pack: center;
|
16
20
|
-ms-flex-align: center;
|
17
|
-
/* Firefox */
|
18
21
|
display: -moz-box;
|
19
22
|
-moz-box-pack: center;
|
20
23
|
-moz-box-align: center;
|
21
|
-
/* Safari, Opera, and Chrome */
|
22
24
|
display: -webkit-box;
|
23
25
|
-webkit-box-pack: center;
|
24
26
|
-webkit-box-align: center;
|
25
|
-
/* W3C */
|
26
27
|
display: box;
|
27
28
|
box-pack: center;
|
28
29
|
box-align: center;
|
29
30
|
}
|
30
31
|
|
31
|
-
html, body{
|
32
|
-
width: 100%;
|
33
|
-
height: 100%;
|
34
|
-
}
|
35
|
-
|
36
|
-
canvas {
|
37
|
-
max-width: 100%;
|
38
|
-
max-height: 100%;
|
39
|
-
}
|
40
|
-
|
41
32
|
.hidden {
|
42
33
|
display: none;
|
43
34
|
}
|
44
35
|
</style>
|
36
|
+
|
37
|
+
<script>
|
38
|
+
function scaleDisplay() {
|
39
|
+
var canvas = document.getElementsByTagName('canvas')[0],
|
40
|
+
|
41
|
+
width_scale = window.innerWidth / canvas.width,
|
42
|
+
height_scale = window.innerHeight / canvas.height,
|
43
|
+
|
44
|
+
scale = Math.min(width_scale, height_scale);
|
45
|
+
|
46
|
+
if (FACTORIAL_SCALING && scale >= 1) {
|
47
|
+
scale = Math.floor(scale);
|
48
|
+
}
|
49
|
+
|
50
|
+
var width = canvas.width * scale,
|
51
|
+
height = canvas.height * scale,
|
52
|
+
|
53
|
+
sizeStyle = "width:"+width+"px; height:"+height+"px";
|
54
|
+
|
55
|
+
canvas.setAttribute('style', sizeStyle);
|
56
|
+
}
|
57
|
+
</script>
|
45
58
|
</head>
|
46
|
-
<body class="center-content">
|
59
|
+
<body class="center-content" onresize="scaleDisplay()">
|
47
60
|
<canvas></canvas>
|
48
61
|
|
49
62
|
<div class="hidden">
|
@@ -54,8 +67,11 @@
|
|
54
67
|
<%= script_include_tag 'yeah/web' %>
|
55
68
|
<%= script_include_tag 'yeah/web/setup' %>
|
56
69
|
|
70
|
+
<%= script_include_tag 'config' %>
|
57
71
|
<%= script_include_tag 'game' %>
|
58
72
|
|
59
73
|
<%= script_include_tag 'yeah/web/start' %>
|
74
|
+
|
75
|
+
<script>scaleDisplay()</script>
|
60
76
|
</body>
|
61
77
|
</html>
|
data/lib/yeah/web/server.rb
CHANGED
@@ -69,6 +69,10 @@ class Server
|
|
69
69
|
case path
|
70
70
|
when /\.(ogg|wav|mp3)$/
|
71
71
|
"<audio src=\"/#{path}\"></audio>"
|
72
|
+
when /\.(otf|ttf|woff)$/
|
73
|
+
"<style>" +
|
74
|
+
"@font-face { font-family: \"#{path[7..-1]}\"; src: url(#{path}) }" +
|
75
|
+
"</style>"
|
72
76
|
else
|
73
77
|
"<img src=\"/#{path}\" />"
|
74
78
|
end
|
data/lib/yeah/web/setup.rb
CHANGED
data/opal/yeah/web.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'math'
|
2
|
+
|
1
3
|
require 'yeah/web/constants'
|
4
|
+
require 'yeah/web/class_methods'
|
2
5
|
require 'yeah/web/asset'
|
3
6
|
require 'yeah/web/image'
|
4
7
|
require 'yeah/web/sound'
|
8
|
+
require 'yeah/web/font'
|
5
9
|
require 'yeah/web/display'
|
6
10
|
require 'yeah/web/keyboard'
|
7
11
|
require 'yeah/web/mouse'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Yeah
|
2
|
+
module Web
|
3
|
+
module ClassMethods
|
4
|
+
def configure(&block)
|
5
|
+
config = Struct.new(:title, :factorial_scaling).new
|
6
|
+
|
7
|
+
yield config
|
8
|
+
|
9
|
+
`window.document.title = #{config.title}` unless config.title.nil?
|
10
|
+
`FACTORIAL_SCALING = #{config.factorial_scaling}`
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/opal/yeah/web/display.opal
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Yeah
|
2
2
|
module Web
|
3
3
|
class Display
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :text_font, :text_size
|
5
5
|
|
6
6
|
def initialize(options = {})
|
7
7
|
canvas_selector = options.fetch(:canvas_selector, DEFAULT_CANVAS_SELECTOR)
|
@@ -9,8 +9,8 @@ class Display
|
|
9
9
|
@canvas = `document.querySelectorAll(#{canvas_selector})[0]`
|
10
10
|
@context = `#@canvas.getContext('2d')`
|
11
11
|
self.size = options.fetch(:size, DEFAULT_DISPLAY_SIZE)
|
12
|
-
self.
|
13
|
-
self.
|
12
|
+
self.text_font = Font['']
|
13
|
+
self.text_size = DEFAULT_DISPLAY_TEXT_SIZE
|
14
14
|
@transform = [1, 0, 0, 1, 0, 0]
|
15
15
|
@transforms = []
|
16
16
|
end
|
@@ -27,14 +27,14 @@ class Display
|
|
27
27
|
`#@canvas.width`
|
28
28
|
end
|
29
29
|
def width=(value)
|
30
|
-
`#@canvas.width = #{value
|
30
|
+
`#@canvas.width = #{value}`
|
31
31
|
end
|
32
32
|
|
33
33
|
def height
|
34
34
|
`#@canvas.height`
|
35
35
|
end
|
36
36
|
def height=(value)
|
37
|
-
`#@canvas.height = #{value
|
37
|
+
`#@canvas.height = #{value}`
|
38
38
|
end
|
39
39
|
|
40
40
|
def fill_color
|
@@ -58,17 +58,17 @@ class Display
|
|
58
58
|
`#@context.lineWidth = #{numeric}`
|
59
59
|
end
|
60
60
|
|
61
|
-
def
|
62
|
-
@
|
61
|
+
def text_font=(font)
|
62
|
+
@text_font = font
|
63
63
|
|
64
|
-
font = "#{@
|
64
|
+
font = "#{@text_size}px \"#{@text_font.path}\""
|
65
65
|
`#@context.font = #{font}`
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
69
|
-
@
|
68
|
+
def text_size=(size)
|
69
|
+
@text_size = size
|
70
70
|
|
71
|
-
font = "#{@
|
71
|
+
font = "#{@text_size}px \"#{@text_font.path}\""
|
72
72
|
`#@context.font = #{font}`
|
73
73
|
end
|
74
74
|
|
@@ -77,10 +77,6 @@ class Display
|
|
77
77
|
C[`data[0]`, `data[1]`, `data[2]`]
|
78
78
|
end
|
79
79
|
|
80
|
-
def transformation
|
81
|
-
@transform + [0, 0, 1] # appendage to fulfill signature
|
82
|
-
end
|
83
|
-
|
84
80
|
def translate(displacement)
|
85
81
|
@transform[4] += `#{@transform[0]} * #{displacement.x} +
|
86
82
|
#{@transform[2]} * #{displacement.y}`
|
@@ -93,6 +89,29 @@ class Display
|
|
93
89
|
#{@transform[4]}, #{@transform[5]}); }
|
94
90
|
end
|
95
91
|
|
92
|
+
def translate_x(displacement)
|
93
|
+
@transform[4] += `#{@transform[0]} * #{displacement} + #{@transform[2]}`
|
94
|
+
@transform[5] += `#{@transform[1]} * #{displacement} + #{@transform[3]}`
|
95
|
+
|
96
|
+
%x{
|
97
|
+
#@context.setTransform(#{@transform[0]}, #{@transform[1]},
|
98
|
+
#{@transform[2]}, #{@transform[3]},
|
99
|
+
#{@transform[4]}, #{@transform[5]}); }
|
100
|
+
end
|
101
|
+
|
102
|
+
def translate_y(displacement)
|
103
|
+
@transform[4] += `#{@transform[0]} + #{@transform[2]} * #{displacement}`
|
104
|
+
@transform[5] += `#{@transform[1]} + #{@transform[3]} * #{displacement}`
|
105
|
+
|
106
|
+
%x{
|
107
|
+
#@context.setTransform(#{@transform[0]}, #{@transform[1]},
|
108
|
+
#{@transform[2]}, #{@transform[3]},
|
109
|
+
#{@transform[4]}, #{@transform[5]}); }
|
110
|
+
end
|
111
|
+
|
112
|
+
def translate_z(displacement)
|
113
|
+
end
|
114
|
+
|
96
115
|
def scale(multiplier)
|
97
116
|
%x{
|
98
117
|
#{@transform} = [#{@transform[0]} * #{multiplier.x},
|
@@ -106,7 +125,44 @@ class Display
|
|
106
125
|
#{@transform[4]}, #{@transform[5]}); }
|
107
126
|
end
|
108
127
|
|
128
|
+
def scale_x(multiplier)
|
129
|
+
%x{
|
130
|
+
#{@transform} = [#{@transform[0]} * #{multiplier},
|
131
|
+
#{@transform[1]} * #{multiplier},
|
132
|
+
#{@transform[2]}, #{@transform[3]},
|
133
|
+
#{@transform[4]}, #{@transform[5]}];
|
134
|
+
|
135
|
+
#@context.setTransform(#{@transform[0]}, #{@transform[1]},
|
136
|
+
#{@transform[2]}, #{@transform[3]},
|
137
|
+
#{@transform[4]}, #{@transform[5]}); }
|
138
|
+
end
|
139
|
+
|
140
|
+
def scale_y(multiplier)
|
141
|
+
%x{
|
142
|
+
#{@transform} = [#{@transform[0]}, #{@transform[1]},
|
143
|
+
#{@transform[2]} * #{multiplier},
|
144
|
+
#{@transform[3]} * #{multiplier},
|
145
|
+
#{@transform[4]}, #{@transform[5]}];
|
146
|
+
|
147
|
+
#@context.setTransform(#{@transform[0]}, #{@transform[1]},
|
148
|
+
#{@transform[2]}, #{@transform[3]},
|
149
|
+
#{@transform[4]}, #{@transform[5]}); }
|
150
|
+
end
|
151
|
+
|
152
|
+
def scale_z(multiplier)
|
153
|
+
end
|
154
|
+
|
109
155
|
def rotate(radians)
|
156
|
+
rotate_z(radians.z)
|
157
|
+
end
|
158
|
+
|
159
|
+
def rotate_x(radians)
|
160
|
+
end
|
161
|
+
|
162
|
+
def rotate_y(radians)
|
163
|
+
end
|
164
|
+
|
165
|
+
def rotate_z(radians)
|
110
166
|
%x{
|
111
167
|
var cos = Math.cos(#{radians}),
|
112
168
|
sin = Math.sin(#{radians}),
|
@@ -145,6 +201,29 @@ class Display
|
|
145
201
|
}
|
146
202
|
end
|
147
203
|
|
204
|
+
def stroke_curve(start_pos, end_pos, control)
|
205
|
+
%x{
|
206
|
+
#@context.beginPath();
|
207
|
+
#@context.moveTo(#{start_pos.x}, #{start_pos.y});
|
208
|
+
#@context.quadraticCurveTo(#{control.x}, #{control.y},
|
209
|
+
#{end_pos.x}, #{end_pos.y});
|
210
|
+
#@context.closePath();
|
211
|
+
#@context.stroke();
|
212
|
+
}
|
213
|
+
end
|
214
|
+
|
215
|
+
def stroke_curve2(start_pos, end_pos, control1, control2)
|
216
|
+
%x{
|
217
|
+
#@context.beginPath();
|
218
|
+
#@context.moveTo(#{start_pos.x}, #{start_pos.y});
|
219
|
+
#@context.bezierCurveTo(#{control1.x}, #{control1.y},
|
220
|
+
#{control2.x}, #{control2.y},
|
221
|
+
#{end_pos.x}, #{end_pos.y});
|
222
|
+
#@context.closePath();
|
223
|
+
#@context.stroke();
|
224
|
+
}
|
225
|
+
end
|
226
|
+
|
148
227
|
def stroke_rectangle(position, size)
|
149
228
|
`#@context.strokeRect(#{position.x}, #{position.y}, #{size.x}, #{size.y})`
|
150
229
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yeah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Ostrega
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.0.
|
47
|
+
version: 0.0.4
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.0.
|
54
|
+
version: 0.0.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,13 +94,16 @@ files:
|
|
94
94
|
- bin/yeah
|
95
95
|
- lib/yeah.rb
|
96
96
|
- lib/yeah/_platform/asset.rb
|
97
|
+
- lib/yeah/_platform/class_methods.rb
|
97
98
|
- lib/yeah/_platform/display.rb
|
99
|
+
- lib/yeah/_platform/font.rb
|
98
100
|
- lib/yeah/_platform/image.rb
|
99
101
|
- lib/yeah/_platform/keyboard.rb
|
100
102
|
- lib/yeah/_platform/mouse.rb
|
101
103
|
- lib/yeah/_platform/sound.rb
|
102
104
|
- lib/yeah/_platform/ticker.rb
|
103
105
|
- lib/yeah/_template/Gemfile
|
106
|
+
- lib/yeah/_template/code/config.rb
|
104
107
|
- lib/yeah/_template/code/game.rb
|
105
108
|
- lib/yeah/_web.rb
|
106
109
|
- lib/yeah/color.rb
|
@@ -116,8 +119,10 @@ files:
|
|
116
119
|
- lib/yeah/web/start.rb
|
117
120
|
- opal/yeah/web.rb
|
118
121
|
- opal/yeah/web/asset.opal
|
122
|
+
- opal/yeah/web/class_methods.opal
|
119
123
|
- opal/yeah/web/constants.opal
|
120
124
|
- opal/yeah/web/display.opal
|
125
|
+
- opal/yeah/web/font.opal
|
121
126
|
- opal/yeah/web/image.opal
|
122
127
|
- opal/yeah/web/keyboard.opal
|
123
128
|
- opal/yeah/web/mouse.opal
|