dxruby_sdl 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.rubocop.yml +4 -0
- data/.travis.yml +1 -1
- data/LEGAL +21 -0
- data/lib/dxruby_sdl/image.rb +62 -10
- data/lib/dxruby_sdl/input.rb +127 -0
- data/lib/dxruby_sdl/sound.rb +54 -0
- data/lib/dxruby_sdl/version.rb +1 -1
- data/lib/dxruby_sdl/window.rb +16 -10
- data/lib/dxruby_sdl.rb +204 -3
- data/samples/bgm.mid +0 -0
- data/samples/data.png +0 -0
- data/samples/sound.wav +0 -0
- data/samples/tutorial-2-01.rb +7 -0
- data/samples/tutorial-2-02.rb +9 -0
- data/samples/tutorial-2-03.rb +12 -0
- data/samples/tutorial-2-04.rb +10 -0
- data/samples/tutorial-2-05.rb +14 -0
- data/samples/tutorial-2-06.rb +24 -0
- data/samples/tutorial-2-07.rb +12 -0
- data/samples/tutorial-2-08.rb +12 -0
- data/samples/tutorial-2-09.rb +9 -0
- data/samples/tutorial-2-10.rb +14 -0
- data/spec/dxruby_sdl/image_spec.rb +111 -8
- data/spec/dxruby_sdl/input_spec.rb +230 -0
- data/spec/dxruby_sdl/sound_spec.rb +79 -0
- data/spec/dxruby_sdl/window__draw_spec.rb +85 -0
- data/spec/dxruby_sdl/window_spec.rb +25 -66
- data/spec/dxruby_sdl_spec.rb +201 -16
- data/spec/dxruby_spec.rb +22 -0
- data/spec/fixtures/bgm.mid +0 -0
- data/spec/fixtures/sound.wav +0 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/fixture_helper.rb +8 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGIxYTRjODcxNGNiZjU5MDlkNDY5ZjMxZmZhOTA3MTBjYzk1NmE0ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODQ2MTgzODg3YWY5YWJkNzNkZDI2NjRhYzczMDAxNTUzNmU1MGVjOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmQ0YTVjNzFjZjlkZTQ4OGM3MmIwNzgyZjRiZTdkMmUzZTQ1ZDY0OWUyNzA5
|
10
|
+
ZjEyZjhlNzM3NGM5N2UwNTBmNDQwYjdmMjE5MzM5NGM0NDUzODMyZjAzZTI0
|
11
|
+
OWEzMWFmOTA2ODY1NDkyN2Q2ZTZlYzAyZjQxN2FiNGY3NGZlZjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzQ5NTBmNjJhMTljMTQyOGM2OWU0NmY0NTQzNjEzODVkZmMwODcxODg1M2U4
|
14
|
+
Mzc5M2Q1MjNlZTkzNzg2MGU4MzAzMDJmYzc1MTg0YTViNmU2MmJhY2M5NjQz
|
15
|
+
MzlkZDkzZjU5NzFlMDg4ZjVlNWVjOTEzY2ZmNDI2Y2Y5Njc0YTQ=
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -8,4 +8,4 @@ env:
|
|
8
8
|
|
9
9
|
before_install:
|
10
10
|
- sudo apt-get update -qq
|
11
|
-
- sudo apt-get install -qq libsdl1.2-dev libsdl-ttf2.0-dev libsdl-sge-dev otf-ipafont-gothic
|
11
|
+
- sudo apt-get install -qq libsdl1.2-dev libsdl-mixer1.2-dev timidity libsdl-ttf2.0-dev libsdl-sge-dev otf-ipafont-gothic
|
data/LEGAL
CHANGED
@@ -9,3 +9,24 @@ lib/dxruby_sdl/window/fpstimer.rb:
|
|
9
9
|
|
10
10
|
FPSTimer (Original name is FPSTimerSample) class is implemented in
|
11
11
|
http://www.kmc.gr.jp/~ohai/fpstimer.rb.
|
12
|
+
|
13
|
+
samples/tutorial-2-01.rb, samples/tutorial-2-02.rb,
|
14
|
+
samples/tutorial-2-03.rb, samples/tutorial-2-04.rb,
|
15
|
+
samples/tutorial-2-05.rb, samples/tutorial-2-06.rb,
|
16
|
+
samples/tutorial-2-07.rb, samples/tutorial-2-08.rb,
|
17
|
+
samples/tutorial-2-09.rb, samples/tutorial-2-10.rb:
|
18
|
+
|
19
|
+
These sample programs are copied from DXRuby's tutorial
|
20
|
+
http://dxruby.sourceforge.jp/DXRubyReference/200953183259625.htm.
|
21
|
+
|
22
|
+
spec/fixtures/sound.wav:
|
23
|
+
|
24
|
+
This is downloaded from maokai(魔王魂)
|
25
|
+
http://maoudamashii.jokersounds.com/.
|
26
|
+
Original name is 'se_maoudamashii_onepoint26.wav'.
|
27
|
+
|
28
|
+
spec/fixtures/bgm.mid:
|
29
|
+
|
30
|
+
This is downloaded from maokai(魔王魂)
|
31
|
+
http://maoudamashii.jokersounds.com/.
|
32
|
+
Original name is 'song_32_grandiflora.mid'.
|
data/lib/dxruby_sdl/image.rb
CHANGED
@@ -6,6 +6,29 @@ module DXRubySDL
|
|
6
6
|
|
7
7
|
attr_reader :_surface
|
8
8
|
|
9
|
+
def self.load(filename, x = nil, y = nil, width = nil, height = nil)
|
10
|
+
image = new(0, 0)
|
11
|
+
surface = SDL::Surface.load(filename)
|
12
|
+
image.instance_variable_set('@_surface', surface)
|
13
|
+
return image
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load_tiles(filename, xcount, ycount)
|
17
|
+
surface = SDL::Surface.load(filename)
|
18
|
+
width = surface.w / xcount
|
19
|
+
height = surface.h / ycount
|
20
|
+
images = []
|
21
|
+
ycount.times do |y|
|
22
|
+
xcount.times do |x|
|
23
|
+
image = new(0, 0)
|
24
|
+
s = surface.copy_rect(x * width, y * height, width, height)
|
25
|
+
image.instance_variable_set('@_surface', s)
|
26
|
+
images << image
|
27
|
+
end
|
28
|
+
end
|
29
|
+
return images
|
30
|
+
end
|
31
|
+
|
9
32
|
def initialize(width, height, color = [0, 0, 0, 0])
|
10
33
|
@color = color
|
11
34
|
|
@@ -26,14 +49,25 @@ module DXRubySDL
|
|
26
49
|
return @_surface.h
|
27
50
|
end
|
28
51
|
|
52
|
+
def slice(x, y, width, height)
|
53
|
+
s = @_surface.copy_rect(x, y, width, height)
|
54
|
+
image = Image.new(0, 0)
|
55
|
+
image.instance_variable_set('@_surface', s)
|
56
|
+
return image
|
57
|
+
end
|
58
|
+
|
29
59
|
def line(x1, y1, x2, y2, color)
|
30
|
-
|
31
|
-
|
60
|
+
lock do
|
61
|
+
@_surface.draw_line(x1, y1, x2, y2,
|
62
|
+
to_sdl_color(color), true, to_sdl_alpha(color))
|
63
|
+
end
|
32
64
|
end
|
33
65
|
|
34
66
|
def circle(x, y, r, color)
|
35
|
-
|
36
|
-
|
67
|
+
lock do
|
68
|
+
@_surface.draw_circle(x, y, r, to_sdl_color(color), false, true,
|
69
|
+
to_sdl_alpha(color))
|
70
|
+
end
|
37
71
|
end
|
38
72
|
|
39
73
|
def box(x1, y1, x2, y2, color)
|
@@ -41,14 +75,32 @@ module DXRubySDL
|
|
41
75
|
w = (x2 - x1).abs
|
42
76
|
y = y1 < y2 ? y1 : y2
|
43
77
|
h = (y2 - y1).abs
|
44
|
-
|
78
|
+
lock do
|
79
|
+
@_surface.draw_rect(x, y, w, h, to_sdl_color(color))
|
80
|
+
end
|
45
81
|
end
|
46
82
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
83
|
+
# rubocop:disable SymbolName
|
84
|
+
class << self
|
85
|
+
alias_method :loadTiles, :load_tiles
|
86
|
+
alias_method :load_to_array, :load_tiles
|
87
|
+
alias_method :loadToArray, :load_to_array
|
88
|
+
end
|
89
|
+
# rubocop:enable SymbolName
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def lock(&block)
|
94
|
+
if SDL::Surface.auto_lock?
|
95
|
+
yield
|
96
|
+
else
|
97
|
+
begin
|
98
|
+
@_surface.lock
|
99
|
+
yield
|
100
|
+
ensure
|
101
|
+
@_surface.unlock
|
102
|
+
end
|
103
|
+
end
|
52
104
|
end
|
53
105
|
end
|
54
106
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DXRubySDL
|
4
|
+
module Input
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def x(pad_number = 0)
|
8
|
+
res = 0
|
9
|
+
if key_press?(SDL::Key::LEFT)
|
10
|
+
res -= 1
|
11
|
+
end
|
12
|
+
if key_press?(SDL::Key::RIGHT)
|
13
|
+
res += 1
|
14
|
+
end
|
15
|
+
return res
|
16
|
+
end
|
17
|
+
|
18
|
+
def y(pad_number = 0)
|
19
|
+
res = 0
|
20
|
+
if key_press?(SDL::Key::UP)
|
21
|
+
res -= 1
|
22
|
+
end
|
23
|
+
if key_press?(SDL::Key::DOWN)
|
24
|
+
res += 1
|
25
|
+
end
|
26
|
+
return res
|
27
|
+
end
|
28
|
+
|
29
|
+
def pad_down?(button_code, pad_number = 0)
|
30
|
+
if button_code == P_BUTTON0 && key_press?(SDL::Key::Z) ||
|
31
|
+
button_code == P_BUTTON1 && key_press?(SDL::Key::X) ||
|
32
|
+
button_code == P_BUTTON2 && key_press?(SDL::Key::C) ||
|
33
|
+
((j = joystick(pad_number)) && j.button(button_code))
|
34
|
+
return true
|
35
|
+
end
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
|
39
|
+
def mouse_pos_x
|
40
|
+
return SDL::Mouse.state[0]
|
41
|
+
end
|
42
|
+
|
43
|
+
def mouse_pos_y
|
44
|
+
return SDL::Mouse.state[1]
|
45
|
+
end
|
46
|
+
|
47
|
+
def key_push?(key_code)
|
48
|
+
return key_press?(to_sdl_key(key_code))
|
49
|
+
end
|
50
|
+
|
51
|
+
# rubocop:disable SymbolName
|
52
|
+
class << self
|
53
|
+
alias_method :padDown?, :pad_down?
|
54
|
+
alias_method :mousePosX, :mouse_pos_x
|
55
|
+
alias_method :mousePosY, :mouse_pos_y
|
56
|
+
alias_method :keyPush?, :key_push?
|
57
|
+
end
|
58
|
+
# rubocop:enable SymbolName
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
@joysticks = []
|
63
|
+
|
64
|
+
class << self
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
KEY_TABLE = {}
|
69
|
+
replace_table = {
|
70
|
+
'BACK' => 'BACKSPACE',
|
71
|
+
'ADD' => 'PLUS',
|
72
|
+
'DIVIDE' => 'SLASH',
|
73
|
+
'LCONTROL' => 'LCTRL',
|
74
|
+
'RCONTROL' => 'RCTRL',
|
75
|
+
'SCROLL' => 'SCROLLOCK',
|
76
|
+
'GRAVE' => 'BACKQUOTE',
|
77
|
+
'LBRACKET' => 'LEFTBRACKET',
|
78
|
+
'RBRACKET' => 'RIGHTBRACKET',
|
79
|
+
'LWIN' => 'LSUPER',
|
80
|
+
'RWIN' => 'RSUPER',
|
81
|
+
'YEN' => 'BACKSLASH',
|
82
|
+
}
|
83
|
+
::DXRubySDL.constants.grep(/^K_/).each do |k|
|
84
|
+
name = k.to_s.sub(/^K_/, '')
|
85
|
+
name.gsub!('COMMA', 'PERIOD')
|
86
|
+
if replace_table.key?(name)
|
87
|
+
name = replace_table[name]
|
88
|
+
end
|
89
|
+
case name
|
90
|
+
when /^\d$/
|
91
|
+
name = "K#{name}"
|
92
|
+
when /^NUMPAD(.+)$/
|
93
|
+
md = Regexp.last_match
|
94
|
+
if md[1].length > 1
|
95
|
+
name = "KP_#{md[1]}"
|
96
|
+
else
|
97
|
+
name = "KP#{md[1]}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
begin
|
101
|
+
KEY_TABLE[DXRubySDL.const_get(k)] = SDL::Key.const_get(name.to_sym)
|
102
|
+
rescue NameError
|
103
|
+
end
|
104
|
+
end
|
105
|
+
private_constant :KEY_TABLE
|
106
|
+
|
107
|
+
def key_press?(key)
|
108
|
+
SDL::Key.scan
|
109
|
+
return SDL::Key.press?(key)
|
110
|
+
end
|
111
|
+
|
112
|
+
def joystick(pad_number)
|
113
|
+
if pad_number >= SDL::Joystick.num
|
114
|
+
return nil
|
115
|
+
end
|
116
|
+
if !@joysticks[pad_number]
|
117
|
+
@joysticks[pad_number] = SDL::Joystick.open(pad_number)
|
118
|
+
end
|
119
|
+
return @joysticks[pad_number]
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_sdl_key(key_code)
|
123
|
+
return KEY_TABLE[key_code]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DXRubySDL
|
4
|
+
class Sound
|
5
|
+
@sdl_mixer_openend = false
|
6
|
+
|
7
|
+
def initialize(filename)
|
8
|
+
if !self.class.instance_variable_get('@sdl_mixer_openend')
|
9
|
+
SDL::Mixer.open
|
10
|
+
SDL::Mixer.allocate_channels(2)
|
11
|
+
self.class.instance_variable_set('@sdl_mixer_openend', true)
|
12
|
+
end
|
13
|
+
if /\.mid$/ =~ filename
|
14
|
+
@sound = Music.new(filename)
|
15
|
+
else
|
16
|
+
@sound = Wave.new(filename)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def play
|
21
|
+
@sound.play
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
class Music
|
27
|
+
def initialize(filename)
|
28
|
+
@music = SDL::Mixer::Music.load(filename)
|
29
|
+
end
|
30
|
+
|
31
|
+
def play
|
32
|
+
SDL::Mixer.play_music(@music, -1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
private_constant :Music
|
36
|
+
|
37
|
+
class Wave
|
38
|
+
def initialize(filename)
|
39
|
+
@wave = SDL::Mixer::Wave.load(filename)
|
40
|
+
@last_played_channel = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def play
|
44
|
+
@last_played_channel = SDL::Mixer.play_channel(-1, @wave, 0)
|
45
|
+
rescue SDL::Error => e
|
46
|
+
if /No free channels available/ =~ e.message
|
47
|
+
SDL::Mixer.halt(@last_played_channel == 0 ? 1 : 0)
|
48
|
+
retry
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
private_constant :Wave
|
53
|
+
end
|
54
|
+
end
|
data/lib/dxruby_sdl/version.rb
CHANGED
data/lib/dxruby_sdl/window.rb
CHANGED
@@ -14,23 +14,23 @@ module DXRubySDL
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def loop(&block)
|
17
|
-
_screen.fill_rect(0, 0, DEFAULTS[:width], DEFAULTS[:height],
|
18
|
-
DEFAULTS[:background_color])
|
19
|
-
_screen.update_rect(0, 0, 0, 0)
|
20
|
-
|
21
17
|
timer = FPSTimer.instance
|
22
18
|
timer.reset
|
23
19
|
|
24
20
|
Kernel.loop do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
timer.wait_frame do
|
22
|
+
while (event = SDL::Event.poll)
|
23
|
+
case event
|
24
|
+
when SDL::Event::Quit
|
25
|
+
exit
|
26
|
+
end
|
29
27
|
end
|
30
|
-
end
|
31
28
|
|
32
|
-
|
29
|
+
_screen.fill_rect(0, 0, DEFAULTS[:width], DEFAULTS[:height],
|
30
|
+
DEFAULTS[:background_color])
|
31
|
+
|
33
32
|
yield
|
33
|
+
|
34
34
|
_screen.update_rect(0, 0, 0, 0)
|
35
35
|
end
|
36
36
|
end
|
@@ -49,6 +49,12 @@ module DXRubySDL
|
|
49
49
|
font._ttf.draw_blended_utf8(_screen, string, x, y, r, g, b)
|
50
50
|
end
|
51
51
|
|
52
|
+
# rubocop:disable SymbolName
|
53
|
+
class << self
|
54
|
+
alias_method :drawFont, :draw_font
|
55
|
+
end
|
56
|
+
# rubocop:enable SymbolName
|
57
|
+
|
52
58
|
private
|
53
59
|
|
54
60
|
DEFAULTS = {
|
data/lib/dxruby_sdl.rb
CHANGED
@@ -2,12 +2,213 @@
|
|
2
2
|
|
3
3
|
require 'dxruby_sdl/version'
|
4
4
|
require 'sdl'
|
5
|
+
|
6
|
+
module DXRubySDL
|
7
|
+
%w[
|
8
|
+
DIK_0
|
9
|
+
DIK_1
|
10
|
+
DIK_2
|
11
|
+
DIK_3
|
12
|
+
DIK_4
|
13
|
+
DIK_5
|
14
|
+
DIK_6
|
15
|
+
DIK_7
|
16
|
+
DIK_8
|
17
|
+
DIK_9
|
18
|
+
DIK_A
|
19
|
+
DIK_ABNT_C1
|
20
|
+
DIK_ABNT_C2
|
21
|
+
DIK_ADD
|
22
|
+
DIK_APOSTROPHE
|
23
|
+
DIK_APPS
|
24
|
+
DIK_AT
|
25
|
+
DIK_AX
|
26
|
+
DIK_B
|
27
|
+
DIK_BACK
|
28
|
+
DIK_BACKSLASH
|
29
|
+
DIK_C
|
30
|
+
DIK_CALCULATOR
|
31
|
+
DIK_CAPITAL
|
32
|
+
DIK_COLON
|
33
|
+
DIK_COMMA
|
34
|
+
DIK_CONVERT
|
35
|
+
DIK_D
|
36
|
+
DIK_DECIMAL
|
37
|
+
DIK_DELETE
|
38
|
+
DIK_DIVIDE
|
39
|
+
DIK_DOWN
|
40
|
+
DIK_E
|
41
|
+
DIK_END
|
42
|
+
DIK_EQUALS
|
43
|
+
DIK_ESCAPE
|
44
|
+
DIK_F
|
45
|
+
DIK_F1
|
46
|
+
DIK_F2
|
47
|
+
DIK_F3
|
48
|
+
DIK_F4
|
49
|
+
DIK_F5
|
50
|
+
DIK_F6
|
51
|
+
DIK_F7
|
52
|
+
DIK_F8
|
53
|
+
DIK_F9
|
54
|
+
DIK_F10
|
55
|
+
DIK_F11
|
56
|
+
DIK_F12
|
57
|
+
DIK_F13
|
58
|
+
DIK_F14
|
59
|
+
DIK_F15
|
60
|
+
DIK_G
|
61
|
+
DIK_GRAVE
|
62
|
+
DIK_H
|
63
|
+
DIK_HOME
|
64
|
+
DIK_I
|
65
|
+
DIK_INSERT
|
66
|
+
DIK_J
|
67
|
+
DIK_K
|
68
|
+
DIK_KANA
|
69
|
+
DIK_KANJI
|
70
|
+
DIK_L
|
71
|
+
DIK_LBRACKET
|
72
|
+
DIK_LCONTROL
|
73
|
+
DIK_LEFT
|
74
|
+
DIK_LMENU
|
75
|
+
DIK_LSHIFT
|
76
|
+
DIK_LWIN
|
77
|
+
DIK_M
|
78
|
+
DIK_MAIL
|
79
|
+
DIK_MEDIASELECT
|
80
|
+
DIK_MEDIASTOP
|
81
|
+
DIK_MINUS
|
82
|
+
DIK_MULTIPLY
|
83
|
+
DIK_MUTE
|
84
|
+
DIK_MYCOMPUTER
|
85
|
+
DIK_N
|
86
|
+
DIK_NEXT
|
87
|
+
DIK_NEXTTRACK
|
88
|
+
DIK_NOCONVERT
|
89
|
+
DIK_NUMLOCK
|
90
|
+
DIK_NUMPAD0
|
91
|
+
DIK_NUMPAD1
|
92
|
+
DIK_NUMPAD2
|
93
|
+
DIK_NUMPAD3
|
94
|
+
DIK_NUMPAD4
|
95
|
+
DIK_NUMPAD5
|
96
|
+
DIK_NUMPAD6
|
97
|
+
DIK_NUMPAD7
|
98
|
+
DIK_NUMPAD8
|
99
|
+
DIK_NUMPAD9
|
100
|
+
DIK_NUMPADCOMMA
|
101
|
+
DIK_NUMPADENTER
|
102
|
+
DIK_NUMPADEQUALS
|
103
|
+
DIK_O
|
104
|
+
DIK_OEM_102
|
105
|
+
DIK_P
|
106
|
+
DIK_PAUSE
|
107
|
+
DIK_PERIOD
|
108
|
+
DIK_PLAYPAUSE
|
109
|
+
DIK_POWER
|
110
|
+
DIK_PREVTRACK
|
111
|
+
DIK_PRIOR
|
112
|
+
DIK_Q
|
113
|
+
DIK_R
|
114
|
+
DIK_RBRACKET
|
115
|
+
DIK_RCONTROL
|
116
|
+
DIK_RETURN
|
117
|
+
DIK_RIGHT
|
118
|
+
DIK_RMENU
|
119
|
+
DIK_RSHIFT
|
120
|
+
DIK_RWIN
|
121
|
+
DIK_S
|
122
|
+
DIK_SCROLL
|
123
|
+
DIK_SEMICOLON
|
124
|
+
DIK_SLASH
|
125
|
+
DIK_SLEEP
|
126
|
+
DIK_SPACE
|
127
|
+
DIK_STOP
|
128
|
+
DIK_SUBTRACT
|
129
|
+
DIK_SYSRQ
|
130
|
+
DIK_T
|
131
|
+
DIK_TAB
|
132
|
+
DIK_U
|
133
|
+
DIK_UNDERLINE
|
134
|
+
DIK_UNLABELED
|
135
|
+
DIK_UP
|
136
|
+
DIK_V
|
137
|
+
DIK_VOLUMEDOWN
|
138
|
+
DIK_VOLUMEUP
|
139
|
+
DIK_W
|
140
|
+
DIK_WAKE
|
141
|
+
DIK_WEBBACK
|
142
|
+
DIK_WEBFAVORITES
|
143
|
+
DIK_WEBFORWARD
|
144
|
+
DIK_WEBHOME
|
145
|
+
DIK_WEBREFRESH
|
146
|
+
DIK_WEBSEARCH
|
147
|
+
DIK_WEBSTOP
|
148
|
+
DIK_X
|
149
|
+
DIK_Y
|
150
|
+
DIK_YEN
|
151
|
+
DIK_Z
|
152
|
+
].each.with_index do |dik_name, i|
|
153
|
+
const_set(dik_name.sub(/\ADI/, '').to_sym, i)
|
154
|
+
end
|
155
|
+
|
156
|
+
%w[
|
157
|
+
P_LEFT
|
158
|
+
P_RIGHT
|
159
|
+
P_UP
|
160
|
+
P_DOWN
|
161
|
+
P_BUTTON0
|
162
|
+
P_BUTTON1
|
163
|
+
P_BUTTON2
|
164
|
+
P_BUTTON3
|
165
|
+
P_BUTTON4
|
166
|
+
P_BUTTON5
|
167
|
+
P_BUTTON6
|
168
|
+
P_BUTTON7
|
169
|
+
P_BUTTON8
|
170
|
+
P_BUTTON9
|
171
|
+
P_BUTTON10
|
172
|
+
P_BUTTON11
|
173
|
+
P_BUTTON12
|
174
|
+
P_BUTTON13
|
175
|
+
P_BUTTON14
|
176
|
+
P_BUTTON15
|
177
|
+
P_D_LEFT
|
178
|
+
P_D_RIGHT
|
179
|
+
P_D_UP
|
180
|
+
P_D_DOWN
|
181
|
+
P_R_LEFT
|
182
|
+
P_R_RIGHT
|
183
|
+
P_R_UP
|
184
|
+
P_R_DOWN
|
185
|
+
].each.with_index do |name, i|
|
186
|
+
const_set(name.to_sym, i)
|
187
|
+
end
|
188
|
+
|
189
|
+
%w[
|
190
|
+
P_L_LEFT
|
191
|
+
P_L_RIGHT
|
192
|
+
P_L_UP
|
193
|
+
P_L_DOWN
|
194
|
+
].each.with_index do |name, i|
|
195
|
+
const_set(name.to_sym, i)
|
196
|
+
end
|
197
|
+
|
198
|
+
%w[
|
199
|
+
M_LBUTTON
|
200
|
+
M_RBUTTON
|
201
|
+
M_MBUTTON
|
202
|
+
].each.with_index do |name, i|
|
203
|
+
const_set(name.to_sym, i)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
5
207
|
require 'dxruby_sdl/window'
|
6
208
|
require 'dxruby_sdl/color'
|
7
209
|
require 'dxruby_sdl/image'
|
8
210
|
require 'dxruby_sdl/font'
|
9
|
-
|
10
|
-
|
11
|
-
end
|
211
|
+
require 'dxruby_sdl/input'
|
212
|
+
require 'dxruby_sdl/sound'
|
12
213
|
|
13
214
|
SDL.init(SDL::INIT_EVERYTHING)
|
data/samples/bgm.mid
ADDED
Binary file
|
data/samples/data.png
ADDED
Binary file
|
data/samples/sound.wav
ADDED
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# http://dxruby.sourceforge.jp/DXRubyReference/2009531224032156.htm
|
3
|
+
require 'dxruby'
|
4
|
+
|
5
|
+
image = Image.loadToArray('data.png', 2, 2) # data.pngを読み込んで、横2つ、縦2つに分割する
|
6
|
+
|
7
|
+
Window.loop do
|
8
|
+
Window.draw(100, 100, image[0]) # data.pngの左上を描画する
|
9
|
+
Window.draw(150, 100, image[1]) # data.pngの右上を描画する
|
10
|
+
Window.draw(100, 150, image[2]) # data.pngの左下を描画する
|
11
|
+
Window.draw(150, 150, image[3]) # data.pngの右下を描画する
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# http://dxruby.sourceforge.jp/DXRubyReference/2009531224931296.htm
|
3
|
+
require 'dxruby'
|
4
|
+
|
5
|
+
baseimage = Image.load('data.png') # data.pngを読み込む
|
6
|
+
image = baseimage.slice(0, 0, 20, 20) # data.pngの(0, 0)から20*20pixel分だけ画像を切り出す
|
7
|
+
|
8
|
+
Window.loop do
|
9
|
+
Window.draw(100, 100, image) # data.pngの左上20pixel正方形を描画する
|
10
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# http://dxruby.sourceforge.jp/DXRubyReference/200953122575875.htm
|
3
|
+
require 'dxruby'
|
4
|
+
|
5
|
+
image = Image.load('data.png') # data.pngを読み込む
|
6
|
+
x = 0
|
7
|
+
y = 0
|
8
|
+
|
9
|
+
Window.loop do
|
10
|
+
x = x + Input.x # x座標の更新
|
11
|
+
y = y + Input.y # y座標の更新
|
12
|
+
|
13
|
+
Window.draw(x, y, image) # data.pngを描画する
|
14
|
+
end
|