cyberarm_engine 0.16.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -4
  3. data/assets/textures/logo.png +0 -0
  4. data/cyberarm_engine.gemspec +2 -2
  5. data/lib/cyberarm_engine/animator.rb +172 -9
  6. data/lib/cyberarm_engine/background_nine_slice.rb +51 -34
  7. data/lib/cyberarm_engine/builtin/intro_state.rb +131 -0
  8. data/lib/cyberarm_engine/common.rb +19 -2
  9. data/lib/cyberarm_engine/console/command.rb +158 -0
  10. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -0
  11. data/lib/cyberarm_engine/console/subcommand.rb +100 -0
  12. data/lib/cyberarm_engine/console.rb +248 -0
  13. data/lib/cyberarm_engine/game_state.rb +5 -0
  14. data/lib/cyberarm_engine/model.rb +6 -1
  15. data/lib/cyberarm_engine/opengl/perspective_camera.rb +2 -2
  16. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +9 -0
  17. data/lib/cyberarm_engine/opengl/texture.rb +1 -1
  18. data/lib/cyberarm_engine/text.rb +82 -45
  19. data/lib/cyberarm_engine/ui/dsl.rb +3 -2
  20. data/lib/cyberarm_engine/ui/element.rb +236 -47
  21. data/lib/cyberarm_engine/ui/elements/button.rb +0 -63
  22. data/lib/cyberarm_engine/ui/elements/check_box.rb +4 -1
  23. data/lib/cyberarm_engine/ui/elements/container.rb +65 -35
  24. data/lib/cyberarm_engine/ui/elements/edit_line.rb +20 -13
  25. data/lib/cyberarm_engine/ui/elements/text_block.rb +13 -7
  26. data/lib/cyberarm_engine/ui/event.rb +9 -2
  27. data/lib/cyberarm_engine/ui/gui_state.rb +37 -4
  28. data/lib/cyberarm_engine/ui/style.rb +14 -3
  29. data/lib/cyberarm_engine/ui/theme.rb +26 -1
  30. data/lib/cyberarm_engine/version.rb +1 -1
  31. data/lib/cyberarm_engine/window.rb +7 -1
  32. data/lib/cyberarm_engine.rb +11 -4
  33. metadata +12 -7
  34. data/lib/cyberarm_engine/ui/elements/label.rb +0 -156
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 074b1687997e6415e2af20d723a2641823e3f3704ae5485bdda305124e5babcc
4
- data.tar.gz: 01a0161471ff3492f6267b0f2f6460e547c03a937dc305ea0e46de1746774e31
3
+ metadata.gz: c8a871fd51f7fb568600a1668f93f37b2fdc3a077d8e6b7310ff297ff60690df
4
+ data.tar.gz: 80fb6e494d039fb78f03c656159d70f7388dd50673bf6171a27d7b63a973cdef
5
5
  SHA512:
6
- metadata.gz: 9c35814f0690460e76d8d4050c1ad6fd1599f287de40477976252c228b7a2051545d55f98f223518d148cff6aa3ea8cdd01291871bb28639167a9bbee1fc469f
7
- data.tar.gz: bf2b94247d7f3ed5519d884235c51298f19f433a11acb198a36c8a29d976f26b68cd2bca159d0088e65ca02f51651113ff3b0da0ff6129c9165a06bedf0c7685
6
+ metadata.gz: 9a4f3bddd2d3a146fc6a71496eb0bb8d00c10ce7fddaadd2ab81fa4972471ca47d029b43d141a4c39fca3b2d6c75018b1f97e7925d3a943c88891b0e1e79a30a
7
+ data.tar.gz: 43bc7a87c50e0f56c9cecae84dbb1fc03c45ce3a2e30503b8074c42e0d981cabb1e1eb592a5e4e716d27aeb8ae5952421bd514332699f07a4bb8d894240a6e4b
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # CyberarmEngine
1
+ ![CyberarmEngine](https://raw.githubusercontent.com/cyberarm/cyberarm_engine/master/assets/textures/logo.png)
2
2
 
3
3
  Yet Another Game Engine On Top Of Gosu
4
4
 
@@ -32,6 +32,8 @@ require "cyberarm_engine"
32
32
 
33
33
  class Hello < CyberarmEngine::GuiState
34
34
  def setup
35
+ background Gosu::Color::GRAY
36
+
35
37
  stack do
36
38
  label "Hello World!"
37
39
 
@@ -43,15 +45,14 @@ class Hello < CyberarmEngine::GuiState
43
45
  end
44
46
 
45
47
  class Window < CyberarmEngine::Window
46
- def initialize
47
- super
48
+ def setup
48
49
  self.show_cursor = true
49
50
 
50
51
  push_state(Hello)
51
52
  end
52
53
  end
53
54
 
54
- Window.new.show
55
+ Window.new(width: 800, height: 600, fullscreen: false, resizable: true).show
55
56
  ```
56
57
 
57
58
  ## Development
Binary file
@@ -29,11 +29,11 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_dependency "clipboard", "~> 1.3.5"
31
31
  spec.add_dependency "excon", "~> 0.78.0"
32
- spec.add_dependency "gosu", "~> 1.0.0"
32
+ spec.add_dependency "gosu", "~> 1.1"
33
33
  spec.add_dependency "gosu_more_drawables", "~> 0.3"
34
34
  # spec.add_dependency "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows
35
35
 
36
- spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "bundler", "~> 2.2"
37
37
  spec.add_development_dependency "minitest", "~> 5.0"
38
38
  spec.add_development_dependency "rake", "~> 13.0"
39
39
  end
@@ -1,11 +1,11 @@
1
1
  module CyberarmEngine
2
2
  class Animator
3
- DEFAULT_TWEEN = :linear
4
- def initialize(start_time:, duration:, from:, to:, &block)
3
+ def initialize(start_time:, duration:, from:, to:, tween: :linear, &block)
5
4
  @start_time = start_time
6
5
  @duration = duration
7
6
  @from = from.dup
8
7
  @to = to.dup
8
+ @tween = tween
9
9
  @block = block
10
10
  end
11
11
 
@@ -14,18 +14,18 @@ module CyberarmEngine
14
14
  end
15
15
 
16
16
  def progress
17
- (@start_time.to_f + (Gosu.milliseconds - @start_time)) / (@start_time + @duration.to_f)
17
+ ((Gosu.milliseconds - @start_time) / @duration.to_f).clamp(0.0, 1.0)
18
18
  end
19
19
 
20
20
  def complete?
21
21
  progress >= 1.0
22
22
  end
23
23
 
24
- def transition(from, to, tween = DEFAULT_TWEEN)
24
+ def transition(from = @from, to = @to, tween = @tween)
25
25
  from + (to - from) * send("tween_#{tween}", progress)
26
26
  end
27
27
 
28
- def color_transition(from, to, _tween = DEFAULT_TWEEN)
28
+ def color_transition(from = @from, to = @to, _tween = @tween)
29
29
  r = transition(from.red, to.red)
30
30
  g = transition(from.green, to.green)
31
31
  b = transition(from.blue, to.blue)
@@ -34,7 +34,7 @@ module CyberarmEngine
34
34
  Gosu::Color.rgba(r, g, b, a)
35
35
  end
36
36
 
37
- def color_hsv_transition(from, to, tween = DEFAULT_TWEEN)
37
+ def color_hsv_transition(from = @from, to = @to, tween = @tween)
38
38
  hue = transition(from.hue, to.hue, tween)
39
39
  saturation = transition(from.saturation, to.saturation, tween)
40
40
  value = transition(from.value, to.value, tween)
@@ -43,14 +43,177 @@ module CyberarmEngine
43
43
  Gosu::Color.from_ahsv(alpha, hue, saturation, value)
44
44
  end
45
45
 
46
- # NOTE: Use this for future reference? https://github.com/danro/easing-js/blob/master/easing.js
46
+ # Tween functions based on those provided here: https://github.com/danro/easing-js/blob/master/easing.js
47
+ # Under MIT / BSD
47
48
 
48
49
  def tween_linear(t)
49
50
  t
50
51
  end
51
52
 
52
- def tween_sine(t)
53
- Math.sin(t) * t
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
54
217
  end
55
218
  end
56
219
  end
@@ -1,10 +1,11 @@
1
1
  module CyberarmEngine
2
2
  class BackgroundNineSlice
3
3
  include CyberarmEngine::Common
4
- attr_accessor :x, :y, :z, :width, :height
4
+ attr_accessor :x, :y, :z, :width, :height, :left, :top, :right, :bottom, :mode, :color
5
+ attr_reader :image
5
6
 
6
- def initialize(image_path:, x: 0, y: 0, z: 0, width: 64, height: 64, mode: :tiled, left: 4, top: 4, right: 56, bottom: 56)
7
- @image = get_image(image_path)
7
+ def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :tiled, left: 1, top: 1, right: 1, bottom: 1, color: Gosu::Color::WHITE)
8
+ @image = get_image(image_path) if image_path
8
9
 
9
10
  @x = x
10
11
  @y = y
@@ -20,23 +21,33 @@ module CyberarmEngine
20
21
  @right = right
21
22
  @bottom = bottom
22
23
 
23
- nine_slice
24
+ @color = color
25
+
26
+ nine_slice if @image
27
+ end
28
+
29
+ def image=(image_path)
30
+ old_image = @image
31
+ @image = image_path ? get_image(image_path) : image_path
32
+ nine_slice if @image && old_image != @image
24
33
  end
25
34
 
26
35
  def nine_slice
27
- @segment_top_left = Gosu.render(@left, @top) { @image.draw(0, 0, 0) }
28
- @segment_top_right = Gosu.render(@image.width - @right, @top) { @image.draw(-@right, 0, 0) }
36
+ # pp [@left, @top, @right, @bottom, @image.width]
29
37
 
30
- @segment_left = Gosu.render(@left, @bottom - @top) { @image.draw(0, -@top, 0) }
31
- @segment_right = Gosu.render(@image.width - @right, @bottom - @top) { @image.draw(-@right, -@top, 0) }
38
+ @segment_top_left = @image.subimage(0, 0, @left, @top)
39
+ @segment_top_right = @image.subimage(@image.width - @right, 0, @right, @top)
32
40
 
33
- @segment_bottom_left = Gosu.render(@left, @image.height - @bottom) { @image.draw(0, -@bottom, 0) }
34
- @segment_bottom_right = Gosu.render(@image.width - @right, @image.height - @bottom) { @image.draw(-@right, -@bottom, 0) }
41
+ @segment_left = @image.subimage(0, @top, @left, @image.height - (@top + @bottom))
42
+ @segment_right = @image.subimage(@image.width - @right, @top, @left, @image.height - (@top + @bottom))
35
43
 
36
- @segment_top = Gosu.render(@right - @left, @top) { @image.draw(-@left, 0, 0) }
37
- @segment_bottom = Gosu.render(@right - @left, @image.height - @bottom) { @image.draw(-@left, -@bottom, 0) }
44
+ @segment_bottom_left = @image.subimage(0, @image.height - @bottom, @left, @bottom)
45
+ @segment_bottom_right = @image.subimage(@image.width - @right, @image.height - @bottom, @right, @bottom)
38
46
 
39
- @segment_middle = Gosu.render(@right - @left, @bottom - @top) { @image.draw(-@left, -@top, 0) }
47
+ @segment_top = @image.subimage(@left, 0, @image.width - (@left + @right), @top)
48
+ @segment_bottom = @image.subimage(@left, @image.height - @bottom, @image.width - (@left + @right), @bottom)
49
+
50
+ @segment_middle = @image.subimage(@left, @top, @image.width - (@left + @right), @image.height - (@top + @bottom))
40
51
  end
41
52
 
42
53
  def cx
@@ -56,67 +67,73 @@ module CyberarmEngine
56
67
  end
57
68
 
58
69
  def width_scale
59
- width_scale = (@width - (@left + (@image.width - @right))).to_f / (@right - @left)
70
+ scale = (@width.to_f - (@left + @right)) / (@image.width - (@left + @right))
71
+ scale.abs
60
72
  end
61
73
 
62
74
  def height_scale
63
- height_scale = (@height - (@top + (@image.height - @bottom))).to_f / (@bottom - @top)
75
+ scale = (@height - (@top + @bottom)).to_f / (@image.height - (@top + @bottom))
76
+ scale.abs
64
77
  end
65
78
 
66
79
  def draw
80
+ return unless @image && @segment_top_left
81
+
67
82
  @mode == :tiled ? draw_tiled : draw_stretched
68
83
  end
69
84
 
70
85
  def draw_stretched
71
- @segment_top_left.draw(@x, @y, @z)
72
- @segment_top.draw(@x + @segment_top_left.width, @y, @z, width_scale) # SCALE X
73
- @segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z)
74
-
75
- @segment_right.draw((@x + @width) - @segment_right.width, @y + @top, @z, 1, height_scale) # SCALE Y
76
- @segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z)
77
- @segment_bottom.draw(@x + @segment_bottom_left.width, (@y + @height) - @segment_bottom.height, @z, width_scale) # SCALE X
78
- @segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z)
79
- @segment_left.draw(@x, @y + @top, @z, 1, height_scale) # SCALE Y
80
- @segment_middle.draw(@x + @segment_top_left.width, @y + @segment_top.height, @z, width_scale, height_scale) # SCALE X and SCALE Y
86
+ @segment_top_left.draw(@x, @y, @z, 1, 1, @color)
87
+ @segment_top.draw(@x + @segment_top_left.width, @y, @z, width_scale, 1, @color) # SCALE X
88
+ @segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color)
89
+
90
+ @segment_right.draw((@x + @width) - @segment_right.width, @y + @top, @z, 1, height_scale, @color) # SCALE Y
91
+ @segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color)
92
+ @segment_bottom.draw(@x + @segment_bottom_left.width, (@y + @height) - @segment_bottom.height, @z, width_scale, 1, @color) # SCALE X
93
+ @segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color)
94
+ @segment_left.draw(@x, @y + @top, @z, 1, height_scale, @color) # SCALE Y
95
+ @segment_middle.draw(@x + @segment_top_left.width, @y + @segment_top.height, @z, width_scale, height_scale, @color) # SCALE X and SCALE Y
81
96
  end
82
97
 
83
98
  def draw_tiled
84
- @segment_top_left.draw(@x, @y, @z)
99
+ @segment_top_left.draw(@x, @y, @z, 1, 1, @color)
100
+
101
+ # p [width_scale, height_scale]
85
102
 
86
103
  Gosu.clip_to(@x + @segment_top_left.width, @y, @segment_top.width * width_scale, @segment_top.height) do
87
104
  width_scale.ceil.times do |i|
88
- @segment_top.draw(@x + @segment_top_left.width + (@segment_top.width * i), @y, @z) # SCALE X
105
+ @segment_top.draw(@x + @segment_top_left.width + (@segment_top.width * i), @y, @z, 1, 1, @color) # SCALE X
89
106
  end
90
107
  end
91
108
 
92
- @segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z)
109
+ @segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color)
93
110
 
94
111
  Gosu.clip_to(@x + @width - @segment_top_right.width, @y + @top, @segment_right.width, @segment_right.height * height_scale) do
95
112
  height_scale.ceil.times do |i|
96
- @segment_right.draw((@x + @width) - @segment_right.width, @y + @top + (@segment_right.height * i), @z) # SCALE Y
113
+ @segment_right.draw((@x + @width) - @segment_right.width, @y + @top + (@segment_right.height * i), @z, 1, 1, @color) # SCALE Y
97
114
  end
98
115
  end
99
116
 
100
- @segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z)
117
+ @segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color)
101
118
 
102
119
  Gosu.clip_to(@x + @segment_top_left.width, @y + @height - @segment_bottom.height, @segment_top.width * width_scale, @segment_bottom.height) do
103
120
  width_scale.ceil.times do |i|
104
- @segment_bottom.draw(@x + @segment_bottom_left.width + (@segment_bottom.width * i), (@y + @height) - @segment_bottom.height, @z) # SCALE X
121
+ @segment_bottom.draw(@x + @segment_bottom_left.width + (@segment_bottom.width * i), (@y + @height) - @segment_bottom.height, @z, 1, 1, @color) # SCALE X
105
122
  end
106
123
  end
107
124
 
108
- @segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z)
125
+ @segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color)
109
126
 
110
127
  Gosu.clip_to(@x, @y + @top, @segment_left.width, @segment_left.height * height_scale) do
111
128
  height_scale.ceil.times do |i|
112
- @segment_left.draw(@x, @y + @top + (@segment_left.height * i), @z) # SCALE Y
129
+ @segment_left.draw(@x, @y + @top + (@segment_left.height * i), @z, 1, 1, @color) # SCALE Y
113
130
  end
114
131
  end
115
132
 
116
133
  Gosu.clip_to(@x + @segment_top_left.width, @y + @segment_top.height, @width - (@segment_left.width + @segment_right.width), @height - (@segment_top.height + @segment_bottom.height)) do
117
134
  height_scale.ceil.times do |y|
118
135
  width_scale.ceil.times do |x|
119
- @segment_middle.draw(@x + @segment_top_left.width + (@segment_middle.width * x), @y + @segment_top.height + (@segment_middle.height * y), @z) # SCALE X and SCALE Y
136
+ @segment_middle.draw(@x + @segment_top_left.width + (@segment_middle.width * x), @y + @segment_top.height + (@segment_middle.height * y), @z, 1, 1, @color) # SCALE X and SCALE Y
120
137
  end
121
138
  end
122
139
  end
@@ -0,0 +1,131 @@
1
+ module CyberarmEngine
2
+ class IntroState < CyberarmEngine::GameState
3
+ def setup
4
+ @display_width = 800
5
+ @display_height = 600
6
+
7
+ @title_size = 56
8
+ @caption_size = 24
9
+
10
+ @title = CyberarmEngine::Text.new("", size: @title_size, shadow_color: 0xaa_222222)
11
+ @caption = CyberarmEngine::Text.new("", size: @caption_size, shadow_color: 0xaa_222222)
12
+
13
+ @spacer_width = 256
14
+ @spacer_height = 6
15
+ @padding = 6
16
+
17
+ @cyberarm_engine_logo = get_image "#{CYBERARM_ENGINE_ROOT_PATH}/assets/textures/logo.png"
18
+
19
+ @gosu_logo = generate_proxy("Gosu", "Game Library", 0xff_111111)
20
+ @ruby_logo = generate_proxy("Ruby", "Programming Language", 0xff_880000)
21
+ @opengl_logo = generate_proxy("OpenGL", "Graphics API", 0xff_5586a4) if defined?(OpenGL)
22
+
23
+ base_time = Gosu.milliseconds
24
+
25
+ @born_time = Gosu.milliseconds
26
+ @continue_after = 5_000
27
+
28
+ @animators = [
29
+ Animator.new(start_time: base_time += 1000, duration: 100, from: 0.0, to: 1.0, tween: :ease_in_out),
30
+ Animator.new(start_time: base_time += -500, duration: 1_000, from: 0.0, to: 1.0, tween: :ease_in_out),
31
+ Animator.new(start_time: base_time += 500, duration: 1_000, from: 0.0, to: 1.0, tween: :ease_in_out),
32
+ Animator.new(start_time: base_time += 500, duration: 1_000, from: 0.0, to: 1.0, tween: :ease_in_out),
33
+ Animator.new(start_time: base_time + 500, duration: 1_000, from: 0.0, to: 1.0, tween: :ease_in_out),
34
+ Animator.new(start_time: Gosu.milliseconds + @continue_after - 1_000, duration: 1_000, from: 0.0, to: 1.0, tween: :ease_in_out),
35
+
36
+ Animator.new(start_time: Gosu.milliseconds + 250, duration: 500, from: 0.0, to: 1.0, tween: :swing_to) # CyberarmEngine LOGO
37
+ ]
38
+ end
39
+
40
+ def draw
41
+ Gosu.draw_rect(0, 0, window.width, window.height, 0xff_222222)
42
+
43
+ scale = (@display_width - @padding * 2).to_f / @cyberarm_engine_logo.width * @animators.last.transition
44
+
45
+ @cyberarm_engine_logo.draw_rot(
46
+ window.width / 2,
47
+ (window.height) / 2 - @cyberarm_engine_logo.height / 2 - @padding * 2,
48
+ 2,
49
+ 0,
50
+ 0.5,
51
+ 0.5,
52
+ scale,
53
+ scale
54
+ )
55
+
56
+ Gosu.draw_rect(
57
+ window.width / 2 - (@display_width / 2 + @padding),
58
+ window.height / 2 - @spacer_height / 2,
59
+ @display_width + @padding,
60
+ @spacer_height * @animators[0].transition,
61
+ Gosu::Color::WHITE
62
+ )
63
+
64
+ @title.x = window.width / 2 - @title.text_width / 2
65
+ @title.y = (window.height / 2 + (@spacer_height / 2) + @padding) * @animators[1].transition
66
+ @title.text = "Powered By"
67
+
68
+ Gosu.clip_to(0, window.height / 2 + (@spacer_height / 2), window.width, @title.height) do
69
+ @title.draw
70
+ end
71
+
72
+ y = @title.y + @title.height * 2
73
+
74
+ Gosu.clip_to(0, y, window.width, @gosu_logo.height) do
75
+ Gosu.translate(@opengl_logo.nil? ? @ruby_logo.width / 2 : 0, 0) do
76
+ @gosu_logo.draw(
77
+ window.width.to_f / 2 - @ruby_logo.width / 2 - (@ruby_logo.width - @padding),
78
+ y * @animators[2].transition,
79
+ 2
80
+ )
81
+ @ruby_logo.draw(
82
+ window.width.to_f / 2 - @ruby_logo.width / 2,
83
+ y * @animators[3].transition,
84
+ 2
85
+ )
86
+ @opengl_logo&.draw(
87
+ window.width.to_f / 2 - @ruby_logo.width / 2 + (@ruby_logo.width - @padding),
88
+ y * @animators[4].transition,
89
+ 2
90
+ )
91
+ end
92
+ end
93
+
94
+ Gosu.draw_rect(0, 0, window.width, window.height, Gosu::Color.rgba(0, 0, 0, 255 * @animators[5].transition), 10_000)
95
+ end
96
+
97
+ def update
98
+ @animators.each(&:update)
99
+
100
+ return unless Gosu.milliseconds - @born_time >= @continue_after
101
+
102
+ pop_state
103
+ push_state(@options[:forward], @options[:forward_options] || {}) if @options[:forward]
104
+ end
105
+
106
+ def button_down(_id)
107
+ @continue_after = 0
108
+ end
109
+
110
+ def generate_proxy(title, caption, color_hint)
111
+ @title.text = title
112
+ @caption.text = caption
113
+
114
+ width = @spacer_width + 2 * @padding
115
+ height = @title_size + @caption_size + @spacer_height + 2 * @padding + @spacer_height
116
+
117
+ Gosu.record(width.ceil, height.ceil) do
118
+ @title.x = (width - @padding * 2) / 2 - @title.text_width / 2
119
+ @title.y = @padding
120
+ @title.draw
121
+
122
+ Gosu.draw_rect(0, @padding + @title_size + @padding, @spacer_width, @spacer_height, Gosu::Color::WHITE)
123
+ Gosu.draw_rect(1, @padding + @title_size + @padding + 1, @spacer_width - 2, @spacer_height - 2, color_hint)
124
+
125
+ @caption.x = (width - @padding * 2) / 2 - @caption.text_width / 2
126
+ @caption.y = @padding + @title_size + @padding + @spacer_height + @padding
127
+ @caption.draw
128
+ end
129
+ end
130
+ end
131
+ end
@@ -16,6 +16,10 @@ module CyberarmEngine
16
16
  window.pop_state
17
17
  end
18
18
 
19
+ def shift_state
20
+ window.shift_state
21
+ end
22
+
19
23
  def show_cursor
20
24
  window.show_cursor
21
25
  end
@@ -24,8 +28,8 @@ module CyberarmEngine
24
28
  window.show_cursor = boolean
25
29
  end
26
30
 
27
- def draw_rect(x, y, width, height, color, z = 0)
28
- Gosu.draw_rect(x, y, width, height, color, z)
31
+ def draw_rect(x, y, width, height, color, z = 0, mode = :default)
32
+ Gosu.draw_rect(x, y, width, height, color, z, mode)
29
33
  end
30
34
 
31
35
  def fill(color, z = 0)
@@ -70,6 +74,7 @@ module CyberarmEngine
70
74
  else
71
75
  klass.new(path)
72
76
  end
77
+
73
78
  hash[path] = instance
74
79
  asset = instance
75
80
  end
@@ -92,5 +97,17 @@ module CyberarmEngine
92
97
  def window
93
98
  $window
94
99
  end
100
+
101
+ def control_down?
102
+ Gosu.button_down?(Gosu::KB_LEFT_CONTROL) || Gosu.button_down?(Gosu::KB_RIGHT_CONTROL)
103
+ end
104
+
105
+ def shift_down?
106
+ Gosu.button_down?(Gosu::KB_LEFT_SHIFT) || Gosu.button_down?(Gosu::KB_RIGHT_SHIFT)
107
+ end
108
+
109
+ def alt_down?
110
+ Gosu.button_down?(Gosu::KB_LEFT_ALT) || Gosu.button_down?(Gosu::KB_RIGHT_ALT)
111
+ end
95
112
  end
96
113
  end