├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── dxruby.gemspec ├── ext └── dxruby │ ├── COPYING │ ├── collision.c │ ├── collision.h │ ├── dxruby-i386-mswin32.def │ ├── dxruby.c │ ├── dxruby.h │ ├── extconf.rb │ ├── font.c │ ├── font.h │ ├── image.c │ ├── image.h │ ├── input.c │ ├── input.h │ ├── matrix.c │ ├── matrix.h │ ├── messagethread.c │ ├── messagethread.h │ ├── sound.c │ ├── sound.h │ ├── sprite.c │ ├── sprite.h │ └── version.h ├── lib ├── 2.5 │ └── dxruby.so ├── 2.6 │ └── dxruby.so ├── 2.6_x64 │ └── dxruby.so ├── 2.7 │ └── dxruby.so ├── 2.7_x64 │ └── dxruby.so ├── 3.0 │ └── dxruby.so ├── 3.0_x64 │ └── dxruby.so └── dxruby.rb └── sample ├── classic_sample ├── 8_puzzle.rb ├── block_destroy.rb ├── block_fall.rb ├── data.png ├── dot.rb ├── drawtile.rb ├── flight.rb ├── hitrangeview.rb ├── mapedit.rb ├── meiro.rb ├── minsample.rb ├── race.rb ├── readme_sample.txt ├── sample.rb └── soundeffect.rb ├── new_sample ├── biyo.rb ├── image │ ├── enemy1.png │ ├── enemy1bomb.png │ ├── enemy2.png │ ├── enemy2bomb.png │ ├── enemyshot1.png │ ├── enemyshot2.png │ ├── maptile.png │ ├── myship.png │ └── myshot.png ├── iraira.rb ├── laser2.rb ├── raycast.rb ├── readme_sample.txt ├── rubima.rb ├── ruby.png ├── slg.rb ├── sprite_animation.rb ├── sprite_collision1.rb ├── sprite_collision2.rb └── sprite_simple.rb ├── new_sample2 ├── autocall.rb ├── effecttest.rb ├── fibersprite.rb ├── hitrange.rb ├── hlstest.rb ├── mapedit_perlin.rb ├── noise.rb ├── particle.rb ├── readme_sample.txt ├── scenetest.rb └── scenetest2.rb ├── scroll_sample ├── map.dat ├── map.rb ├── map_sub.dat ├── mapedit.rb ├── readme_sample.txt ├── scroll1.rb ├── scroll2.rb ├── scroll3.rb └── simple.rb └── shader_sample ├── Shader ├── Flash.rb ├── RasterScroll.rb ├── RgssSprite.rb └── Transition.rb ├── bgimage ├── BG00a1_80.jpg ├── BG10a_80.jpg ├── BG13a_80.jpg ├── BG32a.jpg ├── BG42a.jpg ├── course.png ├── image1.png └── world_map2.png ├── fan.rb ├── image ├── enemy1.png ├── enemy2.png └── maptile.png ├── readme_sample.txt ├── rule ├── チェッカー.png ├── 右渦巻き.png └── 横ブラインド.png ├── sample_blur.rb ├── sample_divide.rb ├── sample_flash.rb ├── sample_lens.rb ├── sample_mapping.rb ├── sample_rasterscroll.rb ├── sample_rgsssprite.rb ├── sample_spehari.rb ├── sample_sphere.rb ├── sample_transition.rb ├── sample_vertexshader.rb ├── sample_wingman.rb └── turn_transition.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | /.config 4 | /coverage/ 5 | /InstalledFiles 6 | /pkg/ 7 | /spec/reports/ 8 | /test/tmp/ 9 | /test/version_tmp/ 10 | /tmp/ 11 | 12 | ## Specific to RubyMotion: 13 | .dat* 14 | .repl_history 15 | build/ 16 | 17 | ## Documentation cache and generated files: 18 | /.yardoc/ 19 | /_yardoc/ 20 | /doc/ 21 | /rdoc/ 22 | 23 | ## Environment normalisation: 24 | /.bundle/ 25 | /vendor/bundle 26 | /lib/bundler/man/ 27 | 28 | # for a library or gem, you might want to ignore these files since the code is 29 | # intended to run in multiple environments; otherwise, check them in: 30 | # Gemfile.lock 31 | # .ruby-version 32 | # .ruby-gemset 33 | 34 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 35 | .rvmrc 36 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in dxruby.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The zlib/libpng License 2 | Copyright (c) <2012> 3 | 4 | This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. 5 | 6 | Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 7 | 8 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 9 | 10 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 11 | 12 | 3. This notice may not be removed or altered from any source distribution. 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DXRuby 2 | 3 | 使う人は 4 | 5 | gem install dxruby 6 | 7 | でどうぞ。 8 | Ruby2.3~2.6までの32bit用バイナリが入っており、Rubyのバージョンにより自動的に選択されます。RubyInstaller2なら後述する方法で自前ビルドできます。 9 | 10 | リファレンスマニュアルは 11 | http://mirichi.github.io/dxruby-doc/index.html 12 | にあります。 13 | 14 | ## ビルドする方法 15 | 16 | 1. RubyInstaller2をコンパイラ込みでインストールします。 17 | 2. このリポジトリをクローンして、コマンドプロンプトを起動してソースがあるところに移動します。 18 | 3. ridk enableと入力してEnterすると、コンパイラが使えるようになります。 19 | 4. ruby extconf.rbと入力してEnterすると、Makefileが作成されます。 20 | 5. makeと入力してEnterすると、ビルドできます。dxruby.soファイルが作成されたはずです。 21 | 6. とりあえずmake installと入力してEnterするとインストールができますが、gemじゃないのでアンインストールは自分でファイルを削除する必要があります。 22 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /dxruby.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'dxruby' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "dxruby" 8 | spec.version = DXRuby::VERSION 9 | spec.authors = ["mirichi"] 10 | spec.email = ["sawara01@gmail.com"] 11 | spec.description = %q{2D game library for Windows(DirectX9)} 12 | spec.summary = %q{:-)} 13 | spec.homepage = "http://dxruby.osdn.jp/" 14 | spec.license = "zlib/libpng" 15 | 16 | spec.files = `git ls-files lib`.split($/) 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_development_dependency "bundler", "~> 1.3" 22 | spec.add_development_dependency "rake" 23 | end 24 | -------------------------------------------------------------------------------- /ext/dxruby/COPYING: -------------------------------------------------------------------------------- 1 | The zlib/libpng License 2 | Copyright (c) <2012> 3 | 4 | This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. 5 | 6 | Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 7 | 8 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 9 | 10 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 11 | 12 | 3. This notice may not be removed or altered from any source distribution. 13 | 14 | -------------------------------------------------------------------------------- /ext/dxruby/collision.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/collision.c -------------------------------------------------------------------------------- /ext/dxruby/collision.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/collision.h -------------------------------------------------------------------------------- /ext/dxruby/dxruby-i386-mswin32.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | Init_dxruby 3 | DXRuby_lock 4 | DXRuby_unlock 5 | -------------------------------------------------------------------------------- /ext/dxruby/dxruby.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/dxruby.c -------------------------------------------------------------------------------- /ext/dxruby/dxruby.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/dxruby.h -------------------------------------------------------------------------------- /ext/dxruby/extconf.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/extconf.rb -------------------------------------------------------------------------------- /ext/dxruby/font.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/font.c -------------------------------------------------------------------------------- /ext/dxruby/font.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/font.h -------------------------------------------------------------------------------- /ext/dxruby/image.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/image.c -------------------------------------------------------------------------------- /ext/dxruby/image.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/image.h -------------------------------------------------------------------------------- /ext/dxruby/input.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/input.c -------------------------------------------------------------------------------- /ext/dxruby/input.h: -------------------------------------------------------------------------------- 1 | void Init_dxruby_Input( void ); 2 | void inputupdate_internal( void ); 3 | VALUE Input_update( VALUE obj ); 4 | int InitDirectInput( void ); 5 | -------------------------------------------------------------------------------- /ext/dxruby/matrix.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/matrix.c -------------------------------------------------------------------------------- /ext/dxruby/matrix.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/matrix.h -------------------------------------------------------------------------------- /ext/dxruby/messagethread.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/messagethread.c -------------------------------------------------------------------------------- /ext/dxruby/messagethread.h: -------------------------------------------------------------------------------- 1 | void DXRuby_raise( int errorcode, char *msg ); 2 | void InitMessageThread( void ); 3 | void ExitMessageThread( void ); 4 | void WindowCreateMessage( void ); 5 | int ResetMessage( void ); 6 | void ShowCursorMessage( void ); 7 | void HideCursorMessage( void ); 8 | void SetCursorMessage( int cursorname ); 9 | void SetImeEnable( int flag ); 10 | int GetImeEnable( void ); 11 | 12 | enum DXRubyErrorMessage 13 | { 14 | ERR_OUTOFMEMORY = 1, 15 | ERR_INTERNAL, 16 | ERR_NOEXISTSCREENMODE, 17 | ERR_WINDOWCREATE, 18 | ERR_D3DERROR, 19 | ERR_DINPUTERROR, 20 | ERR_MAX 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /ext/dxruby/sound.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/sound.c -------------------------------------------------------------------------------- /ext/dxruby/sound.h: -------------------------------------------------------------------------------- 1 | void Init_dxruby_Sound( void ); 2 | -------------------------------------------------------------------------------- /ext/dxruby/sprite.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/ext/dxruby/sprite.c -------------------------------------------------------------------------------- /ext/dxruby/sprite.h: -------------------------------------------------------------------------------- 1 | struct DXRubySprite { 2 | VALUE vx; 3 | VALUE vy; 4 | VALUE vz; 5 | VALUE vimage; 6 | VALUE vtarget; 7 | VALUE vangle; 8 | VALUE vscale_x; 9 | VALUE vscale_y; 10 | VALUE vcenter_x; 11 | VALUE vcenter_y; 12 | VALUE valpha; 13 | VALUE vblend; 14 | VALUE vvisible; 15 | VALUE vshader; 16 | VALUE vcollision; 17 | VALUE vcollision_enable; 18 | VALUE vcollision_sync; 19 | #ifdef DXRUBY15 20 | VALUE vxy; 21 | VALUE vxyz; 22 | #endif 23 | VALUE voffset_sync; 24 | int vanish; 25 | }; 26 | 27 | void Sprite_release( struct DXRubySprite *sprite ); 28 | void Sprite_internal_draw( VALUE self, VALUE vrt ); 29 | 30 | -------------------------------------------------------------------------------- /ext/dxruby/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | ################################### 3 | # 4 | # DXRuby 1.4.7 5 | # 6 | ################################### 7 | */ 8 | #define DXRUBY_VERSION "1.4.7" 9 | 10 | //#define DXRUBY15 11 | -------------------------------------------------------------------------------- /lib/2.5/dxruby.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/lib/2.5/dxruby.so -------------------------------------------------------------------------------- /lib/2.6/dxruby.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/lib/2.6/dxruby.so -------------------------------------------------------------------------------- /lib/2.6_x64/dxruby.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/lib/2.6_x64/dxruby.so -------------------------------------------------------------------------------- /lib/2.7/dxruby.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/lib/2.7/dxruby.so -------------------------------------------------------------------------------- /lib/2.7_x64/dxruby.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/lib/2.7_x64/dxruby.so -------------------------------------------------------------------------------- /lib/3.0/dxruby.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/lib/3.0/dxruby.so -------------------------------------------------------------------------------- /lib/3.0_x64/dxruby.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/lib/3.0_x64/dxruby.so -------------------------------------------------------------------------------- /lib/dxruby.rb: -------------------------------------------------------------------------------- 1 | major, minor, micro, = RUBY_VERSION.split(/\./) 2 | if /x64/ =~ RUBY_PLATFORM 3 | require "#{major}.#{minor}_x64/dxruby.so" 4 | else 5 | require "#{major}.#{minor}/dxruby.so" 6 | end 7 | -------------------------------------------------------------------------------- /sample/classic_sample/8_puzzle.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/8_puzzle.rb -------------------------------------------------------------------------------- /sample/classic_sample/block_destroy.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/block_destroy.rb -------------------------------------------------------------------------------- /sample/classic_sample/block_fall.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/block_fall.rb -------------------------------------------------------------------------------- /sample/classic_sample/data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/data.png -------------------------------------------------------------------------------- /sample/classic_sample/dot.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/dot.rb -------------------------------------------------------------------------------- /sample/classic_sample/drawtile.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/drawtile.rb -------------------------------------------------------------------------------- /sample/classic_sample/flight.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/flight.rb -------------------------------------------------------------------------------- /sample/classic_sample/hitrangeview.rb: -------------------------------------------------------------------------------- 1 | module HitRange 2 | PointImage = Image.new(1, 1, [200, 255, 255, 0]) 3 | BoxImage = {} 4 | CircleImage = {} 5 | TriangleImage = {} 6 | 7 | def HitRange.view(ary) 8 | ary.each do |d| 9 | range = d.getHitRange 10 | case range.size 11 | when 2 # point 12 | Window.draw(range[0], range[1], PointImage, 10000) 13 | when 3 # circle 14 | x = range[0] 15 | y = range[1] 16 | r = range[2] 17 | if CircleImage.has_key?(r) == false then 18 | image = Image.new(r*2+1, r*2+1).circle(r, r, r, [200, 255, 255, 0]) 19 | CircleImage[r] = image 20 | end 21 | Window.draw(x - r, y - r, CircleImage[r], 10000) 22 | when 4 # box 23 | x1 = range[0] 24 | y1 = range[1] 25 | x2 = range[2] 26 | y2 = range[3] 27 | key = (x2 - x1).to_s + "," + (y2 - y1).to_s 28 | if BoxImage.has_key?(key) == false then 29 | image = Image.new(x2-x1+1, y2-y1+1) 30 | image.line(0, 0, x2-x1, 0, [200, 255, 255, 0]) 31 | image.line(x2-x1, 0, x2-x1, y2-y1, [200, 255, 255, 0]) 32 | image.line(x2-x1, y2-y1, 0, y2-y1, [200, 255, 255, 0]) 33 | image.line(0, y2-y1, 0, 0, [200, 255, 255, 0]) 34 | BoxImage[key] = image 35 | end 36 | Window.draw(x1, y1, BoxImage[key], 10000) 37 | when 6 # triangle 38 | x1 = range[0] 39 | y1 = range[1] 40 | x2 = range[2] 41 | y2 = range[3] 42 | x3 = range[4] 43 | y3 = range[5] 44 | key = (x2 - x1).to_s + "," + (y2 - y1).to_s + "," + (x3 - x1).to_s + "," + (y3 - y1).to_s 45 | temp = (x1 < x2 ? x1 : x2) 46 | minx = (temp < x3 ? temp : x3) 47 | temp = (x1 > x2 ? x1 : x2) 48 | maxx = (temp > x3 ? temp : x3) 49 | temp = (y1 < y2 ? y1 : y2) 50 | miny = (temp < y3 ? temp : y3) 51 | temp = (y1 > y2 ? y1 : y2) 52 | maxy = (temp > y3 ? temp : y3) 53 | 54 | if TriangleImage.has_key?(key) == false then 55 | image = Image.new(maxx-minx+1, maxy-miny+1) 56 | image.line(x1-minx, y1-miny, x2-minx, y2-miny, [200, 255, 255, 0]) 57 | image.line(x2-minx, y2-miny, x3-minx, y3-miny, [200, 255, 255, 0]) 58 | image.line(x3-minx, y3-miny, x1-minx, y1-miny, [200, 255, 255, 0]) 59 | TriangleImage[key] = image 60 | end 61 | Window.draw(minx, miny, TriangleImage[key], 10000) 62 | end 63 | end 64 | end 65 | end 66 | 67 | -------------------------------------------------------------------------------- /sample/classic_sample/mapedit.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/mapedit.rb -------------------------------------------------------------------------------- /sample/classic_sample/meiro.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/meiro.rb -------------------------------------------------------------------------------- /sample/classic_sample/minsample.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/minsample.rb -------------------------------------------------------------------------------- /sample/classic_sample/race.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/race.rb -------------------------------------------------------------------------------- /sample/classic_sample/readme_sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/readme_sample.txt -------------------------------------------------------------------------------- /sample/classic_sample/sample.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/sample.rb -------------------------------------------------------------------------------- /sample/classic_sample/soundeffect.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/classic_sample/soundeffect.rb -------------------------------------------------------------------------------- /sample/new_sample/biyo.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/biyo.rb -------------------------------------------------------------------------------- /sample/new_sample/image/enemy1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/image/enemy1.png -------------------------------------------------------------------------------- /sample/new_sample/image/enemy1bomb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/image/enemy1bomb.png -------------------------------------------------------------------------------- /sample/new_sample/image/enemy2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/image/enemy2.png -------------------------------------------------------------------------------- /sample/new_sample/image/enemy2bomb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/image/enemy2bomb.png -------------------------------------------------------------------------------- /sample/new_sample/image/enemyshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/image/enemyshot1.png -------------------------------------------------------------------------------- /sample/new_sample/image/enemyshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/image/enemyshot2.png -------------------------------------------------------------------------------- /sample/new_sample/image/maptile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/image/maptile.png -------------------------------------------------------------------------------- /sample/new_sample/image/myship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/image/myship.png -------------------------------------------------------------------------------- /sample/new_sample/image/myshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/image/myshot.png -------------------------------------------------------------------------------- /sample/new_sample/iraira.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | def create_block_sprite(*ary) 4 | image = Image.new(640,480) 5 | col = [] 6 | ary.each do |a| 7 | case a.size 8 | when 3 9 | image.circle_fill(a[0], a[1], a[2], C_RED) 10 | when 4 11 | image.box_fill(a[0], a[1], a[2], a[3], C_CYAN) 12 | end 13 | col << a 14 | end 15 | s = Sprite.new(0, 0, image) 16 | s.collision = col 17 | return s 18 | end 19 | 20 | block1 = create_block_sprite([100,100,150,380], [490,100,540,380]) 21 | block2 = create_block_sprite([100,100,150,380], [490,100,540,380]) 22 | block2.angle = 90 23 | block3 = create_block_sprite([100,100,150,380], [490,100,540,380]) 24 | block3.angle = 45 25 | block4 = create_block_sprite([100,100,150,380], [490,100,540,380]) 26 | block4.angle = 135 27 | circle = create_block_sprite([320, 240, 100]) 28 | bar = create_block_sprite([300, 60, 340, 420]) 29 | 30 | objects = [block1, block2, block3, block4, circle, bar] 31 | 32 | cursor = Sprite.new(0, 0, Image.new(10, 10).circle_fill(5, 5, 5, C_WHITE)) 33 | Input.set_mouse_pos(0, 0) 34 | 35 | Window.loop do 36 | cursor.x, cursor.y = Input.mouse_pos_x, Input.mouse_pos_y 37 | block1.angle += 0.05 38 | block2.angle += 0.05 39 | block3.angle -= 0.1 40 | block4.angle -= 0.1 41 | bar.angle += 1 42 | Sprite.draw(objects) 43 | 44 | Input.set_mouse_pos(0, 0) if cursor === objects 45 | 46 | cursor.draw 47 | 48 | break if Input.key_push?(K_ESCAPE) 49 | end 50 | -------------------------------------------------------------------------------- /sample/new_sample/laser2.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/laser2.rb -------------------------------------------------------------------------------- /sample/new_sample/raycast.rb: -------------------------------------------------------------------------------- 1 | #!ruby -Ks 2 | require 'dxruby' 3 | 4 | class Vector 5 | def initialize(*v) 6 | @vec = v 7 | end 8 | 9 | def rotate(angle) 10 | x = @vec[0] * Math.cos(Math::PI / 180 * angle) - @vec[1] * Math.sin(Math::PI / 180 * angle) 11 | y = @vec[0] * Math.sin(Math::PI / 180 * angle) + @vec[1] * Math.cos(Math::PI / 180 * angle) 12 | temp = @vec.dup 13 | temp[0] = x 14 | temp[1] = y 15 | Vector.new(*temp) 16 | end 17 | 18 | def +(v) 19 | case v 20 | when Vector 21 | Vector.new(*@vec.map.with_index{|s,i|s+v[i]}) 22 | when Array 23 | Vector.new(*@vec.map.with_index{|s,i|s+v[i]}) 24 | when Numeric 25 | Vector.new(*@vec.map{|s|s+v}) 26 | else 27 | nil 28 | end 29 | end 30 | 31 | def *(matrix) 32 | result = [] 33 | for i in 0..(matrix.size-1) 34 | data = 0 35 | for j in 0..(@vec.size-1) 36 | data += @vec[j] * matrix[j][i] 37 | end 38 | result.push(data) 39 | end 40 | return Vector.new(*result) 41 | end 42 | 43 | def [](i) 44 | @vec[i] 45 | end 46 | 47 | def size 48 | @vec.size 49 | end 50 | 51 | def to_a 52 | @vec 53 | end 54 | 55 | def x 56 | @vec[0] 57 | end 58 | def y 59 | @vec[1] 60 | end 61 | def z 62 | @vec[2] 63 | end 64 | def w 65 | @vec[3] 66 | end 67 | end 68 | 69 | class Matrix 70 | def initialize(*arr) 71 | @arr = Array.new(4) {|i| Vector.new(*arr[i])} 72 | end 73 | 74 | def *(a) 75 | result = [] 76 | for i in 0..(a.size-1) 77 | result.push(@arr[i] * a) 78 | end 79 | return Matrix.new(*result) 80 | end 81 | 82 | def [](i) 83 | @arr[i] 84 | end 85 | 86 | def size 87 | @arr.size 88 | end 89 | 90 | def self.create_rotation_z(angle) 91 | cos = Math.cos(Math::PI/180 * angle) 92 | sin = Math.sin(Math::PI/180 * angle) 93 | return Matrix.new( 94 | [ cos, sin, 0, 0], 95 | [-sin, cos, 0, 0], 96 | [ 0, 0, 1, 0], 97 | [ 0, 0, 0, 1] 98 | ) 99 | end 100 | 101 | def self.create_rotation_x(angle) 102 | cos = Math.cos(Math::PI/180 * angle) 103 | sin = Math.sin(Math::PI/180 * angle) 104 | return Matrix.new( 105 | [ 1, 0, 0, 0], 106 | [ 0, cos, sin, 0], 107 | [ 0,-sin, cos, 0], 108 | [ 0, 0, 0, 1] 109 | ) 110 | end 111 | 112 | def self.create_rotation_y(angle) 113 | cos = Math.cos(Math::PI/180 * angle) 114 | sin = Math.sin(Math::PI/180 * angle) 115 | return Matrix.new( 116 | [ cos, 0,-sin, 0], 117 | [ 0, 1, 0, 0], 118 | [ sin, 0, cos, 0], 119 | [ 0, 0, 0, 1] 120 | ) 121 | end 122 | 123 | def self.create_transration(x, y, z) 124 | return Matrix.new( 125 | [ 1, 0, 0, 0], 126 | [ 0, 1, 0, 0], 127 | [ 0, 0, 1, 0], 128 | [ x, y, z, 1] 129 | ) 130 | end 131 | 132 | def to_a 133 | @arr.map {|v|v.to_a}.flatten 134 | end 135 | end 136 | 137 | 138 | line1 = [568, 438, 568, 438, 607, 261, 607, 261, 520, 200, 520, 200, 531, 151, 139 | 531, 151, 602, 115, 602, 115, 562, 19, 562, 19, 113, 21, 113, 21, 34, 83, 140 | 34, 83, 81, 180, 81, 180, 221, 207, 221, 207, 251, 274, 251, 274, 204, 299, 141 | 204, 299, 61, 262, 61, 262, 26, 358, 26, 358, 53, 430] 142 | line2 = [88, 380, 88, 380, 479, 392, 479, 392, 536, 302, 536, 302, 534, 267, 143 | 534, 267, 461, 210, 461, 210, 459, 151, 459, 151, 518, 91, 518, 91, 487, 53, 144 | 487, 53, 156, 77, 156, 77, 125, 110, 125, 110, 292, 197, 292, 197, 311, 268, 145 | 311, 268, 227, 342, 227, 342, 93, 330] 146 | 147 | $walls = [] 148 | 149 | class Wall < Sprite 150 | attr_reader :height 151 | def initialize(x1, y1, x2, y2, height) 152 | super(0,0) 153 | self.collision = [x1, y1, x2, y2, x2, y2] 154 | @height = height 155 | end 156 | end 157 | 158 | 159 | tx = 53 160 | ty = 430 161 | line1.each_slice(2) do |x, y| 162 | $walls << Wall.new(tx, ty, x, y, 1) 163 | tx = x 164 | ty = y 165 | end 166 | tx = 93 167 | ty = 330 168 | line2.each_slice(2) do |x, y| 169 | $walls << Wall.new(tx, ty, x, y, 1) 170 | tx = x 171 | ty = y 172 | end 173 | 174 | 175 | $ray = [] 176 | (0..639).each do |x| 177 | s = Sprite.new(0,0) 178 | temp = Vector.new(400,0).rotate((x / 639.0 * 2 - 1) * 30) 179 | s.collision = [0, 0, temp.x, temp.y, temp.x, temp.y] 180 | s.center_x = s.center_y = 0 181 | $ray << s 182 | end 183 | 184 | 185 | x = 300 186 | y = 400 187 | angle = 0 188 | 189 | image = Image.new(1,1,C_RED) 190 | 191 | Window.loop do 192 | 193 | angle += Input.x*5 194 | if Input.key_down?(K_UP) 195 | x += Math.cos(Math::PI / 180 * angle) * 3 196 | y += Math.sin(Math::PI / 180 * angle) * 3 197 | end 198 | if Input.key_down?(K_DOWN) 199 | x -= Math.cos(Math::PI / 180 * angle) * 3 200 | y -= Math.sin(Math::PI / 180 * angle) * 3 201 | end 202 | 203 | $ray.each_with_index do |r, i| 204 | r.x = x 205 | r.y = y 206 | r.angle = angle 207 | ary = r.check($walls) 208 | z = 250000 209 | ax, ay = Vector.new(r.collision[0], r.collision[1]).rotate(angle).to_a 210 | ax += r.x + 0.5 211 | ay += r.y + 0.5 212 | bx, by = Vector.new(r.collision[2], r.collision[3]).rotate(angle).to_a 213 | bx += r.x + 0.5 214 | by += r.y + 0.5 215 | px = 0 216 | py = 0 217 | height = 0 218 | if ary.size > 0 then 219 | ary.each do |w| 220 | cx = w.collision[0] + w.x + 0.5 221 | cy = w.collision[1] + w.y + 0.5 222 | dx = w.collision[2] + w.x + 0.5 223 | dy = w.collision[3] + w.y + 0.5 224 | tempx = dx-cx 225 | tempy = dy-cy 226 | 227 | dR = (tempy * (cx - ax) - tempx * (cy - ay) ) / ((bx - ax) * tempy - (by - ay) * tempx) 228 | 229 | ix = ax + dR * (bx - ax) 230 | iy = ay + dR * (by - ay) 231 | 232 | length = (ix - r.x)**2 + (iy - r.y)**2 233 | 234 | if length < z 235 | z = length 236 | px = ix 237 | py = iy 238 | height = w.height 239 | end 240 | end 241 | z = Math::sqrt(z) 242 | c = 255 - z / 400 * 255 243 | Window.draw_line(i, 240 + 400.0 / z * 10, i, 240 - 400.0 / z * 10 * height, [c, c, c]) 244 | Window.draw(px, py, image) 245 | end 246 | end 247 | break if Input.key_push?(K_ESCAPE) 248 | end 249 | 250 | -------------------------------------------------------------------------------- /sample/new_sample/readme_sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/readme_sample.txt -------------------------------------------------------------------------------- /sample/new_sample/rubima.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/rubima.rb -------------------------------------------------------------------------------- /sample/new_sample/ruby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/ruby.png -------------------------------------------------------------------------------- /sample/new_sample/slg.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | map_image = [ 4 | Image.new(32,32,[128,128,128]), 5 | Image.new(32,32,[100,230,100]), 6 | Image.new(32,32,[0,200,0]), 7 | Image.new(32,32,[255,220,100]), 8 | Image.new(32,32,[255,100,0]), 9 | Image.new(32,32,[0,0,255]) 10 | ] 11 | 12 | $map = [ 13 | [1,3,3,3,1,0,1,2,2,2,2,4,4,4,4,4], 14 | [3,3,3,3,2,0,1,1,2,2,2,4,4,4,4,4], 15 | [1,3,3,3,1,0,2,1,1,2,2,2,2,2,2,1], 16 | [5,1,3,3,1,0,1,1,1,1,1,1,2,2,2,2], 17 | [5,1,3,3,1,0,1,2,1,1,1,2,1,1,1,1], 18 | [5,1,2,3,1,0,0,1,1,2,1,1,1,1,2,1], 19 | [5,5,1,1,1,1,0,0,0,0,0,1,1,2,1,1], 20 | [5,5,5,5,5,1,1,1,1,1,0,0,0,0,1,1], 21 | [5,5,5,5,5,5,5,5,5,1,1,1,1,0,0,2], 22 | [5,5,5,5,1,1,1,1,5,5,5,5,1,1,0,1], 23 | [5,5,5,1,1,1,2,1,1,1,1,5,5,5,0,5], 24 | [5,5,5,1,2,4,4,4,4,4,1,1,2,1,0,1], 25 | ] 26 | 27 | x = 5 28 | y = 5 29 | s = Sprite.new(x*32, y*32, Image.new(32,32).circle_fill(16,16,16,C_WHITE)) 30 | speed = 9 31 | 32 | $d = [[0,0],[0,0],[0,1],[0,0],[-1,0],[0,0],[1,0],[0,0],[0,-1],[0,0]] 33 | 34 | def find(x, y, speed, temp) 35 | [2,4,6,8].each do |i| 36 | tx = x + $d[i][0] 37 | ty = y + $d[i][1] 38 | next if tx < 0 or tx > 15 or ty < 0 or ty > 11 39 | 40 | if speed - $map[ty][tx] - 1 >= 0 41 | if temp[ty][tx] == nil or temp[ty][tx] < speed - $map[ty][tx] - 1 42 | temp[ty][tx] = speed - $map[ty][tx] - 1 43 | find(tx, ty, speed - $map[ty][tx] - 1, temp) 44 | end 45 | end 46 | end 47 | end 48 | 49 | range = Image.new(32,32,[150,255,180,180]) 50 | cursor = Image.new(32,32).box(0,0,31,31,C_WHITE) 51 | 52 | temp = Array.new(12) { Array.new(15) } 53 | find(x, y, speed, temp) 54 | 55 | Window.loop do 56 | 57 | if Input.mouse_push?(M_LBUTTON) 58 | if temp[Input.mouse_pos_y / 32][Input.mouse_pos_x / 32] 59 | x = Input.mouse_pos_x / 32 60 | y = Input.mouse_pos_y / 32 61 | temp = Array.new(12) { Array.new(15) } 62 | find(x, y, speed, temp) 63 | s.x = x * 32 64 | s.y = y * 32 65 | end 66 | end 67 | 68 | Window.draw_tile(0,0,$map,map_image,0,0,16,12) 69 | 70 | (0..11).each do |iy| 71 | (0..15).each do |ix| 72 | if temp[iy][ix] 73 | Window.draw(ix*32, iy*32, range) 74 | end 75 | end 76 | end 77 | 78 | s.draw 79 | Window.draw((Input.mouse_pos_x / 32) * 32, (Input.mouse_pos_y / 32) * 32, cursor) 80 | 81 | break if Input.key_push?(K_ESCAPE) 82 | end 83 | -------------------------------------------------------------------------------- /sample/new_sample/sprite_animation.rb: -------------------------------------------------------------------------------- 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 | 134 | -------------------------------------------------------------------------------- /sample/new_sample/sprite_collision1.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/sprite_collision1.rb -------------------------------------------------------------------------------- /sample/new_sample/sprite_collision2.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/sprite_collision2.rb -------------------------------------------------------------------------------- /sample/new_sample/sprite_simple.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample/sprite_simple.rb -------------------------------------------------------------------------------- /sample/new_sample2/autocall.rb: -------------------------------------------------------------------------------- 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 | 25 | -------------------------------------------------------------------------------- /sample/new_sample2/effecttest.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample2/effecttest.rb -------------------------------------------------------------------------------- /sample/new_sample2/fibersprite.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | module FiberSprite 4 | def initialize(x=0,y=0,image=nil) 5 | super 6 | @fiber = Fiber.new do 7 | self.fiber_proc 8 | end 9 | end 10 | 11 | def update 12 | @fiber.resume 13 | super 14 | end 15 | 16 | def wait(t=1) 17 | t.times {Fiber.yield} 18 | end 19 | 20 | def add_x(x, t=1) 21 | t.times {self.x += x;Fiber.yield} 22 | end 23 | 24 | def add_y(y, t=1) 25 | t.times {self.y += y;Fiber.yield} 26 | end 27 | end 28 | 29 | class Enemy < Sprite 30 | include FiberSprite 31 | 32 | @@image = Image.load_tiles("new_sample/image/enemy2.png", 4, 1) 33 | 34 | def self.objects=(ary) 35 | @@objects = ary 36 | end 37 | 38 | def initialize(x=0, y=0) 39 | super(x, y, @@image[0]) 40 | @angle = 90 41 | end 42 | 43 | def fire(angle) 44 | @@objects << Shot.new(self.x+20, self.y+@@image[0].height/2+20, angle) 45 | @@objects << Shot.new(self.x+108, self.y+@@image[0].height/2+20, angle) 46 | end 47 | 48 | def fiber_proc 49 | loop do 50 | fire(@angle) 51 | @angle += 15 52 | wait 5 53 | end 54 | end 55 | end 56 | 57 | class Shot < Sprite 58 | @@image = Image.load("new_sample/image/enemyshot2.png") 59 | 60 | def self.objects=(ary) 61 | @@objects = ary 62 | end 63 | 64 | def initialize(x=0, y=0, angle=0) 65 | super(x-@@image.width/2, y-@@image.height/2, @@image) 66 | @dx = Math.cos(angle / 180.0 * Math::PI) * 3.5 67 | @dy = Math.sin(angle / 180.0 * Math::PI) * 3.5 68 | end 69 | 70 | def update 71 | self.x += @dx 72 | self.y += @dy 73 | if self.x < -@@image.width or self.x > 640 or self.y < -@@image.height or self.y > 480 74 | vanish 75 | end 76 | end 77 | end 78 | 79 | objs = [] 80 | Enemy.objects = objs 81 | Shot.objects = objs 82 | 83 | objs << Enemy.new(260,160) 84 | 85 | Window.loop do 86 | Sprite.update(objs) 87 | Sprite.draw(objs) 88 | Sprite.clean(objs) 89 | end 90 | -------------------------------------------------------------------------------- /sample/new_sample2/hitrange.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | module HitRange 4 | def draw 5 | super 6 | if self.visible and self.collision_enable and !self.vanished? 7 | if @hitrange_image == nil or @hitrange_collision != self.collision or 8 | @hitrange_image_width != self.image.width or 9 | @hitrange_image_height != self.image.height 10 | 11 | @hitrange_image_width = self.image.width 12 | @hitrange_image_height = self.image.height 13 | 14 | @hitrange_image.dispose if @hitrange_image != nil 15 | 16 | color = [255, 255, 255, 0] 17 | color_fill = [100, 255, 255, 0] 18 | 19 | if self.collision == nil 20 | @hitrange_collision = nil 21 | @hitrange_image = Image.new(self.image.width, self.image.height) 22 | @hitrange_image.box_fill(0, 0, @hitrange_image.width-1, @hitrange_image.height-1, color_fill) 23 | @hitrange_image.box(0, 0, @hitrange_image.width-1, @hitrange_image.height-1, color) 24 | @hitrange_x = @hitrange_y = 0 25 | else 26 | @hitrange_collision = [] 27 | self.collision.each do |v| 28 | if v === Array 29 | @hitrange_collision << v.dup 30 | else 31 | @hitrange_collision << v 32 | end 33 | end 34 | temp = self.collision 35 | temp = [temp] if temp[0].class != Array 36 | 37 | x1 = y1 = 0 38 | x2 = y2 = 0 39 | temp.each do |col| 40 | case col.size 41 | when 2 # point 42 | x1 = [x1, col[0]].min 43 | y1 = [y1, col[1]].min 44 | x2 = [x2, col[0]].max 45 | y2 = [y2, col[1]].max 46 | when 3 # circle 47 | x1 = [x1, col[0] - col[2]].min 48 | y1 = [y1, col[1] - col[2]].min 49 | x2 = [x2, col[0] + col[2]].max 50 | y2 = [y2, col[1] + col[2]].max 51 | when 4 # box 52 | x1 = [x1, col[0], col[2]].min 53 | y1 = [y1, col[1], col[3]].min 54 | x2 = [x2, col[0], col[2]].max 55 | y2 = [y2, col[1], col[3]].max 56 | when 6 # triangle 57 | x1 = [x1, col[0], col[2], col[4]].min 58 | y1 = [y1, col[1], col[3], col[5]].min 59 | x2 = [x2, col[0], col[2], col[4]].max 60 | y2 = [y2, col[1], col[3], col[5]].max 61 | end 62 | end 63 | 64 | @hitrange_image = Image.new(x2 - x1 + 1, y2 - y1 + 1) 65 | @hitrange_x = x = x1 66 | @hitrange_y = y = y1 67 | 68 | temp.each do |col| 69 | case col.size 70 | when 2 # point 71 | @hitrange_image[col[0] - x, col[1] - y] = color 72 | when 3 # circle 73 | @hitrange_image.circle_fill(col[0] - x, col[1] - y, col[2], color_fill) 74 | @hitrange_image.circle(col[0] - x, col[1] - y, col[2], color) 75 | when 4 # box 76 | @hitrange_image.box_fill(col[0] - x, col[1] - y, col[2] - x, col[3] - y, color_fill) 77 | @hitrange_image.box(col[0] - x, col[1] - y, col[2] - x, col[3] - y, color) 78 | when 6 # triangle 79 | @hitrange_image.triangle_fill(col[0] - x, col[1] - y, col[2] - x, col[3] - y, col[4] - x, col[5] - y, color_fill) 80 | @hitrange_image.triangle(col[0] - x, col[1] - y, col[2] - x, col[3] - y, col[4] - x, col[5] - y, color) 81 | end 82 | end 83 | 84 | end 85 | end 86 | 87 | hash = {} 88 | if self.collision_sync 89 | hash[:scale_x] = self.scale_x 90 | hash[:scale_y] = self.scale_y 91 | hash[:center_x] = self.center_x - @hitrange_x 92 | hash[:center_y] = self.center_y - @hitrange_y 93 | hash[:angle] = self.angle 94 | end 95 | hash[:z] = self.z + 1 96 | 97 | ox = oy = 0 98 | if self.offset_sync 99 | ox = self.center_x 100 | oy = self.center_y 101 | end 102 | 103 | target = self.target ? self.target : Window 104 | 105 | target.draw_ex(self.x - ox + @hitrange_x, self.y - oy + @hitrange_y, @hitrange_image, hash) 106 | end 107 | end 108 | end 109 | 110 | 111 | 112 | if __FILE__ == $0 113 | class TestSprite < Sprite 114 | include HitRange 115 | end 116 | 117 | s = TestSprite.new(100,100) 118 | s.image = Image.new(100,100,C_BLUE) 119 | s.offset_sync=true 120 | s.center_x = 0 121 | s.center_y = 0 122 | 123 | y = 90 124 | Window.loop do 125 | y += Input.y 126 | s.collision = [10,10,90,0,50,y] 127 | s.angle += 1 128 | s.draw 129 | end 130 | end 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /sample/new_sample2/hlstest.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | image = Image.load("./shader_sample/bgimage/BG10a_80.jpg") 4 | Window.width, Window.height = 800, 600 5 | Window.mag_filter = TEXF_POINT 6 | 7 | hue = 0 8 | luminance = 0 9 | saturation = 0 10 | 11 | Window.loop do 12 | hue += Input.y*5 13 | saturation += Input.x 14 | if Input.key_down?(K_Z) 15 | luminance -= 1 16 | end 17 | if Input.key_down?(K_X) 18 | luminance += 1 19 | end 20 | 21 | img = image.change_hls(hue, luminance, saturation) 22 | img.delayed_dispose 23 | Window.draw(0,0,img) 24 | end 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sample/new_sample2/mapedit_perlin.rb: -------------------------------------------------------------------------------- 1 | #!ruby -Ks 2 | # DXRuby 簡易マップエディタ 3 | require 'dxruby' 4 | 5 | # マップデータ 6 | map=[ 7 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 8 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 9 | [1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 10 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 11 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1], 12 | [0, 0, 0, 0, 1, 4, 4, 4, 4, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 1, 1, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1], 13 | [2, 2, 2, 2, 1, 1, 4, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 3, 1, 1, 1, 1], 14 | [2, 2, 2, 1, 2, 1, 1, 4, 4, 4, 4, 0, 0, 0, 0, 4, 4, 4, 1, 1, 1, 1, 3, 3, 3, 3, 1, 3, 1, 3, 1, 1], 15 | [2, 2, 2, 1, 1, 1, 1, 1, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 3, 1, 3, 3, 3, 3, 3, 3, 1, 1], 16 | [2, 2, 2, 2, 2, 2, 1, 1, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 1, 1], 17 | [1, 2, 2, 2, 2, 2, 2, 1, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 1], 18 | [1, 1, 1, 2, 2, 1, 2, 1, 4, 4, 4, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3], 19 | [1, 1, 2, 1, 2, 2, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 4, 4, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3], 20 | [1, 1, 1, 2, 2, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3], 21 | [1, 1, 1, 2, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3], 22 | [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3], 23 | [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1], 24 | [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 4, 4, 1, 4, 1, 4, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 25 | [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 26 | [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 4, 4, 4, 4, 4, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 27 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 4, 4, 4, 4, 4, 4, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1], 28 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 4, 4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 29 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 1, 4, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1], 30 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1], 31 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 0], 32 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 0, 0], 33 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 0, 0, 0], 34 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0], 35 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 4, 4, 4, 0, 0, 0, 0, 0, 0], 36 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 37 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 38 | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1] 39 | ] 40 | takasa=[ 41 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], 42 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], 43 | [3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], 44 | [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], 45 | [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3], 46 | [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 3, 3, 3, 3, 3], 47 | [4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 6, 6, 6, 3, 3, 3, 3], 48 | [4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 7, 7, 8, 7, 3, 3, 3], 49 | [4, 3, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 5, 6, 7, 8, 8, 6, 3, 3], 50 | [3, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 5, 6, 6, 8, 9, 6, 5, 3], 51 | [4, 5, 3, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 5, 6, 6, 8, 7, 6, 6, 3], 52 | [3, 3, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, 6, 6, 5], 53 | [3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 5, 5, 5, 6, 6, 6, 5], 54 | [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5], 55 | [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5], 56 | [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5], 57 | [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4], 58 | [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 4], 59 | [3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 4], 60 | [3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3], 61 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3], 62 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3], 63 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3], 64 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3], 65 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2], 66 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2], 67 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 2], 68 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2], 69 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 70 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 71 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 72 | [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3] 73 | ] 74 | Image.perlin_seed(1.hash) 75 | 76 | 32.times do |y| 77 | 32.times do |x| 78 | c = Image.octave_perlin_noise(x / 32.0, y / 32.0, 20.5, 8, 0.8) 79 | t = ((c-0.5) * 60 + 6).to_i 80 | takasa[y][x] = t 81 | map[y][x] = t < 4 ? 4 : (t > 7 ? 3 : (t == 4 ? 4 : 1)) 82 | map[y][x] = t == 7 ? 2 : map[y][x] 83 | end 84 | end 85 | 86 | # 絵のデータを作る 87 | mapimage = Array.new(5) {Image.new(32, 32)} 88 | for i in 0..7 do # ひし形に地面を描く 89 | mapimage[0].line(15 - i * 2, i + 16, 16 + i * 2, i + 16, [100, 100, 200]) # 水 90 | mapimage[0].line(15 - i * 2, 31 - i, 16 + i * 2, 31 - i, [100, 100, 200]) 91 | mapimage[0][15 - i * 2, i + 16] = [0, 0, 0] 92 | mapimage[0][16 + i * 2, i + 16] = [0, 0, 0] 93 | for j in 1..3 do 94 | mapimage[j].line(15 - i * 2, i + 16, 16 + i * 2, i + 16, [50, 200, 50]) # 平地 95 | mapimage[j].line(15 - i * 2, 31 - i, 16 + i * 2, 31 - i, [50, 200, 50]) 96 | mapimage[j][15 - i * 2, i + 16] = [0, 0, 0] 97 | mapimage[j][16 + i * 2, i + 16] = [0, 0, 0] 98 | end 99 | mapimage[4].line(15 - i * 2, i + 16, 16 + i * 2, i + 16, [200, 200, 150]) # 砂地 100 | mapimage[4].line(15 - i * 2, 31 - i, 16 + i * 2, 31 - i, [200, 200, 150]) 101 | mapimage[4][15 - i * 2, i + 16] = [0, 0, 0] 102 | mapimage[4][16 + i * 2, i + 16] = [0, 0, 0] 103 | end 104 | mapimage[2].boxFill(13, 16, 18, 26, [200, 50, 50]) # 木 105 | mapimage[2].line(13, 16, 13, 26, [0, 0, 0]) 106 | mapimage[2].line(18, 16, 18, 26, [0, 0, 0]) 107 | mapimage[2].circleFill(16, 8, 8, [0, 255, 0]) 108 | mapimage[2].circle(16, 8, 8, [0, 0, 0]) 109 | for i in 1..24 do # 山 110 | mapimage[3].line(15 - i*2/4, i, 16 + i*2/4, i, [200, 100, 100]) 111 | mapimage[3][15 - i*2/4, i] = [0, 0, 0] 112 | mapimage[3][16 + i*2/4, i] = [0, 0, 0] 113 | end 114 | # 地面のサイド画像を作る 115 | sideimage = Array.new(5) {Image.new(32, 16)} 116 | for i in 0..15 do 117 | sideimage[0].line(i, i / 2, i, i / 2 + 8, [60, 60, 180]) # 水 118 | sideimage[0].line(31 - i, i / 2, 31 - i, i / 2 + 8, [130, 130, 200]) 119 | for j in 1..3 do 120 | sideimage[j].line(i, i / 2, i, i / 2 + 8, [40, 150, 40]) # 水以外 121 | sideimage[j].line(31 - i, i / 2, 31 - i, i / 2 + 8, [100, 220, 100]) 122 | end 123 | sideimage[4].line(i, i / 2, i, i / 2 + 8, [150, 150, 120]) # 砂地 124 | sideimage[4].line(31 - i, i / 2, 31 - i, i / 2 + 8, [220, 220, 170]) 125 | end 126 | wakuimage = Image.new(36, 36, [255, 255, 255]). # 選択枠 127 | boxFill(2, 2, 33, 33, [0, 0, 0]) 128 | blackimage = Image.new(128, 480, [0, 0, 0]) # 右側背景 129 | 130 | select = 0 131 | 132 | # クリック位置判定関数 133 | def check(x, y, map, takasa) 134 | # 手前から検索するために逆順 135 | 31.downto(0) do |i| 136 | 31.downto(0) do |j| 137 | # ひし形の中にあるかを調べる 138 | if ((j * 16 - i * 16 + 176 - x)/2).abs + (j * 8 + i * 8 - takasa[i][j]*8 + 24 - y).abs < 9 then 139 | return [i, j] 140 | end 141 | end 142 | end 143 | return nil 144 | end 145 | 146 | # メインループ 147 | Window.loop do 148 | 149 | # マウスクリック 150 | if Input.mouseDown?(M_LBUTTON) or Input.mouseDown?(M_RBUTTON) then 151 | x, y = Input.mousePosX, Input.mousePosY 152 | if x >= 512 then # 右のほうなら 153 | for i in 0..mapimage.size-1 154 | if x >= 560 and x < 592 and y >= i * 64 + 64 and y < i * 64 + 96 then 155 | select = i 156 | break 157 | end 158 | end 159 | else # 左のほうなら 160 | if x > 0 and y > 0 and y < 480 then 161 | if Input.keyDown?(K_LSHIFT) then 162 | if Input.mousePush?(M_LBUTTON) then # シフト左クリックで地面を上げる 163 | temp = check(x, y, map, takasa) 164 | if temp != nil then 165 | takasa[temp[0]][temp[1]] += 1 if takasa[temp[0]][temp[1]] < 10 166 | end 167 | end 168 | if Input.mousePush?(M_RBUTTON) then # シフト右クリックで地面を下げる 169 | temp = check(x, y, map, takasa) 170 | if temp != nil then 171 | takasa[temp[0]][temp[1]] -= 1 if takasa[temp[0]][temp[1]] > 0 172 | end 173 | end 174 | else 175 | if Input.mouseDown?(M_LBUTTON) then # 左クリックはマップチップセット 176 | temp = check(x, y, map, takasa) 177 | if temp != nil then 178 | map[temp[0]][temp[1]] = select 179 | end 180 | end 181 | if Input.mouseDown?(M_RBUTTON) then # 右クリックでスポイト機能 182 | temp = check(x, y, map, takasa) 183 | if temp != nil then 184 | select = map[temp[0]][temp[1]] 185 | end 186 | end 187 | end 188 | end 189 | end 190 | end 191 | 192 | # カーソルキーの左右 193 | if Input.keyPush?(K_RIGHT) then # 右回転 194 | map = map.transpose 195 | takasa = takasa.transpose 196 | map.each do |d| 197 | d.reverse! 198 | end 199 | takasa.each do |d| 200 | d.reverse! 201 | end 202 | end 203 | if Input.keyPush?(K_LEFT) then # 左回転 204 | 3.times do 205 | map = map.transpose 206 | takasa = takasa.transpose 207 | map.each do |d| 208 | d.reverse! 209 | end 210 | takasa.each do |d| 211 | d.reverse! 212 | end 213 | end 214 | end 215 | 216 | # マップ全体描画 217 | for i in 0..30 do 218 | for j in 0..30 do 219 | z = 0 220 | tmp = takasa[i][j] 221 | if takasa[i][j+1] < tmp or takasa[i+1][j] < tmp then 222 | tmp2 = takasa[i][j+1] > takasa[i+1][j] ? takasa[i+1][j] : takasa[i][j+1] 223 | z = tmp2 * 8 224 | (tmp - tmp2).times do # 高さ分、サイド画像を描画するループ 225 | Window.draw(j * 16 - i * 16 + 160, j * 8 + i * 8 - z + 16, sideimage[map[i][j]]) 226 | z = z + 8 227 | end 228 | else 229 | z = takasa[i][j] * 8 230 | end 231 | Window.draw(j * 16 - i * 16 + 160, j * 8 + i * 8 - z, mapimage[map[i][j]]) 232 | if takasa[i][j] < 4 233 | Window.draw_alpha(j * 16 - i * 16 + 160, j * 8 + i * 8 - 32, mapimage[0], 192) 234 | end 235 | end 236 | end 237 | for i in 0..31 do 238 | z = 0 239 | takasa[i][31].times do # 高さ分、サイド画像を描画するループ 240 | Window.draw(31 * 16 - i * 16 + 160, 31 * 8 + i * 8 - z + 16, sideimage[map[i][31]]) 241 | z = z + 8 242 | end 243 | Window.draw(31 * 16 - i * 16 + 160, 31 * 8 + i * 8 - z, mapimage[map[i][31]]) 244 | if takasa[i][31] < 4 245 | Window.draw_alpha(31 * 16 - i * 16 + 160, 31 * 8 + i * 8 - 32, mapimage[0], 192) 246 | end 247 | end 248 | for j in 0..31 do 249 | z = 0 250 | takasa[31][j].times do # 高さ分、サイド画像を描画するループ 251 | Window.draw(j * 16 - 31 * 16 + 160, j * 8 + 31 * 8 - z + 16, sideimage[map[31][j]]) 252 | z = z + 8 253 | end 254 | Window.draw(j * 16 - 31 * 16 + 160, j * 8 + 31 * 8 - z, mapimage[map[31][j]]) 255 | if takasa[31][j] < 4 256 | Window.draw_alpha(j * 16 - 31 * 16 + 160, j * 8 + 31 * 8 - 32, mapimage[0], 192) 257 | end 258 | end 259 | 260 | # 右側背景描画 261 | Window.draw(512, 0, blackimage) 262 | 263 | # 選択枠描画 264 | Window.draw(558, select * 64 + 62, wakuimage) 265 | 266 | # マップチップ描画 267 | mapimage.each_with_index do |m, i| 268 | Window.draw(560, i * 64 + 64, m) 269 | end 270 | 271 | # 画面データクリア 272 | if Input.keyPush?(K_C) then 273 | map = Array.new(32) { [1] * 32 } 274 | takasa = Array.new(32) { [3] * 32 } 275 | end 276 | 277 | # マップデータ出力 278 | if Input.keyPush?(K_ESCAPE) then 279 | s1 = "map=[\n" 280 | s2 = "takasa=[\n" 281 | for i in 0..30 do 282 | s1 = s1 + map[i].inspect + ",\n" 283 | s2 = s2 + takasa[i].inspect + ",\n" 284 | end 285 | s1 = s1 + map[31].inspect + "\n]\n" 286 | s2 = s2 + takasa[31].inspect + "\n]\n" 287 | print s1 288 | print s2 289 | break 290 | end 291 | end 292 | -------------------------------------------------------------------------------- /sample/new_sample2/noise.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | Window.width = 300 4 | Window.height = 300 5 | 6 | bg = Image.new(300,300,C_BLUE) 7 | image = Image.new(300,900) 8 | repeat_x = 3 9 | repeat_y = 9 10 | octave = 5 11 | subsistence = 0.4 12 | w = 1/image.width.to_f*repeat_x 13 | h = 1/image.height.to_f*repeat_y 14 | 15 | Image.perlin_seed(1.hash) 16 | 17 | image.height.times do |y| 18 | image.width.times do |x| 19 | c = (Image.octave_perlin_noise(x*w, 20 | y*h, 21 | 1, octave, subsistence, repeat_x, repeat_y) * 255 - 70) * 2.2 22 | image[x, y] = [c>255?255:c, 255, 255, 255] if c>0 23 | end 24 | end 25 | y = 0 26 | Window.loop do 27 | Window.draw(0,0,bg) 28 | Window.draw_tile(0,0,[[0]], [image], nil, y, nil, nil) 29 | y-=5 30 | break if Input.key_push?(K_ESCAPE) 31 | end 32 | 33 | 34 | -------------------------------------------------------------------------------- /sample/new_sample2/particle.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | class Sprite 4 | def on_screen?(range = nil) 5 | if range == nil 6 | if self.target == nil 7 | screen = [0, 0, Window.width, Window.height] 8 | else 9 | screen = [0, 0, self.target.width, self.target.height] 10 | end 11 | else 12 | screen = range 13 | end 14 | 15 | xary = [0, self.image.width, 0, self.image.width] 16 | yary = [0, 0, self.image.height, self.image.height] 17 | 18 | if self.angle != 0 or self.scale_x != 1.0 or self.scale_y != 1.0 19 | cos = Math.cos(self.angle / 180.0 * Math::PI) 20 | sin = Math.sin(self.angle / 180.0 * Math::PI) 21 | 4.times do |i| 22 | tempx = ((xary[i] - self.center_x) * cos - (yary[i] - self.center_x) * sin) * scale_x + self.center_x 23 | tempy = ((xary[i] - self.center_x) * sin + (yary[i] - self.center_x) * cos) * scale_y + self.center_x 24 | xary[i] = tempx 25 | yary[i] = tempy 26 | end 27 | end 28 | return !(screen[0] >= xary.max+self.x or screen[1] >= yary.max+self.y or screen[2] <= xary.min+self.x or screen[3] <= yary.min+self.y) 29 | end 30 | end 31 | 32 | class StandardParticle < Sprite 33 | attr_accessor :dx, :dy, :lifetime, :parent 34 | 35 | def initialize 36 | @dx = 0 37 | @dy = 0 38 | @lifetime = nil 39 | end 40 | 41 | def update 42 | if @lifetime 43 | @lifetime -= 1 44 | if @lifetime == 0 45 | self.vanish 46 | return 47 | end 48 | end 49 | 50 | if self.alpha > 0 51 | self.alpha += @parent.d_alpha 52 | self.alpha = 0 if self.alpha < 0 53 | end 54 | 55 | self.x += @dx 56 | self.y += @dy 57 | 58 | self.vanish unless self.on_screen? 59 | 60 | @dy += @parent.gravity 61 | end 62 | end 63 | 64 | class ParticleFactory 65 | attr_accessor :particles 66 | 67 | @@all_objects = [] 68 | 69 | def self.step 70 | obj = @@all_objects.map{|o|o.particles} 71 | Sprite.update obj 72 | Sprite.draw obj 73 | Sprite.clean obj 74 | @@all_objects.delete_if {|v| v.particles.empty?} 75 | end 76 | 77 | def self.count 78 | c = 0 79 | @@all_objects.each do |o| 80 | c += o.particles.size 81 | end 82 | c 83 | end 84 | 85 | def initialize(particle_class) 86 | @particle_class = particle_class 87 | @particles = [] 88 | end 89 | 90 | def generate(count) 91 | flag = @particles.empty? 92 | count.times do |i| 93 | temp = @particle_class.new 94 | yield temp, i 95 | @particles << temp 96 | end 97 | @@all_objects.push(self) if flag 98 | end 99 | end 100 | 101 | class SampleEmitter 102 | attr_accessor :gravity, :d_alpha, :image, :lifetime 103 | 104 | class EmitterGenerator 105 | attr_accessor :b, :interval, :count 106 | def initialize(b, interval) 107 | @b = b 108 | @interval = interval 109 | @count = 0 110 | end 111 | end 112 | 113 | def initialize(particle_class) 114 | @factory = ParticleFactory.new(particle_class) 115 | @screen = Sprite.new 116 | @screen.collision = [0, 0, 639, 479] 117 | @generator = [] 118 | @d_alpha = 0 119 | end 120 | 121 | def generate(count) 122 | @factory.generate(count) do |p, i| 123 | p.parent = self 124 | p.lifetime = @lifetime 125 | yield p, i 126 | end 127 | end 128 | 129 | def generate_line(count, x1, y1, x2, y2) 130 | diff_x = x2 - x1 + 1 131 | diff_y = y2 - y1 + 1 132 | @factory.generate(count) do |p, i| 133 | r = rand() 134 | p.x = x1 + r * diff_x 135 | p.y = y1 + r * diff_y 136 | p.parent = self 137 | p.lifetime = @lifetime 138 | p.image = @image 139 | yield p, i if block_given? 140 | end 141 | end 142 | 143 | def generate_circle(count, x, y, r, angle_min, angle_max) 144 | @factory.generate(count) do |p, i| 145 | angle = angle_min + rand() * (angle_max - angle_min) 146 | p.x = x + Math.cos(angle / 180.0 * Math::PI) * r 147 | p.y = y + Math.sin(angle / 180.0 * Math::PI) * r 148 | p.parent = self 149 | p.lifetime = @lifetime 150 | p.image = @image 151 | yield p, i, angle if block_given? 152 | end 153 | end 154 | 155 | def add_generator(interval, &b) 156 | @generator << EmitterGenerator.new(b, interval) 157 | end 158 | 159 | def update 160 | @generator.each do |g| 161 | g.count += 1 162 | if g.count >= g.interval 163 | g.count = 0 164 | g.b.call 165 | end 166 | end 167 | end 168 | end 169 | 170 | 171 | class TestParticle < StandardParticle 172 | 173 | def initialize 174 | super 175 | end 176 | 177 | def hit(o) 178 | @dy = -@dy * 0.5 179 | self.collision_enable = false 180 | end 181 | end 182 | 183 | class TestEmitter < SampleEmitter 184 | attr_accessor :wall 185 | 186 | def update 187 | super 188 | Sprite.check @wall, @factory.particles 189 | end 190 | end 191 | 192 | image = Image.new(3,3) 193 | image[1,0] = [128, 255, 255, 255] 194 | image[1,2] = [128, 255, 255, 255] 195 | image[0,1] = [128, 255, 255, 255] 196 | image[2,1] = [128, 255, 255, 255] 197 | image[1,1] = C_WHITE 198 | 199 | emitter = TestEmitter.new(TestParticle) 200 | emitter.gravity = 0.1 201 | emitter.image = image 202 | emitter.wall = Sprite.new(0, 400, Image.new(640, 180, C_WHITE)) 203 | 204 | emitter.add_generator(1) do 205 | emitter.generate_circle(5, 200, 100, 1, 0, 360) do |p, i, angle| 206 | p.dx = Math.cos(angle / 180.0 * Math::PI)*3 207 | p.dy = Math.sin(angle / 180.0 * Math::PI)*3 208 | p.blend = :add 209 | end 210 | end 211 | 212 | font = Font.new(32) 213 | Window.after_call[:particle] = ParticleFactory.method(:step) 214 | 215 | Window.loop do 216 | emitter.update 217 | Window.draw_font(0,0,ParticleFactory.count.to_s, font) 218 | Window.draw_font(0,32,Window.fps.to_s, font) 219 | end 220 | 221 | -------------------------------------------------------------------------------- /sample/new_sample2/readme_sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample2/readme_sample.txt -------------------------------------------------------------------------------- /sample/new_sample2/scenetest.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/new_sample2/scenetest.rb -------------------------------------------------------------------------------- /sample/new_sample2/scenetest2.rb: -------------------------------------------------------------------------------- 1 | #!ruby -Ks 2 | require 'dxruby' 3 | 4 | class ExitException < StandardError 5 | end 6 | 7 | module Window 8 | @@created = false 9 | 10 | def self.loop 11 | unless @@created 12 | Window.create 13 | @@created = true 14 | end 15 | 16 | while(true) do 17 | raise ExitException if Input.update 18 | yield 19 | Window.sync 20 | Window.update 21 | end 22 | end 23 | end 24 | 25 | 26 | class Scene 27 | end 28 | 29 | class FirstScene < Scene 30 | @@image = Image.new(1,1,C_GREEN) 31 | def initialize 32 | end 33 | 34 | def run 35 | Window.loop do 36 | if Input.key_push?(K_ESCAPE) 37 | break 38 | end 39 | if Input.key_push?(K_SPACE) 40 | MenuScene.new([self], 100, 100).run 41 | end 42 | 43 | draw 44 | end 45 | return nil 46 | end 47 | 48 | def draw 49 | Window.draw_scale(0,0,@@image,640,480,0,0) 50 | end 51 | end 52 | 53 | class MenuScene < Scene 54 | 55 | @@font = Font.new(24) 56 | @@image = Image.new(204,124,C_BLACK).box_fill(2,2,201,121,C_WHITE).box_fill(7,7,196,116,C_BLACK) 57 | @@image.draw_font_ex(32, 22, "0001", @@font).draw_font_ex(120, 22, "0002", @@font) 58 | @@image.draw_font_ex(32, 54, "0003", @@font).draw_font_ex(120, 54, "0004", @@font) 59 | @@image.draw_font_ex(32, 86, "0005", @@font).draw_font_ex(120, 86, "0006", @@font) 60 | @@image.box_fill(60, 0, 139, 23, [0,0,0,0]) 61 | @@cursor = Image.new(12,12).triangle_fill(0,0,5,5,0,10,C_WHITE) 62 | @@menu = Image.new(80, 24, C_BLACK).draw_font_ex(10, -2, "MENU", @@font) 63 | 64 | def initialize(s, x, y) 65 | @s = s 66 | @x = x 67 | @y = y 68 | @cx = 0 69 | @cy = 0 70 | end 71 | 72 | def run 73 | Window.loop do 74 | if Input.key_push?(K_ESCAPE) 75 | break 76 | end 77 | if Input.key_push?(K_SPACE) 78 | MenuScene.new(@s + [self], @x + @cx * 88 - 45, @y + @cy * 32 + 24).run 79 | end 80 | 81 | @cx = 1 - @cx if Input.key_push?(K_LEFT) or Input.key_push?(K_RIGHT) 82 | @cy -= 1 if Input.key_push?(K_UP) 83 | @cy += 1 if Input.key_push?(K_DOWN) 84 | @cy = 2 if @cy < 0 85 | @cy = 0 if @cy >2 86 | 87 | Sprite.draw @s 88 | draw 89 | Window.draw(@x + @cx * 88 + 16,@y + @cy * 32 + 29, @@cursor) 90 | end 91 | 92 | return nil 93 | end 94 | 95 | def draw 96 | Window.draw(@x, @y, @@image) 97 | if @s.size == 1 98 | Window.draw(@x + 60, @y, @@menu) 99 | end 100 | end 101 | end 102 | 103 | 104 | scene = FirstScene.new 105 | 106 | begin 107 | 108 | loop do 109 | result = scene.run 110 | if Scene === result 111 | scene = result 112 | else 113 | break 114 | end 115 | end 116 | 117 | rescue ExitException 118 | end 119 | 120 | 121 | -------------------------------------------------------------------------------- /sample/scroll_sample/map.dat: -------------------------------------------------------------------------------- 1 | 11111111121111111113311111111111 2 | 11111111111111111333331111112111 3 | 12111111111111111113333111211111 4 | 11111111111111112111333111111121 5 | 11111111111111111111113311111111 6 | 11111110000000111111111311111111 7 | 11111100000000001111111131111111 8 | 11111000333000001111112111111311 9 | 11120003333200000111111111111311 10 | 11120000333220000111111111111311 11 | 11220000011220000111111111113111 12 | 11220000001220000111111311113111 13 | 11222000000000001111111331133111 14 | 11112220000000000111111133331111 15 | 11111222100000000011111133331111 16 | 11211112211000111001111133331111 17 | 11111111221111111100111333331111 18 | 11111111111111111110111333311111 19 | 11111111111222111111013333311111 20 | 11111111111112221111303333111111 21 | 11111111111111111111303331111111 22 | 11121111111111111113303331111111 23 | 11111111333331111333033331111121 24 | 11111111113333333331233311111222 25 | 11111111111113333333331111122222 26 | 11111111211111133333311111222222 27 | 11111111111111111333111111222221 28 | 11111211111111111111111111122211 29 | 11111111111111111111112111111111 30 | 11111111111121111111111111111111 31 | 11111111111111111111111111111111 32 | 11111111111111111111111111111111 33 | -------------------------------------------------------------------------------- /sample/scroll_sample/map.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/scroll_sample/map.rb -------------------------------------------------------------------------------- /sample/scroll_sample/map_sub.dat: -------------------------------------------------------------------------------- 1 | xxxxxxxxxxxxxxxxxxxxxxxxxxxx4xxx 2 | x4xxxxxxxxxxxxxxxxxxxxxxxx4xxxxx 3 | xxxxxxxxxxxxxxxx4xxxxxxxxxxxxx4x 4 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 5 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 6 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 7 | xxxxxxxxxxxxxxxxxxxxxx4xxxxxxxxx 8 | xxx4xxxxxxx4xxxxxxxxxxxxxxxxxxxx 9 | xxx4xxxxxxx44xxxxxxxxxxxxxxxxxxx 10 | xx44xxxxxxx44xxxxxxxxxxxxxxxxxxx 11 | xx44xxxxxxx44xxxxxxxxxxxxxxxxxxx 12 | xx444xxxxxxxxxxxxxxxxxxxxxxxxxxx 13 | xxxx444xxxxxxxxxxxxxxxxxxxxxxxxx 14 | xxxxx444xxxxxxxxxxxxxxxxxxxxxxxx 15 | xx4xxxx44xxxxxxxxxxxxxxxxxxxxxxx 16 | xxxxxxxx44xxxxxxxxxxxxxxxxxxxxxx 17 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 18 | xxxxxxxxxxx444xxxxxxxxxxxxxxxxxx 19 | xxxxxxxxxxxxx444xxxxxxxxxxxxxxxx 20 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 21 | xxx4xxxxxxxxxxxxxxxxxxxxxxxxxxxx 22 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4x 23 | xxxxxxxxxxxxxxxxxxxx4xxxxxxxx444 24 | xxxxxxxxxxxxxxxxxxxxxxxxxxx44444 25 | xxxxxxxx4xxxxxxxxxxxxxxxxx444444 26 | xxxxxxxxxxxxxxxxxxxxxxxxxx44444x 27 | xxxxx4xxxxxxxxxxxxxxxxxxxxx444xx 28 | xxxxxxxxxxxxxxxxxxxxxx4xxxxxxxxx 29 | xxxxxxxxxxxx4xxxxxxxxxxxxxxxxxxx 30 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 31 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 32 | xxxxxxxxx4xxxxxxxxxxxxxxxxxxxxxx 33 | -------------------------------------------------------------------------------- /sample/scroll_sample/mapedit.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/scroll_sample/mapedit.rb -------------------------------------------------------------------------------- /sample/scroll_sample/readme_sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/scroll_sample/readme_sample.txt -------------------------------------------------------------------------------- /sample/scroll_sample/scroll1.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/scroll_sample/scroll1.rb -------------------------------------------------------------------------------- /sample/scroll_sample/scroll2.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/scroll_sample/scroll2.rb -------------------------------------------------------------------------------- /sample/scroll_sample/scroll3.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/scroll_sample/scroll3.rb -------------------------------------------------------------------------------- /sample/scroll_sample/simple.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | count = 0 4 | image = Image.new(200, 200).box_fill(0, 0, 99, 99, C_RED) 5 | .box_fill(100, 0, 199, 99, C_YELLOW) 6 | .box_fill(0, 100, 99, 199, C_GREEN) 7 | .box_fill(100, 100, 199, 199, C_BLUE) 8 | 9 | Window.loop do 10 | Window.drawTile(0, 0, [[0]], [image], count, count, 5, 4) 11 | count += 1 12 | break if Input.key_push?(K_ESCAPE) 13 | end 14 | -------------------------------------------------------------------------------- /sample/shader_sample/Shader/Flash.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/Shader/Flash.rb -------------------------------------------------------------------------------- /sample/shader_sample/Shader/RasterScroll.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/Shader/RasterScroll.rb -------------------------------------------------------------------------------- /sample/shader_sample/Shader/RgssSprite.rb: -------------------------------------------------------------------------------- 1 | class SpriteShader < Shader 2 | hlsl = <; 10 | }; 11 | 12 | struct PixelIn 13 | { 14 | float2 UV : TEXCOORD0; 15 | }; 16 | struct PixelOut 17 | { 18 | float4 Color : COLOR0; 19 | }; 20 | 21 | PixelOut PS(PixelIn input) 22 | { 23 | PixelOut output; 24 | float3 temp; 25 | float3 ntsc = {0.298912, 0.586611, 0.114478}; 26 | float ntscy; 27 | output.Color = tex2D( Samp, input.UV ); 28 | 29 | ntsc = ntsc * output.Color.rgb; 30 | ntscy = ntsc.r + ntsc.g + ntsc.b; 31 | temp.r = output.Color.r + ((ntscy - output.Color.r) * g_tone.a); 32 | temp.g = output.Color.g + ((ntscy - output.Color.g) * g_tone.a); 33 | temp.b = output.Color.b + ((ntscy - output.Color.b) * g_tone.a); 34 | 35 | output.Color.rgb = min(1.0, temp + g_tone.rgb) * (1.0 - g_blend.a) + g_blend.rgb * g_blend.a; 36 | 37 | return output; 38 | } 39 | 40 | technique TShader 41 | { 42 | pass P0 43 | { 44 | PixelShader = compile ps_2_0 PS(); 45 | } 46 | } 47 | EOS 48 | 49 | @@core = Shader::Core.new(hlsl, 50 | { 51 | :g_blend => :float, 52 | :g_tone => :float, 53 | } 54 | ) 55 | 56 | def initialize 57 | super(@@core, "TShader") 58 | self.g_blend = [0.0,0.0,0.0,0.0] 59 | self.g_tone = [0.0,0.0,0.0,0.0] 60 | @tone = [0.0,0.0,0.0] 61 | @gray = 0.0 62 | class << self 63 | protected :g_blend, :g_blend=, :g_tone, :g_tone= 64 | end 65 | end 66 | 67 | def tone=(ary) 68 | self.g_tone = [ary[0] / 255.0, ary[1] / 255.0, ary[2] / 255.0, @gray / 255.0] 69 | @tone = ary 70 | end 71 | 72 | def gray=(gray) 73 | self.g_tone = [@tone[0] / 255.0, @tone[1] / 255.0, @tone[2] / 255.0, gray / 255.0] 74 | @gray = gray 75 | end 76 | 77 | def color=(ary) 78 | self.g_blend = [ary[1] / 255.0, ary[2] / 255.0, ary[3] / 255.0, ary[0] / 255.0] 79 | end 80 | end 81 | 82 | class RgssSprite < Sprite 83 | def initialize(x=0, y=0, image=nil) 84 | super 85 | self.shader = SpriteShader.new 86 | @rgss_sprite_color = nil 87 | @rgss_sprite_flash_color = nil 88 | @rgss_sprite_flash_duration = 1 89 | @rgss_sprite_flash_count = 0 90 | end 91 | 92 | def tone=(ary) 93 | if ary == nil 94 | self.shader.tone = [0,0,0] 95 | else 96 | self.shader.tone = ary 97 | end 98 | end 99 | 100 | def gray=(gray) 101 | self.shader.gray = gray 102 | end 103 | 104 | def color=(ary) 105 | @rgss_sprite_color = ary 106 | end 107 | 108 | def flash(color=[255,255,255,255], duration=30) 109 | @rgss_sprite_flash_color = color 110 | @rgss_sprite_flash_duration = duration 111 | @rgss_sprite_flash_count = duration 112 | end 113 | 114 | def update 115 | @rgss_sprite_flash_count -= 1 if @rgss_sprite_flash_count > 0 116 | end 117 | 118 | def draw 119 | if @rgss_sprite_color != nil and @rgss_sprite_flash_count > 0 120 | if @rgss_sprite_color[0] > @rgss_sprite_flash_color[0] * @rgss_sprite_flash_count / @rgss_sprite_flash_duration 121 | self.shader.color = @rgss_sprite_color 122 | else 123 | self.shader.color = [@rgss_sprite_flash_color[0] * @rgss_sprite_flash_count / @rgss_sprite_flash_duration, 124 | @rgss_sprite_flash_color[1], 125 | @rgss_sprite_flash_color[2], 126 | @rgss_sprite_flash_color[3] 127 | ] 128 | end 129 | elsif @rgss_sprite_flash_count > 0 130 | self.shader.color = [@rgss_sprite_flash_color[0] * @rgss_sprite_flash_count / @rgss_sprite_flash_duration, 131 | @rgss_sprite_flash_color[1], 132 | @rgss_sprite_flash_color[2], 133 | @rgss_sprite_flash_color[3] 134 | ] 135 | elsif @rgss_sprite_color != nil 136 | self.shader.color = @rgss_sprite_color 137 | else 138 | self.shader.color = [0,0,0,0] 139 | end 140 | super 141 | end 142 | end 143 | 144 | -------------------------------------------------------------------------------- /sample/shader_sample/Shader/Transition.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/Shader/Transition.rb -------------------------------------------------------------------------------- /sample/shader_sample/bgimage/BG00a1_80.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/bgimage/BG00a1_80.jpg -------------------------------------------------------------------------------- /sample/shader_sample/bgimage/BG10a_80.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/bgimage/BG10a_80.jpg -------------------------------------------------------------------------------- /sample/shader_sample/bgimage/BG13a_80.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/bgimage/BG13a_80.jpg -------------------------------------------------------------------------------- /sample/shader_sample/bgimage/BG32a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/bgimage/BG32a.jpg -------------------------------------------------------------------------------- /sample/shader_sample/bgimage/BG42a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/bgimage/BG42a.jpg -------------------------------------------------------------------------------- /sample/shader_sample/bgimage/course.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/bgimage/course.png -------------------------------------------------------------------------------- /sample/shader_sample/bgimage/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/bgimage/image1.png -------------------------------------------------------------------------------- /sample/shader_sample/bgimage/world_map2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/bgimage/world_map2.png -------------------------------------------------------------------------------- /sample/shader_sample/fan.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | hlsl = <; 11 | }; 12 | 13 | float4 PS(float2 input : TEXCOORD0) : COLOR0 14 | { 15 | float temp; 16 | temp = degrees(atan2(0.5 - input.y ,0.5 - input.x)) + 180.0; 17 | clip(float2((temp - start_angle) * (end_angle - temp) * flag, length - distance(float2(0.5, 0.5), input))); 18 | 19 | return color; 20 | } 21 | 22 | technique 23 | { 24 | pass 25 | { 26 | PixelShader = compile ps_2_0 PS(); 27 | } 28 | } 29 | EOS 30 | 31 | core = Shader::Core.new(hlsl, :color => :float, :start_angle => :float, :end_angle => :float, :flag => :float, :length => :float) 32 | shader = Shader.new(core) 33 | 34 | image = Image.new(300,300) 35 | 36 | shader.color = [255, 255, 255, 255] 37 | shader.start_angle = 0 38 | shader.end_angle = 0 39 | shader.flag = 1 40 | shader.length = 0.4 41 | 42 | x = 1 43 | 44 | Window.loop do 45 | x += 5 46 | x = 0 if x > 360 47 | shader.start_angle = x 48 | Window.draw_ex(100, 100, image, shader:shader) 49 | end 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /sample/shader_sample/image/enemy1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/image/enemy1.png -------------------------------------------------------------------------------- /sample/shader_sample/image/enemy2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/image/enemy2.png -------------------------------------------------------------------------------- /sample/shader_sample/image/maptile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/image/maptile.png -------------------------------------------------------------------------------- /sample/shader_sample/readme_sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/readme_sample.txt -------------------------------------------------------------------------------- /sample/shader_sample/rule/チェッカー.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/rule/チェッカー.png -------------------------------------------------------------------------------- /sample/shader_sample/rule/右渦巻き.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/rule/右渦巻き.png -------------------------------------------------------------------------------- /sample/shader_sample/rule/横ブラインド.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/rule/横ブラインド.png -------------------------------------------------------------------------------- /sample/shader_sample/sample_blur.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | hlsl = <; 10 | AddressU=BORDER; 11 | AddressV=BORDER; 12 | }; 13 | 14 | float4 PS1(float2 In : TEXCOORD0) : COLOR0 15 | { 16 | float2 Texel0 = In + float2( -1.0/g_size.x, 0.0f ); 17 | float2 Texel1 = In + float2( -1.0/g_size.x*2, 0.0f ); 18 | float2 Texel2 = In + float2( -1.0/g_size.x*3, 0.0f ); 19 | float2 Texel3 = In + float2( -1.0/g_size.x*4, 0.0f ); 20 | float2 Texel4 = In + float2( -1.0/g_size.x*5, 0.0f ); 21 | 22 | float2 Texel5 = In + float2( 1.0/g_size.x, 0.0f ); 23 | float2 Texel6 = In + float2( 1.0/g_size.x*2, 0.0f ); 24 | float2 Texel7 = In + float2( 1.0/g_size.x*3, 0.0f ); 25 | float2 Texel8 = In + float2( 1.0/g_size.x*4, 0.0f ); 26 | float2 Texel9 = In + float2( 1.0/g_size.x*5, 0.0f ); 27 | 28 | float4 p0 = tex2D( Samp0, In ) * 0.20f; 29 | 30 | float4 p1 = tex2D( Samp0, Texel0 ) * 0.12f; 31 | float4 p2 = tex2D( Samp0, Texel1 ) * 0.10f; 32 | float4 p3 = tex2D( Samp0, Texel2 ) * 0.08f; 33 | float4 p4 = tex2D( Samp0, Texel3 ) * 0.06f; 34 | float4 p5 = tex2D( Samp0, Texel4 ) * 0.04f; 35 | 36 | float4 p6 = tex2D( Samp0, Texel5 ) * 0.12f; 37 | float4 p7 = tex2D( Samp0, Texel6 ) * 0.10f; 38 | float4 p8 = tex2D( Samp0, Texel7 ) * 0.08f; 39 | float4 p9 = tex2D( Samp0, Texel8 ) * 0.06f; 40 | float4 p10 = tex2D( Samp0, Texel9 ) * 0.04f; 41 | 42 | return p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10; 43 | } 44 | 45 | float4 PS2(float2 In : TEXCOORD0) : COLOR0 46 | { 47 | float2 Texel0 = In + float2( 0.0f, -1.0/g_size.y ); 48 | float2 Texel1 = In + float2( 0.0f, -1.0/g_size.y*2 ); 49 | float2 Texel2 = In + float2( 0.0f, -1.0/g_size.y*3 ); 50 | float2 Texel3 = In + float2( 0.0f, -1.0/g_size.y*4 ); 51 | float2 Texel4 = In + float2( 0.0f, -1.0/g_size.y*5 ); 52 | 53 | float2 Texel5 = In + float2( 0.0f, 1.0/g_size.y ); 54 | float2 Texel6 = In + float2( 0.0f, 1.0/g_size.y*2 ); 55 | float2 Texel7 = In + float2( 0.0f, 1.0/g_size.y*3 ); 56 | float2 Texel8 = In + float2( 0.0f, 1.0/g_size.y*4 ); 57 | float2 Texel9 = In + float2( 0.0f, 1.0/g_size.y*5 ); 58 | 59 | float4 p0 = tex2D( Samp0, In ) * 0.20f; 60 | 61 | float4 p1 = tex2D( Samp0, Texel0 ) * 0.12f; 62 | float4 p2 = tex2D( Samp0, Texel1 ) * 0.10f; 63 | float4 p3 = tex2D( Samp0, Texel2 ) * 0.08f; 64 | float4 p4 = tex2D( Samp0, Texel3 ) * 0.06f; 65 | float4 p5 = tex2D( Samp0, Texel4 ) * 0.04f; 66 | 67 | float4 p6 = tex2D( Samp0, Texel5 ) * 0.12f; 68 | float4 p7 = tex2D( Samp0, Texel6 ) * 0.10f; 69 | float4 p8 = tex2D( Samp0, Texel7 ) * 0.08f; 70 | float4 p9 = tex2D( Samp0, Texel8 ) * 0.06f; 71 | float4 p10 = tex2D( Samp0, Texel9 ) * 0.04f; 72 | 73 | return p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10; 74 | } 75 | 76 | technique Blur1 77 | { 78 | pass P0 79 | { 80 | PixelShader = compile ps_2_0 PS1(); 81 | } 82 | } 83 | technique Blur2 84 | { 85 | pass P0 86 | { 87 | PixelShader = compile ps_2_0 PS2(); 88 | } 89 | } 90 | EOS 91 | 92 | core = Shader::Core.new(hlsl,{:g_size => :float}) 93 | shader1 = Shader.new(core, "Blur1") 94 | shader2 = Shader.new(core, "Blur2") 95 | 96 | image = Image.load("./image/maptile.png") 97 | 98 | shader1.g_size = [image.width,image.height] 99 | shader2.g_size = [image.width,image.height] 100 | 101 | rt1 = RenderTarget.new(image.width,image.height) 102 | rt2 = RenderTarget.new(image.width,image.height) 103 | 104 | Window.loop do 105 | Window.draw(50, 50, image) 106 | rt1.draw_ex(0, 0, image, :blend=>:nond, :shader=>shader1) 107 | rt1.update 108 | rt2.draw_ex(0, 0, rt1, :blend=>:nond, :shader=>shader2) 109 | rt2.update 110 | Window.draw(350, 50, rt2) 111 | break if Input.key_push?(K_ESCAPE) 112 | end 113 | -------------------------------------------------------------------------------- /sample/shader_sample/sample_divide.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | hlsl = <; 10 | }; 11 | 12 | float4 PS1(float2 input : TEXCOORD0) : COLOR0 13 | { 14 | clip( cross( float3(p2.x - p1.x, p2.y - p1.y, 0), float3(input.x - p1.x, input.y - p1.y, 0) ).z ); 15 | return tex2D( Samp0, input ); 16 | } 17 | 18 | float4 PS2(float2 input : TEXCOORD0) : COLOR0 19 | { 20 | clip( cross( float3(p1.x - p2.x, p1.y - p2.y, 0), float3(input.x - p1.x, input.y - p1.y, 0) ).z ); 21 | return tex2D( Samp0, input ); 22 | } 23 | 24 | technique Zan1 25 | { 26 | pass P0 27 | { 28 | PixelShader = compile ps_2_0 PS1(); 29 | } 30 | } 31 | technique Zan2 32 | { 33 | pass P0 34 | { 35 | PixelShader = compile ps_2_0 PS2(); 36 | } 37 | } 38 | EOS 39 | 40 | Window.width, Window.height = 800, 600 41 | 42 | core = Shader::Core.new(hlsl,{:p1=>:float, :p2=>:float}) 43 | shader1 = Shader.new(core, "Zan1") 44 | shader2 = Shader.new(core, "Zan2") 45 | image = Image.load("bgimage/BG42a.jpg") 46 | image1 = image2 = nil 47 | 48 | rt = RenderTarget.new(image.width, image.height) 49 | 50 | point = nil 51 | transition_flg = false 52 | 53 | x1 = y1 = x2 = y2 = 0 54 | angle = 0 55 | alpha = 255 56 | 57 | Window.loop do 58 | if !transition_flg 59 | if Input.mouse_push?(M_LBUTTON) 60 | point = [Input.mouse_pos_x, Input.mouse_pos_y] 61 | end 62 | 63 | if point 64 | if Input.mouse_down?(M_LBUTTON) 65 | Window.draw_line(point[0], point[1], Input.mouse_pos_x, Input.mouse_pos_y, C_WHITE, 1) 66 | else 67 | transition_flg = true 68 | shader1.p1 = shader2.p1 = [point[0].quo(image.width), point[1].quo(image.height),0] 69 | shader1.p2 = shader2.p2 = [Input.mouse_pos_x.quo(image.width), Input.mouse_pos_y.quo(image.height),0] 70 | angle = Math.atan2( Input.mouse_pos_y - point[1], Input.mouse_pos_x - point[0] ) 71 | image1 = rt.draw_shader(0, 0, image, shader1).update.to_image 72 | image2 = rt.draw_shader(0, 0, image, shader2).update.to_image 73 | alpha = 255 74 | point = nil 75 | x1 = y1 = x2 = y2 = 0 76 | end 77 | end 78 | Window.draw(0, 0, image) 79 | else 80 | x1 -= Math.cos(angle) * 5 81 | y1 -= Math.sin(angle) * 5 82 | x2 += Math.cos(angle) * 5 83 | y2 += Math.sin(angle) * 5 84 | alpha -= 3 85 | Window.draw_alpha(x1, y1, image1, alpha) 86 | Window.draw_alpha(x2, y2, image2, alpha) 87 | transition_flg = false if alpha < 10 88 | end 89 | break if Input.key_push?(K_ESCAPE) 90 | end 91 | 92 | -------------------------------------------------------------------------------- /sample/shader_sample/sample_flash.rb: -------------------------------------------------------------------------------- 1 | #!ruby -Ks 2 | require 'dxruby' 3 | require './shader/flash.rb' 4 | 5 | map = [[0, 0, 0, 0, 0, 0, 0, 0, 29, 11, 11, 30, 34, 66, 67, 67], 6 | [0, 0, 0, 24, 25, 26, 0, 0, 29, 11, 11, 39, 40, 6, 34, 34], 7 | [0, 0, 24, 17, 31, 35, 0, 0, 12, 20, 11, 11, 11, 39, 40, 40], 8 | [0, 24, 17, 34, 7, 44, 0, 28, 28, 29, 11, 11, 11, 11, 11, 11], 9 | [0, 33, 31, 34, 35, 0, 28, 3, 37, 38, 11, 11, 11, 18, 19, 19], 10 | [0, 42, 43, 43, 44, 28, 3, 38, 11, 11, 11, 18, 19, 13, 28, 28], 11 | [0, 0, 0, 0, 3, 37, 38, 11, 11, 18, 19, 13, 28, 28, 28, 0], 12 | [0, 0, 0, 3, 38, 11, 11, 11, 18, 13, 28, 28, 51, 52, 52, 52], 13 | [0, 0, 3, 38, 11, 11, 18, 19, 13, 51, 52, 52, 86, 58, 61, 76], 14 | [28, 0, 29, 11, 11, 18, 13, 28, 51, 86, 58, 58, 61, 61, 58, 62], 15 | [0, 28, 29, 11, 18, 13, 28, 0, 60, 58, 61, 61, 61, 61, 76, 71], 16 | [0, 28, 29, 11, 27, 28, 28, 51, 86, 61, 61, 58, 76, 70, 71, 0], 17 | [0, 0, 29, 11, 36, 4, 28, 60, 58, 61, 58, 76, 71, 0, 1, 2], 18 | [0, 28, 29, 11, 11, 36, 4, 69, 70, 70, 70, 71, 0, 1, 2, 0], 19 | [0, 0, 12, 20, 11, 11, 27, 0, 1, 0, 1, 1, 1, 2, 2, 0], 20 | [0, 0, 28, 12, 20, 11, 27, 0, 0, 0, 2, 2, 0, 2, 2, 0], 21 | [0, 0, 0, 2, 29, 11, 27, 1, 2, 2, 2, 0, 0, 2, 2, 2], 22 | [0, 0, 0, 2, 29, 11, 27, 1, 0, 1, 1, 2, 2, 0, 0, 2], 23 | [0, 0, 0, 0, 29, 11, 27, 1, 0, 2, 2, 2, 1, 1, 2, 2], 24 | [0, 45, 47, 2, 29, 11, 36, 4, 1, 2, 2, 0, 0, 2, 2, 0], 25 | [45, 82, 56, 0, 29, 11, 11, 36, 4, 1, 2, 2, 2, 2, 0, 0], 26 | [54, 0, 56, 0, 12, 20, 11, 11, 36, 37, 4, 0, 2, 2, 2, 2], 27 | [54, 55, 81, 46, 47, 12, 20, 11, 11, 11, 36, 4, 1, 1, 1, 2], 28 | [54, 55, 0, 0, 56, 0, 12, 19, 20, 11, 11, 36, 37, 4, 1, 1], 29 | [54, 0, 55, 55, 56, 0, 0, 0, 12, 20, 11, 11, 11, 36, 37, 37], 30 | [63, 73, 55, 55, 56, 0, 0, 2, 2, 29, 11, 11, 11, 11, 11, 11], 31 | [0, 54, 0, 55, 81, 47, 0, 2, 3, 38, 11, 11, 11, 11, 11, 11], 32 | [0, 54, 0, 0, 55, 56, 2, 0, 29, 11, 11, 11, 21, 22, 22, 22], 33 | [0, 63, 64, 64, 64, 65, 0, 0, 29, 11, 11, 21, 15, 48, 49, 49], 34 | [0, 0, 0, 0, 0, 0, 0, 0, 29, 11, 11, 30, 34, 57, 34, 34], 35 | ] 36 | 37 | shader = FlashShader.new(30, [255,255,255]) 38 | 39 | rt = RenderTarget.new(640, 480) 40 | image = Image.loadToArray("image/maptile.png", 9, 10) 41 | 42 | Window.loop do 43 | rt.draw_tile(0, 0, map, image, 0, 0, 12, 14) 44 | rt.draw_tile(300, 200, map, image, 0, 0, 12, 14) 45 | rt.update 46 | 47 | shader.start if Input.keyPush?(K_Z) 48 | shader.next 49 | 50 | Window.draw_ex(0, 0, rt, :shader=>shader, :angle => 20) 51 | 52 | break if Input.keyPush?(K_ESCAPE) 53 | end 54 | 55 | -------------------------------------------------------------------------------- /sample/shader_sample/sample_lens.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | hlsl = <; 13 | }; 14 | sampler Samp1 = sampler_state 15 | { 16 | Texture =; 17 | AddressU = BORDER; 18 | AddressV = BORDER; 19 | }; 20 | 21 | float4 PS(float2 input : TEXCOORD0) : COLOR0 22 | { 23 | float4 output; 24 | float d; 25 | 26 | clip(tex2D( Samp0, input ).r - 1.0); 27 | 28 | d = sqrt((input.x-0.5)*(input.x-0.5) + (input.y-0.5)*(input.y-0.5))+1; 29 | output = tex2D( Samp1, float2( pos.x + (input.x-0.5) / scale.x * distance / r * d, pos.y + (input.y-0.5) / scale.y * distance / r * d)); 30 | return output; 31 | } 32 | 33 | technique Lens 34 | { 35 | pass P0 36 | { 37 | PixelShader = compile ps_2_0 PS(); 38 | } 39 | } 40 | EOS 41 | 42 | Window.width, Window.height = 800, 600 43 | bgimage = Image.load("bgimage/BG42a.jpg") 44 | image = Image.new(200,200).circle_fill(100,100,100,C_WHITE) 45 | loupeimage = Image.new(200,200).circle(100,100,100,C_WHITE) 46 | 47 | core = DXRuby::Shader::Core.new(hlsl, {:scale=>:float, :r=>:float, :distance=>:float, :tex1=>:texture, :pos=>:float}) 48 | shader = Shader.new(core, "Lens") 49 | shader.scale = [bgimage.width.quo(image.width), bgimage.height.quo(image.height)] 50 | shader.r = 1000 51 | shader.distance = 500 52 | shader.tex1 = bgimage 53 | 54 | Window.loop do 55 | shader.pos = [Input.mouse_pos_x.quo(bgimage.width), Input.mouse_pos_y.quo(bgimage.height)] 56 | shader.distance += Input.y*10 57 | shader.distance = 0 if shader.distance < 0 58 | shader.distance = shader.r if shader.distance > shader.r 59 | 60 | Window.draw(0,0,bgimage) 61 | Window.draw_shader(Input.mouse_pos_x-image.width/2, Input.mouse_pos_y-image.width/2, image, shader) 62 | Window.draw(Input.mouse_pos_x-image.width/2, Input.mouse_pos_y-image.width/2, loupeimage) 63 | break if Input.key_push?(K_ESCAPE) 64 | end 65 | 66 | -------------------------------------------------------------------------------- /sample/shader_sample/sample_mapping.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | hlsl = <; 10 | AddressU = BORDER; 11 | AddressV = BORDER; 12 | }; 13 | 14 | float4 PS(float2 input : TEXCOORD0) : COLOR0 15 | { 16 | float4 output; 17 | float dist = radians(distance(input, float2(0.5, 0.5)) * 360 * 4 - g_start); 18 | float height = sin(dist); 19 | float slope = cos(dist); 20 | float d = clamp(-1,1,dot(normalize(float3(input.y - 0.5, input.x - 0.5,0 )), float3(0.5,-0.5,0.5)))*slope+1; 21 | input.y = input.y + height * g_level; 22 | 23 | output = tex2D( Samp, input ) * d; 24 | 25 | return output; 26 | } 27 | 28 | technique Raster 29 | { 30 | pass P0 31 | { 32 | PixelShader = compile ps_2_0 PS(); 33 | } 34 | } 35 | EOS 36 | 37 | Window.width, Window.height = 800, 600 38 | core = DXRuby::Shader::Core.new(hlsl, {:g_start=>:float, :g_level=>:float}) 39 | shader = Shader.new(core, "Raster") 40 | shader.g_start = 0 41 | shader.g_level = 0 42 | image = Image.load("bgimage/BG42a.jpg") 43 | 44 | Window.loop do 45 | shader.g_start += 3 46 | shader.g_level = 0.15 47 | Window.draw_shader(0, 0, image, shader) 48 | break if Input.key_push?(K_ESCAPE) 49 | end 50 | 51 | -------------------------------------------------------------------------------- /sample/shader_sample/sample_rasterscroll.rb: -------------------------------------------------------------------------------- 1 | #!ruby -Ks 2 | require 'dxruby' 3 | require './shader/rasterscroll.rb' 4 | 5 | map = [[0, 0, 0, 0, 0, 0, 0, 0, 29, 11, 11, 30, 34, 66, 67, 67], 6 | [0, 0, 0, 24, 25, 26, 0, 0, 29, 11, 11, 39, 40, 6, 34, 34], 7 | [0, 0, 24, 17, 31, 35, 0, 0, 12, 20, 11, 11, 11, 39, 40, 40], 8 | [0, 24, 17, 34, 7, 44, 0, 28, 28, 29, 11, 11, 11, 11, 11, 11], 9 | [0, 33, 31, 34, 35, 0, 28, 3, 37, 38, 11, 11, 11, 18, 19, 19], 10 | [0, 42, 43, 43, 44, 28, 3, 38, 11, 11, 11, 18, 19, 13, 28, 28], 11 | [0, 0, 0, 0, 3, 37, 38, 11, 11, 18, 19, 13, 28, 28, 28, 0], 12 | [0, 0, 0, 3, 38, 11, 11, 11, 18, 13, 28, 28, 51, 52, 52, 52], 13 | [0, 0, 3, 38, 11, 11, 18, 19, 13, 51, 52, 52, 86, 58, 61, 76], 14 | [28, 0, 29, 11, 11, 18, 13, 28, 51, 86, 58, 58, 61, 61, 58, 62], 15 | [0, 28, 29, 11, 18, 13, 28, 0, 60, 58, 61, 61, 61, 61, 76, 71], 16 | [0, 28, 29, 11, 27, 28, 28, 51, 86, 61, 61, 58, 76, 70, 71, 0], 17 | [0, 0, 29, 11, 36, 4, 28, 60, 58, 61, 58, 76, 71, 0, 1, 2], 18 | [0, 28, 29, 11, 11, 36, 4, 69, 70, 70, 70, 71, 0, 1, 2, 0], 19 | [0, 0, 12, 20, 11, 11, 27, 0, 1, 0, 1, 1, 1, 2, 2, 0], 20 | [0, 0, 28, 12, 20, 11, 27, 0, 0, 0, 2, 2, 0, 2, 2, 0], 21 | [0, 0, 0, 2, 29, 11, 27, 1, 2, 2, 2, 0, 0, 2, 2, 2], 22 | [0, 0, 0, 2, 29, 11, 27, 1, 0, 1, 1, 2, 2, 0, 0, 2], 23 | [0, 0, 0, 0, 29, 11, 27, 1, 0, 2, 2, 2, 1, 1, 2, 2], 24 | [0, 45, 47, 2, 29, 11, 36, 4, 1, 2, 2, 0, 0, 2, 2, 0], 25 | [45, 82, 56, 0, 29, 11, 11, 36, 4, 1, 2, 2, 2, 2, 0, 0], 26 | [54, 0, 56, 0, 12, 20, 11, 11, 36, 37, 4, 0, 2, 2, 2, 2], 27 | [54, 55, 81, 46, 47, 12, 20, 11, 11, 11, 36, 4, 1, 1, 1, 2], 28 | [54, 55, 0, 0, 56, 0, 12, 19, 20, 11, 11, 36, 37, 4, 1, 1], 29 | [54, 0, 55, 55, 56, 0, 0, 0, 12, 20, 11, 11, 11, 36, 37, 37], 30 | [63, 73, 55, 55, 56, 0, 0, 2, 2, 29, 11, 11, 11, 11, 11, 11], 31 | [0, 54, 0, 55, 81, 47, 0, 2, 3, 38, 11, 11, 11, 11, 11, 11], 32 | [0, 54, 0, 0, 55, 56, 2, 0, 29, 11, 11, 11, 21, 22, 22, 22], 33 | [0, 63, 64, 64, 64, 65, 0, 0, 29, 11, 11, 21, 15, 48, 49, 49], 34 | [0, 0, 0, 0, 0, 0, 0, 0, 29, 11, 11, 30, 34, 57, 34, 34], 35 | ] 36 | 37 | shader = RasterScrollShader.new(5, 0.1) 38 | rt = RenderTarget.new(640, 480) 39 | image = Image.load_to_array("image/maptile.png", 9, 10) 40 | 41 | Window.loop do 42 | rt.draw_tile(150, 16, map, image, 0, 0, 12, 14) 43 | rt.update 44 | shader.update 45 | Window.draw_shader(0, 0, rt, shader) 46 | break if Input.key_push?(K_ESCAPE) 47 | end 48 | 49 | -------------------------------------------------------------------------------- /sample/shader_sample/sample_rgsssprite.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/sample_rgsssprite.rb -------------------------------------------------------------------------------- /sample/shader_sample/sample_spehari.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | hlsl = <; 9 | AddressU = WRAP; 10 | AddressV = WRAP; 11 | }; 12 | 13 | float4 PS(float2 input : TEXCOORD0) : COLOR0 14 | { 15 | return tex2D( Samp0, float2((input.x-0.5) / (input.y+0.20), (input.y-1) / (input.y+0.20)) ); 16 | } 17 | 18 | technique SH 19 | { 20 | pass P0 21 | { 22 | PixelShader = compile ps_2_0 PS(); 23 | } 24 | } 25 | EOS 26 | 27 | core = Shader::Core.new(hlsl,{}) 28 | shader = Shader.new(core, "SH") 29 | 30 | image = Image.new(80, 80,[0, 255, 0]) 31 | image.box_fill(0, 0, 39, 39, [150,250,150]) 32 | image.box_fill(40, 0, 79, 39, [100,250,100]) 33 | image.box_fill(0, 40, 39, 79, [200,250,200]) 34 | image.box_fill(40, 40, 79, 79, [0,220,0]) 35 | 36 | rt = RenderTarget.new(640,240) 37 | z = 0 38 | x = 0 39 | y = 0 40 | Window.loop do 41 | z -= 10 42 | x += Input.x * 5 43 | y -= Input.y * 2 44 | y = 0 if y < 0 45 | y = 100 if y > 100 46 | 47 | rt.draw_tile(0, 0, [[0]], [image], x, z, 8, 3).update 48 | Window.draw_ex(0, 240, rt, :shader=>shader, :scaley=>y/200.0+0.5, :centery=>240.0) 49 | break if Input.key_push?(K_ESCAPE) 50 | end 51 | -------------------------------------------------------------------------------- /sample/shader_sample/sample_sphere.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | hlsl = <; 10 | AddressU = BORDER; 11 | AddressV = BORDER; 12 | }; 13 | 14 | float4 PS1(float2 input : TEXCOORD0) : COLOR0 15 | { 16 | float pi = acos(-1); 17 | return tex2D( Samp0, 18 | float2( ((1 - (acos((input.x*2 - 1.0) ) / pi)) - 0.5) + 0.5 19 | , ((1 - (acos((input.y*2 - 1.0) ) / pi)) - 0.5) + 0.5) ); 20 | // , input.y )); 21 | } 22 | 23 | float4 PS2(float2 input : TEXCOORD0) : COLOR0 24 | { 25 | return tex2D( Samp0, 26 | float2((input.x - 0.5) / cos(asin((input.y*2 - 1.0))) / raito.x + 0.5 27 | , (input.y - 0.5) / raito.y + 0.5) ); 28 | } 29 | 30 | technique Sphere1 31 | { 32 | pass P0 33 | { 34 | PixelShader = compile ps_2_0 PS1(); 35 | } 36 | } 37 | technique Sphere2 38 | { 39 | pass P0 40 | { 41 | PixelShader = compile ps_2_0 PS2(); 42 | } 43 | } 44 | EOS 45 | 46 | Window.width, Window.height = 800, 600 47 | image = Image.load("bgimage/world_map2.png") 48 | image = image.slice(4, 5, image.width - 10, image.height - 9) 49 | 50 | core = DXRuby::Shader::Core.new(hlsl, {:raito=>:float}) 51 | shader1 = Shader.new(core, "Sphere1") 52 | shader2 = Shader.new(core, "Sphere2") 53 | shader1.raito = shader2.raito = [600.quo(Window.width), 600.quo(Window.height)] 54 | 55 | rt1 = RenderTarget.new(image.width/2, image.height) 56 | rt2 = RenderTarget.new(Window.width, Window.height) 57 | x = 0 58 | 59 | Window.loop do 60 | x -= 3 61 | rt1.draw_tile(0, 0, [[0]], [image], x, 0, 2, 1).update 62 | rt2.draw_ex(0, 0, rt1, :shader=>shader1, :centerx=>0, :centery=>0, :scalex=>Window.width.quo(rt1.width), :scaley=>Window.height.quo(rt1.height) ).update 63 | Window.draw_ex(0, 0, rt2, :shader=>shader2,:angle=>23.4) 64 | break if Input.key_push?(K_ESCAPE) 65 | end 66 | 67 | -------------------------------------------------------------------------------- /sample/shader_sample/sample_transition.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/sample_transition.rb -------------------------------------------------------------------------------- /sample/shader_sample/sample_vertexshader.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | 3 | class Vector 4 | def initialize(*v) 5 | @vec = v 6 | end 7 | 8 | def rotate(angle) 9 | x = @vec[0] * Math.cos(Math::PI / 180 * angle) - @vec[1] * Math.sin(Math::PI / 180 * angle) 10 | y = @vec[0] * Math.sin(Math::PI / 180 * angle) + @vec[1] * Math.cos(Math::PI / 180 * angle) 11 | temp = @vec.dup 12 | temp[0] = x 13 | temp[1] = y 14 | Vector.new(*temp) 15 | end 16 | 17 | def +(v) 18 | case v 19 | when Vector 20 | Vector.new(*@vec.map.with_index{|s,i|s+v[i]}) 21 | when Array 22 | Vector.new(*@vec.map.with_index{|s,i|s+v[i]}) 23 | when Numeric 24 | Vector.new(*@vec.map{|s|s+v}) 25 | else 26 | nil 27 | end 28 | end 29 | 30 | def *(matrix) 31 | result = [] 32 | for i in 0..(matrix.size-1) 33 | data = 0 34 | for j in 0..(@vec.size-1) 35 | data += @vec[j] * matrix[j][i] 36 | end 37 | result.push(data) 38 | end 39 | return Vector.new(*result) 40 | end 41 | 42 | def [](i) 43 | @vec[i] 44 | end 45 | 46 | def size 47 | @vec.size 48 | end 49 | 50 | def to_a 51 | @vec 52 | end 53 | 54 | def x 55 | @vec[0] 56 | end 57 | def y 58 | @vec[1] 59 | end 60 | def z 61 | @vec[2] 62 | end 63 | def w 64 | @vec[3] 65 | end 66 | end 67 | 68 | class Matrix 69 | def initialize(*arr) 70 | @arr = Array.new(4) {|i| Vector.new(*arr[i])} 71 | end 72 | 73 | def *(a) 74 | result = [] 75 | for i in 0..(a.size-1) 76 | result.push(@arr[i] * a) 77 | end 78 | return Matrix.new(*result) 79 | end 80 | 81 | def [](i) 82 | @arr[i] 83 | end 84 | 85 | def size 86 | @arr.size 87 | end 88 | 89 | def self.create_rotation_z(angle) 90 | cos = Math.cos(Math::PI/180 * angle) 91 | sin = Math.sin(Math::PI/180 * angle) 92 | return Matrix.new( 93 | [ cos, sin, 0, 0], 94 | [-sin, cos, 0, 0], 95 | [ 0, 0, 1, 0], 96 | [ 0, 0, 0, 1] 97 | ) 98 | end 99 | 100 | def self.create_rotation_x(angle) 101 | cos = Math.cos(Math::PI/180 * angle) 102 | sin = Math.sin(Math::PI/180 * angle) 103 | return Matrix.new( 104 | [ 1, 0, 0, 0], 105 | [ 0, cos, sin, 0], 106 | [ 0,-sin, cos, 0], 107 | [ 0, 0, 0, 1] 108 | ) 109 | end 110 | 111 | def self.create_rotation_y(angle) 112 | cos = Math.cos(Math::PI/180 * angle) 113 | sin = Math.sin(Math::PI/180 * angle) 114 | return Matrix.new( 115 | [ cos, 0,-sin, 0], 116 | [ 0, 1, 0, 0], 117 | [ sin, 0, cos, 0], 118 | [ 0, 0, 0, 1] 119 | ) 120 | end 121 | 122 | def self.create_transration(x, y, z) 123 | return Matrix.new( 124 | [ 1, 0, 0, 0], 125 | [ 0, 1, 0, 0], 126 | [ 0, 0, 1, 0], 127 | [ x, y, z, 1] 128 | ) 129 | end 130 | 131 | def to_a 132 | @arr.map {|v|v.to_a}.flatten 133 | end 134 | end 135 | 136 | 137 | hlsl = <; 144 | }; 145 | 146 | struct VS_OUTPUT 147 | { 148 | float4 pos : POSITION; 149 | float2 tex : TEXCOORD0; 150 | }; 151 | 152 | VS_OUTPUT VS(float4 pos: POSITION, float2 tex: TEXCOORD0) 153 | { 154 | VS_OUTPUT output; 155 | 156 | output.pos = mul(mul(mul(pos, g_world), g_view), g_proj); 157 | output.tex = tex; 158 | 159 | return output; 160 | } 161 | 162 | float4 PS(float2 input : TEXCOORD0) : COLOR0 163 | { 164 | return tex2D( Samp, input ); 165 | } 166 | 167 | technique 168 | { 169 | pass 170 | { 171 | VertexShader = compile vs_2_0 VS(); 172 | PixelShader = compile ps_2_0 PS(); 173 | } 174 | } 175 | EOS 176 | 177 | core = Shader::Core.new(hlsl, {:g_world=>:float, :g_view=>:float, :g_proj=>:float}) 178 | shader = Shader.new(core) 179 | 180 | shader.g_view = Matrix.new([1, 0, 0, 0], 181 | [0, -1, 0, 0], 182 | [0, 0, 1, 0], 183 | [-Window.width/2, Window.height/2, 0, 1] 184 | ).to_a 185 | 186 | zn = 700.0 187 | zf = 5000.0 188 | sw = 640.0 189 | sh = 480.0 190 | shader.g_proj = Matrix.new([2.0 * zn / sw, 0, 0, 0], 191 | [ 0, 2.0 * zn / sh, 0, 0], 192 | [ 0, 0, zf / (zf - zn), 1], 193 | [ 0, 0, -zn * zf / (zf - zn), 0] 194 | ).to_a 195 | 196 | 197 | image = [Image.load("bgimage/BG42a.jpg"), Image.load("bgimage/BG00a1_80.jpg"), 198 | Image.load("bgimage/BG10a_80.jpg"), Image.load("bgimage/BG13a_80.jpg"), 199 | Image.load("bgimage/BG32a.jpg")] 200 | 201 | a=0 202 | Window.loop do 203 | a += 1 204 | idx = 0 205 | image.map{|img| 206 | idx += 1 207 | [img, 208 | Matrix.create_transration(0,0,-1000) * 209 | Matrix.create_rotation_y(a+idx*72) * 210 | Matrix.create_transration(0,0,1000) * 211 | Matrix.create_rotation_x(20) * 212 | Matrix.create_transration(300,300,1500) 213 | ] 214 | }.sort_by{|ary| 215 | -(Vector.new(0,0,0,1) * ary[1]).z 216 | }.each do |ary| 217 | shader.g_world = ary[1].to_a 218 | Window.draw_shader(-ary[0].width/2, -ary[0].height/2, ary[0], shader) 219 | end 220 | break if Input.key_push?(K_ESCAPE) 221 | end 222 | 223 | 224 | -------------------------------------------------------------------------------- /sample/shader_sample/sample_wingman.rb: -------------------------------------------------------------------------------- 1 | require 'dxruby' 2 | require './shader/rgsssprite' 3 | 4 | Window.width = 800 5 | Window.height = 600 6 | 7 | class Wingman 8 | @@image = Image.load('./bgimage/BG42a.jpg') 9 | @@shader = SpriteShader.new 10 | def initialize 11 | @count = 0 12 | @flag = false 13 | @@shader.gray = 255 14 | end 15 | def start 16 | @flag = true 17 | end 18 | def update 19 | @count += 2 if @flag 20 | end 21 | def draw 22 | if @count < 180 23 | Window.draw_ex(0, 0, @@image, :alpha => 128, :blend => :add, :angle => @count) 24 | Window.draw_ex(0, 0, @@image, :alpha => 128, :blend => :add, :angle => -@count) 25 | elsif @count < 300 26 | @@shader.gray = (@count - 180) * 255 / 120 27 | Window.draw_ex(0, 0, @@image, :angle => 180, :shader => @@shader) 28 | else 29 | Window.draw_ex(0, 0, @@image, :angle => 180, :shader => @@shader) 30 | end 31 | end 32 | end 33 | 34 | w = Wingman.new 35 | 36 | Window.loop do 37 | w.update 38 | w.draw 39 | w.start if Input.key_push?(K_SPACE) 40 | break if Input.key_push?(K_ESCAPE) 41 | end 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /sample/shader_sample/turn_transition.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirichi/dxruby/0aded5738c6f3659e26e8cfc076428788178db6e/sample/shader_sample/turn_transition.rb --------------------------------------------------------------------------------