yeah 0.2.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +52 -20
- data/bin/yeah +30 -0
- data/lib/yeah.rb +6 -9
- data/lib/yeah/_platform/asset.rb +24 -0
- data/lib/yeah/_platform/display.rb +181 -0
- data/lib/yeah/_platform/image.rb +16 -0
- data/lib/yeah/_platform/keyboard.rb +37 -0
- data/lib/yeah/_platform/mouse.rb +30 -0
- data/lib/yeah/_platform/sound.rb +15 -0
- data/lib/yeah/_platform/ticker.rb +21 -0
- data/lib/yeah/_template/Gemfile +4 -0
- data/lib/yeah/_template/code/code.rb +4 -0
- data/lib/yeah/_template/code/game.rb +7 -0
- data/lib/yeah/_web.rb +9 -0
- data/lib/yeah/color.rb +45 -13
- data/lib/yeah/constants.rb +6 -0
- data/lib/yeah/game.rb +89 -41
- data/lib/yeah/vector.rb +122 -99
- data/lib/yeah/version.rb +3 -0
- data/lib/yeah/web/dependencies.rb +2 -0
- data/lib/yeah/web/runner.html.erb +61 -0
- data/lib/yeah/web/server.rb +60 -0
- data/lib/yeah/web/setup.rb +5 -0
- data/lib/yeah/web/start.rb +1 -0
- data/opal/yeah/web.rb +8 -0
- data/opal/yeah/web/asset.opal +38 -0
- data/opal/yeah/web/constants.opal +5 -0
- data/opal/yeah/web/display.opal +244 -0
- data/opal/yeah/web/image.opal +23 -0
- data/opal/yeah/web/keyboard.opal +139 -0
- data/opal/yeah/web/mouse.opal +58 -0
- data/opal/yeah/web/sound.opal +19 -0
- data/opal/yeah/web/ticker.opal +39 -0
- metadata +111 -19
- data/CHANGELOG.md +0 -28
- data/lib/monkey/numeric.rb +0 -6
- data/lib/yeah/basic_physics.rb +0 -11
- data/lib/yeah/desktop.rb +0 -72
- data/lib/yeah/entity.rb +0 -137
- data/lib/yeah/map.rb +0 -40
- data/lib/yeah/rectangle.rb +0 -21
- data/lib/yeah/surface.rb +0 -66
@@ -0,0 +1,139 @@
|
|
1
|
+
module Yeah
|
2
|
+
module Web
|
3
|
+
class Keyboard
|
4
|
+
KEY_MAP = {
|
5
|
+
0 => :fn,
|
6
|
+
8 => :backspace,
|
7
|
+
9 => :tab,
|
8
|
+
13 => :enter,
|
9
|
+
16 => :shift,
|
10
|
+
17 => :ctrl,
|
11
|
+
18 => :alt,
|
12
|
+
19 => :pause,
|
13
|
+
20 => :caps_lock,
|
14
|
+
27 => :escape,
|
15
|
+
33 => :page_up,
|
16
|
+
34 => :page_down,
|
17
|
+
35 => :end,
|
18
|
+
36 => :home,
|
19
|
+
37 => :left,
|
20
|
+
38 => :up,
|
21
|
+
39 => :right,
|
22
|
+
40 => :down,
|
23
|
+
45 => :insert,
|
24
|
+
46 => :delete,
|
25
|
+
48 => 0,
|
26
|
+
49 => 1,
|
27
|
+
50 => 2,
|
28
|
+
51 => 3,
|
29
|
+
52 => 4,
|
30
|
+
53 => 5,
|
31
|
+
54 => 6,
|
32
|
+
55 => 7,
|
33
|
+
56 => 8,
|
34
|
+
57 => 9,
|
35
|
+
65 => :a,
|
36
|
+
66 => :b,
|
37
|
+
67 => :c,
|
38
|
+
68 => :d,
|
39
|
+
69 => :e,
|
40
|
+
70 => :f,
|
41
|
+
71 => :g,
|
42
|
+
72 => :h,
|
43
|
+
73 => :i,
|
44
|
+
74 => :j,
|
45
|
+
75 => :k,
|
46
|
+
76 => :l,
|
47
|
+
77 => :m,
|
48
|
+
78 => :n,
|
49
|
+
79 => :o,
|
50
|
+
80 => :p,
|
51
|
+
81 => :q,
|
52
|
+
82 => :r,
|
53
|
+
83 => :s,
|
54
|
+
84 => :t,
|
55
|
+
85 => :u,
|
56
|
+
86 => :v,
|
57
|
+
87 => :w,
|
58
|
+
88 => :x,
|
59
|
+
89 => :y,
|
60
|
+
90 => :z,
|
61
|
+
91 => :super,
|
62
|
+
92 => :super,
|
63
|
+
96 => :num0,
|
64
|
+
97 => :num1,
|
65
|
+
98 => :num2,
|
66
|
+
99 => :num3,
|
67
|
+
100 => :num4,
|
68
|
+
101 => :num5,
|
69
|
+
102 => :num6,
|
70
|
+
103 => :num7,
|
71
|
+
104 => :num8,
|
72
|
+
105 => :num9,
|
73
|
+
106 => :num_asterisk,
|
74
|
+
107 => :num_plus,
|
75
|
+
109 => :num_minus,
|
76
|
+
110 => :num_dot,
|
77
|
+
111 => :num_slash,
|
78
|
+
112 => :f1,
|
79
|
+
113 => :f2,
|
80
|
+
114 => :f3,
|
81
|
+
115 => :f4,
|
82
|
+
116 => :f5,
|
83
|
+
117 => :f6,
|
84
|
+
118 => :f7,
|
85
|
+
119 => :f8,
|
86
|
+
120 => :f9,
|
87
|
+
121 => :f10,
|
88
|
+
122 => :f11,
|
89
|
+
123 => :f12,
|
90
|
+
144 => :num_lock,
|
91
|
+
145 => :scroll_lock,
|
92
|
+
186 => :semicolon,
|
93
|
+
187 => :equals,
|
94
|
+
188 => :comma,
|
95
|
+
189 => :minus,
|
96
|
+
190 => :dot,
|
97
|
+
191 => :slash,
|
98
|
+
192 => :backquote,
|
99
|
+
219 => :left_bracket,
|
100
|
+
220 => :backslash,
|
101
|
+
221 => :right_bracket,
|
102
|
+
222 => :quote
|
103
|
+
}
|
104
|
+
|
105
|
+
def initialize(options = {})
|
106
|
+
@ticker = options.fetch(:ticker)
|
107
|
+
@pressed_keys = {}
|
108
|
+
@released_keys = {}
|
109
|
+
|
110
|
+
%x{
|
111
|
+
window.addEventListener('keydown', function(event) {
|
112
|
+
#{key = KEY_MAP[`event.keyCode`]}
|
113
|
+
if (#{!@pressed_keys[key]}) {
|
114
|
+
#{@pressed_keys[key] = @ticker.tick_count}
|
115
|
+
}
|
116
|
+
});
|
117
|
+
|
118
|
+
window.addEventListener('keyup', function(event) {
|
119
|
+
#{key = KEY_MAP[`event.keyCode`]}
|
120
|
+
#{@released_keys[key] = @ticker.tick_count}
|
121
|
+
#{@pressed_keys[key] = nil}
|
122
|
+
});
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
def pressing?(key)
|
127
|
+
!!@pressed_keys[key] || false
|
128
|
+
end
|
129
|
+
|
130
|
+
def pressed?(key)
|
131
|
+
@pressed_keys[key] == @ticker.tick_count
|
132
|
+
end
|
133
|
+
|
134
|
+
def released?(key)
|
135
|
+
@released_keys[key] == @ticker.tick_count
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Yeah
|
2
|
+
module Web
|
3
|
+
class Mouse
|
4
|
+
BUTTON_MAP = {
|
5
|
+
0 => :left,
|
6
|
+
1 => :middle,
|
7
|
+
2 => :right,
|
8
|
+
3 => 4,
|
9
|
+
4 => 5
|
10
|
+
}
|
11
|
+
|
12
|
+
attr_reader :position
|
13
|
+
|
14
|
+
def initialize(args = {})
|
15
|
+
canvas_selector = args.fetch(:canvas_selector, DEFAULT_CANVAS_SELECTOR)
|
16
|
+
@ticker = args.fetch(:ticker)
|
17
|
+
@canvas = `document.querySelectorAll(#{canvas_selector})[0]`
|
18
|
+
@pressed_buttons = {}
|
19
|
+
@released_buttons = {}
|
20
|
+
|
21
|
+
%x{
|
22
|
+
#@canvas.addEventListener('mousemove', function(event) {
|
23
|
+
if (event.offsetX) {
|
24
|
+
#{@position = V[`event.offsetX`, `event.offsetY`]}
|
25
|
+
} else {
|
26
|
+
#{@position = V[`event.layerX`, `event.layerY`]}
|
27
|
+
}
|
28
|
+
});
|
29
|
+
|
30
|
+
#@canvas.addEventListener('mousedown', function(event) {
|
31
|
+
#{button = BUTTON_MAP[`event.button`]}
|
32
|
+
if (#{!@pressed_buttons[button]}) {
|
33
|
+
#{@pressed_buttons[button] = @ticker.tick_count}
|
34
|
+
}
|
35
|
+
});
|
36
|
+
|
37
|
+
#@canvas.addEventListener('mouseup', function(event) {
|
38
|
+
#{button = BUTTON_MAP[`event.button`]}
|
39
|
+
#{@released_buttons[button] = @ticker.tick_count}
|
40
|
+
#{@pressed_buttons[button] = nil}
|
41
|
+
});
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def pressing?(button)
|
46
|
+
!!@pressed_buttons[button] || false
|
47
|
+
end
|
48
|
+
|
49
|
+
def pressed?(button)
|
50
|
+
@pressed_buttons[button] == @ticker.tick_count
|
51
|
+
end
|
52
|
+
|
53
|
+
def released?(button)
|
54
|
+
@released_buttons[button] == @ticker.tick_count
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Yeah
|
2
|
+
module Web
|
3
|
+
class Ticker
|
4
|
+
attr_reader :rate, :tick_count
|
5
|
+
|
6
|
+
def initialize(args = {})
|
7
|
+
@rate = args.fetch(:rate, DEFAULT_TICKER_RATE)
|
8
|
+
@tick_count = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def on_tick(&block)
|
12
|
+
# TODO: add to ticks before yielding
|
13
|
+
%x{
|
14
|
+
var lastTime = (new Date()).getTime(),
|
15
|
+
elapsed = 0,
|
16
|
+
interval = 1/#{rate},
|
17
|
+
currentTime;
|
18
|
+
|
19
|
+
var loop = function() {
|
20
|
+
currentTime = new Date().getTime();
|
21
|
+
elapsed = (currentTime - lastTime) / 1000;
|
22
|
+
|
23
|
+
if (elapsed > interval) {
|
24
|
+
#{yield `elapsed`}
|
25
|
+
|
26
|
+
#{@tick_count += 1}
|
27
|
+
|
28
|
+
lastTime = currentTime - (elapsed % interval);
|
29
|
+
}
|
30
|
+
|
31
|
+
window.requestAnimationFrame(loop);
|
32
|
+
};
|
33
|
+
|
34
|
+
window.requestAnimationFrame(loop);
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,35 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yeah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Ostrega
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 10.3.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 10.3.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.3.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.3.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: opal-minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.7.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.7.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: kramdown
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.1
|
83
|
+
description: Video game framework designed to be easy to learn and fast to build games
|
84
|
+
with.
|
14
85
|
email: skoofoo@gmail.com
|
15
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- yeah
|
16
88
|
extensions: []
|
17
89
|
extra_rdoc_files: []
|
18
90
|
files:
|
19
|
-
- lib/yeah/map.rb
|
20
|
-
- lib/yeah/game.rb
|
21
|
-
- lib/yeah/color.rb
|
22
|
-
- lib/yeah/surface.rb
|
23
|
-
- lib/yeah/vector.rb
|
24
|
-
- lib/yeah/basic_physics.rb
|
25
|
-
- lib/yeah/desktop.rb
|
26
|
-
- lib/yeah/rectangle.rb
|
27
|
-
- lib/yeah/entity.rb
|
28
|
-
- lib/monkey/numeric.rb
|
29
|
-
- lib/yeah.rb
|
30
91
|
- LICENSE.txt
|
31
92
|
- README.md
|
32
|
-
-
|
93
|
+
- bin/yeah
|
94
|
+
- lib/yeah.rb
|
95
|
+
- lib/yeah/_platform/asset.rb
|
96
|
+
- lib/yeah/_platform/display.rb
|
97
|
+
- lib/yeah/_platform/image.rb
|
98
|
+
- lib/yeah/_platform/keyboard.rb
|
99
|
+
- lib/yeah/_platform/mouse.rb
|
100
|
+
- lib/yeah/_platform/sound.rb
|
101
|
+
- lib/yeah/_platform/ticker.rb
|
102
|
+
- lib/yeah/_template/Gemfile
|
103
|
+
- lib/yeah/_template/code/code.rb
|
104
|
+
- lib/yeah/_template/code/game.rb
|
105
|
+
- lib/yeah/_web.rb
|
106
|
+
- lib/yeah/color.rb
|
107
|
+
- lib/yeah/constants.rb
|
108
|
+
- lib/yeah/game.rb
|
109
|
+
- lib/yeah/vector.rb
|
110
|
+
- lib/yeah/version.rb
|
111
|
+
- lib/yeah/web/dependencies.rb
|
112
|
+
- lib/yeah/web/runner.html.erb
|
113
|
+
- lib/yeah/web/server.rb
|
114
|
+
- lib/yeah/web/setup.rb
|
115
|
+
- lib/yeah/web/start.rb
|
116
|
+
- opal/yeah/web.rb
|
117
|
+
- opal/yeah/web/asset.opal
|
118
|
+
- opal/yeah/web/constants.opal
|
119
|
+
- opal/yeah/web/display.opal
|
120
|
+
- opal/yeah/web/image.opal
|
121
|
+
- opal/yeah/web/keyboard.opal
|
122
|
+
- opal/yeah/web/mouse.opal
|
123
|
+
- opal/yeah/web/sound.opal
|
124
|
+
- opal/yeah/web/ticker.opal
|
33
125
|
homepage: https://github.com/skofo/yeah
|
34
126
|
licenses:
|
35
127
|
- MIT
|
@@ -50,9 +142,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
142
|
version: '0'
|
51
143
|
requirements: []
|
52
144
|
rubyforge_project:
|
53
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.2.2
|
54
146
|
signing_key:
|
55
147
|
specification_version: 4
|
56
|
-
summary:
|
148
|
+
summary: Practical Ruby video game framework
|
57
149
|
test_files: []
|
58
150
|
has_rdoc:
|
data/CHANGELOG.md
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
## 0.2.3 [pend]
|
2
|
-
* Yemo demo
|
3
|
-
|
4
|
-
## 0.2.2 [2013-11-12]
|
5
|
-
* Shootguy -> Vyzer
|
6
|
-
* Expanded and revised Vyzer demo
|
7
|
-
* Optimized drawing
|
8
|
-
* Input interface
|
9
|
-
* Entity-Game relationship
|
10
|
-
* Entity subpositions and basic collision detection
|
11
|
-
* 16:9 default resolution
|
12
|
-
* Basic Map API
|
13
|
-
* Vector V shorthand
|
14
|
-
* Misc.
|
15
|
-
|
16
|
-
## 0.2.1 [2013-10-18]
|
17
|
-
* Shootguy demo/API model
|
18
|
-
* Cleanup
|
19
|
-
* Documentation
|
20
|
-
* Misc.
|
21
|
-
|
22
|
-
## 0.2.0 [2013-09-21]
|
23
|
-
* Added Color, Surface, Rectangle, Map and Desktop classes.
|
24
|
-
* Extended Vector, Entity and Game classes.
|
25
|
-
* Added Happy Rectangle demo.
|
26
|
-
|
27
|
-
## 0.1.0 [2013-09-05]
|
28
|
-
* Added basic Vector, Entity and Game classes.
|