cyberarm_engine 0.24.4 → 0.24.5
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.
- checksums.yaml +4 -4
- data/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/assets/shaders/fragment/g_buffer.glsl +30 -30
- data/assets/shaders/fragment/lighting.glsl +115 -69
- data/assets/shaders/include/light_struct.glsl +11 -11
- data/assets/shaders/include/material_struct.glsl +16 -16
- data/assets/shaders/vertex/g_buffer.glsl +28 -28
- data/assets/shaders/vertex/lighting.glsl +24 -24
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +36 -36
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +180 -179
- data/lib/cyberarm_engine/background_image.rb +93 -93
- data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
- data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +128 -128
- data/lib/cyberarm_engine/config_file.rb +46 -46
- data/lib/cyberarm_engine/console/command.rb +157 -157
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
- data/lib/cyberarm_engine/console/subcommand.rb +99 -99
- data/lib/cyberarm_engine/console.rb +248 -248
- data/lib/cyberarm_engine/game_object.rb +244 -244
- data/lib/cyberarm_engine/game_state.rb +124 -124
- data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +97 -97
- data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
- data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/{model_object.rb → mesh.rb} +131 -131
- data/lib/cyberarm_engine/model/parser.rb +74 -74
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
- data/lib/cyberarm_engine/model.rb +216 -213
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/notification.rb +82 -82
- data/lib/cyberarm_engine/notification_manager.rb +241 -241
- data/lib/cyberarm_engine/opengl/light.rb +52 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -165
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -304
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
- data/lib/cyberarm_engine/opengl/shader.rb +408 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +53 -40
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +200 -200
- data/lib/cyberarm_engine/text.rb +260 -260
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/trees/aabb_node.rb +126 -0
- data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -0
- data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -0
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +142 -142
- data/lib/cyberarm_engine/ui/element.rb +662 -662
- data/lib/cyberarm_engine/ui/elements/button.rb +100 -100
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +404 -404
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +297 -297
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
- data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
- data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
- data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/progress.rb +93 -93
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +107 -107
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +216 -216
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +67 -67
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +321 -321
- data/lib/cyberarm_engine/ui/style.rb +50 -50
- data/lib/cyberarm_engine/ui/theme.rb +225 -225
- data/lib/cyberarm_engine/vector.rb +312 -312
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +195 -195
- data/lib/cyberarm_engine.rb +70 -78
- data/mrbgem.rake +29 -29
- metadata +8 -7
@@ -1,28 +1,28 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
layout(location = 0) in vec3 in_position;
|
4
|
-
layout(location = 1) in vec3 in_color;
|
5
|
-
layout(location = 2) in vec3 in_normal;
|
6
|
-
layout(location = 3) in vec3 in_uv;
|
7
|
-
|
8
|
-
uniform mat4 projection, view, model;
|
9
|
-
uniform int has_texture;
|
10
|
-
uniform vec3 camera_pos;
|
11
|
-
|
12
|
-
out vec3 out_position, out_color, out_normal, out_uv;
|
13
|
-
out vec3 out_frag_pos, out_view_pos, out_camera_pos;
|
14
|
-
flat out int out_has_texture;
|
15
|
-
|
16
|
-
void main() {
|
17
|
-
// projection * view * model * position
|
18
|
-
out_position = in_position;
|
19
|
-
out_color = in_color;
|
20
|
-
out_normal= normalize(transpose(inverse(mat3(model))) * in_normal);
|
21
|
-
out_uv = in_uv;
|
22
|
-
out_has_texture = has_texture;
|
23
|
-
out_camera_pos = camera_pos;
|
24
|
-
|
25
|
-
out_frag_pos = vec3(model * vec4(in_position, 1.0));
|
26
|
-
|
27
|
-
gl_Position = projection * view * model * vec4(in_position, 1.0);
|
28
|
-
}
|
1
|
+
#version 330 core
|
2
|
+
|
3
|
+
layout(location = 0) in vec3 in_position;
|
4
|
+
layout(location = 1) in vec3 in_color;
|
5
|
+
layout(location = 2) in vec3 in_normal;
|
6
|
+
layout(location = 3) in vec3 in_uv;
|
7
|
+
|
8
|
+
uniform mat4 projection, view, model;
|
9
|
+
uniform int has_texture;
|
10
|
+
uniform vec3 camera_pos;
|
11
|
+
|
12
|
+
out vec3 out_position, out_color, out_normal, out_uv;
|
13
|
+
out vec3 out_frag_pos, out_view_pos, out_camera_pos;
|
14
|
+
flat out int out_has_texture;
|
15
|
+
|
16
|
+
void main() {
|
17
|
+
// projection * view * model * position
|
18
|
+
out_position = in_position;
|
19
|
+
out_color = in_color;
|
20
|
+
out_normal= normalize(transpose(inverse(mat3(model))) * in_normal);
|
21
|
+
out_uv = in_uv;
|
22
|
+
out_has_texture = has_texture;
|
23
|
+
out_camera_pos = camera_pos;
|
24
|
+
|
25
|
+
out_frag_pos = vec3(model * vec4(in_position, 1.0));
|
26
|
+
|
27
|
+
gl_Position = projection * view * model * vec4(in_position, 1.0);
|
28
|
+
}
|
@@ -1,24 +1,24 @@
|
|
1
|
-
#version 330 core
|
2
|
-
@include "light_struct"
|
3
|
-
|
4
|
-
layout (location = 0) in vec3 in_position;
|
5
|
-
layout (location = 1) in vec2 in_tex_coords;
|
6
|
-
|
7
|
-
uniform sampler2D diffuse, position, texcoord, normal, depth;
|
8
|
-
uniform int light_count;
|
9
|
-
uniform Light lights[7];
|
10
|
-
|
11
|
-
out vec2 out_tex_coords;
|
12
|
-
flat out int out_light_count;
|
13
|
-
flat out Light out_lights[7];
|
14
|
-
|
15
|
-
void main() {
|
16
|
-
gl_Position = vec4(in_position.x, in_position.y, in_position.z, 1.0);
|
17
|
-
out_tex_coords = in_tex_coords;
|
18
|
-
out_light_count = light_count;
|
19
|
-
|
20
|
-
for(int i = 0; i < light_count; i++)
|
21
|
-
{
|
22
|
-
out_lights[i] = lights[i];
|
23
|
-
}
|
24
|
-
}
|
1
|
+
#version 330 core
|
2
|
+
@include "light_struct"
|
3
|
+
|
4
|
+
layout (location = 0) in vec3 in_position;
|
5
|
+
layout (location = 1) in vec2 in_tex_coords;
|
6
|
+
|
7
|
+
uniform sampler2D diffuse, position, texcoord, normal, depth;
|
8
|
+
uniform int light_count;
|
9
|
+
uniform Light lights[7];
|
10
|
+
|
11
|
+
out vec2 out_tex_coords;
|
12
|
+
flat out int out_light_count;
|
13
|
+
flat out Light out_lights[7];
|
14
|
+
|
15
|
+
void main() {
|
16
|
+
gl_Position = vec4(in_position.x, in_position.y, in_position.z, 1.0);
|
17
|
+
out_tex_coords = in_tex_coords;
|
18
|
+
out_light_count = light_count;
|
19
|
+
|
20
|
+
for(int i = 0; i < light_count; i++)
|
21
|
+
{
|
22
|
+
out_lights[i] = lights[i];
|
23
|
+
}
|
24
|
+
}
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "cyberarm_engine"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cyberarm_engine"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
data/cyberarm_engine.gemspec
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
lib = File.expand_path("lib", __dir__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "cyberarm_engine/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "cyberarm_engine"
|
7
|
-
spec.version = CyberarmEngine::VERSION
|
8
|
-
spec.authors = ["Cyberarm"]
|
9
|
-
spec.email = ["matthewlikesrobots@gmail.com"]
|
10
|
-
|
11
|
-
spec.summary = "Make games quickly and easily with gosu"
|
12
|
-
spec.description = "Yet another game making framework around gosu"
|
13
|
-
spec.homepage = "https://github.com/cyberarm/cyberarm_engine"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
if spec.respond_to?(:metadata)
|
17
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
-
else
|
19
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
20
|
-
"public gem pushes."
|
21
|
-
end
|
22
|
-
|
23
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
24
|
-
f.match(%r{^(test|spec|features)/})
|
25
|
-
end
|
26
|
-
spec.bindir = "exe"
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = %w[lib assets]
|
29
|
-
|
30
|
-
spec.add_dependency "gosu", "~> 1.1"
|
31
|
-
# spec.add_dependency "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows
|
32
|
-
|
33
|
-
spec.add_development_dependency "bundler", "~> 2.2"
|
34
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
35
|
-
spec.add_development_dependency "rake", "~> 13.0"
|
36
|
-
end
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "cyberarm_engine/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cyberarm_engine"
|
7
|
+
spec.version = CyberarmEngine::VERSION
|
8
|
+
spec.authors = ["Cyberarm"]
|
9
|
+
spec.email = ["matthewlikesrobots@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Make games quickly and easily with gosu"
|
12
|
+
spec.description = "Yet another game making framework around gosu"
|
13
|
+
spec.homepage = "https://github.com/cyberarm/cyberarm_engine"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
if spec.respond_to?(:metadata)
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
else
|
19
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
20
|
+
"public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
f.match(%r{^(test|spec|features)/})
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = %w[lib assets]
|
29
|
+
|
30
|
+
spec.add_dependency "gosu", "~> 1.1"
|
31
|
+
# spec.add_dependency "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.2"
|
34
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
35
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
36
|
+
end
|
@@ -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
|