dxruby64 1.4.7

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 (101) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +14 -0
  3. data/README-ja.md +125 -0
  4. data/README.md +120 -0
  5. data/lib/31/dxruby.so +0 -0
  6. data/lib/32/dxruby.so +0 -0
  7. data/lib/33/dxruby.so +0 -0
  8. data/lib/34/dxruby.so +0 -0
  9. data/lib/dxruby.rb +2 -0
  10. data/sample/classic_sample/8_puzzle.rb +55 -0
  11. data/sample/classic_sample/block_destroy.rb +161 -0
  12. data/sample/classic_sample/block_fall.rb +194 -0
  13. data/sample/classic_sample/data.png +0 -0
  14. data/sample/classic_sample/dot.rb +80 -0
  15. data/sample/classic_sample/drawtile.rb +173 -0
  16. data/sample/classic_sample/flight.rb +75 -0
  17. data/sample/classic_sample/hitrangeview.rb +66 -0
  18. data/sample/classic_sample/mapedit.rb +270 -0
  19. data/sample/classic_sample/meiro.rb +106 -0
  20. data/sample/classic_sample/minsample.rb +14 -0
  21. data/sample/classic_sample/race.rb +119 -0
  22. data/sample/classic_sample/readme_sample.txt +42 -0
  23. data/sample/classic_sample/sample.rb +110 -0
  24. data/sample/classic_sample/soundeffect.rb +46 -0
  25. data/sample/new_sample/biyo.rb +25 -0
  26. data/sample/new_sample/image/enemy1.png +0 -0
  27. data/sample/new_sample/image/enemy1bomb.png +0 -0
  28. data/sample/new_sample/image/enemy2.png +0 -0
  29. data/sample/new_sample/image/enemy2bomb.png +0 -0
  30. data/sample/new_sample/image/enemyshot1.png +0 -0
  31. data/sample/new_sample/image/enemyshot2.png +0 -0
  32. data/sample/new_sample/image/maptile.png +0 -0
  33. data/sample/new_sample/image/myship.png +0 -0
  34. data/sample/new_sample/image/myshot.png +0 -0
  35. data/sample/new_sample/iraira.rb +49 -0
  36. data/sample/new_sample/laser2.rb +292 -0
  37. data/sample/new_sample/raycast.rb +249 -0
  38. data/sample/new_sample/readme_sample.txt +27 -0
  39. data/sample/new_sample/rubima.rb +597 -0
  40. data/sample/new_sample/ruby.png +0 -0
  41. data/sample/new_sample/slg.rb +82 -0
  42. data/sample/new_sample/sprite_animation.rb +133 -0
  43. data/sample/new_sample/sprite_collision1.rb +216 -0
  44. data/sample/new_sample/sprite_collision2.rb +93 -0
  45. data/sample/new_sample/sprite_simple.rb +65 -0
  46. data/sample/new_sample2/ImageFont.dat +0 -0
  47. data/sample/new_sample2/ImageFont.dat.png +0 -0
  48. data/sample/new_sample2/autocall.rb +24 -0
  49. data/sample/new_sample2/effecttest.rb +136 -0
  50. data/sample/new_sample2/fibersprite.rb +89 -0
  51. data/sample/new_sample2/hitrange.rb +133 -0
  52. data/sample/new_sample2/hlstest.rb +27 -0
  53. data/sample/new_sample2/mapedit_perlin.rb +291 -0
  54. data/sample/new_sample2/noise.rb +33 -0
  55. data/sample/new_sample2/particle.rb +220 -0
  56. data/sample/new_sample2/readme_sample.txt +29 -0
  57. data/sample/new_sample2/scenetest.rb +200 -0
  58. data/sample/new_sample2/scenetest2.rb +120 -0
  59. data/sample/scroll_sample/map.dat +32 -0
  60. data/sample/scroll_sample/map.rb +77 -0
  61. data/sample/scroll_sample/map_sub.dat +32 -0
  62. data/sample/scroll_sample/mapedit.rb +102 -0
  63. data/sample/scroll_sample/readme_sample.txt +24 -0
  64. data/sample/scroll_sample/scroll1.rb +108 -0
  65. data/sample/scroll_sample/scroll2.rb +149 -0
  66. data/sample/scroll_sample/scroll3.rb +148 -0
  67. data/sample/scroll_sample/simple.rb +13 -0
  68. data/sample/shader_sample/Shader/Flash.rb +93 -0
  69. data/sample/shader_sample/Shader/RasterScroll.rb +71 -0
  70. data/sample/shader_sample/Shader/RgssSprite.rb +143 -0
  71. data/sample/shader_sample/Shader/Transition.rb +108 -0
  72. data/sample/shader_sample/bgimage/BG00a1_80.jpg +0 -0
  73. data/sample/shader_sample/bgimage/BG10a_80.jpg +0 -0
  74. data/sample/shader_sample/bgimage/BG13a_80.jpg +0 -0
  75. data/sample/shader_sample/bgimage/BG32a.jpg +0 -0
  76. data/sample/shader_sample/bgimage/BG42a.jpg +0 -0
  77. data/sample/shader_sample/bgimage/course.png +0 -0
  78. data/sample/shader_sample/bgimage/image1.png +0 -0
  79. data/sample/shader_sample/bgimage/world_map2.png +0 -0
  80. data/sample/shader_sample/fan.rb +53 -0
  81. data/sample/shader_sample/image/enemy1.png +0 -0
  82. data/sample/shader_sample/image/enemy2.png +0 -0
  83. data/sample/shader_sample/image/maptile.png +0 -0
  84. data/sample/shader_sample/readme_sample.txt +43 -0
  85. data/sample/shader_sample/rule//343/203/201/343/202/247/343/203/203/343/202/253/343/203/274.png +0 -0
  86. data/sample/shader_sample/rule//345/217/263/346/270/246/345/267/273/343/201/215.png +0 -0
  87. data/sample/shader_sample/rule//346/250/252/343/203/226/343/203/251/343/202/244/343/203/263/343/203/211.png +0 -0
  88. data/sample/shader_sample/sample_blur.rb +112 -0
  89. data/sample/shader_sample/sample_divide.rb +91 -0
  90. data/sample/shader_sample/sample_flash.rb +54 -0
  91. data/sample/shader_sample/sample_lens.rb +65 -0
  92. data/sample/shader_sample/sample_mapping.rb +50 -0
  93. data/sample/shader_sample/sample_rasterscroll.rb +48 -0
  94. data/sample/shader_sample/sample_rgsssprite.rb +41 -0
  95. data/sample/shader_sample/sample_spehari.rb +50 -0
  96. data/sample/shader_sample/sample_sphere.rb +66 -0
  97. data/sample/shader_sample/sample_transition.rb +62 -0
  98. data/sample/shader_sample/sample_vertexshader.rb +223 -0
  99. data/sample/shader_sample/sample_wingman.rb +47 -0
  100. data/sample/shader_sample/turn_transition.rb +74 -0
  101. metadata +141 -0
@@ -0,0 +1,133 @@
1
+ require 'dxruby'
2
+
3
+ class AnimeSprite < Sprite
4
+
5
+ def initialize(x=0, y=0, image=nil)
6
+ super
7
+ @anime_sprite_count = 0
8
+ @anime_sprite_frame_count = 1
9
+ @anime_sprite_pause = true
10
+ @anime_sprite_animation_pattern = nil
11
+ @anime_sprite_hash = {}
12
+ @anime_sprite_next = nil
13
+ end
14
+
15
+ def start_animation(v, animation_pattern=nil, nxt=nil)
16
+ temp = @anime_sprite_hash[v]
17
+ if temp
18
+ @anime_sprite_frame_count = temp[0]
19
+ @anime_sprite_animation_pattern = temp[1]
20
+ @anime_sprite_next = temp[2]
21
+ else
22
+ @anime_sprite_frame_count = v
23
+ @anime_sprite_animation_pattern = animation_pattern
24
+ @anime_sprite_next = nxt
25
+ end
26
+ @anime_sprite_pause = false
27
+ @anime_sprite_count = 0
28
+ end
29
+
30
+ def change_animation(v, animation_pattern=nil, nxt=nil)
31
+ temp = @anime_sprite_hash[v]
32
+ if temp
33
+ @anime_sprite_frame_count = temp[0]
34
+ @anime_sprite_animation_pattern = temp[1]
35
+ @anime_sprite_next = temp[2]
36
+ else
37
+ @anime_sprite_frame_count = v
38
+ @anime_sprite_animation_pattern = animation_pattern
39
+ @anime_sprite_next = nxt
40
+ end
41
+ end
42
+
43
+ def pause_animation
44
+ @anime_sprite_pause = true
45
+ end
46
+
47
+ def resume_animation
48
+ @anime_sprite_pause = false
49
+ end
50
+
51
+ def add_animation(v, frame_count, animation_pattern=nil, nxt=nil)
52
+ @anime_sprite_hash[v] = [frame_count, animation_pattern, nxt]
53
+ end
54
+
55
+ def update
56
+ if @anime_sprite_animation_pattern
57
+ unless @anime_sprite_pause
58
+ @anime_sprite_count += 1
59
+ if @anime_sprite_count >= @anime_sprite_frame_count * @anime_sprite_animation_pattern.size
60
+ if @anime_sprite_next
61
+ temp = @anime_sprite_hash[@anime_sprite_next]
62
+ if temp
63
+ @anime_sprite_frame_count = temp[0]
64
+ @anime_sprite_animation_pattern = temp[1]
65
+ @anime_sprite_next = temp[2]
66
+ else
67
+ self.send @anime_sprite_next
68
+ end
69
+ end
70
+ @anime_sprite_count = 0
71
+ end
72
+ end
73
+ self.image = @anime_sprite_animation_image[@anime_sprite_animation_pattern[@anime_sprite_count / @anime_sprite_frame_count]]
74
+ else
75
+ unless @anime_sprite_pause
76
+ @anime_sprite_count += 1
77
+ if @anime_sprite_count >= @anime_sprite_frame_count * @anime_sprite_animation_image.size
78
+ if @anime_sprite_next
79
+ temp = @anime_sprite_hash[@anime_sprite_next]
80
+ if temp
81
+ @anime_sprite_frame_count = temp[0]
82
+ @anime_sprite_animation_pattern = temp[1]
83
+ @anime_sprite_next = temp[2]
84
+ else
85
+ self.send @anime_sprite_next
86
+ end
87
+ end
88
+ @anime_sprite_count = 0
89
+ end
90
+ end
91
+ self.image = @anime_sprite_animation_image[@anime_sprite_count / @anime_sprite_frame_count]
92
+ end
93
+ super
94
+ end
95
+
96
+ def animation_image
97
+ @anime_sprite_animation_image
98
+ end
99
+
100
+ def animation_image=(v)
101
+ @anime_sprite_animation_image = v
102
+ self.image = v[0]
103
+ end
104
+ end
105
+
106
+
107
+ image = Image.load_tiles("./image/enemy1.png", 4, 1)
108
+
109
+ s = AnimeSprite.new
110
+ s.x = 0
111
+ s.y = 0
112
+ s.animation_image = image
113
+ s.add_animation(:anime1, 10,[0,1,2,3], :anime1)
114
+ s.add_animation(:anime2, 4,[0,1,0,1,0,1,0,1,0,1], :anime1)
115
+ s.start_animation(:anime1)
116
+
117
+ Window.loop do
118
+ if Input.key_push?(K_Z)
119
+ s.pause_animation
120
+ end
121
+ if Input.key_push?(K_X)
122
+ s.resume_animation
123
+ end
124
+ if Input.key_push?(K_C)
125
+ s.start_animation(:anime2)
126
+ end
127
+ s.update
128
+ s.draw
129
+ break if Input.key_push?(K_ESCAPE)
130
+ end
131
+
132
+
133
+
@@ -0,0 +1,216 @@
1
+ #!ruby -Ks
2
+ require "dxruby"
3
+
4
+ class CollisionObject < Sprite
5
+ def initialize(image)
6
+ super(rand(Window.width-image.width), rand(Window.height-image.height), image)
7
+ @hit = false
8
+ @dx = (rand(4)*2-3)/4.0
9
+ @dy = (rand(4)*2-3)/4.0
10
+ end
11
+
12
+ def update
13
+ self.x += @dx
14
+ self.y += @dy
15
+ @dx = -@dx if self.x <= 0 or self.x >= Window.width-self.image.width
16
+ @dy = -@dy if self.y <= 0 or self.y >= Window.height-self.image.height
17
+ end
18
+ end
19
+
20
+ # ������
21
+ class Box < CollisionObject
22
+ @@image1 = Image.new(30, 30, [255, 200, 0, 0])
23
+ @@image2 = Image.new(30, 30, [255, 255, 255])
24
+ def initialize
25
+ super(@@image1)
26
+ # @collision = [0, 0, 29, 29]
27
+ self.scale_x = rand(2.0)+1
28
+ self.scale_y = rand(2.0)+1
29
+ self.center_x = rand(self.image.width)
30
+ self.center_y = rand(self.image.height)
31
+ self.angle = rand(360)
32
+ @rot_speed = (rand(2.0)+1)*2-3
33
+ end
34
+
35
+ def update
36
+ super
37
+ self.angle += @rot_speed
38
+ self.image = @@image1
39
+ end
40
+
41
+ def hit(d)
42
+ self.image = @@image2
43
+ end
44
+ end
45
+
46
+ # ������2
47
+ class Box2 < CollisionObject
48
+ @@image1 = Image.new(30, 30, [255, 200, 0, 0])
49
+ @@image2 = Image.new(30, 30, [255, 255, 255])
50
+ def initialize
51
+ super(@@image1)
52
+ # @collision = [0, 0, 29, 29]
53
+ end
54
+ def update
55
+ super
56
+ self.image = @@image1
57
+ end
58
+
59
+ def hit(d)
60
+ self.image = @@image2
61
+ end
62
+ end
63
+
64
+ # �܂�
65
+ class Circle < CollisionObject
66
+ @@image1 = Image.new(30, 30).circle_fill(15, 15, 15, [255, 200, 0])
67
+ @@image2 = Image.new(30, 30).circle_fill(15, 15, 15, [255, 255, 255])
68
+ def initialize
69
+ super(@@image1)
70
+ self.collision = [15, 15, 15]
71
+ self.scale_x = rand(2.0)+1
72
+ self.scale_y = rand(2.0)+1
73
+ self.center_x = rand(self.image.width)
74
+ self.center_y = rand(self.image.height)
75
+ self.angle = rand(360)
76
+ @rot_speed = (rand(2.0)+1)*2-3
77
+ end
78
+ def update
79
+ super
80
+ self.angle += @rot_speed
81
+ self.image = @@image1
82
+ end
83
+ def hit(d)
84
+ self.image = @@image2
85
+ end
86
+ end
87
+
88
+ # �܂�2
89
+ class Circle2 < CollisionObject
90
+ @@image1 = Image.new(30, 30).circle_fill(15, 15, 15, [255, 200, 0])
91
+ @@image2 = Image.new(30, 30).circle_fill(15, 15, 15, [255, 255, 255])
92
+ def initialize
93
+ super(@@image1)
94
+ self.collision = [15, 15, 15]
95
+ end
96
+ def update
97
+ super
98
+ self.image = @@image1
99
+ end
100
+ def hit(d)
101
+ self.image = @@image2
102
+ end
103
+ end
104
+
105
+ # ���񂩂�
106
+ class Triangle < CollisionObject
107
+ @@image1 = Image.new(30, 30).triangle_fill(15,0,29,29,0,29,C_GREEN)
108
+ @@image2 = Image.new(30, 30).triangle_fill(15,0,29,29,0,29,C_WHITE)
109
+ def initialize
110
+ super(@@image1)
111
+ self.collision = [15,0,29,29,0,29]
112
+ self.scale_x = rand(2.0)+1
113
+ self.scale_y = rand(2.0)+1
114
+ self.center_x = rand(self.image.width)
115
+ self.center_y = rand(self.image.height)
116
+ self.angle = rand(360)
117
+ @rot_speed = (rand(2.0)+1)*2-3
118
+ end
119
+
120
+ def update
121
+ super
122
+ self.angle += @rot_speed
123
+ self.image = @@image1
124
+ end
125
+ def hit(d)
126
+ self.image = @@image2
127
+ end
128
+ end
129
+
130
+ # ���񂩂�2
131
+ class Triangle2 < CollisionObject
132
+ @@image1 = Image.new(30, 30).triangle_fill(15,0,29,29,0,29,C_GREEN)
133
+ @@image2 = Image.new(30, 30).triangle_fill(15,0,29,29,0,29,C_WHITE)
134
+ def initialize
135
+ super(@@image1)
136
+ self.collision = [15,0,29,29,0,29]
137
+ end
138
+ def update
139
+ super
140
+ self.image = @@image1
141
+ end
142
+ def hit(d)
143
+ self.image = @@image2
144
+ end
145
+ end
146
+
147
+ # �ق�
148
+ class Star < CollisionObject
149
+ @@image1 = Image.new(100,100)
150
+ @@image2 = Image.new(100,100)
151
+
152
+ bx = 0
153
+ by = -20
154
+
155
+ x1 = []
156
+ y1 = []
157
+ (0..4).each do |i|
158
+ x1[i] = bx * Math.cos(Math::PI / 180 * (i * 72 - 36)) - by * Math.sin(Math::PI / 180 * (i * 72 - 36)) + @@image1.width / 2
159
+ y1[i] = bx * Math.sin(Math::PI / 180 * (i * 72 - 36)) + by * Math.cos(Math::PI / 180 * (i * 72 - 36)) + @@image1.height / 2
160
+ end
161
+ sx = x1[0] + (x1[1] - x1[0]) / 2 - @@image1.width / 2
162
+ sy = y1[0] - (x1[1] - x1[0]) / 2 * Math.tan(Math::PI / 180 * 72) - @@image1.height / 2
163
+ x2 = []
164
+ y2 = []
165
+ (0..4).each do |i|
166
+ x2[i] = sx * Math.cos(Math::PI / 180 * i * 72) - sy * Math.sin(Math::PI / 180 * i * 72) + @@image1.width / 2
167
+ y2[i] = sx * Math.sin(Math::PI / 180 * i * 72) + sy * Math.cos(Math::PI / 180 * i * 72) + @@image1.height / 2
168
+ end
169
+ @@cols = [[x2[0], y2[0], x1[2], y1[2], x1[4], y1[4]],
170
+ [x2[1], y2[1], x1[3], y1[3], x1[0], y1[0]],
171
+ [x2[2], y2[2], x1[4], y1[4], x1[1], y1[1]],
172
+ [x2[3], y2[3], x1[0], y1[0], x1[2], y1[2]],
173
+ [x2[4], y2[4], x1[1], y1[1], x1[3], y1[3]]]
174
+
175
+ @@cols.each do |ary|
176
+ @@image1.triangle_fill(ary[0], ary[1], ary[2], ary[3], ary[4], ary[5], C_CYAN)
177
+ @@image2.triangle_fill(ary[0], ary[1], ary[2], ary[3], ary[4], ary[5], C_WHITE)
178
+ end
179
+
180
+ def initialize
181
+ super(@@image1)
182
+ self.collision = @@cols
183
+ end
184
+ def update
185
+ super
186
+ self.image = @@image1
187
+ self.angle += 1
188
+ end
189
+ def hit(d)
190
+ self.image = @@image2
191
+ end
192
+ end
193
+
194
+
195
+
196
+ Window.width, Window.height = 800, 600
197
+
198
+ font = Font.new(24)
199
+
200
+ object = Array.new(20) {Box.new} + Array.new(20) {Box2.new} +
201
+ Array.new(20) {Triangle.new} + Array.new(20) {Triangle2.new} +
202
+ Array.new(20) {Circle.new} + Array.new(20) {Circle2.new} +
203
+ Array.new(5) {Star.new}
204
+
205
+ Window.loop do
206
+ Sprite.update(object)
207
+
208
+ Sprite.check(object)
209
+
210
+ Sprite.draw(object)
211
+
212
+ break if Input.keyPush?(K_ESCAPE)
213
+
214
+ Window.drawFont(0, 0, Window.fps.to_s + " fps", font)
215
+ Window.drawFont(0, 24, Window.getLoad.to_i.to_s + " %", font)
216
+ end
@@ -0,0 +1,93 @@
1
+ #!ruby -Ks
2
+ require "dxruby"
3
+
4
+ # ������
5
+ class Box < Sprite
6
+ def initialize(size)
7
+ self.x = rand(639-size)
8
+ self.y = rand(439-size)
9
+ self.collision = [0, 0, size - 1, size - 1]
10
+ self.image = Image.new(size, size, [255, 200, 0, 0])
11
+ end
12
+ end
13
+
14
+ # �܂�
15
+ class Circle < Sprite
16
+ def initialize(size)
17
+ self.x = rand(639-size*2)
18
+ self.y = rand(439-size*2)
19
+ self.collision = [size, size, size]
20
+ self.image = Image.new(size*2, size*2).circle_fill(size, size, size, [255, 0, 0, 200])
21
+ end
22
+ end
23
+
24
+ # ���񂩂�
25
+ class Triangle < Sprite
26
+ def initialize(size)
27
+ self.x = rand(639-size)
28
+ self.y = rand(439-size)
29
+ self.collision = [size/2,0,0,size-1,size-1,size-1]
30
+ self.image = Image.new(size, size).triangle_fill(size/2,0,0,size-1,size-1,size-1, [255,0,200,0])
31
+ end
32
+ end
33
+
34
+ font = Font.new(24)
35
+
36
+ # ���܃}�E�X�Œ͂�ł�I�u�W�F�N�g
37
+ item = nil
38
+
39
+ # �I�u�W�F�N�g�z��
40
+ arr = [Circle.new(20), Circle.new(40),
41
+ Triangle.new(60), Triangle.new(100),
42
+ Box.new(40), Box.new(80)]
43
+
44
+ # �}�E�X�J�[�\���̏Փ˔���pSprite
45
+ mouse = Sprite.new
46
+ mouse.collision = [0,0]
47
+
48
+ # ���C�����[�v
49
+ Window.loop do
50
+ oldx, oldy = mouse.x, mouse.y
51
+ mouse.x, mouse.y = Input.mouse_pos_x, Input.mouse_pos_y
52
+
53
+ # �{�^�����������画��
54
+ if Input.mouse_push?(M_LBUTTON) or Input.mouse_push?(M_RBUTTON)
55
+ arr.each_with_index do |obj, i|
56
+ if mouse === obj
57
+ # �I�u�W�F�N�g���N���b�N�ł�������בւ���item�ݒ�
58
+ arr.delete_at(i)
59
+ arr.unshift(obj)
60
+ item = obj
61
+ break
62
+ end
63
+ end
64
+ end
65
+
66
+ # �{�^���������Ă���Ԃ̏���
67
+ if Input.mouse_down?(M_RBUTTON) or Input.mouse_down?(M_LBUTTON)
68
+ if item then
69
+ if Input.mouse_down?(M_RBUTTON)
70
+ item.angle += 5
71
+ end
72
+ if Input.mouse_down?(M_LBUTTON)
73
+ item.x += mouse.x - oldx
74
+ item.y += mouse.y - oldy
75
+ end
76
+ end
77
+ else
78
+ # �{�^���������ꂽ��I�u�W�F�N�g�����
79
+ item = nil
80
+ end
81
+
82
+ # �I�u�W�F�N�g���m�̔���
83
+ if Sprite.check(arr) then
84
+ Window.draw_font(0, 0, "hit!", font)
85
+ end
86
+
87
+ # �`��
88
+ arr.reverse.each do |obj|
89
+ obj.draw
90
+ end
91
+
92
+ break if Input.key_push?(K_ESCAPE)
93
+ end
@@ -0,0 +1,65 @@
1
+ #!ruby -Ks
2
+ require "dxruby"
3
+
4
+ class Ruby < Sprite
5
+ RT = RenderTarget.new(640,480)
6
+ MAX_X = 639 - 32
7
+ MAX_Y = 479 - 32
8
+
9
+ # Image�I�u�W�F�N�g���쐬
10
+ @@image = Image.load("ruby.png")
11
+
12
+ # ���������\�b�h
13
+ def initialize
14
+ super
15
+ self.x = rand(MAX_X)+1 # x���W
16
+ self.y = rand(MAX_Y)+1 # y���W
17
+ self.image = @@image # �摜
18
+ self.target = RT # �`���
19
+
20
+ @dx = rand(2) * 2 - 1 # x����
21
+ @dy = rand(2) * 2 - 1 # y����
22
+ end
23
+
24
+ # �X�V
25
+ def update
26
+ self.x += @dx
27
+ self.y += @dy
28
+ if self.x <= 0 or MAX_X <= self.x
29
+ @dx = -@dx
30
+ end
31
+ if self.y <= 0 or MAX_Y <= self.y
32
+ @dy = -@dy
33
+ end
34
+ end
35
+ end
36
+
37
+ # Sprite �I�u�W�F�N�g�̔z��𐶐�����B
38
+ sprites = Array.new(6000){ Ruby.new }
39
+
40
+ font = Font.new(32)
41
+
42
+ # �E�B���h�E�̃L���v�V������ݒ肷��B
43
+ Window.caption = "Sprites"
44
+
45
+ # fps��ݒ肷��B
46
+ Window.fps = 60
47
+
48
+ # ���C�����[�v�B
49
+ # �E�B���h�E���‚���ꂽ�ꍇ�͎����I�ɏI������B
50
+ # ��ʂ͖��t���[�����Z�b�g�����B
51
+ Window.loop do
52
+ # ESC �L�[�������ꂽ�ꍇ�I������B
53
+ break if Input.keyPush?(K_ESCAPE)
54
+
55
+ Sprite.update(sprites)
56
+ Sprite.draw(sprites)
57
+
58
+ Ruby::RT.update
59
+ Window.draw(0,0,Ruby::RT)
60
+
61
+ Window.drawFont(0,0,Window.fps.to_s + " fps", font)
62
+ Window.drawFont(0,40,sprites.size.to_s + " objects", font)
63
+ Window.drawFont(0,80,Window.getLoad.to_i.to_s + " %", font)
64
+ end
65
+
Binary file
@@ -0,0 +1,24 @@
1
+ require 'dxruby'
2
+
3
+ x1 = 0
4
+ x2 = 0
5
+ image = Image.new(100,100,C_WHITE)
6
+
7
+ proc1 = Proc.new do
8
+ x1 += 2
9
+ Window.draw(x1, 100, image)
10
+ end
11
+
12
+ proc2 = Proc.new do
13
+ x2 += 2
14
+ Window.draw(x2, 201, image)
15
+ end
16
+
17
+ Window.before_call[:test] = proc1
18
+ Window.after_call[:test] = proc2
19
+
20
+ Window.loop do
21
+ break if Input.key_push?(K_ESCAPE)
22
+ end
23
+
24
+
@@ -0,0 +1,136 @@
1
+ #!ruby -Ks
2
+ require 'dxruby'
3
+
4
+ # �����_�����O�ς݃t�H���g�����N���X
5
+ class ImageFontMaker
6
+ ImageFontData = Struct.new(:x, :y, :width, :ox)
7
+ ImageFontSaveData = Struct.new(:data_hash, :image, :height)
8
+
9
+ def initialize(size, fontname = nil)
10
+ @font = Font.new(size, fontname)
11
+ @hash = {}
12
+ end
13
+
14
+ def add_data(str)
15
+ str.each_char do |c|
16
+ @hash[c] = @font.info(c)
17
+ end
18
+ end
19
+
20
+ def output(filename)
21
+ # �K�v�ȉ摜�T�C�Y�𒲂ׂ�
22
+ # �v�Z����₱�������ƂɂȂ��Ă�̂�f��j�ȂǍ��E�ɂ͂ݏo������ȕ����̑Ή�
23
+ width = 0
24
+ height = 0
25
+ keys = @hash.keys.shuffle
26
+ keys.each do |k|
27
+ v = @hash[k]
28
+ ox = v.gmpt_glyphorigin_x < 0 ? -v.gmpt_glyphorigin_x : 0
29
+ cx = (v.gm_blackbox_x + v.gmpt_glyphorigin_x) > v.gm_cellinc_x + ox ? (v.gm_blackbox_x + v.gmpt_glyphorigin_x) : v.gm_cellinc_x + ox
30
+ width += cx
31
+ if width > 640
32
+ height += @font.size
33
+ width = cx
34
+ end
35
+ end
36
+ height += @font.size
37
+
38
+ # �摜����
39
+ image = Image.new(640, height, C_BLACK)
40
+
41
+ # �����`������
42
+ x = 0
43
+ y = 0
44
+ data_hash = {}
45
+ keys.each do |k|
46
+ v = @hash[k]
47
+ ox = v.gmpt_glyphorigin_x < 0 ? -v.gmpt_glyphorigin_x : 0
48
+ cx = (v.gm_blackbox_x + v.gmpt_glyphorigin_x) > v.gm_cellinc_x + ox ? (v.gm_blackbox_x + v.gmpt_glyphorigin_x) : v.gm_cellinc_x + ox
49
+ if x + cx > 640
50
+ x = 0
51
+ y += @font.size
52
+ end
53
+ image.draw_font(x + ox, y, k, @font)
54
+ data_hash[k] = ImageFontData.new(x, y, cx, ox)
55
+ x += cx
56
+ end
57
+
58
+ # ��������ۑ�
59
+ image.save(filename + ".png")
60
+
61
+ # �o�C�i���œǂݍ���
62
+ image_binary = nil
63
+ open(filename + ".png", "rb") do |fh|
64
+ image_binary = fh.read
65
+ end
66
+
67
+ # �}�[�V�������ăt�@�C����
68
+ imagefont = ImageFontSaveData.new(data_hash, image_binary, @font.size)
69
+
70
+ open(filename, "wb") do |fh|
71
+ fh.write(Marshal.dump(imagefont))
72
+ end
73
+ end
74
+ end
75
+
76
+ # �����_�����O�ς݃t�H���g���g���N���X
77
+ class ImageFont
78
+ attr_accessor :target
79
+
80
+ # �������̃p�����[�^��draw_font_ex�̃n�b�V�������Ɠ���
81
+ def initialize(filename)
82
+ open(filename, "rb") do |fh|
83
+ temp = Marshal.load(fh.read)
84
+ @data_hash = temp.data_hash
85
+ @image = Image.load_from_file_in_memory(temp.image)
86
+ @height = temp.height
87
+ end
88
+ @cache = {}
89
+ end
90
+
91
+ # ������`��
92
+ def draw(x, y, s, hash)
93
+ rt = @target == nil ? Window : @target
94
+ edge_width = hash[:edge_width] == nil ? 2 : hash[:edge_width]
95
+
96
+ image_hash = nil
97
+ if !@cache.has_key?(hash)
98
+ image_hash = @cache[hash] = {}
99
+ else
100
+ image_hash = @cache[hash]
101
+ end
102
+
103
+ s.each_char do |c|
104
+ temp = @data_hash[c]
105
+
106
+ if !image_hash.has_key?(c)
107
+ image = @image.slice(temp.x, temp.y, temp.width, @height)
108
+ image_hash[c] = image.effect_image_font(hash)
109
+ image.delayed_dispose
110
+ end
111
+ rt.draw(x - temp.ox - edge_width, y - edge_width, image_hash[c])
112
+ x += temp.width - temp.ox
113
+ end
114
+ end
115
+ end
116
+
117
+ Window.bgcolor = [100,100,100]
118
+
119
+ # �����_�����O�ς݃t�H���g�쐬
120
+ imagefontmaker = ImageFontMaker.new(48, "�l�r �o�S�V�b�N")
121
+ imagefontmaker.add_data(" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef��ghijklmnopqrstuvwxyz�����������������������������������������������������‚ĂƂ����ÂłǂȂɂʂ˂̂͂Ђӂւق΂тԂׂڂς҂Ղ؂ۂ܂݂ނ߂�����������������������������A�B")
122
+ imagefontmaker.output("ImageFont.dat")
123
+
124
+ # �����_�����O�ς݃t�H���g�ǂݍ���
125
+ imagefont = ImageFont.new("ImageFont.dat")
126
+
127
+ Window.loop do
128
+ imagefont.draw(50, 60, "���傤�͂��������邾�����B", :shadow=>true, :edge=>true, :edge_color=>C_CYAN)
129
+ imagefont.draw(50, 108, "f��������������������", :shadow=>false, :edge=>true, :edge_color=>C_CYAN)
130
+ imagefont.draw(50, 156, "j���������������‚Ă�", :shadow=>true, :edge=>false, :edge_color=>C_CYAN)
131
+ imagefont.draw(50, 204, "k�Ȃɂʂ˂̂͂Ђӂւ�", :shadow=>true, :edge=>true, :edge_color=>C_RED)
132
+ end
133
+
134
+
135
+
136
+