cyberarm_engine 0.13.0 → 0.13.1

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -8
  3. data/.travis.yml +5 -5
  4. data/Gemfile +6 -6
  5. data/LICENSE.txt +21 -21
  6. data/README.md +73 -43
  7. data/Rakefile +10 -10
  8. data/bin/console +14 -14
  9. data/bin/setup +8 -8
  10. data/cyberarm_engine.gemspec +36 -36
  11. data/lib/cyberarm_engine.rb +49 -47
  12. data/lib/cyberarm_engine/animator.rb +53 -53
  13. data/lib/cyberarm_engine/background.rb +175 -175
  14. data/lib/cyberarm_engine/bounding_box.rb +149 -149
  15. data/lib/cyberarm_engine/common.rb +96 -96
  16. data/lib/cyberarm_engine/config_file.rb +46 -0
  17. data/lib/cyberarm_engine/engine.rb +101 -101
  18. data/lib/cyberarm_engine/game_object.rb +256 -256
  19. data/lib/cyberarm_engine/game_state.rb +88 -88
  20. data/lib/cyberarm_engine/gosu_ext/circle.rb +8 -8
  21. data/lib/cyberarm_engine/ray.rb +55 -55
  22. data/lib/cyberarm_engine/shader.rb +398 -262
  23. data/lib/cyberarm_engine/text.rb +146 -146
  24. data/lib/cyberarm_engine/timer.rb +22 -22
  25. data/lib/cyberarm_engine/transform.rb +272 -272
  26. data/lib/cyberarm_engine/ui/border_canvas.rb +100 -100
  27. data/lib/cyberarm_engine/ui/dsl.rb +98 -98
  28. data/lib/cyberarm_engine/ui/element.rb +275 -275
  29. data/lib/cyberarm_engine/ui/elements/button.rb +66 -66
  30. data/lib/cyberarm_engine/ui/elements/check_box.rb +58 -58
  31. data/lib/cyberarm_engine/ui/elements/container.rb +176 -176
  32. data/lib/cyberarm_engine/ui/elements/edit_line.rb +171 -171
  33. data/lib/cyberarm_engine/ui/elements/flow.rb +16 -16
  34. data/lib/cyberarm_engine/ui/elements/image.rb +51 -51
  35. data/lib/cyberarm_engine/ui/elements/label.rb +49 -49
  36. data/lib/cyberarm_engine/ui/elements/progress.rb +49 -49
  37. data/lib/cyberarm_engine/ui/elements/stack.rb +12 -12
  38. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +55 -55
  39. data/lib/cyberarm_engine/ui/event.rb +46 -46
  40. data/lib/cyberarm_engine/ui/gui_state.rb +134 -134
  41. data/lib/cyberarm_engine/ui/style.rb +36 -36
  42. data/lib/cyberarm_engine/ui/theme.rb +120 -120
  43. data/lib/cyberarm_engine/vector.rb +289 -202
  44. data/lib/cyberarm_engine/version.rb +4 -4
  45. metadata +3 -2
@@ -1,150 +1,150 @@
1
- module CyberarmEngine
2
- class BoundingBox
3
- attr_accessor :min, :max
4
-
5
- def initialize(*args)
6
- case args.size
7
- when 0
8
- @min = Vector.new(0, 0, 0)
9
- @max = Vector.new(0, 0, 0)
10
- when 2
11
- @min = args.first.clone
12
- @max = args.last.clone
13
- when 4
14
- @min = Vector.new(args[0], args[1], 0)
15
- @max = Vector.new(args[2], args[3], 0)
16
- when 6
17
- @min = Vector.new(args[0], args[1], args[2])
18
- @max = Vector.new(args[3], args[4], args[5])
19
- else
20
- raise "Invalid number of arguments! Got: #{args.size}, expected: 0, 2, 4, or 6."
21
- end
22
- end
23
-
24
- def ==(other)
25
- @min == other.min &&
26
- @max == other.max
27
- end
28
-
29
- # returns a new bounding box that includes both bounding boxes
30
- def union(other)
31
- temp = BoundingBox.new
32
- temp.min.x = [@min.x, other.min.x].min
33
- temp.min.y = [@min.y, other.min.y].min
34
- temp.min.z = [@min.z, other.min.z].min
35
-
36
- temp.max.x = [@max.x, other.max.x].max
37
- temp.max.y = [@max.y, other.max.y].max
38
- temp.max.z = [@max.z, other.max.z].max
39
-
40
- return temp
41
- end
42
-
43
- # returns the difference between both bounding boxes
44
- def difference(other)
45
- temp = BoundingBox.new
46
- temp.min = @min - other.min
47
- temp.max = @max - other.max
48
-
49
- return temp
50
- end
51
-
52
- # returns whether bounding box intersects other
53
- def intersect?(other)
54
- if other.is_a?(Ray)
55
- other.intersect?(self)
56
- elsif other.is_a?(BoundingBox)
57
- (@min.x <= other.max.x && @max.x >= other.min.x) &&
58
- (@min.y <= other.max.y && @max.y >= other.min.y) &&
59
- (@min.z <= other.max.z && @max.z >= other.min.z)
60
- else
61
- raise "Unknown collider: #{other.class}"
62
- end
63
- end
64
-
65
- # does this bounding box envelop other bounding box? (inclusive of border)
66
- def contains?(other)
67
- other.min.x >= min.x && other.min.y >= min.y && other.min.z >= min.z &&
68
- other.max.x <= max.x && other.max.y <= max.y && other.max.z <= max.z
69
- end
70
-
71
- # returns whether the 3D vector is inside of the bounding box
72
- def inside?(vector)
73
- (vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
74
- (vector.y.between?(@min.y, @max.y) || vector.y.between?(@max.y, @min.y)) &&
75
- (vector.z.between?(@min.z, @max.z) || vector.z.between?(@max.z, @min.z))
76
- end
77
-
78
- # returns whether the 2D vector is inside of the bounding box
79
- def point?(vector)
80
- (vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
81
- (vector.y.between?(@min.y, @max.y) || vector.y.between?(@max.y, @min.y))
82
- end
83
-
84
- def volume
85
- width * height * depth
86
- end
87
-
88
- def width
89
- @max.x - @min.x
90
- end
91
-
92
- def height
93
- @max.y - @min.y
94
- end
95
-
96
- def depth
97
- @max.z - @min.z
98
- end
99
-
100
- def normalize(entity)
101
- temp = BoundingBox.new
102
- temp.min.x = @min.x.to_f * entity.scale.x
103
- temp.min.y = @min.y.to_f * entity.scale.y
104
- temp.min.z = @min.z.to_f * entity.scale.z
105
-
106
- temp.max.x = @max.x.to_f * entity.scale.x
107
- temp.max.y = @max.y.to_f * entity.scale.y
108
- temp.max.z = @max.z.to_f * entity.scale.z
109
-
110
- return temp
111
- end
112
-
113
- def normalize_with_offset(entity)
114
- temp = BoundingBox.new
115
- temp.min.x = @min.x.to_f * entity.scale.x + entity.position.x
116
- temp.min.y = @min.y.to_f * entity.scale.y + entity.position.y
117
- temp.min.z = @min.z.to_f * entity.scale.z + entity.position.z
118
-
119
- temp.max.x = @max.x.to_f * entity.scale.x + entity.position.x
120
- temp.max.y = @max.y.to_f * entity.scale.y + entity.position.y
121
- temp.max.z = @max.z.to_f * entity.scale.z + entity.position.z
122
-
123
- return temp
124
- end
125
-
126
- def +(other)
127
- box = BoundingBox.new
128
- box.min = self.min + other.min
129
- box.min = self.max + other.max
130
-
131
- return box
132
- end
133
-
134
- def -(other)
135
- box = BoundingBox.new
136
- box.min = self.min - other.min
137
- box.min = self.max - other.max
138
-
139
- return box
140
- end
141
-
142
- def sum
143
- @min.sum + @max.sum
144
- end
145
-
146
- def clone
147
- BoundingBox.new(@min.x, @min.y, @min.z, @max.x, @max.y, @max.z)
148
- end
149
- end
1
+ module CyberarmEngine
2
+ class BoundingBox
3
+ attr_accessor :min, :max
4
+
5
+ def initialize(*args)
6
+ case args.size
7
+ when 0
8
+ @min = Vector.new(0, 0, 0)
9
+ @max = Vector.new(0, 0, 0)
10
+ when 2
11
+ @min = args.first.clone
12
+ @max = args.last.clone
13
+ when 4
14
+ @min = Vector.new(args[0], args[1], 0)
15
+ @max = Vector.new(args[2], args[3], 0)
16
+ when 6
17
+ @min = Vector.new(args[0], args[1], args[2])
18
+ @max = Vector.new(args[3], args[4], args[5])
19
+ else
20
+ raise "Invalid number of arguments! Got: #{args.size}, expected: 0, 2, 4, or 6."
21
+ end
22
+ end
23
+
24
+ def ==(other)
25
+ @min == other.min &&
26
+ @max == other.max
27
+ end
28
+
29
+ # returns a new bounding box that includes both bounding boxes
30
+ def union(other)
31
+ temp = BoundingBox.new
32
+ temp.min.x = [@min.x, other.min.x].min
33
+ temp.min.y = [@min.y, other.min.y].min
34
+ temp.min.z = [@min.z, other.min.z].min
35
+
36
+ temp.max.x = [@max.x, other.max.x].max
37
+ temp.max.y = [@max.y, other.max.y].max
38
+ temp.max.z = [@max.z, other.max.z].max
39
+
40
+ return temp
41
+ end
42
+
43
+ # returns the difference between both bounding boxes
44
+ def difference(other)
45
+ temp = BoundingBox.new
46
+ temp.min = @min - other.min
47
+ temp.max = @max - other.max
48
+
49
+ return temp
50
+ end
51
+
52
+ # returns whether bounding box intersects other
53
+ def intersect?(other)
54
+ if other.is_a?(Ray)
55
+ other.intersect?(self)
56
+ elsif other.is_a?(BoundingBox)
57
+ (@min.x <= other.max.x && @max.x >= other.min.x) &&
58
+ (@min.y <= other.max.y && @max.y >= other.min.y) &&
59
+ (@min.z <= other.max.z && @max.z >= other.min.z)
60
+ else
61
+ raise "Unknown collider: #{other.class}"
62
+ end
63
+ end
64
+
65
+ # does this bounding box envelop other bounding box? (inclusive of border)
66
+ def contains?(other)
67
+ other.min.x >= min.x && other.min.y >= min.y && other.min.z >= min.z &&
68
+ other.max.x <= max.x && other.max.y <= max.y && other.max.z <= max.z
69
+ end
70
+
71
+ # returns whether the 3D vector is inside of the bounding box
72
+ def inside?(vector)
73
+ (vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
74
+ (vector.y.between?(@min.y, @max.y) || vector.y.between?(@max.y, @min.y)) &&
75
+ (vector.z.between?(@min.z, @max.z) || vector.z.between?(@max.z, @min.z))
76
+ end
77
+
78
+ # returns whether the 2D vector is inside of the bounding box
79
+ def point?(vector)
80
+ (vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
81
+ (vector.y.between?(@min.y, @max.y) || vector.y.between?(@max.y, @min.y))
82
+ end
83
+
84
+ def volume
85
+ width * height * depth
86
+ end
87
+
88
+ def width
89
+ @max.x - @min.x
90
+ end
91
+
92
+ def height
93
+ @max.y - @min.y
94
+ end
95
+
96
+ def depth
97
+ @max.z - @min.z
98
+ end
99
+
100
+ def normalize(entity)
101
+ temp = BoundingBox.new
102
+ temp.min.x = @min.x.to_f * entity.scale.x
103
+ temp.min.y = @min.y.to_f * entity.scale.y
104
+ temp.min.z = @min.z.to_f * entity.scale.z
105
+
106
+ temp.max.x = @max.x.to_f * entity.scale.x
107
+ temp.max.y = @max.y.to_f * entity.scale.y
108
+ temp.max.z = @max.z.to_f * entity.scale.z
109
+
110
+ return temp
111
+ end
112
+
113
+ def normalize_with_offset(entity)
114
+ temp = BoundingBox.new
115
+ temp.min.x = @min.x.to_f * entity.scale.x + entity.position.x
116
+ temp.min.y = @min.y.to_f * entity.scale.y + entity.position.y
117
+ temp.min.z = @min.z.to_f * entity.scale.z + entity.position.z
118
+
119
+ temp.max.x = @max.x.to_f * entity.scale.x + entity.position.x
120
+ temp.max.y = @max.y.to_f * entity.scale.y + entity.position.y
121
+ temp.max.z = @max.z.to_f * entity.scale.z + entity.position.z
122
+
123
+ return temp
124
+ end
125
+
126
+ def +(other)
127
+ box = BoundingBox.new
128
+ box.min = self.min + other.min
129
+ box.min = self.max + other.max
130
+
131
+ return box
132
+ end
133
+
134
+ def -(other)
135
+ box = BoundingBox.new
136
+ box.min = self.min - other.min
137
+ box.min = self.max - other.max
138
+
139
+ return box
140
+ end
141
+
142
+ def sum
143
+ @min.sum + @max.sum
144
+ end
145
+
146
+ def clone
147
+ BoundingBox.new(@min.x, @min.y, @min.z, @max.x, @max.y, @max.z)
148
+ end
149
+ end
150
150
  end
@@ -1,96 +1,96 @@
1
- module CyberarmEngine
2
- module Common
3
- def push_state(klass, options={})
4
- window.push_state(klass, options)
5
- end
6
-
7
- def current_state
8
- window.current_state
9
- end
10
-
11
- def previous_state
12
- window.previous_state
13
- end
14
-
15
- def pop_state
16
- window.pop_state
17
- end
18
-
19
- def show_cursor
20
- window.show_cursor
21
- end
22
-
23
- def show_cursor=boolean
24
- window.show_cursor = boolean
25
- end
26
-
27
- def draw_rect(x, y, width, height, color, z = 0)
28
- Gosu.draw_rect(x, y, width, height, color, z)
29
- end
30
-
31
- def fill(color, z = 0)
32
- draw_rect(0, 0, window.width, window.height, color, z)
33
- end
34
-
35
- def lighten(color, amount = 25)
36
- if defined?(color.alpha)
37
- return Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
38
- else
39
- return Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
40
- end
41
- end
42
-
43
- def darken(color, amount = 25)
44
- if defined?(color.alpha)
45
- return Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
46
- else
47
- return Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
48
- end
49
- end
50
-
51
- def opacity(color, ratio = 1.0)
52
- alpha = 255 * ratio
53
-
54
- return Gosu::Color.rgba(color.red, color.green, color.blue, alpha)
55
- end
56
-
57
- def get_asset(path, hash, klass, retro = false, tileable = false)
58
- asset = nil
59
- hash.detect do |_asset, instance|
60
- if _asset == path
61
- asset = instance
62
- true
63
- end
64
- end
65
-
66
- unless asset
67
- instance = nil
68
- if klass == Gosu::Image
69
- instance = klass.new(path, retro: retro, tileable: tileable)
70
- else
71
- instance = klass.new(path)
72
- end
73
- hash[path] = instance
74
- asset = instance
75
- end
76
-
77
- return asset
78
- end
79
-
80
- def get_image(path, retro: false, tileable: false)
81
- get_asset(path, Engine::IMAGES, Gosu::Image, retro, tileable)
82
- end
83
-
84
- def get_sample(path)
85
- get_asset(path, Engine::SAMPLES, Gosu::Sample)
86
- end
87
-
88
- def get_song(path)
89
- get_asset(path, Engine::SONGS, Gosu::Song)
90
- end
91
-
92
- def window
93
- $window
94
- end
95
- end
96
- end
1
+ module CyberarmEngine
2
+ module Common
3
+ def push_state(klass, options={})
4
+ window.push_state(klass, options)
5
+ end
6
+
7
+ def current_state
8
+ window.current_state
9
+ end
10
+
11
+ def previous_state
12
+ window.previous_state
13
+ end
14
+
15
+ def pop_state
16
+ window.pop_state
17
+ end
18
+
19
+ def show_cursor
20
+ window.show_cursor
21
+ end
22
+
23
+ def show_cursor=boolean
24
+ window.show_cursor = boolean
25
+ end
26
+
27
+ def draw_rect(x, y, width, height, color, z = 0)
28
+ Gosu.draw_rect(x, y, width, height, color, z)
29
+ end
30
+
31
+ def fill(color, z = 0)
32
+ draw_rect(0, 0, window.width, window.height, color, z)
33
+ end
34
+
35
+ def lighten(color, amount = 25)
36
+ if defined?(color.alpha)
37
+ return Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
38
+ else
39
+ return Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
40
+ end
41
+ end
42
+
43
+ def darken(color, amount = 25)
44
+ if defined?(color.alpha)
45
+ return Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
46
+ else
47
+ return Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
48
+ end
49
+ end
50
+
51
+ def opacity(color, ratio = 1.0)
52
+ alpha = 255 * ratio
53
+
54
+ return Gosu::Color.rgba(color.red, color.green, color.blue, alpha)
55
+ end
56
+
57
+ def get_asset(path, hash, klass, retro = false, tileable = false)
58
+ asset = nil
59
+ hash.detect do |_asset, instance|
60
+ if _asset == path
61
+ asset = instance
62
+ true
63
+ end
64
+ end
65
+
66
+ unless asset
67
+ instance = nil
68
+ if klass == Gosu::Image
69
+ instance = klass.new(path, retro: retro, tileable: tileable)
70
+ else
71
+ instance = klass.new(path)
72
+ end
73
+ hash[path] = instance
74
+ asset = instance
75
+ end
76
+
77
+ return asset
78
+ end
79
+
80
+ def get_image(path, retro: false, tileable: false)
81
+ get_asset(path, Engine::IMAGES, Gosu::Image, retro, tileable)
82
+ end
83
+
84
+ def get_sample(path)
85
+ get_asset(path, Engine::SAMPLES, Gosu::Sample)
86
+ end
87
+
88
+ def get_song(path)
89
+ get_asset(path, Engine::SONGS, Gosu::Song)
90
+ end
91
+
92
+ def window
93
+ $window
94
+ end
95
+ end
96
+ end