cyberarm_engine 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cyberarm_engine/engine.rb +2 -2
- data/lib/cyberarm_engine/lib/vector.rb +96 -29
- data/lib/cyberarm_engine/objects/text.rb +26 -14
- data/lib/cyberarm_engine/ui/element.rb +20 -0
- data/lib/cyberarm_engine/ui/label.rb +9 -0
- data/lib/cyberarm_engine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a107f38b291492d95d048693aec005c4dcf3dc73f601ea300ac952ede787bf2
|
4
|
+
data.tar.gz: 1b5a80bb6ba87d35ca5231be6b559020c404e34a48e2c7bda5770f3f83faad72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f7f836d5b1471a9251735593c5a61e44bcbabe126ff1ef4c92a28b626a8395bfcc8201a6428587b981c30a212485e3d715a4658d28b5697ed84af5ce694e460
|
7
|
+
data.tar.gz: a75b1b1260d4e5d4a3ad762d29a39c8bb412d0c786c7368ad331f96400aa9970992573d22746b96fc3f7c177443850f0b4a9f5429295da6ed80c38d64b52e08e
|
@@ -15,10 +15,10 @@ module CyberarmEngine
|
|
15
15
|
$window.last_frame_time/1000.0
|
16
16
|
end
|
17
17
|
|
18
|
-
def initialize(width
|
18
|
+
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0/60, resizable: false)
|
19
19
|
@show_cursor = false
|
20
20
|
|
21
|
-
super(width, height, fullscreen, update_interval)
|
21
|
+
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable)
|
22
22
|
$window = self
|
23
23
|
@last_frame_time = Gosu.milliseconds-1
|
24
24
|
@current_frame_time = Gosu.milliseconds
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module CyberarmEngine
|
2
2
|
class Vector
|
3
|
-
|
4
3
|
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
5
4
|
@x, @y, @z, @weight = x, y, z, weight
|
6
5
|
end
|
@@ -17,10 +16,6 @@ module CyberarmEngine
|
|
17
16
|
def weight; @weight; end
|
18
17
|
def weight=(n); @weight = n; end
|
19
18
|
|
20
|
-
# def xy=(nx, ny); @x = nx; @y = ny; end
|
21
|
-
# def xyz=(nx, ny, nz); @x = nx; @y = ny; @z = nz; end
|
22
|
-
# def xyzw=(nx, ny, nz, nw); @x = nx; @y = ny; @z = nz; @weight = nw; end
|
23
|
-
|
24
19
|
def ==(other)
|
25
20
|
if other.is_a?(Numeric)
|
26
21
|
@x == other &&
|
@@ -35,43 +30,85 @@ module CyberarmEngine
|
|
35
30
|
end
|
36
31
|
end
|
37
32
|
|
33
|
+
# Performs math operation, excluding @weight
|
34
|
+
def operator(function, other)
|
35
|
+
if other.is_a?(Numeric)
|
36
|
+
Vector.new(
|
37
|
+
@x.send(:"#{function}", other),
|
38
|
+
@y.send(:"#{function}", other),
|
39
|
+
@z.send(:"#{function}", other)
|
40
|
+
)
|
41
|
+
else
|
42
|
+
Vector.new(
|
43
|
+
@x.send(:"#{function}", other.x),
|
44
|
+
@y.send(:"#{function}", other.y),
|
45
|
+
@z.send(:"#{function}", other.z)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Adds Vector and Numberic or Vector and Vector, excluding @weight
|
38
51
|
def +(other)
|
39
|
-
|
40
|
-
@x + other.x,
|
41
|
-
@y + other.y,
|
42
|
-
@z + other.z,
|
43
|
-
@weight + other.weight
|
44
|
-
)
|
52
|
+
operator("+", other)
|
45
53
|
end
|
46
54
|
|
55
|
+
# Subtracts Vector and Numberic or Vector and Vector, excluding @weight
|
47
56
|
def -(other)
|
48
|
-
|
49
|
-
@x - other.x,
|
50
|
-
@y - other.y,
|
51
|
-
@z - other.z,
|
52
|
-
@weight - other.weight
|
53
|
-
)
|
57
|
+
operator("-", other)
|
54
58
|
end
|
55
59
|
|
60
|
+
# Multiplies Vector and Numberic or Vector and Vector, excluding @weight
|
56
61
|
def *(other)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
operator("*", other)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Divides Vector and Numberic or Vector and Vector, excluding @weight
|
66
|
+
def /(other)
|
67
|
+
# Duplicated to protect from DivideByZero
|
68
|
+
if other.is_a?(Numeric)
|
69
|
+
Vector.new(
|
70
|
+
(@x == 0 ? 0 : @x / other),
|
71
|
+
(@y == 0 ? 0 : @y / other),
|
72
|
+
(@z == 0 ? 0 : @z / other)
|
62
73
|
)
|
74
|
+
else
|
75
|
+
Vector.new(
|
76
|
+
(@x == 0 ? 0 : @x / other.x),
|
77
|
+
(@y == 0 ? 0 : @y / other.y),
|
78
|
+
(@z == 0 ? 0 : @z / other.z)
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def dot(other)
|
84
|
+
product = 0
|
85
|
+
|
86
|
+
a = self.to_a
|
87
|
+
b = other.to_a
|
88
|
+
|
89
|
+
3.times do |i|
|
90
|
+
product = product + (a[i] * b[i])
|
63
91
|
end
|
64
92
|
|
65
|
-
|
66
|
-
|
93
|
+
return product
|
94
|
+
end
|
95
|
+
|
96
|
+
def cross(other)
|
97
|
+
a = self.to_a
|
98
|
+
b = other.to_a
|
99
|
+
|
67
100
|
Vector.new(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
@weight == 0 || other.weight == 0 ? 0 : @weight / other.weight
|
101
|
+
b[2] * a[1] - b[1] * a[2],
|
102
|
+
b[0] * a[2] - b[2] * a[0],
|
103
|
+
b[1] * a[0] - b[0] * a[1]
|
72
104
|
)
|
73
105
|
end
|
74
106
|
|
107
|
+
# returns degrees
|
108
|
+
def angle(other)
|
109
|
+
Math.acos( self.normalized.dot(other.normalized) ) * 180 / Math::PI
|
110
|
+
end
|
111
|
+
|
75
112
|
# returns magnitude of Vector, ignoring #weight
|
76
113
|
def magnitude
|
77
114
|
Math.sqrt((@x * @x) + (@y * @y) + (@z * @z))
|
@@ -82,8 +119,38 @@ module CyberarmEngine
|
|
82
119
|
self / Vector.new(mag, mag, mag)
|
83
120
|
end
|
84
121
|
|
122
|
+
def direction
|
123
|
+
# z is pitch
|
124
|
+
# y is yaw
|
125
|
+
# x is roll
|
126
|
+
_x = -Math.sin(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
127
|
+
_y = Math.sin(@z.degrees_to_radians)
|
128
|
+
_z = Math.cos(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
129
|
+
|
130
|
+
Vector.new(_x, _y, _z)
|
131
|
+
end
|
132
|
+
|
133
|
+
def inverse
|
134
|
+
Vector.new(1.0 / @x, 1.0 / @y, 1.0 / @z)
|
135
|
+
end
|
136
|
+
|
85
137
|
def sum
|
86
|
-
@x + @y + @z
|
138
|
+
@x + @y + @z
|
139
|
+
end
|
140
|
+
|
141
|
+
# 2D distance using X and Y
|
142
|
+
def distance(other)
|
143
|
+
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2)
|
144
|
+
end
|
145
|
+
|
146
|
+
# 2D distance using X and Z
|
147
|
+
def gl_distance2d(other)
|
148
|
+
Math.sqrt((@x-other.x)**2 + (@z-other.z)**2)
|
149
|
+
end
|
150
|
+
|
151
|
+
# 3D distance using X, Y, and Z
|
152
|
+
def distance3d(other)
|
153
|
+
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2 + (@z-other.z)**2)
|
87
154
|
end
|
88
155
|
|
89
156
|
def to_a
|
@@ -2,8 +2,8 @@ module CyberarmEngine
|
|
2
2
|
class Text
|
3
3
|
CACHE = {}
|
4
4
|
|
5
|
-
attr_accessor :
|
6
|
-
attr_reader :textobject
|
5
|
+
attr_accessor :x, :y, :z, :size, :factor_x, :factor_y, :color, :shadow, :shadow_size, :options
|
6
|
+
attr_reader :text, :textobject
|
7
7
|
|
8
8
|
def initialize(text, options={})
|
9
9
|
@text = text || ""
|
@@ -62,37 +62,49 @@ module CyberarmEngine
|
|
62
62
|
return font
|
63
63
|
end
|
64
64
|
|
65
|
+
def text=(string)
|
66
|
+
@rendered_shadow = nil
|
67
|
+
@text = string
|
68
|
+
end
|
69
|
+
|
65
70
|
def width
|
66
71
|
textobject.text_width(@text)
|
67
72
|
end
|
68
73
|
|
69
74
|
def height
|
70
|
-
@text.lines.count * textobject.height
|
75
|
+
(@text.lines.count) * textobject.height
|
71
76
|
end
|
72
77
|
|
73
78
|
def draw
|
74
79
|
if @shadow && !ARGV.join.include?("--no-shadow")
|
75
|
-
|
76
|
-
|
80
|
+
@shadow_alpha = 30 if @color.alpha > 30
|
81
|
+
@shadow_alpha = @color.alpha if @color.alpha <= 30
|
82
|
+
shadow_color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
|
77
83
|
|
78
|
-
|
79
|
-
|
84
|
+
_x = @shadow_size
|
85
|
+
_y = @shadow_size
|
80
86
|
|
81
|
-
@
|
82
|
-
|
87
|
+
@rendered_shadow ||= Gosu.render((self.width+(shadow_size*2)).ceil, (self.height+(@shadow_size*2)).ceil) do
|
88
|
+
@textobject.draw_markup(@text, _x-@shadow_size, _y, @z)
|
89
|
+
@textobject.draw_markup(@text, _x-@shadow_size, _y-@shadow_size, @z)
|
83
90
|
|
84
|
-
|
85
|
-
|
91
|
+
@textobject.draw_markup(@text, _x, _y-@shadow_size, @z, @factor_x)
|
92
|
+
@textobject.draw_markup(@text, _x+@shadow_size, _y-@shadow_size, @z)
|
86
93
|
|
87
|
-
|
88
|
-
|
94
|
+
@textobject.draw_markup(@text, _x, _y+@shadow_size, @z)
|
95
|
+
@textobject.draw_markup(@text, _x-@shadow_size, _y+@shadow_size, @z)
|
96
|
+
|
97
|
+
@textobject.draw_markup(@text, _x+@shadow_size, _y, @z)
|
98
|
+
@textobject.draw_markup(@text, _x+@shadow_size, _y+@shadow_size, @z)
|
99
|
+
end
|
100
|
+
@rendered_shadow.draw(@x-@shadow_size, @y-@shadow_size, @z, @factor_x, @factor_y, shadow_color)
|
89
101
|
end
|
90
102
|
|
91
103
|
@textobject.draw_markup(@text, @x, @y, @z, @factor_x, @factor_y, @color)
|
92
104
|
end
|
93
105
|
|
94
106
|
def alpha=(n)
|
95
|
-
@color = Gosu::Color.
|
107
|
+
@color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, n)
|
96
108
|
end
|
97
109
|
|
98
110
|
def alpha
|
@@ -186,6 +186,22 @@ module CyberarmEngine
|
|
186
186
|
@border_canvas.update
|
187
187
|
end
|
188
188
|
|
189
|
+
def root
|
190
|
+
unless @root && @root.parent.nil?
|
191
|
+
@root = parent
|
192
|
+
|
193
|
+
loop do
|
194
|
+
if @root.parent.nil?
|
195
|
+
break
|
196
|
+
else
|
197
|
+
@root = @root.parent
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
@root
|
203
|
+
end
|
204
|
+
|
189
205
|
def recalculate
|
190
206
|
raise "#{self.class}#recalculate was not overridden!"
|
191
207
|
end
|
@@ -193,5 +209,9 @@ module CyberarmEngine
|
|
193
209
|
def value
|
194
210
|
raise "#{self.class}#value was not overridden!"
|
195
211
|
end
|
212
|
+
|
213
|
+
def value=(value)
|
214
|
+
raise "#{self.class}#value= was not overridden!"
|
215
|
+
end
|
196
216
|
end
|
197
217
|
end
|
@@ -30,5 +30,14 @@ module CyberarmEngine
|
|
30
30
|
def value
|
31
31
|
@text.text
|
32
32
|
end
|
33
|
+
|
34
|
+
def value=(value)
|
35
|
+
@text.text = value
|
36
|
+
|
37
|
+
old_width, old_height = width, height
|
38
|
+
recalculate
|
39
|
+
|
40
|
+
root.recalculate if old_width != width || old_height != height
|
41
|
+
end
|
33
42
|
end
|
34
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyberarm_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyberarm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|