stylet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +4 -0
- data/.yardopts +2 -0
- data/Gemfile +16 -0
- data/README.org +19 -0
- data/Rakefile +17 -0
- data/bin/setup +63 -0
- data/bin/stylet +8 -0
- data/examples/.ruby-version +1 -0
- data/examples/00100_lib_hello_world.rb +8 -0
- data/examples/00110_lib_sge_check.rb +6 -0
- data/examples/00120_lib_/343/202/254/343/203/263/343/203/236/345/200/244/343/201/256/345/244/211/346/233/264.rb +22 -0
- data/examples/00130_lib_window_title.rb +8 -0
- data/examples/00140_lib_callbacks.rb +8 -0
- data/examples/00150_lib_vector.rb +5 -0
- data/examples/00160_lib_run.rb +4 -0
- data/examples/00170_lib_frame.rb +4 -0
- data/examples/00180_lib_config/347/242/272/350/252/215.rb +7 -0
- data/examples/00190_lib_/343/201/231/343/201/271/343/201/246/345/220/214/343/201/230/343/202/252/343/203/226/343/202/270/343/202/247/343/202/257/343/203/210.rb +10 -0
- data/examples/00200_lib_/343/203/254/343/202/267/343/203/274/343/203/220/343/203/274/343/202/222/347/234/201/347/225/245/343/201/231/343/202/213/346/226/271/346/263/225/343/201/256/343/203/206/343/202/271/343/203/210.rb +28 -0
- data/examples/00210_lib_delegators.rb +7 -0
- data/examples/00220_lib_template_method.rb +13 -0
- data/examples/00230_lib_/350/203/214/346/231/257/347/224/273/345/203/217/350/241/250/347/244/272.rb +9 -0
- data/examples/00240_lib_/350/203/214/346/231/257/347/224/273/345/203/217/343/202/222/346/232/227/343/201/2171_/351/273/222/343/201/256/344/270/212/343/201/253/350/203/214/346/231/257.rb +18 -0
- data/examples/00250_lib_/350/203/214/346/231/257/347/224/273/345/203/217/343/202/222/346/232/227/343/201/2172_/350/203/214/346/231/257/343/201/256/344/270/212/343/201/253/351/273/222.rb +17 -0
- data/examples/00260_lib_/350/203/214/346/231/257/347/224/273/345/203/217/343/202/222/346/232/227/343/201/2173_/350/203/214/346/231/257/343/201/256/344/270/212/343/201/253/351/273/222_/347/224/273/351/235/242/343/202/265/343/202/244/343/202/272/343/203/225/343/202/243/343/203/203/343/203/210_/351/207/215/343/201/204.rb +27 -0
- data/examples/00270_lib_/350/203/214/346/231/257/347/224/273/345/203/217/343/202/222/346/232/227/343/201/2173_/350/203/214/346/231/257/343/201/256/344/270/212/343/201/253/351/273/222_/347/224/273/351/235/242/343/202/265/343/202/244/343/202/272/343/203/225/343/202/243/343/203/203/343/203/210_/351/253/230/351/200/237/345/214/226.rb +44 -0
- data/examples/00280_lib_/347/211/271/345/256/232/343/201/256/343/202/250/343/203/252/343/202/242/343/201/240/343/201/221/345/276/220/343/200/205/343/201/253/346/266/210/343/201/231.rb +26 -0
- data/examples/00290_lib_/350/203/214/346/231/257/350/211/262/345/244/211/346/233/264.rb +5 -0
- data/examples/00300_lib_/343/202/255/343/203/243/343/203/251/343/202/257/343/202/277/347/224/273/345/203/217/343/202/222/350/241/250/347/244/272/343/201/231/343/202/213/344/276/213.rb +17 -0
- data/examples/00310_lib_/343/202/255/343/203/243/343/203/251/343/202/257/343/202/277/347/224/273/345/203/217/343/201/256/343/202/242/343/203/213/343/203/241/343/203/274/343/202/267/343/203/247/343/203/263.rb +18 -0
- data/examples/00320_lib_/343/202/255/343/203/243/343/203/251/343/202/257/343/202/277/346/213/241/345/244/247/347/270/256/345/260/217/345/233/236/350/273/242.rb +21 -0
- data/examples/00330_joystick.rb +5 -0
- data/examples/00340_joystick_PS3/343/202/242/343/203/212/343/203/255/343/202/260/343/203/254/343/203/220/343/203/274/343/201/256/345/213/225/343/201/215/343/201/214/345/206/205/351/203/250/343/201/247/343/201/257/345/233/233/350/247/222.rb +30 -0
- data/examples/00350_joystick_PS3/343/202/242/343/203/212/343/203/255/343/202/260/343/203/254/343/203/220/343/203/274/343/201/256/350/252/277/346/225/264/346/270/210/343/201/277/343/203/231/343/202/257/343/203/210/343/203/253.rb +12 -0
- data/examples/00360_lib_mouse.rb +5 -0
- data/examples/00370_lib_input.rb +29 -0
- data/examples/00380_lib_vputs_align.rb +8 -0
- data/examples/00390_/343/203/225/343/202/251/343/203/263/343/203/210/344/270/200/350/246/247.rb +15 -0
- data/examples/00400_lib_draw_circle.rb +8 -0
- data/examples/00410_SDL/343/201/256draw_rect/343/201/2571/343/203/224/343/202/257/343/202/273/343/203/253/344/275/231/345/210/206/343/201/253/346/217/217/347/224/273/343/201/225/343/202/214/343/202/213/343/201/256/343/201/247/346/263/250/346/204/217.rb +7 -0
- data/examples/00420_circle_on_circle.rb +10 -0
- data/examples/00430_rotate.rb +16 -0
- data/examples/00440_draw_triangle.rb +7 -0
- data/examples/00450_parabora_triangle.rb +37 -0
- data/examples/00460_ice_hockey.rb +88 -0
- data/examples/00470_collision_block_vs_block.rb +120 -0
- data/examples/00480_simple_circle_controll.rb +37 -0
- data/examples/00490_/347/255/211/351/200/237/347/247/273/345/213/225_uniform_velocity_rain.rb +51 -0
- data/examples/00500_/345/212/240/351/200/237/346/224/276/347/211/251/347/267/232_parabora_volcano.rb +94 -0
- data/examples/00510_3d.rb +53 -0
- data/examples/00520_/343/203/210/343/203/253/343/203/215/343/201/256/343/203/241/343/203/213/343/203/245/343/203/274/351/242/250/343/201/256/345/213/225/343/201/215.rb +77 -0
- data/examples/00530_curve_2/346/254/241/343/203/231/343/202/270/343/202/247/346/233/262/347/267/232/343/201/250/347/233/264/347/267/232/343/201/250/343/201/256/344/272/244/347/202/271.rb +43 -0
- data/examples/00540_curve_3/346/254/241/343/203/231/343/202/270/343/202/247/346/233/262/347/267/232.rb +40 -0
- data/examples/00550_curve_N/346/254/241/343/203/231/343/202/270/343/202/247/346/233/262/347/267/232.rb +92 -0
- data/examples/00560_curve_/343/202/271/343/203/227/343/203/251/343/202/244/343/203/263/346/233/262/347/267/232.rb +113 -0
- data/examples/00570_/345/206/206/351/201/213/345/213/225_circle_jet_coaster.rb +52 -0
- data/examples/00580_/345/206/206/343/202/222/346/212/274/343/201/231/343/201/262/343/201/243/343/201/261/343/202/213_collision_circle_vs_circle_push_or_pull.rb +56 -0
- data/examples/00590_/350/212/213/350/231/253/343/202/264/343/203/240/347/264/220/343/203/207/343/203/242_collision_demo_circle_worm.rb +104 -0
- data/examples/00600_/346/214/257/343/202/212/345/255/220_swing.rb +145 -0
- data/examples/00610_/345/206/205/347/251/215/343/201/250/345/244/226/347/251/215_inner_product.rb +36 -0
- data/examples/00620_/346/263/225/347/267/232/343/203/231/343/202/257/343/203/210/343/203/253.rb +23 -0
- data/examples/00630_/345/206/206/343/201/250/345/206/206/343/201/256/345/217/215/345/260/204_collision_reflect_circle_vs_circle.rb +222 -0
- data/examples/00640_/347/202/271/343/201/250/347/267/232/345/210/206/343/201/256/344/272/244/345/267/256/345/210/244/345/256/232_collision_ray_circle_vs_line.rb +261 -0
- data/examples/00650_/345/206/206/343/201/250/347/202/271/343/201/256/345/217/215/345/260/204_collision_circle_vs_dot.rb +36 -0
- data/examples/00660_/345/206/206/343/201/250/345/206/206/343/201/250/347/267/232/345/210/206/343/201/256/345/217/215/345/260/204/343/203/207/343/203/242_collision_demo.rb +305 -0
- data/examples/00670_/343/203/251/343/202/244/343/203/225/343/202/262/343/203/274/343/203/240.rb +86 -0
- data/examples/00680_2/347/202/271/343/202/222/351/200/232/343/202/213/347/233/264/347/267/232/343/201/256/346/226/271/347/250/213/345/274/217.rb +81 -0
- data/examples/00690_/343/203/222/343/203/253/343/203/231/343/203/253/343/203/210/346/233/262/347/267/232.rb +77 -0
- data/examples/00700_/343/202/263/343/203/203/343/203/233/346/233/262/347/267/232.rb +79 -0
- data/examples/00710_/343/202/267/343/202/260/343/203/242/343/202/244/343/203/211/346/233/262/347/267/232.rb +40 -0
- data/examples/00720_/343/202/267/343/203/200/346/244/215/347/211/251.rb +44 -0
- data/examples/00730_/343/202/257/343/203/252/343/203/225/343/202/251/343/203/274/343/203/211/343/202/242/343/203/210/343/203/251/343/202/257/343/202/277_/345/237/272/346/234/254.rb +29 -0
- data/examples/00740_/343/202/257/343/203/252/343/203/225/343/202/251/343/203/274/343/203/211/343/202/242/343/203/210/343/203/251/343/202/257/343/202/277_/346/224/271/350/211/257_/350/211/262/344/273/230/343/201/215.rb +68 -0
- data/examples/00750_/343/202/257/343/203/252/343/203/225/343/202/251/343/203/274/343/203/211/343/202/242/343/203/210/343/203/251/343/202/257/343/202/277_/343/203/211/343/203/274/343/203/212/343/203/204/345/236/213.rb +44 -0
- data/examples/00760_/347/201/253/350/212/261.rb +42 -0
- data/examples/00770_atan/343/201/247atan2/343/202/222/346/233/270/343/201/217.rb +26 -0
- data/examples/00780_/346/250/231/346/272/226/343/203/251/343/202/244/343/203/226/343/203/251/343/203/252/343/201/256atan2_sin_cos/343/202/222/344/275/277/343/201/206.rb +15 -0
- data/examples/00790_/350/247/222/345/272/246/343/201/250/343/203/251/343/202/270/343/202/242/343/203/263/343/201/256/347/233/270/344/272/222/345/244/211/346/217/233.rb +22 -0
- data/examples/00800_/347/220/203/343/201/214/347/233/264/347/267/232/347/232/204/343/201/253/345/213/225/343/201/204/343/201/246/343/201/204/343/202/213/343/201/240/343/201/221/343/201/247/345/233/236/350/273/242/343/201/227/343/201/246/343/201/204/343/202/213/343/202/210/343/201/206/343/201/253/350/246/213/343/201/210/343/202/213.rb +27 -0
- data/examples/00810_/343/202/267/343/203/237/343/203/245/343/203/254/343/203/274/343/202/267/343/203/247/343/203/263_/350/273/212.rb +75 -0
- data/examples/00820_/343/202/267/343/203/237/343/203/245/343/203/254/343/203/274/343/202/267/343/203/247/343/203/263_/346/210/246/350/273/212.rb +90 -0
- data/examples/00830_/350/247/222/345/272/246/345/267/256.rb +36 -0
- data/examples/00840_/346/224/276/347/211/251/347/267/232/343/201/247/347/213/231/346/222/203_/346/231/202/351/226/223/345/233/272/345/256/232.rb +61 -0
- data/examples/00850_/346/224/276/347/211/251/347/267/232/343/201/247/347/213/231/346/222/203_/350/247/222/345/272/246/345/233/272/345/256/232.rb +84 -0
- data/examples/00860_/346/224/276/347/211/251/347/267/232/343/201/247/347/213/231/346/222/203_/351/200/237/345/272/246/345/233/272/345/256/232.rb +66 -0
- data/examples/00870_/350/247/222/345/272/246/350/243/234/346/255/243_/345/212/240/351/200/237/343/203/237/343/202/265/343/202/244/343/203/253.rb +60 -0
- data/examples/00880_/345/210/235/351/200/237/343/201/214/351/200/237/343/201/204/343/203/237/343/202/265/343/202/244/343/203/253.rb +51 -0
- data/examples/00890_/346/255/243/350/246/217/344/271/261/346/225/260/343/201/250/346/250/231/346/272/226/345/201/217/345/267/256/343/201/256/345/217/257/350/246/226/345/214/226.rb +72 -0
- data/examples/00900_/345/220/221/345/277/203/345/212/233/343/201/247/345/233/236/350/273/242/343/200/220/350/247/222/345/272/2460/345/272/246/343/201/213/343/202/211/343/200/221.rb +23 -0
- data/examples/00910_/345/220/221/345/277/203/345/212/233/343/201/247/345/233/236/350/273/242/343/200/220/344/273/273/346/204/217/343/201/256/350/247/222/345/272/246/343/201/213/343/202/211/343/200/221.rb +33 -0
- data/examples/00920_/343/203/236/343/203/252/343/202/252/343/203/226/343/203/251/343/202/266/343/203/274/343/202/272/351/242/250/343/201/253/347/224/273/351/235/242/344/270/241/347/253/257/343/201/214/347/271/213/343/201/243/343/201/246/343/201/204/343/202/213/344/276/213.rb +29 -0
- data/examples/00930_/345/212/271/346/236/234/351/237/263.rb +17 -0
- data/examples/00940_/343/203/236/343/203/203/343/203/227/343/203/201/343/203/203/343/203/227/343/201/256/343/203/236/343/203/203/343/203/227/351/205/215/347/275/256.rb +71 -0
- data/examples/00950_/343/203/236/343/203/203/343/203/227/343/203/201/343/203/203/343/203/227/343/201/256/350/241/250/347/244/272/344/276/213.rb +28 -0
- data/examples/00960_/343/203/236/343/203/203/343/203/227/343/203/201/343/203/203/343/203/227/343/201/250/345/215/230/344/270/200/347/224/273/345/203/217/343/201/256/351/201/225/343/201/204/343/202/222/345/220/270/345/217/216/343/201/231/343/202/213/344/276/213.rb +47 -0
- data/examples/00970_observer_/343/201/235/343/201/2561_/347/233/264/346/216/245.rb +28 -0
- data/examples/00980_observer_/343/201/235/343/201/2562_/346/231/256/351/200/232/343/201/253Singleton/347/211/210.rb +30 -0
- data/examples/00990_observer_/343/201/235/343/201/2563_SimpleDelegator/347/211/210.rb +28 -0
- data/examples/01000_observer_/343/201/235/343/201/2564_/351/200/206/343/201/253/343/203/253/343/203/274/343/203/227/344/270/273/345/260/216.rb +28 -0
- data/examples/01010_observer_/343/201/235/343/201/2565_/343/201/204/343/202/215/343/202/223/343/201/252/346/211/200/343/201/213/343/202/211/345/221/274/343/202/223/343/201/247/343/201/204/343/202/213/343/201/221/343/201/251Singleton/343/201/252/343/201/256/343/201/247/345/256/211/345/205/250.rb +37 -0
- data/examples/01020_observer_/343/201/235/343/201/2566_/343/201/204/343/202/215/343/202/223/343/201/252/346/211/200/343/201/213/343/202/211/345/221/274/343/201/266/345/240/264/345/220/210callbacks/343/202/222/344/275/277/343/202/217/343/201/252/343/201/204/343/202/210/343/201/206/343/201/253.rb +30 -0
- data/examples/01030_observer_/343/201/235/343/201/2567_/343/202/250/343/203/225/343/202/247/343/202/257/343/203/210/343/202/277/343/202/271/343/202/257/343/202/222/345/233/236/343/201/231/344/276/213.rb +57 -0
- data/examples/01040_/343/203/236/343/202/246/343/202/271/343/201/256/344/275/215/347/275/256/343/201/253/343/203/224/343/202/257/343/202/273/343/203/253/343/202/222/346/211/223/343/201/244.rb +18 -0
- data/examples/01050_/343/203/224/343/202/257/343/202/273/343/203/253/345/205/250/344/275/223/343/202/222/346/233/270/343/201/215/350/276/274/343/202/200.rb +27 -0
- data/examples/01060_effect_/347/224/273/345/203/217/343/201/256/343/202/263/343/203/263/343/203/234/343/203/252/343/203/245/343/203/274/343/203/210/346/263/225/343/201/253/343/202/210/343/202/213/343/202/250/343/203/225/343/202/247/343/202/257/343/203/210/345/207/246/347/220/206.rb +116 -0
- data/examples/01070_effect_FF7/343/201/256/346/210/246/351/227/230/343/201/253/345/205/245/343/202/213/343/201/250/343/201/215/343/201/256/343/202/250/343/203/225/343/202/247/343/202/257/343/203/210.rb +33 -0
- data/examples/01080_effect_/350/203/214/346/231/257/343/202/222/347/267/251/343/201/217/346/266/210/343/201/227/343/201/246/343/201/204/343/201/217/343/201/250/343/202/271/343/203/240/343/203/274/343/202/272/343/201/253/343/201/252/343/202/213.rb +16 -0
- data/examples/01090_/347/224/273/345/203/217/343/201/256/343/202/257/343/203/255/343/202/271/343/203/225/343/202/247/343/203/274/343/203/211.rb +37 -0
- data/examples/01100_/343/202/271/343/202/257/343/203/252/343/203/274/343/203/263/346/203/205/345/240/261.rb +8 -0
- data/examples/01110_lib_contrib_menu.rb +19 -0
- data/examples/01120_/351/233/233/345/236/213_2P/345/257/276/346/210/246/351/242/250STG.rb +109 -0
- data/examples/01130_/351/233/233/345/236/213_/346/210/246/350/273/212/345/257/276/346/210/246.rb +396 -0
- data/examples/01140_/351/233/233/345/236/213_2P/345/257/276/346/210/246.rb +60 -0
- data/examples/01150_/351/233/233/345/236/213_/343/202/271/343/203/274/343/203/221/343/203/274/343/203/236/343/203/252/343/202/252/351/242/250/343/202/242/343/202/257/343/202/267/343/203/247/343/203/263.rb +1251 -0
- data/examples/01160_2D/343/202/242/343/203/225/343/202/243/343/203/263/345/244/211/346/217/233.rb +40 -0
- data/examples/01170_stackprof.rb +10 -0
- data/examples/01180_sdl_/343/202/242/343/203/253/343/203/225/343/202/241/343/203/226/343/203/254/343/203/263/343/203/207/343/202/243/343/203/263/343/202/260/343/201/247/351/207/215/343/201/255/345/220/210/343/201/233/345/241/227/343/202/212/346/275/260/343/201/227.rb +11 -0
- data/examples/01190_/343/203/221/343/203/274/343/203/206/343/202/243/343/202/257/343/203/253/345/220/214/345/243/253/343/201/247/344/270/255/345/244/256/343/201/253/345/220/221/343/201/213/343/201/206.rb +79 -0
- data/examples/01200_lib_OpenGL.rb +55 -0
- data/examples/bezier.rb +202 -0
- data/examples/cursor.rb +50 -0
- data/examples/helper.rb +38 -0
- data/examples/lifegame_patterns.rb +102 -0
- data/examples/movable_point.rb +64 -0
- data/examples/mtx33.rb +294 -0
- data/examples/setup.rb +5 -0
- data/examples/stage_infos.rb +1 -0
- data/examples/start.sh +2 -0
- data/examples/test_all.rb +5 -0
- data/examples/testgl.rb +228 -0
- data/examples/trash/__0060_shooting2.rb +37 -0
- data/examples/trash/__0090_collision_circle1.rb +50 -0
- data/examples/trash/__0125_circle_collision.rb +103 -0
- data/examples/trash/__0130_circle_collision2.rb +60 -0
- data/examples/trash/__0270_circle_cycle_shift.rb +29 -0
- data/examples/trash/__bullet_algos.rb +224 -0
- data/examples/trash/gunship.rb +39 -0
- data/examples//343/203/227/343/203/255/343/202/270/343/202/247/343/202/257/343/202/277/343/203/274/343/201/253/350/241/250/347/244/272/343/201/231/343/202/213/343/201/250/343/201/215.sh +2 -0
- data/lib/stylet.rb +1 -0
- data/lib/stylet/application_memory_record.rb +33 -0
- data/lib/stylet/audio.rb +455 -0
- data/lib/stylet/axis_support.rb +62 -0
- data/lib/stylet/base.rb +76 -0
- data/lib/stylet/callbacks.rb +62 -0
- data/lib/stylet/cli.rb +54 -0
- data/lib/stylet/collision_support.rb +56 -0
- data/lib/stylet/config.rb +39 -0
- data/lib/stylet/contrib/menu.rb +508 -0
- data/lib/stylet/contrib/shared_pad.rb +32 -0
- data/lib/stylet/contrib/sprity.rb +149 -0
- data/lib/stylet/core.rb +118 -0
- data/lib/stylet/cpu_stat.rb +58 -0
- data/lib/stylet/delegators.rb +54 -0
- data/lib/stylet/draw.rb +256 -0
- data/lib/stylet/draw_support/arrow.rb +56 -0
- data/lib/stylet/draw_support/circle.rb +63 -0
- data/lib/stylet/draw_support/polygon.rb +22 -0
- data/lib/stylet/font.rb +172 -0
- data/lib/stylet/fps_adjust.rb +23 -0
- data/lib/stylet/fps_stat.rb +41 -0
- data/lib/stylet/input.rb +8 -0
- data/lib/stylet/input/base.rb +105 -0
- data/lib/stylet/input/hardware_bindings.rb +65 -0
- data/lib/stylet/input/key_one.rb +162 -0
- data/lib/stylet/input/support.rb +72 -0
- data/lib/stylet/joystick.rb +31 -0
- data/lib/stylet/joystick_adapter.rb +130 -0
- data/lib/stylet/joystick_adapters/buffalo_snes_adapter.rb +47 -0
- data/lib/stylet/joystick_adapters/elecom_usb_pad_adapter.rb +30 -0
- data/lib/stylet/joystick_adapters/hori_rap_v3_sa_adapter.rb +46 -0
- data/lib/stylet/joystick_adapters/ps3_standard_adapter.rb +40 -0
- data/lib/stylet/joystick_adapters/unknown_adapter.rb +13 -0
- data/lib/stylet/keyboard.rb +15 -0
- data/lib/stylet/logger.rb +12 -0
- data/lib/stylet/mouse.rb +58 -0
- data/lib/stylet/palette.rb +17 -0
- data/lib/stylet/rect.rb +113 -0
- data/lib/stylet/shortcut.rb +8 -0
- data/lib/stylet/state.rb +87 -0
- data/lib/stylet/stylet.rb +44 -0
- data/lib/stylet/system_pause.rb +24 -0
- data/lib/stylet/version.rb +3 -0
- data/log/.gitkeep +0 -0
- data/stylet.gemspec +31 -0
- data/test/test_helper.rb +6 -0
- data/test/test_input_base.rb +12 -0
- data/test/test_input_key_one.rb +43 -0
- data/test/test_input_support.rb +47 -0
- data/test/test_sample.rb +13 -0
- data/test/test_state.rb +26 -0
- data/tips.org +16 -0
- metadata +391 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# 円の動き
|
3
|
+
#
|
4
|
+
require_relative "helper"
|
5
|
+
|
6
|
+
class Ball
|
7
|
+
def initialize(win)
|
8
|
+
@win = win
|
9
|
+
end
|
10
|
+
|
11
|
+
def update
|
12
|
+
pos = vec2.zero
|
13
|
+
pos.x = Stylet::Magic.rcos(1.0 / 512 * (@win.frame_counter * 3)) * @win.srect.w / 2
|
14
|
+
pos.y = Stylet::Magic.rsin(1.0 / 512 * (@win.frame_counter * 4)) * @win.srect.h / 2
|
15
|
+
pos += @win.srect.center
|
16
|
+
@win.draw_polygon(pos, :radius => 64)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class App < Stylet::Base
|
21
|
+
include Helper::CursorWithObjectCollection
|
22
|
+
|
23
|
+
setup do
|
24
|
+
@cursor.display = false
|
25
|
+
@objects << Ball.new(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
run
|
29
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
$LOAD_PATH << ".." if $0 == __FILE__
|
2
|
+
require "shooting"
|
3
|
+
|
4
|
+
# 狙い撃ち弾
|
5
|
+
# n-way弾
|
6
|
+
# 円形弾
|
7
|
+
# 分裂弾
|
8
|
+
# 誘導弾
|
9
|
+
# 誘導レーザー
|
10
|
+
# ミサイル
|
11
|
+
# 加速弾
|
12
|
+
# 落下弾
|
13
|
+
# 狙い撃ち弾+回転弾 # 回転弾が自機を狙う
|
14
|
+
# 渦巻き弾
|
15
|
+
# 停止する誘導弾
|
16
|
+
# 直進するビーム
|
17
|
+
|
18
|
+
module BulletDir
|
19
|
+
def compute
|
20
|
+
super
|
21
|
+
@target_dir = Magic.angle(@x, @y, @target.x, @target.y)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module BulletNeraiutidan
|
26
|
+
def compute
|
27
|
+
super
|
28
|
+
if @win.press_button?(SDL::Key::K1) || (joy && joy.button(0))
|
29
|
+
if @frame_counter.modulo(60 / 10).zero?
|
30
|
+
@win.bullets << Bullet.new(@win, @x, @y, @target_dir, 5.00)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Bullet2 < BulletBase
|
37
|
+
include CircleGrid
|
38
|
+
|
39
|
+
def initialize(target, *args)
|
40
|
+
@target = target
|
41
|
+
super(*args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def compute
|
45
|
+
compute_sincos
|
46
|
+
unless @win.pause_mode
|
47
|
+
if @frame_counter.modulo(1).zero?
|
48
|
+
d = Magic.angle(@x, @y, @target.x, @target.y)
|
49
|
+
gap = (d - @dir) % 1.00
|
50
|
+
if gap >= 0.5
|
51
|
+
sign = -1
|
52
|
+
else
|
53
|
+
sign = +1
|
54
|
+
end
|
55
|
+
@dir = (@dir + (1.0 / 256) * sign) % 1.0
|
56
|
+
@cx = @x
|
57
|
+
@cy = @y
|
58
|
+
@radius = @speed
|
59
|
+
@speed += 0.1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
module BulletTuibi
|
66
|
+
def compute
|
67
|
+
super
|
68
|
+
if @win.press_button?(SDL::Key::K2) || (joy && joy.button(1))
|
69
|
+
div, mod = @frame_counter.divmod(60 / 10)
|
70
|
+
if mod.zero?
|
71
|
+
wide = 2
|
72
|
+
@win.bullets << Bullet2.new(@target, @win, @x, @y, @target_dir + rand * 1.0 / wide - 1.0 / (wide * 2), 1.0)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module Bullet3waydan
|
79
|
+
def compute
|
80
|
+
super
|
81
|
+
if @win.press_button?(SDL::Key::K4) || (joy && joy.button(2))
|
82
|
+
if @frame_counter.modulo(60 / 5).zero?
|
83
|
+
gap = 1.0 / 64
|
84
|
+
n = 3
|
85
|
+
n.times {|i|
|
86
|
+
d = @target_dir - (n / 2 * gap) + gap * i
|
87
|
+
@win.bullets << Bullet.new(@win, @x, @y, d, 5.00)
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
module BulletRandom
|
95
|
+
def compute
|
96
|
+
super
|
97
|
+
if @win.press_button?(SDL::Key::K3) || (joy && joy.button(3))
|
98
|
+
if @frame_counter.modulo(60 / 20).zero?
|
99
|
+
z = 1.0 / 24
|
100
|
+
d = @target_dir + (rand * z - z / 2) * 2
|
101
|
+
@win.bullets << Bullet.new(@win, @x, @y, d, 7)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
module BulletUzumaki
|
108
|
+
def initialize(*)
|
109
|
+
super
|
110
|
+
@uzumaki_count = 0
|
111
|
+
end
|
112
|
+
|
113
|
+
def compute
|
114
|
+
super
|
115
|
+
if @win.press_button?(SDL::Key::K5) || (joy && joy.button(4))
|
116
|
+
div, mod = @frame_counter.divmod(60 / 20)
|
117
|
+
if mod.zero?
|
118
|
+
n = 4
|
119
|
+
n.times {|i|
|
120
|
+
d = 1.0 / n * i + (Magic.rsin(1.0 / 32 * div) * 0.1)
|
121
|
+
@win.bullets << Bullet.new(@win, @x, @y, d, 2)
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
module BulletUzumakix2
|
129
|
+
def compute
|
130
|
+
super
|
131
|
+
if @win.press_button?(SDL::Key::K6) || (joy && joy.button(5))
|
132
|
+
div, mod = @frame_counter.divmod(60 / 10)
|
133
|
+
if mod.zero?
|
134
|
+
uzumaki2(div, +1)
|
135
|
+
uzumaki2(div, -1)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def uzumaki2(frame_counter, sign)
|
141
|
+
n = 5
|
142
|
+
gap = 1.0 / n
|
143
|
+
n.times {|i|
|
144
|
+
d = (n / 2 * gap) + gap * i + (frame_counter * 1.0 / 120 * sign) + (frame_counter * 0.001)
|
145
|
+
@win.bullets << Bullet.new(@win, @x, @y, d, 2.0)
|
146
|
+
}
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
module Bullet128waydan
|
151
|
+
def compute
|
152
|
+
super
|
153
|
+
if @win.press_button?(SDL::Key::K7) || (joy && joy.button(6))
|
154
|
+
if @frame_counter.modulo(60 / 2).zero?
|
155
|
+
n = 64
|
156
|
+
gap = 1.0 / n
|
157
|
+
n.times {|i|
|
158
|
+
@win.bullets << Bullet.new(@win, @x, @y, gap * i, 4.00)
|
159
|
+
}
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
module BulletUzumakix2Fast
|
166
|
+
def compute
|
167
|
+
super
|
168
|
+
if @win.press_button?(SDL::Key::K8) || (joy && joy.button(7))
|
169
|
+
div, mod = @frame_counter.divmod(60 / 20)
|
170
|
+
if mod.zero?
|
171
|
+
uzumaki2fast(div, +1)
|
172
|
+
uzumaki2fast(div, -1)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def uzumaki2fast(frame_counter, sign)
|
178
|
+
n = 3
|
179
|
+
gap = 1.0 / n
|
180
|
+
n.times {|i|
|
181
|
+
d = (n / 2 * gap) + gap * i + (frame_counter * 1.0 / 120 * sign) + (frame_counter * 0.001)
|
182
|
+
@win.bullets << Bullet.new(@win, @x, @y, d, 6.0)
|
183
|
+
}
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
class GunShipA < GunShip1
|
188
|
+
include BulletDir
|
189
|
+
include BulletNeraiutidan
|
190
|
+
include BulletTuibi
|
191
|
+
include Bullet3waydan
|
192
|
+
include BulletRandom
|
193
|
+
include BulletUzumaki
|
194
|
+
include BulletUzumakix2
|
195
|
+
include Bullet128waydan
|
196
|
+
include BulletUzumakix2Fast
|
197
|
+
end
|
198
|
+
|
199
|
+
class GunShipB < GunShip2
|
200
|
+
include BulletDir
|
201
|
+
include BulletNeraiutidan
|
202
|
+
include BulletTuibi
|
203
|
+
include Bullet3waydan
|
204
|
+
include BulletRandom
|
205
|
+
include BulletUzumaki
|
206
|
+
include BulletUzumakix2
|
207
|
+
include Bullet128waydan
|
208
|
+
include BulletUzumakix2Fast
|
209
|
+
end
|
210
|
+
|
211
|
+
class Application < WarSpace
|
212
|
+
def initialize
|
213
|
+
super
|
214
|
+
@draw_inst = Stylet::Sdl::Draw.instance
|
215
|
+
ship1 = GunShipA.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 1)
|
216
|
+
ship2 = GunShipB.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 7)
|
217
|
+
ship1.target = ship2
|
218
|
+
ship2.target = ship1
|
219
|
+
@ships << ship1
|
220
|
+
@ships << ship2
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
Application.new.run
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class GunShip
|
2
|
+
include Stylet::Input::Base
|
3
|
+
|
4
|
+
attr_reader :pos
|
5
|
+
attr_accessor :target
|
6
|
+
|
7
|
+
def initialize(win, pos)
|
8
|
+
super()
|
9
|
+
@win = win
|
10
|
+
@pos = pos
|
11
|
+
@speed = 3
|
12
|
+
@target = nil
|
13
|
+
@size = 8
|
14
|
+
@joystick_index = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def update
|
18
|
+
super if defined? super
|
19
|
+
|
20
|
+
if @joystick_index
|
21
|
+
bit_update_by_joy(@win.joys[@joystick_index])
|
22
|
+
end
|
23
|
+
key_bit_update_all
|
24
|
+
key_counter_update_all
|
25
|
+
|
26
|
+
if dir = axis_angle
|
27
|
+
x = @pos.x + Stylet::Magic.rcos(dir) * @speed
|
28
|
+
y = @pos.y + Stylet::Magic.rsin(dir) * @speed
|
29
|
+
if (@win.srect.min_x..@win.srect.max_x).include?(x)
|
30
|
+
@pos.x = x
|
31
|
+
end
|
32
|
+
if (@win.srect.min_y..@win.srect.max_y).include?(y)
|
33
|
+
@pos.y = y
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
@win.draw_rect(Stylet::Rect4.new(@pos.x - @size, @pos.y - @size, @size * 2, @size * 2))
|
38
|
+
end
|
39
|
+
end
|
data/lib/stylet.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'stylet/stylet'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "memory_record"
|
2
|
+
|
3
|
+
module Stylet
|
4
|
+
module ApplicationMemoryRecord
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include MemoryRecord
|
9
|
+
end
|
10
|
+
|
11
|
+
class_methods do
|
12
|
+
def info
|
13
|
+
collect(&:to_h).to_t
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def info
|
18
|
+
to_h.to_t
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_h
|
22
|
+
attributes
|
23
|
+
end
|
24
|
+
|
25
|
+
def name_with_key
|
26
|
+
"#{name} (#{key})"
|
27
|
+
end
|
28
|
+
|
29
|
+
def logger
|
30
|
+
Stylet.logger
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/stylet/audio.rb
ADDED
@@ -0,0 +1,455 @@
|
|
1
|
+
# 曲と効果音の管理
|
2
|
+
#
|
3
|
+
# 曲
|
4
|
+
#
|
5
|
+
# Music.play("path/to/foo.wav")
|
6
|
+
#
|
7
|
+
# 効果音
|
8
|
+
#
|
9
|
+
# SE.load("path/to/foo.wav")
|
10
|
+
# SE[:foo].play
|
11
|
+
#
|
12
|
+
# ・表示系のライブラリとは独立
|
13
|
+
# ・チャンネルとWAVの音量は独立している
|
14
|
+
# ・SEの解放時、対応チャンネルを誰も使わなくなっていたら消して再割り当てする
|
15
|
+
# ・SE.preparation_channels SE自由席の数。
|
16
|
+
# ・チャンネルは先頭から [自由席] → [指定席] の順で使うようにしている。これ重要。
|
17
|
+
# もし自由席の方が後だったらおかしなことになる。
|
18
|
+
# SDLは《先頭から》空いているチャンネルを探して使う。
|
19
|
+
# 開始合図のラッパが0チャンネルが空いてるからと思って使った直後に0チャンネルを使う予定のSEが鳴ったらラッパの音消えてしまう。
|
20
|
+
# したがってチャンネルは[自由席][指定席]の順になっている
|
21
|
+
#
|
22
|
+
require 'pathname'
|
23
|
+
require 'singleton'
|
24
|
+
require 'active_support/core_ext/module/delegation' # Defines Module#delegate.
|
25
|
+
require 'active_support/core_ext/module/attribute_accessors' # Defines Module#mattr_accessor
|
26
|
+
|
27
|
+
module Stylet
|
28
|
+
class Audio
|
29
|
+
include Singleton
|
30
|
+
|
31
|
+
# 全体のフィイドアウト秒数
|
32
|
+
cattr_accessor :fade_out_default
|
33
|
+
self.fade_out_default = 2
|
34
|
+
|
35
|
+
class << self
|
36
|
+
alias setup_once instance
|
37
|
+
|
38
|
+
delegate :halt, :to => "Stylet::Audio.instance"
|
39
|
+
|
40
|
+
def volume_cast(v)
|
41
|
+
raise if v.is_a? Integer
|
42
|
+
(Stylet::Chore.clamp(v) / 1.0 * 128).to_i
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
if SDL.inited_system(SDL::INIT_AUDIO).zero?
|
48
|
+
SDL.initSubSystem(SDL::INIT_AUDIO)
|
49
|
+
SDL::Mixer.open(Stylet.config.sound_freq, SDL::Mixer::DEFAULT_FORMAT, 2, 512) # デフォルトの4096では効果音が遅延する
|
50
|
+
spec_check
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def halt
|
55
|
+
Music.halt
|
56
|
+
SE.halt
|
57
|
+
end
|
58
|
+
|
59
|
+
def spec_check
|
60
|
+
return unless Stylet.logger
|
61
|
+
Stylet.logger.debug "SDL::Mixer.driver_name: #{SDL::Mixer.driver_name.inspect}"
|
62
|
+
Stylet.logger.debug "SDL::Mixer.spec: #{Hash[[:frequency, :format, :channels].zip(SDL::Mixer.spec)]}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Music
|
67
|
+
extend self
|
68
|
+
|
69
|
+
# 最後に再生したファイル
|
70
|
+
mattr_accessor :last_music_file
|
71
|
+
self.last_music_file = nil
|
72
|
+
|
73
|
+
# ボリュームの倍率
|
74
|
+
mattr_accessor :volume_magnification
|
75
|
+
self.volume_magnification = 1.0
|
76
|
+
|
77
|
+
def play_by(params)
|
78
|
+
play(params[:filename], params)
|
79
|
+
end
|
80
|
+
|
81
|
+
def play(filename, volume: nil, loop: true, fade_in_sec: nil, **unsed_options)
|
82
|
+
return if Stylet.config.mute_music || Stylet.config.mute
|
83
|
+
|
84
|
+
Audio.setup_once
|
85
|
+
|
86
|
+
filename = Pathname(filename).expand_path
|
87
|
+
if filename.exist?
|
88
|
+
Stylet.logger.debug "play: #{filename}" if Stylet.logger
|
89
|
+
bin = load(filename)
|
90
|
+
loop = loop ? -1 : 0
|
91
|
+
if fade_in_sec
|
92
|
+
SDL::Mixer.fade_in_music(bin, loop, fade_in_sec * 1000.0)
|
93
|
+
else
|
94
|
+
SDL::Mixer.play_music(bin, loop)
|
95
|
+
end
|
96
|
+
self.volume = volume if volume
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def volume=(v)
|
101
|
+
SDL::Mixer.set_volume_music(Audio.volume_cast(v * volume_magnification))
|
102
|
+
end
|
103
|
+
|
104
|
+
def play?
|
105
|
+
SDL::Mixer.play_music?
|
106
|
+
end
|
107
|
+
|
108
|
+
def wait_if_play?
|
109
|
+
SDL.delay(1) while SDL::Mixer.play_music?
|
110
|
+
end
|
111
|
+
|
112
|
+
def halt(fade_out_sec: nil)
|
113
|
+
if fade_out_sec
|
114
|
+
SDL::Mixer.fade_out_music(fade_out_sec * 1000.0)
|
115
|
+
else
|
116
|
+
SDL::Mixer.halt_music
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def fade_out(fade_out_sec: Audio.fade_out_default)
|
121
|
+
halt(fade_out_sec: fade_out_sec)
|
122
|
+
end
|
123
|
+
|
124
|
+
def last_music_file?(filename)
|
125
|
+
last_music_file == Pathname(filename).expand_path.to_s
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def load(filename)
|
131
|
+
destroy
|
132
|
+
filename = Pathname(filename).expand_path.to_s
|
133
|
+
self.last_music_file = filename
|
134
|
+
@muisc = SDL::Mixer::Music.load(filename)
|
135
|
+
end
|
136
|
+
|
137
|
+
def destroy
|
138
|
+
if @muisc
|
139
|
+
raise if @muisc.destroyed?
|
140
|
+
@muisc.destroy
|
141
|
+
@muisc = nil
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
module SE
|
147
|
+
extend self
|
148
|
+
|
149
|
+
mattr_accessor :allocated_channels
|
150
|
+
self.allocated_channels = 0
|
151
|
+
|
152
|
+
mattr_accessor :se_hash
|
153
|
+
self.se_hash = {}
|
154
|
+
|
155
|
+
mattr_accessor :channel_groups
|
156
|
+
self.channel_groups = {}
|
157
|
+
|
158
|
+
# 予約チャンネル数 (channel_auto を使うときに関係してくる)
|
159
|
+
mattr_accessor :preparation_channels
|
160
|
+
self.preparation_channels = 0
|
161
|
+
|
162
|
+
# チャンネルボリュームの初期値
|
163
|
+
# SDL は何もしないと 1.0 だけど音が大きすぎるため全チャンネルを 0.5 としている
|
164
|
+
# WAVE毎にボリュームを設定できるため、この値は固定しておいた方がシンプルになる
|
165
|
+
# この設定は不要かもしれない
|
166
|
+
mattr_accessor :default_master_volume
|
167
|
+
self.default_master_volume = 0.5
|
168
|
+
|
169
|
+
# ボリューム倍率
|
170
|
+
# アプリケーションのオプションなどで効果音の音量を設定するときはこの値を変更する
|
171
|
+
# 実際に反映するのはボリュームを設定したときなので注意
|
172
|
+
mattr_accessor :volume_magnification
|
173
|
+
self.volume_magnification = 1.0
|
174
|
+
|
175
|
+
def [](key)
|
176
|
+
se_hash.fetch(key.to_sym) { NullEffect.new }
|
177
|
+
end
|
178
|
+
|
179
|
+
def exist?(key)
|
180
|
+
se_hash[key.to_sym]
|
181
|
+
end
|
182
|
+
|
183
|
+
def load_once(**params)
|
184
|
+
return if exist?(params[:key])
|
185
|
+
load(params[:filename], params.except(:filename))
|
186
|
+
end
|
187
|
+
|
188
|
+
def load(filename, volume: 1.0, key: nil, channel_group: nil, channel_auto: false, preload: false)
|
189
|
+
return if Stylet.config.mute
|
190
|
+
|
191
|
+
filename = Pathname(filename).expand_path
|
192
|
+
unless filename.exist?
|
193
|
+
Stylet.logger.debug "#{filename} が見つかりません" if Stylet.logger
|
194
|
+
return
|
195
|
+
end
|
196
|
+
|
197
|
+
key ||= filename.basename(".*").to_s
|
198
|
+
key = key.to_sym
|
199
|
+
if se_hash[key]
|
200
|
+
Stylet.logger.debug "すでに #{filename} (#{key.inspect}) が登録されています" if Stylet.logger
|
201
|
+
return
|
202
|
+
end
|
203
|
+
|
204
|
+
SoundEffect.new(key: key, :channel_group => channel_group, filename: filename, volume: volume, channel_auto: channel_auto, preload: preload)
|
205
|
+
end
|
206
|
+
|
207
|
+
def destroy_all(keys = se_hash.keys)
|
208
|
+
Array(keys).collect(&:to_sym).uniq.each do |key|
|
209
|
+
if se = se_hash[key]
|
210
|
+
se.destroy
|
211
|
+
end
|
212
|
+
end
|
213
|
+
channel_reset
|
214
|
+
end
|
215
|
+
|
216
|
+
def channel_reset
|
217
|
+
raise if SE.channel_groups.any? {|_, e|e[:counter] < 0}
|
218
|
+
SE.channel_groups.delete_if {|_, e|e[:counter] == 0}
|
219
|
+
allocate_channels
|
220
|
+
channel_groups.each_value.with_index {|e, index|e[:channel] = SE.preparation_channels + index}
|
221
|
+
end
|
222
|
+
|
223
|
+
def allocate_channels
|
224
|
+
self.allocated_channels = SDL::Mixer.allocate_channels(SE.preparation_channels + channel_groups.size)
|
225
|
+
SE.master_volume = SE.default_master_volume
|
226
|
+
end
|
227
|
+
|
228
|
+
# nil while se_hash.values.any? {|e| e.play? } と同等
|
229
|
+
def wait_if_play?
|
230
|
+
SDL.delay(1) while play_any?
|
231
|
+
end
|
232
|
+
|
233
|
+
def play_any?
|
234
|
+
SDL::Mixer.playing_channels.nonzero?
|
235
|
+
end
|
236
|
+
|
237
|
+
def play_none?
|
238
|
+
!play_any?
|
239
|
+
end
|
240
|
+
|
241
|
+
def halt(fade_out_sec: nil)
|
242
|
+
if fade_out_sec
|
243
|
+
SDL::Mixer.fade_out(-1, fade_out_sec * 1000.0)
|
244
|
+
else
|
245
|
+
SDL::Mixer.halt(-1)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def fade_out(fade_out_sec: Audio.fade_out_default)
|
250
|
+
halt(fade_out_sec: fade_out_sec)
|
251
|
+
end
|
252
|
+
|
253
|
+
def master_volume=(v)
|
254
|
+
Audio.setup_once
|
255
|
+
@master_volume = v
|
256
|
+
# チャンネル数が0の状態で呼ぶとエラーになるため1以上としている
|
257
|
+
if allocated_channels >= 1
|
258
|
+
SDL::Mixer.set_volume(-1, Audio.volume_cast(v))
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
class Base
|
263
|
+
def play(*)
|
264
|
+
end
|
265
|
+
|
266
|
+
def play?
|
267
|
+
false
|
268
|
+
end
|
269
|
+
|
270
|
+
def halt(*)
|
271
|
+
end
|
272
|
+
|
273
|
+
def fade_out(fade_out_sec: Audio.fade_out_default)
|
274
|
+
halt(fade_out_sec: fade_out_sec)
|
275
|
+
end
|
276
|
+
|
277
|
+
def volume
|
278
|
+
0
|
279
|
+
end
|
280
|
+
|
281
|
+
def volume=(v)
|
282
|
+
end
|
283
|
+
|
284
|
+
def spec
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
class NullEffect < Base
|
289
|
+
end
|
290
|
+
|
291
|
+
class SoundEffect < Base
|
292
|
+
attr_reader :filename, :key, :channel_group, :volume, :channel_auto
|
293
|
+
|
294
|
+
def initialize(filename:, key:, channel_group:, volume:, channel_auto: false, preload: false)
|
295
|
+
raise if channel_group && channel_auto
|
296
|
+
|
297
|
+
@filename = Pathname(filename).expand_path
|
298
|
+
@key = key
|
299
|
+
@channel_auto = channel_auto
|
300
|
+
@volume = volume
|
301
|
+
|
302
|
+
unless @channel_auto
|
303
|
+
@channel_group = channel_group || key
|
304
|
+
end
|
305
|
+
|
306
|
+
unless @channel_auto
|
307
|
+
SE.channel_groups[@channel_group] ||= {:channel => SE.preparation_channels + SE.channel_groups.size, :counter => 0}
|
308
|
+
SE.channel_groups[@channel_group][:counter] += 1
|
309
|
+
end
|
310
|
+
|
311
|
+
Audio.setup_once
|
312
|
+
SE.allocate_channels
|
313
|
+
SE.se_hash[@key] = self
|
314
|
+
|
315
|
+
if preload
|
316
|
+
preload!
|
317
|
+
end
|
318
|
+
|
319
|
+
Stylet.logger.debug "new: #{spec}" if Stylet.logger
|
320
|
+
end
|
321
|
+
|
322
|
+
def play(loop: false)
|
323
|
+
SDL::Mixer.play_channel(channel, wave, loop ? -1 : 0)
|
324
|
+
rescue SDL::Error => error
|
325
|
+
Stylet.logger.debug "ERROR: #{error.inspect}" if Stylet.logger
|
326
|
+
end
|
327
|
+
|
328
|
+
def play?
|
329
|
+
SDL::Mixer.play?(channel)
|
330
|
+
end
|
331
|
+
|
332
|
+
def halt(fade_out_sec: nil)
|
333
|
+
if fade_out_sec
|
334
|
+
SDL::Mixer.fade_out(channel, fade_out_sec * 1000)
|
335
|
+
else
|
336
|
+
SDL::Mixer.halt(channel)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def volume=(v)
|
341
|
+
@volume = v
|
342
|
+
if @wave
|
343
|
+
wave_volume_set(@wave)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def channel
|
348
|
+
if @channel_auto
|
349
|
+
if SE.allocated_channels == 0
|
350
|
+
raise "SE.preparation_channels でチャンネル数を指定してください"
|
351
|
+
end
|
352
|
+
-1
|
353
|
+
else
|
354
|
+
SE.channel_groups.fetch(@channel_group)[:channel]
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
def destroy
|
359
|
+
raise unless SE.se_hash[@key]
|
360
|
+
unless @channel_auto
|
361
|
+
SE.channel_groups[@channel_group][:counter] -= 1
|
362
|
+
end
|
363
|
+
if @wave
|
364
|
+
raise if @wave.destroyed?
|
365
|
+
@wave.destroy
|
366
|
+
@wave = nil
|
367
|
+
end
|
368
|
+
Stylet.logger.debug "destroy: #{@key.inspect}" if Stylet.logger
|
369
|
+
SE.se_hash.delete(@key)
|
370
|
+
end
|
371
|
+
|
372
|
+
def wave
|
373
|
+
@wave ||= SDL::Mixer::Wave.load(@filename.to_s).tap do |wave|
|
374
|
+
wave_volume_set(wave)
|
375
|
+
Stylet.logger.debug "disk_load: #{@key.inspect}" if Stylet.logger
|
376
|
+
end
|
377
|
+
end
|
378
|
+
alias preload! wave
|
379
|
+
|
380
|
+
def spec
|
381
|
+
"[channel:#{channel}/#{SE.allocated_channels}] [#{@wave ? :loaded : :new}] [volume:#{@volume}] [#{@channel_group}] [#{@key}] #{@filename.basename}"
|
382
|
+
end
|
383
|
+
|
384
|
+
private
|
385
|
+
|
386
|
+
def wave_volume_set(wave)
|
387
|
+
wave.set_volume(Audio.volume_cast(@volume * SE.volume_magnification))
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
if $0 == __FILE__
|
394
|
+
require_relative "../stylet"
|
395
|
+
require "rspec/autorun"
|
396
|
+
|
397
|
+
RSpec.configure do |_config|
|
398
|
+
end
|
399
|
+
|
400
|
+
sub_test_case do
|
401
|
+
setup do
|
402
|
+
Stylet::Audio.setup_once
|
403
|
+
Stylet::SE.destroy_all
|
404
|
+
end
|
405
|
+
|
406
|
+
it do
|
407
|
+
Stylet::Music.volume = 0.2
|
408
|
+
Stylet::Music.play("#{__dir__}/assets/bgm.wav")
|
409
|
+
|
410
|
+
expect(Stylet::Music.play?).to eq true
|
411
|
+
sleep(1)
|
412
|
+
Stylet::Music.halt(fade_out_sec: 3)
|
413
|
+
nil while Stylet::Music.play?
|
414
|
+
end
|
415
|
+
|
416
|
+
it do
|
417
|
+
Stylet::SE.master_volume = 0.2
|
418
|
+
Stylet::SE.load("#{__dir__}/../../assets/audios/pc_puyo_puyo_fever/VOICE/CH00VO00.WAV", :key => :a, :channel_group => :x, :volume => 0.1)
|
419
|
+
Stylet::SE.load("#{__dir__}/../../assets/audios/pc_puyo_puyo_fever/VOICE/CH00VO01.WAV", :key => :b, :volume => 0.1)
|
420
|
+
Stylet::SE.load("#{__dir__}/../../assets/audios/pc_puyo_puyo_fever/VOICE/CH00VO02.WAV", :key => :c, :channel_group => :x, :volume => 0.1)
|
421
|
+
|
422
|
+
expect(Stylet::SE[:a].spec).to match(/new/) # ロードしていない
|
423
|
+
Stylet::SE[:a].preload! # 明示的にロードする
|
424
|
+
expect(Stylet::SE[:a].spec).to match(/loaded/) # ロード済み
|
425
|
+
|
426
|
+
expect(Stylet::SE.se_hash.values.collect(&:channel)).to eq [0, 1, 0] # a と c が同じチャンネルを共有していることがわかる
|
427
|
+
|
428
|
+
Stylet::SE[:a].play # a を再生するが
|
429
|
+
sleep(0.2)
|
430
|
+
Stylet::SE[:c].play # c も同じチャンネルを使っているため a をキャンセルする
|
431
|
+
Stylet::SE[:b].play # b は別のチャンネルなので同時に再生できる
|
432
|
+
Stylet::SE.wait_if_play?
|
433
|
+
Stylet::SE.destroy_all(:a) # a を消しても c が 0 を利用しているため 0 チャンネルは残っている
|
434
|
+
expect(Stylet::SE.se_hash.values.collect(&:channel)).to eq [1, 0]
|
435
|
+
Stylet::SE.destroy_all(:c) # c を消すと 0 チャンネルが消えて
|
436
|
+
expect(Stylet::SE[:b].channel).to eq 0 # 再割り当てするため 1 チャンネルが消えて 0 チャンネルのみになる
|
437
|
+
end
|
438
|
+
|
439
|
+
it "効果音を複数同時にフェイドアウトできる" do
|
440
|
+
Stylet::SE.master_volume = 0.2
|
441
|
+
Stylet::SE.load("#{__dir__}/../../assets/audios/pc_puyo_puyo_fever/VOICE/CH03VO09.WAV", :key => :a, :preload => true, :volume => 0.1)
|
442
|
+
Stylet::SE.load("#{__dir__}/../../assets/audios/pc_puyo_puyo_fever/VOICE/CH04VO20.WAV", :key => :b, :preload => true, :volume => 0.1)
|
443
|
+
Stylet::SE[:a].play
|
444
|
+
Stylet::SE[:b].play
|
445
|
+
Stylet::SE.halt(:fade_out_sec => 1)
|
446
|
+
Stylet::SE.wait_if_play?
|
447
|
+
end
|
448
|
+
|
449
|
+
it do
|
450
|
+
Stylet::SE.preparation_channels = 10
|
451
|
+
Stylet::SE.load("#{__dir__}/../../assets/audios/pc_puyo_puyo_fever/VOICE/CH00VO00.WAV", :key => :a, :channel_auto => true, :volume => 0.1)
|
452
|
+
expect(Stylet::SE[:a].spec).to match("-1/10")
|
453
|
+
end
|
454
|
+
end
|
455
|
+
end
|