cyberarm_engine 0.19.0 → 0.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -8
  3. data/.rubocop.yml +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/LICENSE.txt +21 -21
  7. data/README.md +74 -74
  8. data/Rakefile +10 -10
  9. data/bin/console +14 -14
  10. data/bin/setup +8 -8
  11. data/cyberarm_engine.gemspec +39 -39
  12. data/lib/cyberarm_engine/animator.rb +219 -219
  13. data/lib/cyberarm_engine/background.rb +179 -179
  14. data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
  15. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  16. data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
  17. data/lib/cyberarm_engine/cache/download_manager.rb +121 -121
  18. data/lib/cyberarm_engine/cache.rb +4 -4
  19. data/lib/cyberarm_engine/common.rb +113 -113
  20. data/lib/cyberarm_engine/config_file.rb +46 -46
  21. data/lib/cyberarm_engine/console/command.rb +157 -157
  22. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
  23. data/lib/cyberarm_engine/console/subcommand.rb +99 -99
  24. data/lib/cyberarm_engine/console.rb +248 -248
  25. data/lib/cyberarm_engine/game_object.rb +248 -248
  26. data/lib/cyberarm_engine/game_state.rb +97 -97
  27. data/lib/cyberarm_engine/model/material.rb +21 -21
  28. data/lib/cyberarm_engine/model/model_object.rb +131 -131
  29. data/lib/cyberarm_engine/model/parser.rb +74 -74
  30. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
  31. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
  32. data/lib/cyberarm_engine/model.rb +212 -212
  33. data/lib/cyberarm_engine/model_cache.rb +31 -31
  34. data/lib/cyberarm_engine/opengl/light.rb +50 -50
  35. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
  36. data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -38
  37. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
  38. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -164
  39. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +298 -298
  40. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -22
  41. data/lib/cyberarm_engine/opengl/shader.rb +406 -406
  42. data/lib/cyberarm_engine/opengl/texture.rb +69 -69
  43. data/lib/cyberarm_engine/opengl.rb +28 -28
  44. data/lib/cyberarm_engine/ray.rb +56 -56
  45. data/lib/cyberarm_engine/stats.rb +21 -21
  46. data/lib/cyberarm_engine/text.rb +197 -197
  47. data/lib/cyberarm_engine/timer.rb +23 -23
  48. data/lib/cyberarm_engine/transform.rb +296 -296
  49. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
  50. data/lib/cyberarm_engine/ui/dsl.rb +139 -139
  51. data/lib/cyberarm_engine/ui/element.rb +488 -488
  52. data/lib/cyberarm_engine/ui/elements/button.rb +97 -97
  53. data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
  54. data/lib/cyberarm_engine/ui/elements/container.rb +256 -256
  55. data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
  56. data/lib/cyberarm_engine/ui/elements/edit_line.rb +263 -263
  57. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
  58. data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
  59. data/lib/cyberarm_engine/ui/elements/list_box.rb +88 -82
  60. data/lib/cyberarm_engine/ui/elements/progress.rb +51 -51
  61. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
  62. data/lib/cyberarm_engine/ui/elements/slider.rb +104 -104
  63. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
  64. data/lib/cyberarm_engine/ui/elements/text_block.rb +162 -162
  65. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -65
  66. data/lib/cyberarm_engine/ui/event.rb +54 -54
  67. data/lib/cyberarm_engine/ui/gui_state.rb +256 -256
  68. data/lib/cyberarm_engine/ui/style.rb +49 -49
  69. data/lib/cyberarm_engine/ui/theme.rb +207 -207
  70. data/lib/cyberarm_engine/vector.rb +293 -293
  71. data/lib/cyberarm_engine/version.rb +4 -4
  72. data/lib/cyberarm_engine/window.rb +120 -120
  73. data/lib/cyberarm_engine.rb +71 -71
  74. metadata +3 -3
@@ -1,219 +1,219 @@
1
- module CyberarmEngine
2
- class Animator
3
- def initialize(start_time:, duration:, from:, to:, tween: :linear, &block)
4
- @start_time = start_time
5
- @duration = duration
6
- @from = from.dup
7
- @to = to.dup
8
- @tween = tween
9
- @block = block
10
- end
11
-
12
- def update
13
- @block.call(self, @from, @to) if @block
14
- end
15
-
16
- def progress
17
- ((Gosu.milliseconds - @start_time) / @duration.to_f).clamp(0.0, 1.0)
18
- end
19
-
20
- def complete?
21
- progress >= 1.0
22
- end
23
-
24
- def transition(from = @from, to = @to, tween = @tween)
25
- from + (to - from) * send("tween_#{tween}", progress)
26
- end
27
-
28
- def color_transition(from = @from, to = @to, _tween = @tween)
29
- r = transition(from.red, to.red)
30
- g = transition(from.green, to.green)
31
- b = transition(from.blue, to.blue)
32
- a = transition(from.alpha, to.alpha)
33
-
34
- Gosu::Color.rgba(r, g, b, a)
35
- end
36
-
37
- def color_hsv_transition(from = @from, to = @to, tween = @tween)
38
- hue = transition(from.hue, to.hue, tween)
39
- saturation = transition(from.saturation, to.saturation, tween)
40
- value = transition(from.value, to.value, tween)
41
- alpha = transition(from.alpha, to.alpha, tween)
42
-
43
- Gosu::Color.from_ahsv(alpha, hue, saturation, value)
44
- end
45
-
46
- # Tween functions based on those provided here: https://github.com/danro/easing-js/blob/master/easing.js
47
- # Under MIT / BSD
48
-
49
- def tween_linear(t)
50
- t
51
- end
52
-
53
- def tween_ease_in_quad(t)
54
- t ** 2
55
- end
56
-
57
- def tween_ease_out_quad(t)
58
- -((t - 1) ** 2) -1
59
- end
60
-
61
- def tween_ease_in_out_quad(t)
62
- return 0.5 * (t ** 2) if (t /= 0.5) < 1
63
- return -0.5 * ((t -= 2) * t - 2)
64
- end
65
-
66
- def tween_ease_in_cubic(t)
67
- t ** 3
68
- end
69
-
70
- def tween_ease_out_cubic(t)
71
- ((t - 1) ** 3) + 1
72
- end
73
-
74
- def tween_ease_in_out_cubic(t)
75
- return 0.5 * (t ** 3) if ((t /= 0.5) < 1)
76
- return 0.5 * ((t - 2) ** 3) + 2
77
- end
78
-
79
- def tween_ease_in_quart(t)
80
- t ** 4
81
- end
82
-
83
- def tween_ease_out_quart(t)
84
- -((t - 1) ** 4) - 1
85
- end
86
-
87
- def tween_ease_in_out_quart(t)
88
- return 0.5 * (t ** 4) if ((t /= 0.5) < 1)
89
- return -0.5 * ((t -= 2) * (t ** 3) - 2)
90
- end
91
-
92
- def tween_ease_in_quint(t)
93
- t ** 5
94
- end
95
-
96
- def tween_ease_out_quint(t)
97
- ((t - 1) ** 5) + 1
98
- end
99
-
100
- def tween_ease_in_out_quint(t)
101
- return 0.5 * (t ** 5) if ((t /= 0.5) < 1)
102
- return 0.5 * ((t - 2) ** 5) + 2
103
- end
104
-
105
- def tween_ease_in(t) # sine
106
- -Math.cos(t * (Math::PI / 2)) + 1
107
- end
108
-
109
- def tween_ease_out(t) # sine
110
- Math.sin(t * (Math::PI / 2))
111
- end
112
-
113
- def tween_ease_in_out(t) # sine
114
- (-0.5 * (Math.cos(Math::PI * t) - 1))
115
- end
116
-
117
- def tween_ease_in_expo(t)
118
- (t == 0) ? 0 : 2 ** 10 * (t - 1)
119
- end
120
-
121
- def tween_ease_out_expo(t)
122
- (t == 1) ? 1 : -(2 ** -10 * t) + 1
123
- end
124
-
125
- def tween_ease_in_out_expo(t)
126
- return 0 if (t == 0)
127
- return 1 if (t == 1)
128
- return 0.5 * (2 ** 10 * (t - 1)) if ((t /= 0.5) < 1)
129
- return 0.5 * (-(2 ** -10 * (t -= 1)) + 2)
130
- end
131
-
132
- def tween_ease_in_circ(t)
133
- -(Math.sqrt(1 - (t * t)) - 1)
134
- end
135
-
136
- def tween_ease_out_circ(t)
137
- Math.sqrt(1 - ((t - 1) ** 2))
138
- end
139
-
140
- def tween_ease_in_out_circ(t)
141
- return -0.5 * (Math.sqrt(1 - t * t) - 1) if ((t /= 0.5) < 1)
142
- return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1)
143
- end
144
-
145
- def tween_ease_in_back(t)
146
- s = 1.70158
147
- t * t * ((s + 1) * t - s)
148
- end
149
-
150
- def tween_ease_out_back(t)
151
- s = 1.70158
152
- (t = t - 1) * t * ((s + 1) * t + s) + 1
153
- end
154
-
155
- def tween_ease_in_out_back(t)
156
- s = 1.70158
157
- return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) if ((t /= 0.5) < 1)
158
- return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2)
159
- end
160
-
161
- def tween_elastic(t)
162
- -1 * (4 ** (-8 * t)) * Math.sin((t * 6 - 1) * (2 * Math::PI) / 2) + 1
163
- end
164
-
165
- def tween_swing_from_to(t)
166
- s = 1.70158
167
- return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) if (t /= 0.5) < 1
168
- return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2)
169
- end
170
-
171
- def tween_swing_from(t)
172
- s = 1.70158;
173
- t * t * ((s + 1) * t - s)
174
- end
175
-
176
- def tween_swing_to(t)
177
- s = 1.70158
178
- (t -= 1) * t * ((s + 1) * t + s) + 1
179
- end
180
-
181
- def tween_bounce(t)
182
- if (t < (1 / 2.75))
183
- (7.5625 * t * t)
184
- elsif (t < (2 / 2.75))
185
- (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75)
186
- elsif (t < (2.5 / 2.75))
187
- (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375)
188
- else
189
- (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375)
190
- end
191
- end
192
-
193
- def tween_bounce_past(t)
194
- if (t < (1 / 2.75))
195
- # missing "2 -"?
196
- (7.5625 * t * t)
197
- elsif (t < (2 / 2.75))
198
- 2 - (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75)
199
- elsif (t < (2.5 / 2.75))
200
- 2 - (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375)
201
- else
202
- 2 - (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375)
203
- end
204
- end
205
-
206
- def tween_ease_from_to(t)
207
- return 0.5 * (t ** 4) if ((t /= 0.5) < 1)
208
- return -0.5 * ((t -= 2) * (t ** 3) - 2)
209
- end
210
-
211
- def tween_ease_from(t)
212
- t ** 4
213
- end
214
-
215
- def tween_ease_to(t)
216
- t ** 0.25
217
- end
218
- end
219
- end
1
+ module CyberarmEngine
2
+ class Animator
3
+ def initialize(start_time:, duration:, from:, to:, tween: :linear, &block)
4
+ @start_time = start_time
5
+ @duration = duration
6
+ @from = from.dup
7
+ @to = to.dup
8
+ @tween = tween
9
+ @block = block
10
+ end
11
+
12
+ def update
13
+ @block.call(self, @from, @to) if @block
14
+ end
15
+
16
+ def progress
17
+ ((Gosu.milliseconds - @start_time) / @duration.to_f).clamp(0.0, 1.0)
18
+ end
19
+
20
+ def complete?
21
+ progress >= 1.0
22
+ end
23
+
24
+ def transition(from = @from, to = @to, tween = @tween)
25
+ from + (to - from) * send("tween_#{tween}", progress)
26
+ end
27
+
28
+ def color_transition(from = @from, to = @to, _tween = @tween)
29
+ r = transition(from.red, to.red)
30
+ g = transition(from.green, to.green)
31
+ b = transition(from.blue, to.blue)
32
+ a = transition(from.alpha, to.alpha)
33
+
34
+ Gosu::Color.rgba(r, g, b, a)
35
+ end
36
+
37
+ def color_hsv_transition(from = @from, to = @to, tween = @tween)
38
+ hue = transition(from.hue, to.hue, tween)
39
+ saturation = transition(from.saturation, to.saturation, tween)
40
+ value = transition(from.value, to.value, tween)
41
+ alpha = transition(from.alpha, to.alpha, tween)
42
+
43
+ Gosu::Color.from_ahsv(alpha, hue, saturation, value)
44
+ end
45
+
46
+ # Tween functions based on those provided here: https://github.com/danro/easing-js/blob/master/easing.js
47
+ # Under MIT / BSD
48
+
49
+ def tween_linear(t)
50
+ t
51
+ end
52
+
53
+ def tween_ease_in_quad(t)
54
+ t ** 2
55
+ end
56
+
57
+ def tween_ease_out_quad(t)
58
+ -((t - 1) ** 2) -1
59
+ end
60
+
61
+ def tween_ease_in_out_quad(t)
62
+ return 0.5 * (t ** 2) if (t /= 0.5) < 1
63
+ return -0.5 * ((t -= 2) * t - 2)
64
+ end
65
+
66
+ def tween_ease_in_cubic(t)
67
+ t ** 3
68
+ end
69
+
70
+ def tween_ease_out_cubic(t)
71
+ ((t - 1) ** 3) + 1
72
+ end
73
+
74
+ def tween_ease_in_out_cubic(t)
75
+ return 0.5 * (t ** 3) if ((t /= 0.5) < 1)
76
+ return 0.5 * ((t - 2) ** 3) + 2
77
+ end
78
+
79
+ def tween_ease_in_quart(t)
80
+ t ** 4
81
+ end
82
+
83
+ def tween_ease_out_quart(t)
84
+ -((t - 1) ** 4) - 1
85
+ end
86
+
87
+ def tween_ease_in_out_quart(t)
88
+ return 0.5 * (t ** 4) if ((t /= 0.5) < 1)
89
+ return -0.5 * ((t -= 2) * (t ** 3) - 2)
90
+ end
91
+
92
+ def tween_ease_in_quint(t)
93
+ t ** 5
94
+ end
95
+
96
+ def tween_ease_out_quint(t)
97
+ ((t - 1) ** 5) + 1
98
+ end
99
+
100
+ def tween_ease_in_out_quint(t)
101
+ return 0.5 * (t ** 5) if ((t /= 0.5) < 1)
102
+ return 0.5 * ((t - 2) ** 5) + 2
103
+ end
104
+
105
+ def tween_ease_in(t) # sine
106
+ -Math.cos(t * (Math::PI / 2)) + 1
107
+ end
108
+
109
+ def tween_ease_out(t) # sine
110
+ Math.sin(t * (Math::PI / 2))
111
+ end
112
+
113
+ def tween_ease_in_out(t) # sine
114
+ (-0.5 * (Math.cos(Math::PI * t) - 1))
115
+ end
116
+
117
+ def tween_ease_in_expo(t)
118
+ (t == 0) ? 0 : 2 ** 10 * (t - 1)
119
+ end
120
+
121
+ def tween_ease_out_expo(t)
122
+ (t == 1) ? 1 : -(2 ** -10 * t) + 1
123
+ end
124
+
125
+ def tween_ease_in_out_expo(t)
126
+ return 0 if (t == 0)
127
+ return 1 if (t == 1)
128
+ return 0.5 * (2 ** 10 * (t - 1)) if ((t /= 0.5) < 1)
129
+ return 0.5 * (-(2 ** -10 * (t -= 1)) + 2)
130
+ end
131
+
132
+ def tween_ease_in_circ(t)
133
+ -(Math.sqrt(1 - (t * t)) - 1)
134
+ end
135
+
136
+ def tween_ease_out_circ(t)
137
+ Math.sqrt(1 - ((t - 1) ** 2))
138
+ end
139
+
140
+ def tween_ease_in_out_circ(t)
141
+ return -0.5 * (Math.sqrt(1 - t * t) - 1) if ((t /= 0.5) < 1)
142
+ return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1)
143
+ end
144
+
145
+ def tween_ease_in_back(t)
146
+ s = 1.70158
147
+ t * t * ((s + 1) * t - s)
148
+ end
149
+
150
+ def tween_ease_out_back(t)
151
+ s = 1.70158
152
+ (t = t - 1) * t * ((s + 1) * t + s) + 1
153
+ end
154
+
155
+ def tween_ease_in_out_back(t)
156
+ s = 1.70158
157
+ return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) if ((t /= 0.5) < 1)
158
+ return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2)
159
+ end
160
+
161
+ def tween_elastic(t)
162
+ -1 * (4 ** (-8 * t)) * Math.sin((t * 6 - 1) * (2 * Math::PI) / 2) + 1
163
+ end
164
+
165
+ def tween_swing_from_to(t)
166
+ s = 1.70158
167
+ return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) if (t /= 0.5) < 1
168
+ return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2)
169
+ end
170
+
171
+ def tween_swing_from(t)
172
+ s = 1.70158;
173
+ t * t * ((s + 1) * t - s)
174
+ end
175
+
176
+ def tween_swing_to(t)
177
+ s = 1.70158
178
+ (t -= 1) * t * ((s + 1) * t + s) + 1
179
+ end
180
+
181
+ def tween_bounce(t)
182
+ if (t < (1 / 2.75))
183
+ (7.5625 * t * t)
184
+ elsif (t < (2 / 2.75))
185
+ (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75)
186
+ elsif (t < (2.5 / 2.75))
187
+ (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375)
188
+ else
189
+ (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375)
190
+ end
191
+ end
192
+
193
+ def tween_bounce_past(t)
194
+ if (t < (1 / 2.75))
195
+ # missing "2 -"?
196
+ (7.5625 * t * t)
197
+ elsif (t < (2 / 2.75))
198
+ 2 - (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75)
199
+ elsif (t < (2.5 / 2.75))
200
+ 2 - (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375)
201
+ else
202
+ 2 - (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375)
203
+ end
204
+ end
205
+
206
+ def tween_ease_from_to(t)
207
+ return 0.5 * (t ** 4) if ((t /= 0.5) < 1)
208
+ return -0.5 * ((t -= 2) * (t ** 3) - 2)
209
+ end
210
+
211
+ def tween_ease_from(t)
212
+ t ** 4
213
+ end
214
+
215
+ def tween_ease_to(t)
216
+ t ** 0.25
217
+ end
218
+ end
219
+ end