cyberarm_engine 0.13.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -8
  3. data/.rubocop.yml +8 -0
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/LICENSE.txt +21 -21
  7. data/README.md +73 -43
  8. data/Rakefile +10 -10
  9. data/assets/textures/default.png +0 -0
  10. data/bin/console +14 -14
  11. data/bin/setup +8 -8
  12. data/cyberarm_engine.gemspec +39 -36
  13. data/lib/cyberarm_engine.rb +64 -47
  14. data/lib/cyberarm_engine/animator.rb +56 -54
  15. data/lib/cyberarm_engine/background.rb +179 -175
  16. data/lib/cyberarm_engine/background_nine_slice.rb +125 -0
  17. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  18. data/lib/cyberarm_engine/cache.rb +4 -0
  19. data/lib/cyberarm_engine/cache/download_manager.rb +121 -0
  20. data/lib/cyberarm_engine/common.rb +96 -96
  21. data/lib/cyberarm_engine/config_file.rb +46 -0
  22. data/lib/cyberarm_engine/game_object.rb +248 -257
  23. data/lib/cyberarm_engine/game_state.rb +92 -89
  24. data/lib/cyberarm_engine/model.rb +207 -0
  25. data/lib/cyberarm_engine/model/material.rb +21 -0
  26. data/lib/cyberarm_engine/model/model_object.rb +131 -0
  27. data/lib/cyberarm_engine/model/parser.rb +74 -0
  28. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -0
  29. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -0
  30. data/lib/cyberarm_engine/model_cache.rb +31 -0
  31. data/lib/cyberarm_engine/opengl.rb +28 -0
  32. data/lib/cyberarm_engine/opengl/light.rb +50 -0
  33. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -0
  34. data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -0
  35. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -0
  36. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -0
  37. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +289 -0
  38. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -0
  39. data/lib/cyberarm_engine/opengl/shader.rb +406 -0
  40. data/lib/cyberarm_engine/opengl/texture.rb +69 -0
  41. data/lib/cyberarm_engine/ray.rb +56 -56
  42. data/lib/cyberarm_engine/stats.rb +21 -0
  43. data/lib/cyberarm_engine/text.rb +160 -146
  44. data/lib/cyberarm_engine/timer.rb +23 -23
  45. data/lib/cyberarm_engine/transform.rb +296 -273
  46. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -101
  47. data/lib/cyberarm_engine/ui/dsl.rb +138 -99
  48. data/lib/cyberarm_engine/ui/element.rb +315 -276
  49. data/lib/cyberarm_engine/ui/elements/button.rb +160 -67
  50. data/lib/cyberarm_engine/ui/elements/check_box.rb +51 -59
  51. data/lib/cyberarm_engine/ui/elements/container.rb +256 -176
  52. data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -0
  53. data/lib/cyberarm_engine/ui/elements/edit_line.rb +262 -172
  54. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -17
  55. data/lib/cyberarm_engine/ui/elements/image.rb +72 -52
  56. data/lib/cyberarm_engine/ui/elements/label.rb +156 -50
  57. data/lib/cyberarm_engine/ui/elements/list_box.rb +82 -0
  58. data/lib/cyberarm_engine/ui/elements/progress.rb +51 -50
  59. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -0
  60. data/lib/cyberarm_engine/ui/elements/slider.rb +104 -0
  61. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -13
  62. data/lib/cyberarm_engine/ui/elements/text_block.rb +156 -0
  63. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -56
  64. data/lib/cyberarm_engine/ui/event.rb +47 -47
  65. data/lib/cyberarm_engine/ui/gui_state.rb +226 -135
  66. data/lib/cyberarm_engine/ui/style.rb +38 -37
  67. data/lib/cyberarm_engine/ui/theme.rb +182 -120
  68. data/lib/cyberarm_engine/vector.rb +293 -203
  69. data/lib/cyberarm_engine/version.rb +4 -4
  70. data/lib/cyberarm_engine/{engine.rb → window.rb} +114 -101
  71. metadata +88 -18
  72. data/lib/cyberarm_engine/gosu_ext/circle.rb +0 -9
  73. data/lib/cyberarm_engine/shader.rb +0 -262
@@ -1,54 +1,56 @@
1
- module CyberarmEngine
2
- class Animator
3
- DEFAULT_TWEEN = :linear
4
- def initialize(start_time:, duration:, from:, to:, &block)
5
- @start_time, @duration = start_time, duration
6
- @from, @to = from.dup, to.dup
7
- @block = block
8
- end
9
-
10
- def update
11
- @block.call(self, @from, @to) if @block
12
- end
13
-
14
- def progress
15
- (@start_time.to_f + (Gosu.milliseconds - @start_time)) / (@start_time + @duration.to_f)
16
- end
17
-
18
- def complete?
19
- progress >= 1.0
20
- end
21
-
22
- def transition(from, to, tween = DEFAULT_TWEEN)
23
- from + (to - from) * send("tween_#{tween}", progress)
24
- end
25
-
26
- def color_transition(from, to, tween = DEFAULT_TWEEN)
27
- r = transition(from.red, to.red)
28
- g = transition(from.green, to.green)
29
- b = transition(from.blue, to.blue)
30
- a = transition(from.alpha, to.alpha)
31
-
32
- Gosu::Color.rgba(r, g, b, a)
33
- end
34
-
35
- def color_hsv_transition(from, to, tween = DEFAULT_TWEEN)
36
- hue = transition(from.hue, to.hue, tween)
37
- saturation = transition(from.saturation, to.saturation, tween)
38
- value = transition(from.value, to.value, tween)
39
- alpha = transition(from.alpha, to.alpha, tween)
40
-
41
- Gosu::Color.from_ahsv(alpha, hue, saturation, value)
42
- end
43
-
44
- # NOTE: Use this for future reference? https://github.com/danro/easing-js/blob/master/easing.js
45
-
46
- def tween_linear(t)
47
- t
48
- end
49
-
50
- def tween_sine(t)
51
- Math.sin(t) * t
52
- end
53
- end
54
- end
1
+ module CyberarmEngine
2
+ class Animator
3
+ DEFAULT_TWEEN = :linear
4
+ def initialize(start_time:, duration:, from:, to:, &block)
5
+ @start_time = start_time
6
+ @duration = duration
7
+ @from = from.dup
8
+ @to = to.dup
9
+ @block = block
10
+ end
11
+
12
+ def update
13
+ @block.call(self, @from, @to) if @block
14
+ end
15
+
16
+ def progress
17
+ (@start_time.to_f + (Gosu.milliseconds - @start_time)) / (@start_time + @duration.to_f)
18
+ end
19
+
20
+ def complete?
21
+ progress >= 1.0
22
+ end
23
+
24
+ def transition(from, to, tween = DEFAULT_TWEEN)
25
+ from + (to - from) * send("tween_#{tween}", progress)
26
+ end
27
+
28
+ def color_transition(from, to, _tween = DEFAULT_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, to, tween = DEFAULT_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
+ # NOTE: Use this for future reference? https://github.com/danro/easing-js/blob/master/easing.js
47
+
48
+ def tween_linear(t)
49
+ t
50
+ end
51
+
52
+ def tween_sine(t)
53
+ Math.sin(t) * t
54
+ end
55
+ end
56
+ end
@@ -1,175 +1,179 @@
1
- module CyberarmEngine
2
- class Background
3
- attr_accessor :x, :y, :z, :width, :height, :angle, :debug
4
- attr_reader :background
5
- def initialize(x: 0, y: 0, z: 0, width: 0, height: 0, background: Gosu::Color::BLACK, angle: 0, debug: false)
6
- @x,@y,@z = x,y,z
7
- @width,@height = width,height
8
- @debug = debug
9
-
10
- @paint = Paint.new(background)
11
- @angle = angle
12
-
13
- @top_left = Vector.new(@x, @y)
14
- @top_right = Vector.new(@x + @width, @y)
15
- @bottom_left = Vector.new(@x, @y + @height)
16
- @bottom_right = Vector.new(@x + @width, @y + @height)
17
- end
18
-
19
- def draw
20
- Gosu.clip_to(@x, @y, @width, @height) do
21
- Gosu.draw_quad(
22
- @top_left.x, @top_left.y, @paint.top_left,
23
- @top_right.x, @top_right.y, @paint.top_right,
24
- @bottom_right.x, @bottom_right.y, @paint.bottom_right,
25
- @bottom_left.x, @bottom_left.y, @paint.bottom_left,
26
- @z
27
- )
28
- end
29
-
30
- debug_outline if @debug
31
- end
32
-
33
- def update
34
- origin_x = (@x + (@width/2))
35
- origin_y = (@y + (@height/2))
36
-
37
- points = [
38
- @top_left = Vector.new(@x, @y),
39
- @top_right = Vector.new(@x + @width, @y),
40
- @bottom_left = Vector.new(@x, @y + @height),
41
- @bottom_right = Vector.new(@x + @width, @y + @height)
42
- ]
43
-
44
- [@top_left, @top_right, @bottom_left, @bottom_right].each do |vector|
45
- temp_x = vector.x - origin_x
46
- temp_y = vector.y - origin_y
47
-
48
- # 90 is up here, while gosu uses 0 for up.
49
- radians = (@angle + 90).gosu_to_radians
50
- vector.x = (@x + (@width/2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
51
- vector.y = (@y + (@height/2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
52
- end
53
-
54
- # [
55
- # [:top, @top_left, @top_right],
56
- # [:right, @top_right, @bottom_right],
57
- # [:bottom, @bottom_right, @bottom_left],
58
- # [:left, @bottom_left, @top_left]
59
- # ].each do |edge|
60
- # points.each do |point|
61
- # puts "#{edge.first} -> #{shortest_distance(point, edge[1], edge[2])}"
62
- # end
63
- # end
64
- end
65
-
66
- def shortest_distance(point, la, lb)
67
- a = la.x - lb.x
68
- b = la.y - lb.y
69
- c = Gosu.distance(la.x, la.y, lb.x, lb.y)
70
- p a,b,c
71
- d = (a * point.x + b * point.y + c).abs / (Math.sqrt(a * a + b * b))
72
- puts "Distance: #{d}"
73
- exit!
74
- return d
75
- end
76
-
77
- def debug_outline
78
- # Top
79
- Gosu.draw_line(
80
- @x, @y, Gosu::Color::RED,
81
- @x + @width, @y, Gosu::Color::RED,
82
- @z
83
- )
84
-
85
- # Right
86
- Gosu.draw_line(
87
- @x + @width, @y, Gosu::Color::RED,
88
- @x + @width, @y + @height, Gosu::Color::RED,
89
- @z
90
- )
91
-
92
- # Bottom
93
- Gosu.draw_line(
94
- @x + @width, @y + @height, Gosu::Color::RED,
95
- @x, @y + @height, Gosu::Color::RED,
96
- @z
97
- )
98
-
99
- # Left
100
- Gosu.draw_line(
101
- @x, @y + @height, Gosu::Color::RED,
102
- @x, @y, Gosu::Color::RED,
103
- @z
104
- )
105
- end
106
-
107
- def background=(_background)
108
- @paint.set(_background)
109
- update
110
- end
111
-
112
- def angle=(n)
113
- @angle = n
114
- update
115
- end
116
- end
117
-
118
- class Paint
119
- attr_accessor :top_left, :top_right, :bottom_left, :bottom_right
120
- def initialize(background)
121
- set(background)
122
- end
123
-
124
- def set(background)
125
- @background = background
126
-
127
-
128
- if background.is_a?(Numeric)
129
- @top_left = background
130
- @top_right = background
131
- @bottom_left = background
132
- @bottom_right = background
133
- elsif background.is_a?(Gosu::Color)
134
- @top_left = background
135
- @top_right = background
136
- @bottom_left = background
137
- @bottom_right = background
138
- elsif background.is_a?(Array)
139
- if background.size == 1
140
- set(background.first)
141
- elsif background.size == 2
142
- @top_left = background.first
143
- @top_right = background.last
144
- @bottom_left = background.first
145
- @bottom_right = background.last
146
- elsif background.size == 4
147
- @top_left = background[0]
148
- @top_right = background[1]
149
- @bottom_left = background[2]
150
- @bottom_right = background[3]
151
- else
152
- raise ArgumentError, "background array was empty or had wrong number of elements (expected 2 or 4 elements)"
153
- end
154
- elsif background.is_a?(Hash)
155
- @top_left = background[:top_left]
156
- @top_right = background[:top_right]
157
- @bottom_left = background[:bottom_left]
158
- @bottom_right = background[:bottom_right]
159
- elsif background.is_a?(Range)
160
- set([background.begin, background.begin, background.end, background.end])
161
- else
162
- raise ArgumentError, "background '#{background}' of type '#{background.class}' was not able to be processed"
163
- end
164
- end
165
- end
166
- end
167
-
168
- # Add <=> method to support Range based gradients
169
- module Gosu
170
- class Color
171
- def <=>(other)
172
- self
173
- end
174
- end
175
- end
1
+ module CyberarmEngine
2
+ class Background
3
+ attr_accessor :x, :y, :z, :width, :height, :angle, :debug
4
+ attr_reader :background
5
+
6
+ def initialize(x: 0, y: 0, z: 0, width: 0, height: 0, background: Gosu::Color::BLACK, angle: 0, debug: false)
7
+ @x = x
8
+ @y = y
9
+ @z = z
10
+ @width = width
11
+ @height = height
12
+ @debug = debug
13
+
14
+ @paint = Paint.new(background)
15
+ @angle = angle
16
+
17
+ @top_left = Vector.new(@x, @y)
18
+ @top_right = Vector.new(@x + @width, @y)
19
+ @bottom_left = Vector.new(@x, @y + @height)
20
+ @bottom_right = Vector.new(@x + @width, @y + @height)
21
+ end
22
+
23
+ def draw
24
+ Gosu.clip_to(@x, @y, @width, @height) do
25
+ Gosu.draw_quad(
26
+ @top_left.x, @top_left.y, @paint.top_left,
27
+ @top_right.x, @top_right.y, @paint.top_right,
28
+ @bottom_right.x, @bottom_right.y, @paint.bottom_right,
29
+ @bottom_left.x, @bottom_left.y, @paint.bottom_left,
30
+ @z
31
+ )
32
+ end
33
+
34
+ debug_outline if @debug
35
+ end
36
+
37
+ def update
38
+ origin_x = (@x + (@width / 2))
39
+ origin_y = (@y + (@height / 2))
40
+
41
+ points = [
42
+ @top_left = Vector.new(@x, @y),
43
+ @top_right = Vector.new(@x + @width, @y),
44
+ @bottom_left = Vector.new(@x, @y + @height),
45
+ @bottom_right = Vector.new(@x + @width, @y + @height)
46
+ ]
47
+
48
+ [@top_left, @top_right, @bottom_left, @bottom_right].each do |vector|
49
+ temp_x = vector.x - origin_x
50
+ temp_y = vector.y - origin_y
51
+
52
+ # 90 is up here, while gosu uses 0 for up.
53
+ radians = (@angle + 90).gosu_to_radians
54
+ vector.x = (@x + (@width / 2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
55
+ vector.y = (@y + (@height / 2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
56
+ end
57
+
58
+ # [
59
+ # [:top, @top_left, @top_right],
60
+ # [:right, @top_right, @bottom_right],
61
+ # [:bottom, @bottom_right, @bottom_left],
62
+ # [:left, @bottom_left, @top_left]
63
+ # ].each do |edge|
64
+ # points.each do |point|
65
+ # puts "#{edge.first} -> #{shortest_distance(point, edge[1], edge[2])}"
66
+ # end
67
+ # end
68
+ end
69
+
70
+ def shortest_distance(point, la, lb)
71
+ a = la.x - lb.x
72
+ b = la.y - lb.y
73
+ c = Gosu.distance(la.x, la.y, lb.x, lb.y)
74
+ p a, b, c
75
+ d = (a * point.x + b * point.y + c).abs / Math.sqrt(a * a + b * b)
76
+ puts "Distance: #{d}"
77
+ exit!
78
+ d
79
+ end
80
+
81
+ def debug_outline
82
+ # Top
83
+ Gosu.draw_line(
84
+ @x, @y, Gosu::Color::RED,
85
+ @x + @width, @y, Gosu::Color::RED,
86
+ @z
87
+ )
88
+
89
+ # Right
90
+ Gosu.draw_line(
91
+ @x + @width, @y, Gosu::Color::RED,
92
+ @x + @width, @y + @height, Gosu::Color::RED,
93
+ @z
94
+ )
95
+
96
+ # Bottom
97
+ Gosu.draw_line(
98
+ @x + @width, @y + @height, Gosu::Color::RED,
99
+ @x, @y + @height, Gosu::Color::RED,
100
+ @z
101
+ )
102
+
103
+ # Left
104
+ Gosu.draw_line(
105
+ @x, @y + @height, Gosu::Color::RED,
106
+ @x, @y, Gosu::Color::RED,
107
+ @z
108
+ )
109
+ end
110
+
111
+ def background=(_background)
112
+ @paint.set(_background)
113
+ update
114
+ end
115
+
116
+ def angle=(n)
117
+ @angle = n
118
+ update
119
+ end
120
+ end
121
+
122
+ class Paint
123
+ attr_accessor :top_left, :top_right, :bottom_left, :bottom_right
124
+
125
+ def initialize(background)
126
+ set(background)
127
+ end
128
+
129
+ def set(background)
130
+ @background = background
131
+
132
+ if background.is_a?(Numeric)
133
+ @top_left = background
134
+ @top_right = background
135
+ @bottom_left = background
136
+ @bottom_right = background
137
+ elsif background.is_a?(Gosu::Color)
138
+ @top_left = background
139
+ @top_right = background
140
+ @bottom_left = background
141
+ @bottom_right = background
142
+ elsif background.is_a?(Array)
143
+ if background.size == 1
144
+ set(background.first)
145
+ elsif background.size == 2
146
+ @top_left = background.first
147
+ @top_right = background.last
148
+ @bottom_left = background.first
149
+ @bottom_right = background.last
150
+ elsif background.size == 4
151
+ @top_left = background[0]
152
+ @top_right = background[1]
153
+ @bottom_left = background[2]
154
+ @bottom_right = background[3]
155
+ else
156
+ raise ArgumentError, "background array was empty or had wrong number of elements (expected 2 or 4 elements)"
157
+ end
158
+ elsif background.is_a?(Hash)
159
+ @top_left = background[:top_left]
160
+ @top_right = background[:top_right]
161
+ @bottom_left = background[:bottom_left]
162
+ @bottom_right = background[:bottom_right]
163
+ elsif background.is_a?(Range)
164
+ set([background.begin, background.begin, background.end, background.end])
165
+ else
166
+ raise ArgumentError, "background '#{background}' of type '#{background.class}' was not able to be processed"
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ # Add <=> method to support Range based gradients
173
+ module Gosu
174
+ class Color
175
+ def <=>(_other)
176
+ self
177
+ end
178
+ end
179
+ end