cyberarm_engine 0.12.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/Gemfile +1 -1
- data/README.md +33 -3
- data/Rakefile +1 -1
- data/assets/textures/default.png +0 -0
- data/cyberarm_engine.gemspec +11 -8
- data/lib/cyberarm_engine.rb +24 -4
- data/lib/cyberarm_engine/animator.rb +56 -0
- data/lib/cyberarm_engine/background.rb +19 -15
- data/lib/cyberarm_engine/background_nine_slice.rb +125 -0
- data/lib/cyberarm_engine/bounding_box.rb +18 -18
- data/lib/cyberarm_engine/cache.rb +4 -0
- data/lib/cyberarm_engine/cache/download_manager.rb +121 -0
- data/lib/cyberarm_engine/common.rb +16 -16
- data/lib/cyberarm_engine/config_file.rb +46 -0
- data/lib/cyberarm_engine/game_object.rb +63 -72
- data/lib/cyberarm_engine/game_state.rb +7 -4
- data/lib/cyberarm_engine/model.rb +207 -0
- data/lib/cyberarm_engine/model/material.rb +21 -0
- data/lib/cyberarm_engine/model/model_object.rb +131 -0
- data/lib/cyberarm_engine/model/parser.rb +74 -0
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -0
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -0
- data/lib/cyberarm_engine/model_cache.rb +31 -0
- data/lib/cyberarm_engine/opengl.rb +28 -0
- data/lib/cyberarm_engine/opengl/light.rb +50 -0
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -0
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -0
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -0
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -0
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +289 -0
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -0
- data/lib/cyberarm_engine/opengl/shader.rb +406 -0
- data/lib/cyberarm_engine/opengl/texture.rb +69 -0
- data/lib/cyberarm_engine/ray.rb +5 -5
- data/lib/cyberarm_engine/stats.rb +21 -0
- data/lib/cyberarm_engine/text.rb +45 -31
- data/lib/cyberarm_engine/timer.rb +1 -1
- data/lib/cyberarm_engine/transform.rb +221 -9
- data/lib/cyberarm_engine/ui/border_canvas.rb +4 -3
- data/lib/cyberarm_engine/ui/dsl.rb +68 -50
- data/lib/cyberarm_engine/ui/element.rb +57 -18
- data/lib/cyberarm_engine/ui/elements/button.rb +86 -16
- data/lib/cyberarm_engine/ui/elements/check_box.rb +24 -32
- data/lib/cyberarm_engine/ui/elements/container.rb +88 -24
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -0
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +180 -27
- data/lib/cyberarm_engine/ui/elements/flow.rb +1 -3
- data/lib/cyberarm_engine/ui/elements/image.rb +12 -9
- data/lib/cyberarm_engine/ui/elements/label.rb +96 -15
- data/lib/cyberarm_engine/ui/elements/list_box.rb +68 -0
- data/lib/cyberarm_engine/ui/elements/progress.rb +6 -5
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -0
- data/lib/cyberarm_engine/ui/elements/slider.rb +104 -0
- data/lib/cyberarm_engine/ui/elements/stack.rb +1 -3
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +40 -31
- data/lib/cyberarm_engine/ui/event.rb +8 -7
- data/lib/cyberarm_engine/ui/gui_state.rb +89 -6
- data/lib/cyberarm_engine/ui/style.rb +10 -9
- data/lib/cyberarm_engine/ui/theme.rb +39 -21
- data/lib/cyberarm_engine/vector.rb +132 -38
- data/lib/cyberarm_engine/version.rb +2 -2
- data/lib/cyberarm_engine/{engine.rb → window.rb} +30 -19
- metadata +87 -16
- data/lib/cyberarm_engine/shader.rb +0 -205
@@ -23,7 +23,7 @@ module CyberarmEngine
|
|
23
23
|
|
24
24
|
def ==(other)
|
25
25
|
@min == other.min &&
|
26
|
-
|
26
|
+
@max == other.max
|
27
27
|
end
|
28
28
|
|
29
29
|
# returns a new bounding box that includes both bounding boxes
|
@@ -37,7 +37,7 @@ module CyberarmEngine
|
|
37
37
|
temp.max.y = [@max.y, other.max.y].max
|
38
38
|
temp.max.z = [@max.z, other.max.z].max
|
39
39
|
|
40
|
-
|
40
|
+
temp
|
41
41
|
end
|
42
42
|
|
43
43
|
# returns the difference between both bounding boxes
|
@@ -46,7 +46,7 @@ module CyberarmEngine
|
|
46
46
|
temp.min = @min - other.min
|
47
47
|
temp.max = @max - other.max
|
48
48
|
|
49
|
-
|
49
|
+
temp
|
50
50
|
end
|
51
51
|
|
52
52
|
# returns whether bounding box intersects other
|
@@ -55,8 +55,8 @@ module CyberarmEngine
|
|
55
55
|
other.intersect?(self)
|
56
56
|
elsif other.is_a?(BoundingBox)
|
57
57
|
(@min.x <= other.max.x && @max.x >= other.min.x) &&
|
58
|
-
|
59
|
-
|
58
|
+
(@min.y <= other.max.y && @max.y >= other.min.y) &&
|
59
|
+
(@min.z <= other.max.z && @max.z >= other.min.z)
|
60
60
|
else
|
61
61
|
raise "Unknown collider: #{other.class}"
|
62
62
|
end
|
@@ -65,20 +65,20 @@ module CyberarmEngine
|
|
65
65
|
# does this bounding box envelop other bounding box? (inclusive of border)
|
66
66
|
def contains?(other)
|
67
67
|
other.min.x >= min.x && other.min.y >= min.y && other.min.z >= min.z &&
|
68
|
-
|
68
|
+
other.max.x <= max.x && other.max.y <= max.y && other.max.z <= max.z
|
69
69
|
end
|
70
70
|
|
71
71
|
# returns whether the 3D vector is inside of the bounding box
|
72
72
|
def inside?(vector)
|
73
73
|
(vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
|
74
|
-
|
75
|
-
|
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
76
|
end
|
77
77
|
|
78
78
|
# returns whether the 2D vector is inside of the bounding box
|
79
79
|
def point?(vector)
|
80
80
|
(vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
|
81
|
-
|
81
|
+
(vector.y.between?(@min.y, @max.y) || vector.y.between?(@max.y, @min.y))
|
82
82
|
end
|
83
83
|
|
84
84
|
def volume
|
@@ -107,7 +107,7 @@ module CyberarmEngine
|
|
107
107
|
temp.max.y = @max.y.to_f * entity.scale.y
|
108
108
|
temp.max.z = @max.z.to_f * entity.scale.z
|
109
109
|
|
110
|
-
|
110
|
+
temp
|
111
111
|
end
|
112
112
|
|
113
113
|
def normalize_with_offset(entity)
|
@@ -120,23 +120,23 @@ module CyberarmEngine
|
|
120
120
|
temp.max.y = @max.y.to_f * entity.scale.y + entity.position.y
|
121
121
|
temp.max.z = @max.z.to_f * entity.scale.z + entity.position.z
|
122
122
|
|
123
|
-
|
123
|
+
temp
|
124
124
|
end
|
125
125
|
|
126
126
|
def +(other)
|
127
127
|
box = BoundingBox.new
|
128
|
-
box.min =
|
129
|
-
box.min =
|
128
|
+
box.min = min + other.min
|
129
|
+
box.min = max + other.max
|
130
130
|
|
131
|
-
|
131
|
+
box
|
132
132
|
end
|
133
133
|
|
134
134
|
def -(other)
|
135
135
|
box = BoundingBox.new
|
136
|
-
box.min =
|
137
|
-
box.min =
|
136
|
+
box.min = min - other.min
|
137
|
+
box.min = max - other.max
|
138
138
|
|
139
|
-
|
139
|
+
box
|
140
140
|
end
|
141
141
|
|
142
142
|
def sum
|
@@ -147,4 +147,4 @@ module CyberarmEngine
|
|
147
147
|
BoundingBox.new(@min.x, @min.y, @min.z, @max.x, @max.y, @max.z)
|
148
148
|
end
|
149
149
|
end
|
150
|
-
end
|
150
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module CyberarmEngine
|
2
|
+
module Cache
|
3
|
+
class DownloadManager
|
4
|
+
attr_reader :downloads
|
5
|
+
|
6
|
+
def initialize(max_parallel_downloads: 4)
|
7
|
+
@max_parallel_downloads = max_parallel_downloads
|
8
|
+
@downloads = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def download(url:, save_as: nil, &callback)
|
12
|
+
uri = URI(url)
|
13
|
+
save_as ||= "filename_path" # TODO: if no save_as path is provided, then get one from the Cache controller
|
14
|
+
|
15
|
+
@downloads << Download.new(uri: uri, save_as: save_as, callback: callback)
|
16
|
+
end
|
17
|
+
|
18
|
+
def status
|
19
|
+
if active_downloads > 0
|
20
|
+
:busy
|
21
|
+
else
|
22
|
+
:idle
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def progress
|
27
|
+
remaining_bytes = @downloads.map { |d| d.remaining_bytes }.sum
|
28
|
+
total_bytes = @downloads.map { |d| d.total_bytes }.sum
|
29
|
+
|
30
|
+
v = 1.0 - (remaining_bytes.to_f / total_bytes)
|
31
|
+
return 0.0 if v.nan?
|
32
|
+
|
33
|
+
v
|
34
|
+
end
|
35
|
+
|
36
|
+
def active_downloads
|
37
|
+
@downloads.select { |d| %i[pending downloading].include?(d.status) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def update
|
41
|
+
@downloads.each do |download|
|
42
|
+
if download.status == :pending && active_downloads.size <= @max_parallel_downloads
|
43
|
+
download.status = :downloading
|
44
|
+
Thread.start { download.download }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def prune
|
50
|
+
@downloads.delete_if { |d| d.status == :finished || d.status == :failed }
|
51
|
+
end
|
52
|
+
|
53
|
+
class Download
|
54
|
+
attr_accessor :status
|
55
|
+
attr_reader :uri, :save_as, :callback, :remaining_bytes, :total_downloaded_bytes, :total_bytes,
|
56
|
+
:error_message, :started_at, :finished_at
|
57
|
+
|
58
|
+
def initialize(uri:, save_as:, callback: nil)
|
59
|
+
@uri = uri
|
60
|
+
@save_as = save_as
|
61
|
+
@callback = callback
|
62
|
+
|
63
|
+
@status = :pending
|
64
|
+
|
65
|
+
@remaining_bytes = 0.0
|
66
|
+
@total_downloaded_bytes = 0.0
|
67
|
+
@total_bytes = 0.0
|
68
|
+
|
69
|
+
@error_message = ""
|
70
|
+
end
|
71
|
+
|
72
|
+
def progress
|
73
|
+
v = 1.0 - (@remaining_bytes.to_f / total_bytes)
|
74
|
+
return 0.0 if v.nan?
|
75
|
+
|
76
|
+
v
|
77
|
+
end
|
78
|
+
|
79
|
+
def download
|
80
|
+
@status = :downloading
|
81
|
+
@started_at = Time.now # TODO: monotonic time
|
82
|
+
|
83
|
+
io = File.open(@save_as, "w")
|
84
|
+
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
85
|
+
io.write(chunk)
|
86
|
+
|
87
|
+
@remaining_bytes = remaining_bytes.to_f
|
88
|
+
@total_downloaded_bytes += chunk.size
|
89
|
+
@total_bytes = total_bytes.to_f
|
90
|
+
end
|
91
|
+
|
92
|
+
begin
|
93
|
+
response = Excon.get(
|
94
|
+
@uri.to_s,
|
95
|
+
middlewares: Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
|
96
|
+
response_block: streamer
|
97
|
+
)
|
98
|
+
|
99
|
+
if response.status == 200
|
100
|
+
@status = :finished
|
101
|
+
@finished_at = Time.now # TODO: monotonic time
|
102
|
+
@callback.call(self) if @callback
|
103
|
+
else
|
104
|
+
@error_message = "Got a non 200 HTTP status of #{response.status}"
|
105
|
+
@status = :failed
|
106
|
+
@finished_at = Time.now # TODO: monotonic time
|
107
|
+
@callback.call(self) if @callback
|
108
|
+
end
|
109
|
+
rescue StandardError => e # TODO: cherrypick errors to cature
|
110
|
+
@status = :failed
|
111
|
+
@finished_at = Time.now # TODO: monotonic time
|
112
|
+
@error_message = e.message
|
113
|
+
@callback.call(self) if @callback
|
114
|
+
end
|
115
|
+
ensure
|
116
|
+
io.close if io
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module CyberarmEngine
|
2
2
|
module Common
|
3
|
-
def push_state(klass, options={})
|
3
|
+
def push_state(klass, options = {})
|
4
4
|
window.push_state(klass, options)
|
5
5
|
end
|
6
6
|
|
@@ -20,7 +20,7 @@ module CyberarmEngine
|
|
20
20
|
window.show_cursor
|
21
21
|
end
|
22
22
|
|
23
|
-
def show_cursor=boolean
|
23
|
+
def show_cursor=(boolean)
|
24
24
|
window.show_cursor = boolean
|
25
25
|
end
|
26
26
|
|
@@ -34,24 +34,24 @@ module CyberarmEngine
|
|
34
34
|
|
35
35
|
def lighten(color, amount = 25)
|
36
36
|
if defined?(color.alpha)
|
37
|
-
|
37
|
+
Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
|
38
38
|
else
|
39
|
-
|
39
|
+
Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def darken(color, amount = 25)
|
44
44
|
if defined?(color.alpha)
|
45
|
-
|
45
|
+
Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
|
46
46
|
else
|
47
|
-
|
47
|
+
Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
def opacity(color, ratio = 1.0)
|
52
52
|
alpha = 255 * ratio
|
53
53
|
|
54
|
-
|
54
|
+
Gosu::Color.rgba(color.red, color.green, color.blue, alpha)
|
55
55
|
end
|
56
56
|
|
57
57
|
def get_asset(path, hash, klass, retro = false, tileable = false)
|
@@ -65,28 +65,28 @@ module CyberarmEngine
|
|
65
65
|
|
66
66
|
unless asset
|
67
67
|
instance = nil
|
68
|
-
if klass == Gosu::Image
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
instance = if klass == Gosu::Image
|
69
|
+
klass.new(path, retro: retro, tileable: tileable)
|
70
|
+
else
|
71
|
+
klass.new(path)
|
72
|
+
end
|
73
73
|
hash[path] = instance
|
74
74
|
asset = instance
|
75
75
|
end
|
76
76
|
|
77
|
-
|
77
|
+
asset
|
78
78
|
end
|
79
79
|
|
80
80
|
def get_image(path, retro: false, tileable: false)
|
81
|
-
get_asset(path,
|
81
|
+
get_asset(path, Window::IMAGES, Gosu::Image, retro, tileable)
|
82
82
|
end
|
83
83
|
|
84
84
|
def get_sample(path)
|
85
|
-
get_asset(path,
|
85
|
+
get_asset(path, Window::SAMPLES, Gosu::Sample)
|
86
86
|
end
|
87
87
|
|
88
88
|
def get_song(path)
|
89
|
-
get_asset(path,
|
89
|
+
get_asset(path, Window::SONGS, Gosu::Song)
|
90
90
|
end
|
91
91
|
|
92
92
|
def window
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module CyberarmEngine
|
2
|
+
class ConfigFile
|
3
|
+
def initialize(file:)
|
4
|
+
@file = file
|
5
|
+
|
6
|
+
if File.exist?(@file)
|
7
|
+
deserialize
|
8
|
+
else
|
9
|
+
@data = {}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def []=(*keys, value)
|
14
|
+
last_key = keys.last
|
15
|
+
|
16
|
+
if keys.size == 1
|
17
|
+
hash = @data
|
18
|
+
else
|
19
|
+
keys.pop
|
20
|
+
hash = @data[keys.shift] ||= {}
|
21
|
+
|
22
|
+
keys.each do |key|
|
23
|
+
hash = hash[key] ||= {}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
hash[last_key] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(*keys)
|
31
|
+
@data.dig(*keys)
|
32
|
+
end
|
33
|
+
|
34
|
+
def serialize
|
35
|
+
JSON.dump(@data)
|
36
|
+
end
|
37
|
+
|
38
|
+
def deserialize
|
39
|
+
@data = JSON.parse(File.read(@file), symbolize_names: true)
|
40
|
+
end
|
41
|
+
|
42
|
+
def save!
|
43
|
+
File.open(@file, "w") { |f| f.write(serialize) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -5,55 +5,60 @@ module CyberarmEngine
|
|
5
5
|
attr_accessor :image, :angle, :position, :velocity, :center_x, :center_y, :scale_x, :scale_y,
|
6
6
|
:color, :mode, :options, :paused, :radius, :last_position
|
7
7
|
attr_reader :alpha
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
$window.current_state.add_game_object(self) if options[:auto_manage] || options[:auto_manage].nil?
|
12
11
|
|
13
12
|
@options = options
|
14
13
|
@image = options[:image] ? image(options[:image]) : nil
|
15
|
-
x = options[:x]
|
16
|
-
y = options[:y]
|
17
|
-
z = options[:z]
|
14
|
+
x = options[:x] || 0
|
15
|
+
y = options[:y] || 0
|
16
|
+
z = options[:z] || 0
|
18
17
|
@position = Vector.new(x, y, z)
|
19
18
|
@velocity = Vector.new
|
20
19
|
@last_position = Vector.new
|
21
|
-
@angle = options[:angle]
|
20
|
+
@angle = options[:angle] || 0
|
22
21
|
|
23
|
-
@center_x = options[:center_x]
|
24
|
-
@center_y = options[:center_y]
|
22
|
+
@center_x = options[:center_x] || 0.5
|
23
|
+
@center_y = options[:center_y] || 0.5
|
25
24
|
|
26
|
-
@scale_x = options[:scale_x]
|
27
|
-
@scale_y = options[:scale_y]
|
25
|
+
@scale_x = options[:scale_x] || 1
|
26
|
+
@scale_y = options[:scale_y] || 1
|
28
27
|
|
29
|
-
@color = options[:color]
|
30
|
-
@alpha = options[:alpha]
|
31
|
-
@mode = options[:mode]
|
28
|
+
@color = options[:color] || Gosu::Color.argb(0xff_ffffff)
|
29
|
+
@alpha = options[:alpha] || 255
|
30
|
+
@mode = options[:mode] || :default
|
32
31
|
|
33
32
|
@paused = false
|
34
33
|
@speed = 0
|
35
34
|
@debug_color = Gosu::Color::GREEN
|
36
|
-
@world_center_point = Vector.new(0,0)
|
35
|
+
@world_center_point = Vector.new(0, 0)
|
37
36
|
|
38
37
|
setup
|
39
38
|
|
40
|
-
@debug_text = Text.new("", color: @debug_color, y: @position.y-(
|
39
|
+
@debug_text = Text.new("", color: @debug_color, y: @position.y - (height * scale), z: 9999)
|
41
40
|
@debug_text.x = @position.x
|
42
|
-
if @radius == 0 || @radius
|
43
|
-
@radius =
|
41
|
+
if @radius == 0 || @radius.nil?
|
42
|
+
@radius = if options[:radius]
|
43
|
+
options[:radius]
|
44
|
+
else
|
45
|
+
defined?(@image.width) ? ((@image.width + @image.height) / 4) * scale : 1
|
46
|
+
end
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
47
50
|
def draw
|
48
51
|
if @image
|
49
|
-
@image.draw_rot(@position.x, @position.y, @position.z, @angle, @center_x, @center_y, @scale_x, @scale_y,
|
52
|
+
@image.draw_rot(@position.x, @position.y, @position.z, @angle, @center_x, @center_y, @scale_x, @scale_y,
|
53
|
+
@color, @mode)
|
50
54
|
end
|
51
55
|
|
52
56
|
if $debug
|
53
57
|
show_debug_heading
|
54
58
|
$window.draw_circle(@position.x, @position.y, radius, 9999, @debug_color)
|
55
59
|
if @debug_text.text != ""
|
56
|
-
$window.draw_rect(@debug_text.x-10, (@debug_text.y-10), @debug_text.width+20, @debug_text.height+20,
|
60
|
+
$window.draw_rect(@debug_text.x - 10, (@debug_text.y - 10), @debug_text.width + 20, @debug_text.height + 20,
|
61
|
+
Gosu::Color.rgba(0, 0, 0, 200), 9999)
|
57
62
|
@debug_text.draw
|
58
63
|
end
|
59
64
|
end
|
@@ -64,13 +69,13 @@ module CyberarmEngine
|
|
64
69
|
|
65
70
|
def debug_text(text)
|
66
71
|
@debug_text.text = text
|
67
|
-
@debug_text.x = @position.x-(@debug_text.width / 2)
|
68
|
-
@debug_text.y = @position.y-(@debug_text.height +
|
72
|
+
@debug_text.x = @position.x - (@debug_text.width / 2)
|
73
|
+
@debug_text.y = @position.y - (@debug_text.height + radius + height)
|
69
74
|
end
|
70
75
|
|
71
76
|
def scale
|
72
77
|
if @scale_x == @scale_y
|
73
|
-
|
78
|
+
@scale_x
|
74
79
|
else
|
75
80
|
false
|
76
81
|
# maths?
|
@@ -80,7 +85,7 @@ module CyberarmEngine
|
|
80
85
|
def scale=(int)
|
81
86
|
self.scale_x = int
|
82
87
|
self.scale_y = int
|
83
|
-
self.radius = ((@image.width
|
88
|
+
self.radius = ((@image.width + @image.height) / 4) * scale
|
84
89
|
end
|
85
90
|
|
86
91
|
def visible
|
@@ -97,16 +102,16 @@ module CyberarmEngine
|
|
97
102
|
end
|
98
103
|
|
99
104
|
def _x_visible
|
100
|
-
|
101
|
-
|
105
|
+
x.between?(($window.width / 2) - @world_center_point.x, ($window.width / 2) + @world_center_point.x) ||
|
106
|
+
x.between?((@world_center_point.x - $window.width / 2), ($window.width / 2) + @world_center_point.x)
|
102
107
|
end
|
103
108
|
|
104
109
|
def _y_visible
|
105
|
-
|
106
|
-
|
110
|
+
y.between?(($window.height / 2) - @world_center_point.y, ($window.height / 2) + @world_center_point.y) ||
|
111
|
+
y.between?(@world_center_point.y - ($window.height / 2), ($window.height / 2) + @world_center_point.y)
|
107
112
|
end
|
108
113
|
|
109
|
-
def heading(ahead_by = 100,
|
114
|
+
def heading(ahead_by = 100, _object = nil, angle_only = false)
|
110
115
|
direction = Gosu.angle(@last_position.x, @last_position.x, @position.x, position.y).gosu_to_radians
|
111
116
|
|
112
117
|
_x = @position.x + (ahead_by * Math.cos(direction))
|
@@ -122,11 +127,11 @@ module CyberarmEngine
|
|
122
127
|
end
|
123
128
|
|
124
129
|
def width
|
125
|
-
@image ? @image.width *
|
130
|
+
@image ? @image.width * scale : 0
|
126
131
|
end
|
127
132
|
|
128
133
|
def height
|
129
|
-
@image ? @image.height *
|
134
|
+
@image ? @image.height * scale : 0
|
130
135
|
end
|
131
136
|
|
132
137
|
def pause
|
@@ -138,8 +143,8 @@ module CyberarmEngine
|
|
138
143
|
end
|
139
144
|
|
140
145
|
def rotate(int)
|
141
|
-
self.angle+=int
|
142
|
-
self.angle%=360
|
146
|
+
self.angle += int
|
147
|
+
self.angle %= 360
|
143
148
|
end
|
144
149
|
|
145
150
|
def alpha=(int) # 0-255
|
@@ -149,7 +154,7 @@ module CyberarmEngine
|
|
149
154
|
end
|
150
155
|
|
151
156
|
def draw_rect(x, y, width, height, color, z = 0)
|
152
|
-
$window.draw_rect(x,y,width,height,color,z)
|
157
|
+
$window.draw_rect(x, y, width, height, color, z)
|
153
158
|
end
|
154
159
|
|
155
160
|
def button_up(id)
|
@@ -163,14 +168,14 @@ module CyberarmEngine
|
|
163
168
|
best_distance = 100_000_000_000 # Huge default number
|
164
169
|
|
165
170
|
game_object_class.all.each do |object|
|
166
|
-
distance = Gosu
|
171
|
+
distance = Gosu.distance(x, y, object.x, object.y)
|
167
172
|
if distance <= best_distance
|
168
173
|
best_object = object
|
169
174
|
best_distance = distance
|
170
175
|
end
|
171
176
|
end
|
172
177
|
|
173
|
-
|
178
|
+
best_object
|
174
179
|
end
|
175
180
|
|
176
181
|
def look_at(object)
|
@@ -178,31 +183,24 @@ module CyberarmEngine
|
|
178
183
|
end
|
179
184
|
|
180
185
|
def circle_collision?(object)
|
181
|
-
distance = Gosu.distance(
|
182
|
-
|
183
|
-
true
|
184
|
-
else
|
185
|
-
false
|
186
|
-
end
|
186
|
+
distance = Gosu.distance(x, y, object.x, object.y)
|
187
|
+
distance <= radius + object.radius
|
187
188
|
end
|
188
189
|
|
189
190
|
# Duplication... so DRY.
|
190
|
-
def each_circle_collision(object,
|
191
|
+
def each_circle_collision(object, _resolve_with = :width, &block)
|
191
192
|
if object.class != Class && object.instance_of?(object.class)
|
192
|
-
$window.current_state.game_objects.select {|i| i.
|
193
|
-
distance = Gosu.distance(
|
194
|
-
if distance <=
|
195
|
-
block.call(o, object) if block
|
196
|
-
end
|
193
|
+
$window.current_state.game_objects.select { |i| i.instance_of?(object.class) }.each do |o|
|
194
|
+
distance = Gosu.distance(x, y, object.x, object.y)
|
195
|
+
block.call(o, object) if distance <= radius + object.radius && block
|
197
196
|
end
|
198
197
|
else
|
199
|
-
list = $window.current_state.game_objects.select {|i| i.
|
198
|
+
list = $window.current_state.game_objects.select { |i| i.instance_of?(object) }
|
200
199
|
list.each do |o|
|
201
200
|
next if self == o
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
end
|
201
|
+
|
202
|
+
distance = Gosu.distance(x, y, o.x, o.y)
|
203
|
+
block.call(self, o) if distance <= radius + o.radius && block
|
206
204
|
end
|
207
205
|
end
|
208
206
|
end
|
@@ -210,35 +208,30 @@ module CyberarmEngine
|
|
210
208
|
def destroy
|
211
209
|
if $window.current_state
|
212
210
|
$window.current_state.game_objects.each do |o|
|
213
|
-
if o.is_a?(self.class) && o == self
|
214
|
-
$window.current_state.game_objects.delete(o)
|
215
|
-
end
|
211
|
+
$window.current_state.game_objects.delete(o) if o.is_a?(self.class) && o == self
|
216
212
|
end
|
217
213
|
end
|
218
214
|
end
|
219
215
|
|
220
216
|
# NOTE: This could be implemented more reliably
|
221
217
|
def all
|
222
|
-
INSTANCES.select {|i| i.
|
218
|
+
INSTANCES.select { |i| i.instance_of?(self) }
|
223
219
|
end
|
224
220
|
|
225
|
-
def self.each_circle_collision(object,
|
221
|
+
def self.each_circle_collision(object, _resolve_with = :width, &block)
|
226
222
|
if object.class != Class && object.instance_of?(object.class)
|
227
|
-
$window.current_state.game_objects.select {|i| i.
|
223
|
+
$window.current_state.game_objects.select { |i| i.instance_of?(self) }.each do |o|
|
228
224
|
distance = Gosu.distance(o.x, o.y, object.x, object.y)
|
229
|
-
if distance <= o.radius+object.radius
|
230
|
-
block.call(o, object) if block
|
231
|
-
end
|
225
|
+
block.call(o, object) if distance <= o.radius + object.radius && block
|
232
226
|
end
|
233
227
|
else
|
234
|
-
lista = $window.current_state.game_objects.select {|i| i.
|
235
|
-
listb = $window.current_state.game_objects.select {|i| i.
|
228
|
+
lista = $window.current_state.game_objects.select { |i| i.instance_of?(self) }
|
229
|
+
listb = $window.current_state.game_objects.select { |i| i.instance_of?(object) }
|
236
230
|
lista.product(listb).each do |o, o2|
|
237
231
|
next if o == o2
|
232
|
+
|
238
233
|
distance = Gosu.distance(o.x, o.y, o2.x, o2.y)
|
239
|
-
if distance <= o.radius+o2.radius
|
240
|
-
block.call(o, o2) if block
|
241
|
-
end
|
234
|
+
block.call(o, o2) if distance <= o.radius + o2.radius && block
|
242
235
|
end
|
243
236
|
end
|
244
237
|
end
|
@@ -247,11 +240,9 @@ module CyberarmEngine
|
|
247
240
|
INSTANCES.clear
|
248
241
|
if $window.current_state
|
249
242
|
$window.current_state.game_objects.each do |o|
|
250
|
-
if o.is_a?(self.class)
|
251
|
-
$window.current_state.game_objects.delete(o)
|
252
|
-
end
|
243
|
+
$window.current_state.game_objects.delete(o) if o.is_a?(self.class)
|
253
244
|
end
|
254
245
|
end
|
255
246
|
end
|
256
247
|
end
|
257
|
-
end
|
248
|
+
end
|