rgss3 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -14
- data/lib/rgss3.rb +35 -1
- data/lib/rgss3/audio.rb +96 -0
- data/lib/rgss3/bitmap.rb +290 -0
- data/lib/rgss3/color.rb +163 -0
- data/lib/rgss3/container.rb +42 -0
- data/lib/rgss3/font.rb +50 -0
- data/lib/rgss3/game_window.rb +21 -0
- data/lib/rgss3/graphics.rb +137 -0
- data/lib/rgss3/input.rb +159 -0
- data/lib/rgss3/kernel_ext.rb +41 -0
- data/lib/rgss3/plane.rb +9 -0
- data/lib/rgss3/rect.rb +49 -0
- data/lib/rgss3/rgss3a.rb +129 -0
- data/lib/rgss3/rgss_error.rb +2 -0
- data/lib/rgss3/rgss_reset.rb +2 -0
- data/lib/rgss3/rpg.rb +997 -0
- data/lib/rgss3/sprite.rb +57 -0
- data/lib/rgss3/sprite_container.rb +21 -0
- data/lib/rgss3/table.rb +80 -0
- data/lib/rgss3/tilemap.rb +310 -0
- data/lib/rgss3/tone.rb +69 -0
- data/lib/rgss3/version.rb +1 -1
- data/lib/rgss3/viewport.rb +43 -0
- data/lib/rgss3/window.rb +58 -0
- data/rgss3.gemspec +1 -1
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b5c1106c06327ffdfbb23dd66a62ce472a1be6e
|
4
|
+
data.tar.gz: 615feaa87d056a45c13a0fef50fb3357ce1cc198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 309bf1442812626385755d7a0b106f922f1e6711ac48f0edcbd96ebdc777db77edf65f589dc37ea487dc41f4c50ee72630e5101b8befc0304a1806595f3d3741
|
7
|
+
data.tar.gz: 753682b250cdcf4d8d6344a319bb006f7372ce2e239950e10a08ae483f0a49760a47415997417c640e43bf3406a61d5c64ba2beb1092428703955e75a99b9d8b
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# RGSS3
|
2
2
|
|
3
3
|
An attempt to maintain https://github.com/CaptainJet/RM-Gosu.
|
4
4
|
|
@@ -10,21 +10,12 @@ Depend on:
|
|
10
10
|
* rmagick
|
11
11
|
* gosu
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
Add this line to your application's Gemfile:
|
13
|
+
It is recommended to use a Q8 version of ImageMagick 6.
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
## Installation
|
16
|
+
```
|
17
|
+
gem install rgss3
|
19
18
|
```
|
20
|
-
|
21
|
-
And then execute:
|
22
|
-
|
23
|
-
$ bundle
|
24
|
-
|
25
|
-
Or install it yourself as:
|
26
|
-
|
27
|
-
$ gem install rgss3
|
28
19
|
|
29
20
|
## Usage
|
30
21
|
|
@@ -36,6 +27,15 @@ RGSS3.run do
|
|
36
27
|
end
|
37
28
|
```
|
38
29
|
|
30
|
+
Or with more options:
|
31
|
+
```ruby
|
32
|
+
require 'rgss3'
|
33
|
+
RGSS3.run(width: 544, height: 416, frame_rate: 60, title: "Game") do
|
34
|
+
# TODO: Add your code here
|
35
|
+
# loop { Graphics.update }
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
39
|
## Development
|
40
40
|
|
41
41
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/rgss3.rb
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
require "rgss3/version"
|
2
2
|
|
3
|
+
require 'gosu'
|
4
|
+
require 'zlib'
|
5
|
+
require 'rmagick'
|
6
|
+
require 'fiber'
|
7
|
+
|
8
|
+
require_relative 'rgss3/game_window'
|
9
|
+
require_relative 'rgss3/color'
|
10
|
+
require_relative 'rgss3/audio'
|
11
|
+
require_relative 'rgss3/bitmap'
|
12
|
+
require_relative 'rgss3/font'
|
13
|
+
require_relative 'rgss3/graphics'
|
14
|
+
require_relative 'rgss3/input'
|
15
|
+
require_relative 'rgss3/kernel_ext'
|
16
|
+
require_relative 'rgss3/plane'
|
17
|
+
require_relative 'rgss3/rect'
|
18
|
+
require_relative 'rgss3/rgss_error'
|
19
|
+
require_relative 'rgss3/rgss_reset'
|
20
|
+
require_relative 'rgss3/rpg'
|
21
|
+
require_relative 'rgss3/sprite'
|
22
|
+
require_relative 'rgss3/table'
|
23
|
+
require_relative 'rgss3/tilemap'
|
24
|
+
require_relative 'rgss3/tone'
|
25
|
+
require_relative 'rgss3/viewport'
|
26
|
+
require_relative 'rgss3/window'
|
27
|
+
|
3
28
|
module RGSS3
|
4
|
-
|
29
|
+
class << self
|
30
|
+
attr_reader :fiber, :window
|
31
|
+
|
32
|
+
def run(**options, &block)
|
33
|
+
@fiber = Fiber.new(&block)
|
34
|
+
@window = RGSS3::GameWindow.new(**options)
|
35
|
+
@window.show
|
36
|
+
end
|
37
|
+
end
|
5
38
|
end
|
39
|
+
|
data/lib/rgss3/audio.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
module Audio
|
2
|
+
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def setup_midi
|
6
|
+
end
|
7
|
+
|
8
|
+
def bgm_play(filename, volume = 100, pitch = 100, pos = 0)
|
9
|
+
bgm_stop
|
10
|
+
@bgm = Gosu::Sample.new(filename).play(volume / 100.0, pitch / 100.0, true)
|
11
|
+
@bgm_volume = volume / 100.0
|
12
|
+
end
|
13
|
+
|
14
|
+
def bgm_stop
|
15
|
+
@bgm.stop if @bgm
|
16
|
+
end
|
17
|
+
|
18
|
+
def bgm_fade(time)
|
19
|
+
bgm_stop
|
20
|
+
# return unless @bgm
|
21
|
+
# Thread.new {
|
22
|
+
# incs = @bgm_volume / time
|
23
|
+
# until @bgm_volume <= 0
|
24
|
+
# @bgm_volume -= incs
|
25
|
+
# @bgm.volume -= incs
|
26
|
+
# sleep 0.01
|
27
|
+
# end
|
28
|
+
# bgm_stop
|
29
|
+
# }
|
30
|
+
end
|
31
|
+
|
32
|
+
def bgm_pos
|
33
|
+
0 # Incapable of integration at the time
|
34
|
+
end
|
35
|
+
|
36
|
+
def bgs_play(filename, volume = 100, pitch = 100, pos = 0)
|
37
|
+
bgs_stop
|
38
|
+
@bgs = Gosu::Sample.new(filename).play(volume / 100.0, pitch / 100.0, true)
|
39
|
+
@bgs_volume = volume / 100.0
|
40
|
+
end
|
41
|
+
|
42
|
+
def bgs_stop
|
43
|
+
@bgs.stop if @bgs
|
44
|
+
end
|
45
|
+
|
46
|
+
def bgs_fade(time)
|
47
|
+
bgs_stop
|
48
|
+
# return unless @bgs
|
49
|
+
# Thread.new {
|
50
|
+
# incs = @bgs_volume / time
|
51
|
+
# until @bgs_volume <= 0
|
52
|
+
# @bgs_volume -= incs
|
53
|
+
# @bgs.volume -= incs
|
54
|
+
# sleep 0.01
|
55
|
+
# end
|
56
|
+
# bgs_stop
|
57
|
+
# }
|
58
|
+
end
|
59
|
+
|
60
|
+
def bgs_pos
|
61
|
+
0 # Incapable of integration at the time
|
62
|
+
end
|
63
|
+
|
64
|
+
def me_play(filename, volume = 100, pitch = 100)
|
65
|
+
me_stop
|
66
|
+
@bgm.pause if @bgm
|
67
|
+
@me = Gosu::Sample.new(filename).play(volume / 100.0, pitch / 100.0, false)
|
68
|
+
@me_volume = volume / 100.0
|
69
|
+
end
|
70
|
+
|
71
|
+
def me_stop
|
72
|
+
@me.stop if @me
|
73
|
+
@bgm.resume if @bgm && @bgm.paused?
|
74
|
+
end
|
75
|
+
|
76
|
+
def me_fade(time)
|
77
|
+
me_stop
|
78
|
+
# return unless @me
|
79
|
+
# Thread.new {
|
80
|
+
# incs = @me_volume / time
|
81
|
+
# until @me_volume <= 0
|
82
|
+
# @me_volume -= incs
|
83
|
+
# @me.volume -= incs
|
84
|
+
# sleep 0.01
|
85
|
+
# end
|
86
|
+
# me_stop
|
87
|
+
# }
|
88
|
+
end
|
89
|
+
|
90
|
+
def se_play(filename, volume = 100, pitch = 100)
|
91
|
+
Gosu::Sample.new(filename).play(volume / 100.0, pitch / 100.0, false)
|
92
|
+
end
|
93
|
+
|
94
|
+
def se_stop
|
95
|
+
end
|
96
|
+
end
|
data/lib/rgss3/bitmap.rb
ADDED
@@ -0,0 +1,290 @@
|
|
1
|
+
|
2
|
+
class Bitmap
|
3
|
+
|
4
|
+
attr_reader :rect, :gosu_image
|
5
|
+
attr_accessor :font
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
case args.size
|
9
|
+
when 1
|
10
|
+
basename, = args
|
11
|
+
basename = basename.to_str # raise error if argument is not string compatible
|
12
|
+
["".freeze, ".png".freeze, ".jpg".freeze].each do |ext|
|
13
|
+
filename = basename + ext
|
14
|
+
if File.exist?(filename)
|
15
|
+
return initialize_with_gosu_image(Gosu::Image.new(filename))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
raise "File not found: #{basename}"
|
19
|
+
when 2
|
20
|
+
initialize_with_rmagick_image Magick::Image.new(*args) { self.background_color = 'none' }
|
21
|
+
else
|
22
|
+
raise ArgumentError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize_with_gosu_image(gosu_image)
|
27
|
+
@gosu_image = gosu_image
|
28
|
+
init_other_attr
|
29
|
+
set_dirty
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize_with_rmagick_image(rmagick_image)
|
33
|
+
self.rmagick_image = rmagick_image
|
34
|
+
init_other_attr
|
35
|
+
end
|
36
|
+
|
37
|
+
def init_other_attr
|
38
|
+
@rect = Rect.new(0, 0, @gosu_image.width, @gosu_image.height)
|
39
|
+
@font = Font.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def dispose
|
43
|
+
@disposed = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def disposed?
|
47
|
+
@disposed
|
48
|
+
end
|
49
|
+
|
50
|
+
def width
|
51
|
+
@gosu_image.width
|
52
|
+
end
|
53
|
+
|
54
|
+
def height
|
55
|
+
@gosu_image.height
|
56
|
+
end
|
57
|
+
|
58
|
+
# untested
|
59
|
+
def blt(x, y, src_bitmap, src_rect, opacity = 255)
|
60
|
+
# opacity is not supported
|
61
|
+
im2 = src_bitmap.gosu_image.subimage(*src_rect)
|
62
|
+
@gosu_image.insert(im2, x, y)
|
63
|
+
set_dirty
|
64
|
+
end
|
65
|
+
|
66
|
+
# untested
|
67
|
+
def stretch_blt(dest_rect, src_bitmap, src_rect, opacity = 255)
|
68
|
+
im2 = src_bitmap.gosu_image.subimage(*src_rect)
|
69
|
+
im2 = Bitmap.gosu_to_rmagick(gosu_to_rmagick)
|
70
|
+
im2.resize!(dest_rect.width, dest_rect.height)
|
71
|
+
@gosu_image.insert(im2, dest_rect.x, dest_rect.y)
|
72
|
+
set_dirty
|
73
|
+
end
|
74
|
+
|
75
|
+
def fill_rect(*args)
|
76
|
+
case args.size
|
77
|
+
when 2, 5
|
78
|
+
if args[0].is_a?(Rect)
|
79
|
+
rect, color = args
|
80
|
+
x, y, width, height = *rect
|
81
|
+
else
|
82
|
+
x, y, width, height, color = *args
|
83
|
+
end
|
84
|
+
else
|
85
|
+
raise ArgumentError
|
86
|
+
end
|
87
|
+
img = Magick::Image.new(width, height) { self.background_color = color.to_rmagick_color }
|
88
|
+
@gosu_image.insert(img, x, y)
|
89
|
+
set_dirty
|
90
|
+
end
|
91
|
+
|
92
|
+
def gradient_fill_rect(*args)
|
93
|
+
case args.size
|
94
|
+
when 3, 4
|
95
|
+
rect, start_color, end_color, vertical = args
|
96
|
+
x, y, width, height = *rect
|
97
|
+
when 6, 7
|
98
|
+
x, y, width, height, start_color, end_color, vertical = args
|
99
|
+
else
|
100
|
+
raise ArgumentError
|
101
|
+
end
|
102
|
+
start_color = start_color.to_rmagick_color
|
103
|
+
end_color = end_color.to_rmagick_color
|
104
|
+
|
105
|
+
if vertical
|
106
|
+
x2 = width
|
107
|
+
y2 = 0
|
108
|
+
else
|
109
|
+
x2 = 0
|
110
|
+
y2 = height
|
111
|
+
end
|
112
|
+
|
113
|
+
fill = Magick::GradientFill.new(0, 0, x2, y2, start_color, end_color)
|
114
|
+
|
115
|
+
img = Magick::Image.new(width, height, fill)
|
116
|
+
@gosu_image.insert(img, x, y)
|
117
|
+
set_dirty
|
118
|
+
end
|
119
|
+
|
120
|
+
def clear
|
121
|
+
self.rmagick_image = Magick::Image.new(width, height)
|
122
|
+
end
|
123
|
+
|
124
|
+
def clear_rect(*args)
|
125
|
+
case args.size
|
126
|
+
when 1, 4
|
127
|
+
if args[0].is_a?(Rect)
|
128
|
+
x, y, width, height = *args[0].to_a
|
129
|
+
else
|
130
|
+
x, y, width, height = *args
|
131
|
+
end
|
132
|
+
else
|
133
|
+
raise ArgumentError
|
134
|
+
end
|
135
|
+
f = Magick::Image.new(width, height) { self.background_color = 'none' }
|
136
|
+
@gosu_image.insert(f, x, y)
|
137
|
+
set_dirty
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_pixel(x, y)
|
141
|
+
Color.from_pixel(rmagick_image.pixel_color(x, y))
|
142
|
+
end
|
143
|
+
|
144
|
+
def set_pixel(x, y, color)
|
145
|
+
fill_rect(x, y, 1, 1, color)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Untested
|
149
|
+
def hue_change(hue)
|
150
|
+
image = rmagick_image
|
151
|
+
Bitmap.pixel_map!(rmagick_image) do |pixel|
|
152
|
+
h, *sla = pixel.to_hsla
|
153
|
+
h = (h + hue) % 360
|
154
|
+
Pixel.from_hsla(h, *sla)
|
155
|
+
end
|
156
|
+
self.rmagick_image = image
|
157
|
+
end
|
158
|
+
|
159
|
+
def blur
|
160
|
+
self.rmagick_image = rmagick_image.blur_image
|
161
|
+
end
|
162
|
+
|
163
|
+
def radial_blur(angle, division)
|
164
|
+
blur
|
165
|
+
end
|
166
|
+
|
167
|
+
def draw_text(*args)
|
168
|
+
case args.size
|
169
|
+
when 2, 3
|
170
|
+
rect, string, align = args
|
171
|
+
x, y, width, height = *rect
|
172
|
+
when 5, 6
|
173
|
+
x, y, width, height, string, align = args
|
174
|
+
else
|
175
|
+
raise ArgumentError
|
176
|
+
end
|
177
|
+
|
178
|
+
string = string.to_s
|
179
|
+
string.gsub!('<', '<')
|
180
|
+
string.gsub!('>', '>')
|
181
|
+
if @font.bold
|
182
|
+
string.prepend("<b>") << "</b>"
|
183
|
+
end
|
184
|
+
if @font.italic
|
185
|
+
string.prepend("<i>") << "</i>"
|
186
|
+
end
|
187
|
+
text_image = Gosu::Image.from_text(string, @font.size, font: @font.first_existant_name)
|
188
|
+
text_image = Bitmap.gosu_to_rmagick(text_image)
|
189
|
+
image = text_image.dup
|
190
|
+
font_pixel = @font.color.to_pixel
|
191
|
+
Bitmap.pixel_map!(image) do |pixel|
|
192
|
+
result = font_pixel.dup
|
193
|
+
result.opacity = pixel.opacity
|
194
|
+
result
|
195
|
+
end
|
196
|
+
if @font.outline
|
197
|
+
font_pixel = @font.out_color.to_pixel
|
198
|
+
Bitmap.pixel_map!(text_image) do |pixel|
|
199
|
+
result = font_pixel.dup
|
200
|
+
result.opacity = pixel.opacity
|
201
|
+
result
|
202
|
+
end
|
203
|
+
image.composite!(text_image, 1, 1, Magick::DstOverCompositeOp)
|
204
|
+
end
|
205
|
+
# no shadow support for now
|
206
|
+
# if @font.shadow
|
207
|
+
# shadow = bigger_image
|
208
|
+
# font_pixel = Magick::Pixel.from_color('rgba(0,0,0,128)')
|
209
|
+
# Bitmap.pixel_map!(shadow) do |pixel|
|
210
|
+
# result = font_pixel.dup
|
211
|
+
# result.opacity = pixel.opacity
|
212
|
+
# result
|
213
|
+
# end
|
214
|
+
# image.composite!(shadow, 0, 0, Magick::DstOverCompositeOp)
|
215
|
+
# end
|
216
|
+
# @gosu_image.insert(image, x, y)
|
217
|
+
self.rmagick_image = rmagick_image.composite!(image, x, y, Magick::OverCompositeOp)
|
218
|
+
end
|
219
|
+
|
220
|
+
def text_size(string)
|
221
|
+
f = Gosu::Font.new(@font.size, font: @font.first_existant_name)
|
222
|
+
Rect.new(0, 0, f.text_width(string.to_s, f.height))
|
223
|
+
end
|
224
|
+
|
225
|
+
# NEW
|
226
|
+
|
227
|
+
def self.from_gosu(img)
|
228
|
+
bitmap = allocate
|
229
|
+
bitmap.initialize_with_gosu_image(img)
|
230
|
+
bitmap
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.from_rmagick(img)
|
234
|
+
bitmap = allocate
|
235
|
+
bitmap.rmagick_image = img
|
236
|
+
bitmap
|
237
|
+
end
|
238
|
+
|
239
|
+
def self.gosu_to_rmagick(image)
|
240
|
+
Magick::Image.from_blob(image.to_blob) {
|
241
|
+
self.format = "RGBA"
|
242
|
+
self.size = "#{image.width}x#{image.height}"
|
243
|
+
self.depth = 8
|
244
|
+
}.first
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.pixel_map!(rmagick_image, &block)
|
248
|
+
return to_enum(__method__, rmagick_image) unless block
|
249
|
+
width = rmagick_image.columns
|
250
|
+
height = rmagick_image.rows
|
251
|
+
pixels = rmagick_image.get_pixels(0, 0, width, height)
|
252
|
+
pixels.map!(&block)
|
253
|
+
rmagick_image.store_pixels(0, 0, width, height, pixels)
|
254
|
+
end
|
255
|
+
|
256
|
+
# If bitmap.rmagick_image is changed, the behaviour is undefined.
|
257
|
+
# If you want to change it, call set_dirty or bitmap.rmagick_image = image
|
258
|
+
# after the change.
|
259
|
+
def rmagick_image
|
260
|
+
if @dirty
|
261
|
+
@dirty = false
|
262
|
+
@rmagick_image = Bitmap.gosu_to_rmagick(@gosu_image)
|
263
|
+
else
|
264
|
+
@rmagick_image
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def change_image
|
269
|
+
@dirty = true
|
270
|
+
end
|
271
|
+
|
272
|
+
def check_disposed
|
273
|
+
raise RGSSError, "Disposed Bitmap" if @disposed
|
274
|
+
end
|
275
|
+
|
276
|
+
def dispose!
|
277
|
+
@gosu_image = nil
|
278
|
+
@rmagick_image = nil
|
279
|
+
@disposed = true
|
280
|
+
end
|
281
|
+
|
282
|
+
def rmagick_image=(image)
|
283
|
+
@rmagick_image = image
|
284
|
+
@gosu_image = Gosu::Image.new(@rmagick_image)
|
285
|
+
end
|
286
|
+
|
287
|
+
def set_dirty
|
288
|
+
@dirty = true
|
289
|
+
end
|
290
|
+
end
|