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,60 @@
|
|
1
|
+
# 2P対戦雛型
|
2
|
+
require_relative "helper"
|
3
|
+
|
4
|
+
class Player
|
5
|
+
include Stylet::Delegators
|
6
|
+
include Stylet::Input::Base
|
7
|
+
include Stylet::Input::ExtensionButton
|
8
|
+
|
9
|
+
def initialize(pos)
|
10
|
+
super()
|
11
|
+
@pos = pos
|
12
|
+
end
|
13
|
+
|
14
|
+
def update
|
15
|
+
raise if defined? super
|
16
|
+
bit_update_by_joy(joys[@joystick_index])
|
17
|
+
key_bit_update_all
|
18
|
+
key_counter_update_all
|
19
|
+
|
20
|
+
if angle = axis_angle
|
21
|
+
@pos += vec2.angle_at(angle) * 4
|
22
|
+
end
|
23
|
+
draw_circle(@pos, :vertex => 16, :radius => 32)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Player1 < Player
|
28
|
+
include Stylet::Input::StandardKeybordBind
|
29
|
+
include Stylet::Input::JoystickBindMethod
|
30
|
+
def initialize(*)
|
31
|
+
super
|
32
|
+
@joystick_index = 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Player2 < Player
|
37
|
+
include Stylet::Input::HjklKeyboardBind
|
38
|
+
include Stylet::Input::JoystickBindMethod
|
39
|
+
def initialize(*)
|
40
|
+
super
|
41
|
+
@joystick_index = 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class App < Stylet::Base
|
46
|
+
include Helper::CursorWithObjectCollection
|
47
|
+
|
48
|
+
setup do
|
49
|
+
self.title = "2P対戦雛型"
|
50
|
+
cursor.display = false
|
51
|
+
SDL::Mouse.hide
|
52
|
+
|
53
|
+
@players = []
|
54
|
+
@players << Player1.new(vec2[srect.half_w - srect.half_w * 0.5, srect.half_h])
|
55
|
+
@players << Player2.new(vec2[srect.half_w + srect.half_w * 0.5, srect.half_h])
|
56
|
+
@objects += @players
|
57
|
+
end
|
58
|
+
|
59
|
+
run
|
60
|
+
end
|
@@ -0,0 +1,1251 @@
|
|
1
|
+
# スーパーマリオ風アクション雛型
|
2
|
+
require_relative "helper"
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
Stylet.production = true
|
6
|
+
Stylet.config.full_screen = true
|
7
|
+
|
8
|
+
Stylet::Palette[:background] = [107, 140, 255]
|
9
|
+
Stylet::Palette[:font] = [255, 255, 255]
|
10
|
+
|
11
|
+
module Utils
|
12
|
+
include Stylet::Delegators
|
13
|
+
extend self
|
14
|
+
|
15
|
+
def draw_vline(x)
|
16
|
+
draw_line(vec2[x, srect.min_y], vec2[x, srect.max_y])
|
17
|
+
end
|
18
|
+
|
19
|
+
def draw_hline(y)
|
20
|
+
draw_line(vec2[srect.min_x, y], vec2[srect.max_x, y])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Sprite
|
25
|
+
extend self
|
26
|
+
|
27
|
+
@data ||= {}
|
28
|
+
|
29
|
+
def [](key)
|
30
|
+
@data[key]
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_file(filename, options = {})
|
34
|
+
filename = Pathname(filename).expand_path
|
35
|
+
key = filename.basename(".*").to_s
|
36
|
+
@data[key] ||= surface_load(filename, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def surface_load(filename, mask: true)
|
40
|
+
s = SDL::Surface.load(filename.to_s)
|
41
|
+
s.set_color_key(SDL::SRCCOLORKEY, 0) if mask
|
42
|
+
s.display_format
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class ObjectX
|
47
|
+
include Stylet::Delegators
|
48
|
+
|
49
|
+
attr_accessor :pos, :speed, :rc
|
50
|
+
|
51
|
+
extend Forwardable
|
52
|
+
instance_delegate [:x, :y] => :pos
|
53
|
+
instance_delegate [:w, :h] => :rc
|
54
|
+
end
|
55
|
+
|
56
|
+
class BlockBase < ObjectX
|
57
|
+
attr_accessor :state, :state
|
58
|
+
|
59
|
+
def initialize(pos: nil)
|
60
|
+
@pos = pos
|
61
|
+
@rc = rect2[@image.w, @image.h]
|
62
|
+
@state = :lock
|
63
|
+
@state_counter = 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def update
|
67
|
+
if @state == :fall_down
|
68
|
+
@speed.y += Stylet.context.gravity
|
69
|
+
@pos += @speed
|
70
|
+
if @pos.y >= (Stylet.context.camera.y + Stylet.context.srect.half_h + @rc.half_h)
|
71
|
+
Stylet.context.kill_task self
|
72
|
+
end
|
73
|
+
end
|
74
|
+
if @pos
|
75
|
+
if Stylet.context.active_x_range.include?(x)
|
76
|
+
screen.put(@image, *(@pos - Stylet.context.camera_offset - @rc.half_wh))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
@state_counter += 1
|
80
|
+
end
|
81
|
+
|
82
|
+
def player_panch(player)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class SoftBlock < BlockBase
|
87
|
+
def initialize(*)
|
88
|
+
@image = Sprite.load_file("assets/block.png", :mask => false)
|
89
|
+
super
|
90
|
+
end
|
91
|
+
|
92
|
+
def player_panch(player)
|
93
|
+
@state = :fall_down
|
94
|
+
@speed = player.speed.clone
|
95
|
+
Stylet::SE["nc30529_stomp"].play
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class HardBlock < BlockBase
|
100
|
+
def initialize(*)
|
101
|
+
@image = Sprite.load_file("assets/hard_block.png")
|
102
|
+
super
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class WhiteBlock < BlockBase
|
107
|
+
def initialize(*)
|
108
|
+
@image = Sprite.load_file("assets/white_block.png")
|
109
|
+
super
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class Coin < ObjectX
|
114
|
+
def initialize(pos: nil)
|
115
|
+
@pos = pos
|
116
|
+
@image = Sprite.load_file("assets/coin_anim_x4.png")
|
117
|
+
@rc = rect2[16, 16]
|
118
|
+
@anim_count = 4
|
119
|
+
end
|
120
|
+
|
121
|
+
def update
|
122
|
+
return unless Stylet.context.active_x_range.include?(x)
|
123
|
+
return unless Stylet.context.active_y_range.include?(y)
|
124
|
+
SDL::Surface.blit(@image, (Stylet.context.frame_counter / 8).modulo(@anim_count) * (@image.w / @anim_count), 0, @rc.w, @rc.h, screen, *(@pos - Stylet.context.camera_offset - @rc.half_wh))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class PlayerBase < ObjectX
|
129
|
+
include Stylet::Input::Base
|
130
|
+
include Stylet::Input::ExtensionButton
|
131
|
+
|
132
|
+
attr_accessor :jump_count
|
133
|
+
|
134
|
+
def initialize(pos: nil)
|
135
|
+
super()
|
136
|
+
|
137
|
+
@ground_friction = 0.90 # 摩擦力(地上でのみ発生)
|
138
|
+
|
139
|
+
@ground_accel = 0.20 # 地上での左右加速度
|
140
|
+
@air_accel = 0.07 # 空中での左右加速度
|
141
|
+
@jump_power1 = 10 # ジャンプ力(1回目)
|
142
|
+
@jump_power2 = 8 # ジャンプ力(2回目以降)
|
143
|
+
@jump_cancel = 0.6 # ジャンプキャンセル時のジャンプ量減速率
|
144
|
+
@jump_max = 1 # 2段ジャンプの最大回数
|
145
|
+
@speed_max = 6.0 # 左右移動最大スピード
|
146
|
+
@b_dash = 2.5 # Bダッシュ時の加速度倍率
|
147
|
+
@speed_truncate = 0.03 # この値未満になったら左右のスピードを0とする(停止後にゆっくり横移動するのを防ぐため)
|
148
|
+
@ground_collisiion_diff = 16.0 # ブロックにめり込んだYの差分がこの値より小さければブロックの上にのっける
|
149
|
+
@downl_collision_wsub = 6 # 降りるときどれだけゆるくするか(0なら足の先で立てるが1ブロックの隙間に入れない)
|
150
|
+
@kabenohutuuuno_hansya = 0.3 # 左右の壁にめり込んだときのスピードの減速率
|
151
|
+
@wall_rebound = 0.5 # 壁に衝突したときの反発力(1.0なら減速しない)
|
152
|
+
@break_trigger = 1.1 # どこまでXスピードに差が出たときのブレーキ音にするか
|
153
|
+
@fall_down_func = false # ブロックから降りれるか?(ブロックの横当たり判定がある場合は有効にするのが難しい)
|
154
|
+
|
155
|
+
## ブロックの横判定
|
156
|
+
@block_side_collision = true # 横の当たり判定を有効にするか?
|
157
|
+
@block_side_rebound = 0.5 # ブロックに横に衝突したときの反発力
|
158
|
+
@block_side_ysub = 16 # ブロックに横に衝突する判定を行うときのY座標の当りをどれだけ緩くするか
|
159
|
+
|
160
|
+
## ブロックに下からパンチ
|
161
|
+
@punch_collistion_h = 32.0 # ブロックにめり込んだYの差分がこの値より小さければブロックにパンチできる
|
162
|
+
@punch_collision_wsub = 10 # 横の当たり判定をどれだけゆるくするか?
|
163
|
+
@punch_rebound_ratio = 0.2 # ブロックを壊したときの下方向への反発率
|
164
|
+
|
165
|
+
## 壁蹴り
|
166
|
+
@kabeeno_tikasa = 16 # 壁蹴りが有効な壁との距離
|
167
|
+
@wall_kick_speed_x_gteq = 1.0 # 壁蹴りが可能な横スピード量(n以上で成立)。ある程度強く当たらないといけない。
|
168
|
+
@kabekeri_jump = 10 # 壁蹴りが成立したときのジャンプ量
|
169
|
+
@sankaku_tobi_hatekaeri_tuyosa = 1.0 # 壁蹴りが成立したときの反射量(1.0なら変化なし、1.5で元気よく跳ねかえる)
|
170
|
+
|
171
|
+
@pos = pos # 現在位置
|
172
|
+
@pos_before = pos # 前フレームでの位置
|
173
|
+
@pos_diff = vec2.zero # 直近移動ベクトル(現在位置 - 前回の位置)
|
174
|
+
@speed = vec2.zero # スピードベクトル
|
175
|
+
@before_speed = vec2.zero # 前フレームでのスピードベクトル
|
176
|
+
|
177
|
+
@coin_count = 0 # 所持コイン数
|
178
|
+
|
179
|
+
## 作業用
|
180
|
+
@jump_cancel_count = 0 # ジャンプをキャンセルしようとした回数
|
181
|
+
@jump_count = 0 # 現在のジャンプ回数
|
182
|
+
@wall_kick_count = 0 # 壁蹴りをした回数
|
183
|
+
@current_block = nil # ブロックの上に乗っているときの、そのブロックオブジェクト
|
184
|
+
@ground_collision = false # ブロックまたは床の上にいる状態か?
|
185
|
+
@ground_collision_save = false # ブロックまたは床の上にいる状態か?(前フレーム)
|
186
|
+
|
187
|
+
@image = Sprite.load_file(@image_filename)
|
188
|
+
@rc = rect2[@image.w, @image.h]
|
189
|
+
end
|
190
|
+
|
191
|
+
def update
|
192
|
+
super if defined? super
|
193
|
+
|
194
|
+
if Stylet.context.state != :edit_mode
|
195
|
+
if @ground_collision
|
196
|
+
@speed.x *= @ground_friction # ブロックまたは床にいるときは摩擦で徐々に減速する
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
if Stylet.context.state != :edit_mode
|
201
|
+
key_bit_update_all
|
202
|
+
bit_update_by_joy(joys[@joystick_index]) if @joystick_index
|
203
|
+
key_counter_update_all
|
204
|
+
end
|
205
|
+
|
206
|
+
# ジャンプ
|
207
|
+
begin
|
208
|
+
if @jump_count == 0
|
209
|
+
# 最初のジャンプ
|
210
|
+
if @ground_collision
|
211
|
+
# ブロックの上にいる場合は、下を押してない状態のみ、ジャンプが反応する
|
212
|
+
# ブロックの上にいない場合は、下はチェックしない
|
213
|
+
if @fall_down_func
|
214
|
+
flag = (@current_block && button.btD.trigger? && axis.down.free?) || (!@current_block && button.btD.trigger?)
|
215
|
+
else
|
216
|
+
flag = button.btD.trigger?
|
217
|
+
end
|
218
|
+
if flag
|
219
|
+
@speed.y += -@jump_power1
|
220
|
+
@jump_count += 1
|
221
|
+
jump_process
|
222
|
+
end
|
223
|
+
end
|
224
|
+
elsif @jump_count <= @jump_max
|
225
|
+
# 二段ジャンプ
|
226
|
+
if button.btD.trigger?
|
227
|
+
@speed.y = -@jump_power2
|
228
|
+
@jump_count += 1
|
229
|
+
jump_process
|
230
|
+
end
|
231
|
+
end
|
232
|
+
unless @ground_collision
|
233
|
+
# ジャンプキャンセル(ジャンプ中にボタンを離した)
|
234
|
+
if button.btD.free_trigger?
|
235
|
+
if @jump_cancel_count == 0
|
236
|
+
if @speed.y < 0 # 上昇中なら
|
237
|
+
@speed.y *= @jump_cancel
|
238
|
+
end
|
239
|
+
end
|
240
|
+
@jump_cancel_count += 1
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# 左右移動
|
246
|
+
begin
|
247
|
+
@lr_accel = 0
|
248
|
+
if @jump_count == 0
|
249
|
+
if axis.right.press?
|
250
|
+
@lr_accel = @ground_accel
|
251
|
+
elsif axis.left.press?
|
252
|
+
@lr_accel = -@ground_accel
|
253
|
+
end
|
254
|
+
if button.btA.press?
|
255
|
+
@lr_accel *= @b_dash
|
256
|
+
end
|
257
|
+
else
|
258
|
+
if axis.right.press?
|
259
|
+
@lr_accel = @air_accel
|
260
|
+
elsif axis.left.press?
|
261
|
+
@lr_accel = -@air_accel
|
262
|
+
end
|
263
|
+
end
|
264
|
+
@speed.x += @lr_accel
|
265
|
+
end
|
266
|
+
|
267
|
+
# 降りる(若干違和感あり?)
|
268
|
+
if @fall_down_func
|
269
|
+
if @current_block
|
270
|
+
if axis.down.press? && button.btD.trigger?
|
271
|
+
@pos.y = @current_block.pos.y - @current_block.rc.half_h + @ground_collisiion_diff
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
# 環境補正
|
277
|
+
begin
|
278
|
+
if Stylet.context.state != :edit_mode
|
279
|
+
@speed.y += Stylet.context.gravity
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# 最終計算
|
284
|
+
begin
|
285
|
+
if @speed.x.abs < @speed_truncate
|
286
|
+
@speed.x = 0
|
287
|
+
end
|
288
|
+
|
289
|
+
# if @speed.magnitude > 30.0
|
290
|
+
# @speed = @speed.normalize * 30
|
291
|
+
# end
|
292
|
+
|
293
|
+
@speed.x = Stylet::Chore.clamp(@speed.x, (-@speed_max..@speed_max))
|
294
|
+
@pos_before = @pos.clone
|
295
|
+
@pos += @speed
|
296
|
+
@pos_diff = @pos - @pos_before
|
297
|
+
|
298
|
+
if @ground_collision
|
299
|
+
if (@before_speed.x - @speed.x).abs >= @break_trigger
|
300
|
+
Stylet::SE["se_jump_short"].play
|
301
|
+
end
|
302
|
+
end
|
303
|
+
@before_speed = @speed.clone
|
304
|
+
end
|
305
|
+
|
306
|
+
# ここ以降が当り判定
|
307
|
+
@ground_collision = false
|
308
|
+
|
309
|
+
active_x_range = Stylet.context.active_x_range
|
310
|
+
active_y_range = Stylet.context.active_y_range
|
311
|
+
|
312
|
+
begin
|
313
|
+
collistion_blocks = {}
|
314
|
+
|
315
|
+
# ブロックとの当たり判定
|
316
|
+
if true
|
317
|
+
begin
|
318
|
+
@current_block = nil
|
319
|
+
if @speed.y > 0 # 落下中(重力があるため静止状態も落下中の状態)のみ判定する。つまりジャンプ中だけ判定が消える。
|
320
|
+
active_x_range = Stylet.context.active_x_range
|
321
|
+
Stylet.context.blocks.each do |block|
|
322
|
+
next if block.pos.nil?
|
323
|
+
next unless active_x_range.include?(block.pos.x) # 表示画面外なのでスキップ
|
324
|
+
|
325
|
+
diff_x = (@pos.x - block.pos.x).abs
|
326
|
+
if diff_x < (block.rc.half_w + @rc.half_w) - @downl_collision_wsub # 差分が両者の半径の合計より小さければ同じ列にいる
|
327
|
+
# Y座標の方は床にどれだけ足がめり込んでいるかで調べる
|
328
|
+
# ただし落ちてきているとき speed.y > 0 のみ
|
329
|
+
floor_y = block.pos.y - block.rc.half_h # 床
|
330
|
+
foot_y = @pos.y + @rc.half_h # キャラの足の裏
|
331
|
+
diff_y = foot_y - floor_y
|
332
|
+
|
333
|
+
# ここ確認
|
334
|
+
# Utils.draw_hline(bottom_y - Stylet.context.camera_offset.y)
|
335
|
+
# Utils.draw_hline(head_y - Stylet.context.camera_offset.y)
|
336
|
+
|
337
|
+
if 0 < diff_y && diff_y < @ground_collisiion_diff # ここの block.block_w はうまく調整しないと擦り抜けてしまう
|
338
|
+
@pos.y = floor_y - @rc.half_h
|
339
|
+
@current_block = block
|
340
|
+
stand_on_block_or_ground_process
|
341
|
+
collistion_blocks[block.object_id] = true
|
342
|
+
draw_circle(block.pos - Stylet.context.camera_offset, :radius => block.rc.half_w * 2) unless Stylet.production
|
343
|
+
break
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
# ブロックへのパンチ
|
352
|
+
if true
|
353
|
+
begin
|
354
|
+
# @current_block = nil
|
355
|
+
if @speed.y < 0 # 落下中(重力があるため静止状態も落下中の状態)のみ判定する。つまりジャンプ中だけ判定が消える。
|
356
|
+
Stylet.context.blocks.each do |block|
|
357
|
+
next unless active_x_range.include?(block.pos.x) # 表示画面外なのでスキップ
|
358
|
+
|
359
|
+
diff_x = (@pos.x - block.pos.x).abs
|
360
|
+
if diff_x < (block.rc.half_w + @rc.half_w) - @punch_collision_wsub # 差分が両者の半径の合計より小さければ同じ列にいる
|
361
|
+
# Y座標の方は床にどれだけ足がめり込んでいるかで調べる
|
362
|
+
# ただし落ちてきているとき speed.y > 0 のみ
|
363
|
+
bottom_y = block.pos.y + block.rc.half_h # 床
|
364
|
+
head_y = @pos.y - @rc.half_h # キャラの頭
|
365
|
+
diff_y = bottom_y - head_y
|
366
|
+
# Utils.draw_hline(bottom_y - Stylet.context.camera_offset.y)
|
367
|
+
# Utils.draw_hline(head_y - Stylet.context.camera_offset.y)
|
368
|
+
if 0 <= diff_y && diff_y <= @punch_collistion_h # ここの block.block_w はうまく調整しないと擦り抜けてしまう
|
369
|
+
# Stylet.context.objects << FallBlock.new(pos: block.pos.clone, speed: @speed.clone)
|
370
|
+
# Stylet.context.blocks.delete(block)
|
371
|
+
# Stylet.context.objects.delete(block)
|
372
|
+
block.player_panch(self)
|
373
|
+
@pos.y = bottom_y + @rc.half_h
|
374
|
+
@speed.y = -@speed.y * @punch_rebound_ratio
|
375
|
+
collistion_blocks[block.object_id] = true
|
376
|
+
draw_circle(block.pos - Stylet.context.camera_offset, :radius => block.rc.half_w * 2) unless Stylet.production
|
377
|
+
break
|
378
|
+
|
379
|
+
# @current_block = block
|
380
|
+
# stand_on_block_or_ground_process
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
# ブロックとの左右の当たり判定
|
389
|
+
if @block_side_collision
|
390
|
+
Stylet.context.blocks.each do |block|
|
391
|
+
next unless active_x_range.include?(block.pos.x)
|
392
|
+
next unless active_y_range.include?(block.pos.y)
|
393
|
+
next if collistion_blocks[block.object_id]
|
394
|
+
# next if block.state == :fall_down
|
395
|
+
|
396
|
+
diff_y = block.pos.y - @pos.y
|
397
|
+
len = block.rc.half_h + @rc.half_h
|
398
|
+
len_diff = len - diff_y.abs - @block_side_ysub # 当りを弱くしないと横に移動できなくなる
|
399
|
+
if len_diff <= 0
|
400
|
+
next
|
401
|
+
end
|
402
|
+
|
403
|
+
diff_x = block.pos.x - @pos.x
|
404
|
+
len = block.rc.half_w + @rc.half_w
|
405
|
+
len_diff = len - diff_x.abs
|
406
|
+
if len_diff > 0
|
407
|
+
if diff_x < 0
|
408
|
+
len_diff = -len_diff # 右にいるキャラが左のブロックにめり込んだ場合はキャラを右に補正する
|
409
|
+
end
|
410
|
+
if @ground_collision_save && block.state == :fall_down # 無駄に難しくなるため、地上にいる場合、落ちてくるブロックとの当たり判定をスルーする
|
411
|
+
else
|
412
|
+
@speed.x = -@speed.x
|
413
|
+
@pos.x += -len_diff
|
414
|
+
@speed.x = -@speed.x * @block_side_rebound
|
415
|
+
draw_circle(block.pos - Stylet.context.camera_offset, :radius => block.rc.half_w * 2) unless Stylet.production
|
416
|
+
break
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
# コインとの当たり判定
|
424
|
+
begin
|
425
|
+
active_x_range = Stylet.context.active_x_range
|
426
|
+
Stylet.context.coins.each do |coin|
|
427
|
+
next unless active_x_range.include?(coin.pos.x) # 表示画面外なのでスキップ
|
428
|
+
next unless active_y_range.include?(coin.pos.y) # 表示画面外なのでスキップ
|
429
|
+
|
430
|
+
diff = @pos - coin.pos
|
431
|
+
rdiff = (coin.rc.half_w + @rc.half_w) - diff.magnitude
|
432
|
+
if rdiff > 0
|
433
|
+
@coin_count += 1
|
434
|
+
if @coin_count.modulo(100).zero?
|
435
|
+
Stylet::SE["nc2681_1up"].play
|
436
|
+
else
|
437
|
+
Stylet::SE["nc26792_coin"].play
|
438
|
+
end
|
439
|
+
Stylet.context.kill_task coin
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
# 移動
|
445
|
+
begin
|
446
|
+
# マリオブラザーズ風の折り返し
|
447
|
+
if false
|
448
|
+
@pos.x = @pos.x.modulo(srect.w)
|
449
|
+
end
|
450
|
+
|
451
|
+
# 地面
|
452
|
+
if (@pos.y + @rc.half_h) > Stylet.context.ground_y
|
453
|
+
@pos.y = Stylet.context.ground_y - @rc.half_h
|
454
|
+
stand_on_block_or_ground_process
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
# 三角飛び
|
459
|
+
unless @ground_collision
|
460
|
+
if @wall_kick_count == 0
|
461
|
+
if button.btD.trigger?
|
462
|
+
if @jump_count >= 1
|
463
|
+
if @speed.x.abs >= @wall_kick_speed_x_gteq
|
464
|
+
# 左端
|
465
|
+
v = (Stylet.context.virtual_rect.min_x + @image.w / 2) # 左端から半キャラ右に移動した位置(つまり左手が端に接着している状態)
|
466
|
+
if (v - @pos.x).abs < @kabeeno_tikasa
|
467
|
+
@pos.x = v
|
468
|
+
wall_kick_process
|
469
|
+
end
|
470
|
+
# 右端
|
471
|
+
v = (Stylet.context.virtual_rect.max_x - @image.w / 2) # 右端から半キャラ左に移動した位置(つまり右手が端に接着している状態)
|
472
|
+
if (v - @pos.x).abs < @kabeeno_tikasa
|
473
|
+
@pos.x = v
|
474
|
+
wall_kick_process
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
# 左右の壁
|
483
|
+
if @pos.x < (v = Stylet.context.virtual_rect.min_x + @image.w / 2) || @pos.x > (v = Stylet.context.virtual_rect.max_x - @image.w / 2)
|
484
|
+
@pos.x = v
|
485
|
+
@speed.x = -@speed.x * @wall_rebound
|
486
|
+
end
|
487
|
+
|
488
|
+
# カメラの壁
|
489
|
+
# スト2でお互いが目一杯離れているときテレビ画面の端を越えられないのはこの補正があるから
|
490
|
+
if Stylet.context.state != :edit_mode
|
491
|
+
if @pos.x < (v = (Stylet.context.camera.x - Stylet.context.srect.half_w + rc.half_w)) || @pos.x > (v = (Stylet.context.camera.x + Stylet.context.srect.half_w - rc.half_w))
|
492
|
+
@pos.x = v
|
493
|
+
@speed.x = -@speed.x * @wall_rebound
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
@ground_collision_save = @ground_collision
|
498
|
+
|
499
|
+
draw_texture
|
500
|
+
|
501
|
+
dputs "ground_collision: #{@ground_collision}"
|
502
|
+
dputs "speed: #{@speed.round(2)}"
|
503
|
+
dputs "pos: #{@pos.round(2)}"
|
504
|
+
vputs "#{@name}: #{@coin_count}"
|
505
|
+
end
|
506
|
+
|
507
|
+
def draw_texture
|
508
|
+
screen.put(@image, *(@pos - Stylet.context.camera_offset - @rc.half_wh))
|
509
|
+
# screen.put(@image, *(v - vec2[srect.w, 0]))
|
510
|
+
# screen.put(@image, *(v + vec2[srect.w, 0]))
|
511
|
+
end
|
512
|
+
|
513
|
+
# ブロックまたは地面の上にいるときの処理
|
514
|
+
def stand_on_block_or_ground_process
|
515
|
+
@speed.y = 0
|
516
|
+
@jump_count = 0
|
517
|
+
@ground_collision = true
|
518
|
+
@wall_kick_count = 0
|
519
|
+
end
|
520
|
+
|
521
|
+
# ジャンプしたときの共通処理
|
522
|
+
def jump_process
|
523
|
+
@jump_cancel_count = 0
|
524
|
+
Stylet::SE["nc27131_jump"].play
|
525
|
+
end
|
526
|
+
|
527
|
+
# 壁蹴りしたときの処理
|
528
|
+
def wall_kick_process
|
529
|
+
@speed.y = -@kabekeri_jump
|
530
|
+
@speed.x *= -1
|
531
|
+
@speed.x *= @sankaku_tobi_hatekaeri_tuyosa
|
532
|
+
@wall_kick_count += 1
|
533
|
+
jump_process
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
class Mario < PlayerBase
|
538
|
+
include Stylet::Input::StandardKeybordBind
|
539
|
+
include Stylet::Input::JoystickBindMethod
|
540
|
+
|
541
|
+
def initialize(*)
|
542
|
+
@image_filename = "assets/mario.png"
|
543
|
+
@joystick_index = 0
|
544
|
+
@name = "1P"
|
545
|
+
super
|
546
|
+
end
|
547
|
+
|
548
|
+
def update
|
549
|
+
super
|
550
|
+
if Stylet.production
|
551
|
+
@joystick_index = 0
|
552
|
+
else
|
553
|
+
if Stylet.context.ext_button.btL1.press?
|
554
|
+
@joystick_index = 0
|
555
|
+
else
|
556
|
+
@joystick_index = nil
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
class Luigi < PlayerBase
|
563
|
+
include Stylet::Input::HjklKeyboardBind
|
564
|
+
include Stylet::Input::JoystickBindMethod
|
565
|
+
|
566
|
+
def initialize(*)
|
567
|
+
@image_filename = "assets/luigi.png"
|
568
|
+
@joystick_index = 1
|
569
|
+
@name = "2P"
|
570
|
+
super
|
571
|
+
# @jump_max = 0
|
572
|
+
# @jump_power1 = 15
|
573
|
+
# @ground_friction = 0.93
|
574
|
+
end
|
575
|
+
|
576
|
+
def update
|
577
|
+
super
|
578
|
+
if Stylet.production
|
579
|
+
@joystick_index = 1
|
580
|
+
else
|
581
|
+
if Stylet.context.ext_button.btR1.press?
|
582
|
+
@joystick_index = 0
|
583
|
+
else
|
584
|
+
@joystick_index = nil
|
585
|
+
end
|
586
|
+
end
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
class App < Stylet::Base
|
591
|
+
include Helper::CursorWithObjectCollection
|
592
|
+
|
593
|
+
attr_accessor :blocks
|
594
|
+
attr_accessor :virtual_rect
|
595
|
+
attr_accessor :camera
|
596
|
+
attr_accessor :ground_y
|
597
|
+
attr_accessor :players
|
598
|
+
attr_accessor :coins
|
599
|
+
attr_accessor :gravity
|
600
|
+
attr_accessor :state, :state_counter
|
601
|
+
|
602
|
+
setup do
|
603
|
+
@gravity = 0.4 # 重力
|
604
|
+
@virtual_rect = rect2[srect.w * 2, srect.h * 2] # ゲーム内での広さ
|
605
|
+
@ground_y = @virtual_rect.h - 32 # 地面
|
606
|
+
|
607
|
+
@wall_scroll_distance_x = 240 # 壁にどれだけ近づいたらスクロールするか
|
608
|
+
@wall_scroll_distance_y = 200 # 壁にどれだけ近づいたらスクロールするか
|
609
|
+
@camera_speed = 0.1 # 追従カメラがキャラクタを捉えるまでの速度の倍率(1.0が最大)
|
610
|
+
@camera_auto = false # カメラ自動追従モード(有効にすると画面中央にキャラを表示しようとする)
|
611
|
+
@view_play = 32 # ビューの遊び(ブロックの端が表示されることもあるため若干広めにする)
|
612
|
+
|
613
|
+
# カメラの位置
|
614
|
+
@camera = vec2.zero
|
615
|
+
@camera.x = srect.center.x
|
616
|
+
@camera.y = @virtual_rect.h - srect.center.y
|
617
|
+
@camera_target = vec2.zero
|
618
|
+
|
619
|
+
# キャラとの反発
|
620
|
+
@rebound_power = 0.2 # 衝突時の反発力(@speedに加算する倍率)
|
621
|
+
@rebound_up_frames = 15 # 反発力増加タイミングのフレーム数
|
622
|
+
@rebound_up_powner = 1.0 # 反発力増加分
|
623
|
+
@head_jump_mul = 1.3 # 相手に衝突して跳ねたときのスピードベクトルの倍率(何度も頭上ジャンプすれば高く飛べる)
|
624
|
+
@vertical_correction = 0.6 # 垂直補正。キャラと接触したとき12時に方向に補正する割合(1.0なら常に真上にジャンプする)
|
625
|
+
|
626
|
+
# @blocks = [SoftBlock.new(pos: srect.center, rc: Stylet::Rect4.centered_create(16, 16))]
|
627
|
+
|
628
|
+
# @blocks = (n = 8).times.collect do |i|
|
629
|
+
# SoftBlock.new(pos: vec2[rand(@virtual_rect.w), rand(virtual_rect.h)], rc: Stylet::Rect4.centered_create(32, 32))
|
630
|
+
# end
|
631
|
+
|
632
|
+
# @blocks = 3.times.flat_map{|j|
|
633
|
+
# (n = 14).times.collect do |i|
|
634
|
+
# SoftBlock.new(pos: vec2[@virtual_rect.w / (n - 1) * (i + (j * 0.5)), @virtual_rect.h - srect.center.y - 100 + j * 120])
|
635
|
+
# end
|
636
|
+
# }
|
637
|
+
|
638
|
+
# @blocks = (m = 8).times.flat_map do |j|
|
639
|
+
# (n = 8).times.collect do |i|
|
640
|
+
# SoftBlock.new(pos: vec2[@virtual_rect.w / (n - 1) * (i + (j.modulo(2) * 0.5)), @ground_y - j * 64])
|
641
|
+
# end
|
642
|
+
# end
|
643
|
+
|
644
|
+
# # 斜めに配置
|
645
|
+
# @blocks = (n = 64).times.collect do |i|
|
646
|
+
# SoftBlock.new(pos: vec2[i * 32, @ground_y - 32 - i * 2])
|
647
|
+
# end
|
648
|
+
|
649
|
+
@blocks = []
|
650
|
+
@coins = []
|
651
|
+
|
652
|
+
@players = []
|
653
|
+
|
654
|
+
# s = SDL::Surface.load("assets/bg960x480.png")
|
655
|
+
# s = SDL::Surface.load("assets/bg_sf2.png")
|
656
|
+
# @scene_main_bg = Sprite.surface_load("assets/bg960x640.png", :mask => false)
|
657
|
+
|
658
|
+
# if false
|
659
|
+
# s = SDL::Surface.load("assets/bg800x480.png")
|
660
|
+
# @scene_bg2 = s.display_format
|
661
|
+
# end
|
662
|
+
|
663
|
+
Stylet::SE.load("assets/nc26792_coin.ogg", volume: 0.2)
|
664
|
+
Stylet::SE.load("assets/nc27131_jump.ogg", volume: 0.2)
|
665
|
+
Stylet::SE.load("assets/se_jump_short.ogg", volume: 0.5)
|
666
|
+
Stylet::SE.load("assets/nc30529_stomp.ogg", volume: 0.3)
|
667
|
+
Stylet::SE.load("assets/nc62985_zelda_secret_open.ogg", volume: 0.5)
|
668
|
+
Stylet::SE.load("assets/nc2681_1up.ogg", volume: 0.5)
|
669
|
+
Stylet::SE.load("assets/nc6131_ff_cursor.ogg", volume: 0.05)
|
670
|
+
Stylet::SE.load("assets/nc45878_buu.ogg", volume: 0.5)
|
671
|
+
|
672
|
+
@cursor.display = false
|
673
|
+
SDL::Mouse.hide
|
674
|
+
|
675
|
+
@stage_file = Pathname("stage_infos.rb").expand_path
|
676
|
+
|
677
|
+
@state = :init
|
678
|
+
@state_counter = 0
|
679
|
+
@stg_index = 0
|
680
|
+
|
681
|
+
@bg_mode = :background
|
682
|
+
end
|
683
|
+
|
684
|
+
update do
|
685
|
+
if @state == :init
|
686
|
+
if @state_counter == 0
|
687
|
+
# @players.each{|player|kill_task(player)}
|
688
|
+
# task_set Mario.new(pos: vec2[srect.half_w - srect.half_w * 0.1, @ground_y - 32])
|
689
|
+
# task_set Luigi.new(pos: vec2[srect.half_w + srect.half_w * 0.1, @ground_y - 32])
|
690
|
+
@state = :start
|
691
|
+
@state_counter = 0
|
692
|
+
end
|
693
|
+
end
|
694
|
+
if @state == :start
|
695
|
+
if @state_counter == 0
|
696
|
+
@state = :stg_set
|
697
|
+
@state_counter = 0
|
698
|
+
end
|
699
|
+
end
|
700
|
+
if @state == :stg_set
|
701
|
+
if @state_counter == 0
|
702
|
+
edit_func_stage_reload
|
703
|
+
@state = :stg_loop
|
704
|
+
@state_counter = 0
|
705
|
+
end
|
706
|
+
end
|
707
|
+
if @state == :stg_loop
|
708
|
+
if @coins.empty? || key_down?(SDL::Key::N)
|
709
|
+
@state = :stg_clear
|
710
|
+
@state_counter = 0
|
711
|
+
end
|
712
|
+
end
|
713
|
+
if @state == :stg_clear
|
714
|
+
if @state_counter == 0
|
715
|
+
Stylet::SE["nc62985_zelda_secret_open"].play
|
716
|
+
@bg_mode = :ff_effect
|
717
|
+
end
|
718
|
+
if @state_counter == 60 * 2
|
719
|
+
@state = :stg_set
|
720
|
+
@state_counter = -1
|
721
|
+
@stg_index += 1
|
722
|
+
end
|
723
|
+
end
|
724
|
+
if @state == :edit_mode
|
725
|
+
if @state_counter == 0
|
726
|
+
SDL::Mixer.pause_music
|
727
|
+
|
728
|
+
# @players.each{|player|@objects.delete(player)}
|
729
|
+
# @players.clear
|
730
|
+
|
731
|
+
edit_func_init
|
732
|
+
end
|
733
|
+
|
734
|
+
vputs "edit_cursor: #{@edit_cursor}"
|
735
|
+
vputs "edit_select_object_index: #{@edit_select_object_index}"
|
736
|
+
vputs "blocks: #{@blocks.size}"
|
737
|
+
vputs "objects: #{@objects.size}"
|
738
|
+
vputs "stg_index: #{@stg_index}"
|
739
|
+
|
740
|
+
# カーソル移動
|
741
|
+
_edit_cursor = @edit_cursor.clone
|
742
|
+
@edit_cursor.x += Stylet.context.axis.right.repeat - Stylet.context.axis.left.repeat
|
743
|
+
@edit_cursor.y += Stylet.context.axis.down.repeat - Stylet.context.axis.up.repeat
|
744
|
+
@edit_cursor.x = Stylet::Chore.clamp(@edit_cursor.x, @edit_rect.x_range)
|
745
|
+
@edit_cursor.y = Stylet::Chore.clamp(@edit_cursor.y, @edit_rect.y_range)
|
746
|
+
if @edit_cursor != _edit_cursor
|
747
|
+
Stylet::SE[:nc6131_ff_cursor].play
|
748
|
+
end
|
749
|
+
|
750
|
+
# カーソル表示
|
751
|
+
cursor_left_top = vec2[@edit_cursor.x * @edit_cursor_rc.w, @edit_cursor.y * @edit_cursor_rc.h]
|
752
|
+
@edit_cursor_center = cursor_left_top + @edit_cursor_rc.half_wh
|
753
|
+
@camera_target = @edit_cursor_center
|
754
|
+
draw_rect(rect4[*(cursor_left_top - camera_offset), *@edit_cursor_rc.wh]) # FIXME: 引数
|
755
|
+
|
756
|
+
# ホールドしているブロックを移動
|
757
|
+
if @hold_block
|
758
|
+
@hold_block.pos = @edit_cursor_center.clone
|
759
|
+
end
|
760
|
+
|
761
|
+
# [L1][L2] ブロックの切り替え
|
762
|
+
v = ext_button.btL1.repeat_0or1 - ext_button.btR1.repeat_0or1
|
763
|
+
# v = button.btA.repeat_0or1 - button.btD.repeat_0or1
|
764
|
+
if v.abs > 0
|
765
|
+
Stylet::SE[:nc6131_ff_cursor].play
|
766
|
+
@edit_select_object_index += v
|
767
|
+
edit_func_block_hold_new
|
768
|
+
end
|
769
|
+
|
770
|
+
# △新しいブロックをホールドする
|
771
|
+
if button.btB.trigger?
|
772
|
+
unless @hold_block
|
773
|
+
Stylet::SE[:nc6131_ff_cursor].play
|
774
|
+
edit_func_block_hold_new
|
775
|
+
end
|
776
|
+
end
|
777
|
+
|
778
|
+
# ×ホールドしているブロックを消去する
|
779
|
+
if button.btD.trigger?
|
780
|
+
if @hold_block
|
781
|
+
Stylet::SE[:nc6131_ff_cursor].play
|
782
|
+
edit_func_block_kill
|
783
|
+
else
|
784
|
+
edit_func_kill_object_on_map
|
785
|
+
end
|
786
|
+
end
|
787
|
+
|
788
|
+
# □ホールドしていなければホールド。ホールドしていればコピーを置く
|
789
|
+
if button.btA.trigger?
|
790
|
+
if @hold_block
|
791
|
+
# 置く
|
792
|
+
if @objects.any? {|o|o != @hold_block && o.pos == @hold_block.pos}
|
793
|
+
# 置こうとしたけど自分以外のブロックがある場合
|
794
|
+
# Stylet::SE["nc45878_buu"].play
|
795
|
+
edit_func_kill_hold_object
|
796
|
+
end
|
797
|
+
Stylet::SE["nc6131_ff_cursor"].play
|
798
|
+
edit_func_block_stamp
|
799
|
+
else
|
800
|
+
if true
|
801
|
+
# ホールドする
|
802
|
+
if v = @objects.find {|o|o.pos == @edit_cursor_center}
|
803
|
+
@hold_block = v
|
804
|
+
end
|
805
|
+
else
|
806
|
+
# 消す
|
807
|
+
edit_func_kill_object_on_map
|
808
|
+
end
|
809
|
+
end
|
810
|
+
end
|
811
|
+
|
812
|
+
# ○捕む、離す
|
813
|
+
if button.btC.trigger?
|
814
|
+
if @hold_block
|
815
|
+
edit_func_kill_hold_object
|
816
|
+
Stylet::SE["nc6131_ff_cursor"].play
|
817
|
+
edit_func_block_stamp
|
818
|
+
edit_func_block_kill
|
819
|
+
else
|
820
|
+
edit_func_block_hold
|
821
|
+
end
|
822
|
+
end
|
823
|
+
|
824
|
+
if key_down?(SDL::Key::N) || key_down?(SDL::Key::P)
|
825
|
+
@stg_index += (key_down?(SDL::Key::N) ? 1 : 0) - (key_down?(SDL::Key::P) ? 1 : 0)
|
826
|
+
edit_func_stage_reload
|
827
|
+
end
|
828
|
+
|
829
|
+
# if @hold_block
|
830
|
+
# @wall_scroll_distance_x += (Stylet.context.ext_button.btL2.repeat_0or1 - Stylet.context.ext_button.btR2.repeat_0or1)
|
831
|
+
# end
|
832
|
+
|
833
|
+
# @camera.x += (Stylet.context.ext_button.btL1.repeat_0or1 - Stylet.context.ext_button.btR1.repeat_0or1)
|
834
|
+
# @camera.y += (Stylet.context.ext_button.btL1.repeat_0or1 - Stylet.context.ext_button.btR1.repeat_0or1)
|
835
|
+
|
836
|
+
if key_down?(SDL::Key::S)
|
837
|
+
edit_func_stage_save
|
838
|
+
end
|
839
|
+
|
840
|
+
if key_down?(SDL::Key::E) || ext_button.btPS.trigger?
|
841
|
+
@state = :stg_loop
|
842
|
+
@state_counter = 0
|
843
|
+
SDL::Mixer.resume_music
|
844
|
+
end
|
845
|
+
else
|
846
|
+
if key_down?(SDL::Key::E) || ext_button.btPS.trigger?
|
847
|
+
@state = :edit_mode
|
848
|
+
@state_counter = -1
|
849
|
+
end
|
850
|
+
end
|
851
|
+
|
852
|
+
dputs "#{@state}: #{@state_counter}"
|
853
|
+
|
854
|
+
if key_down?(SDL::Key::R)
|
855
|
+
# edit_func_stage_reload
|
856
|
+
@state = :stg_set
|
857
|
+
@state_counter = -1
|
858
|
+
# @stg_index += 1
|
859
|
+
end
|
860
|
+
@state_counter += 1
|
861
|
+
|
862
|
+
unless Stylet.production
|
863
|
+
# @camera.x += (Stylet.context.ext_button.btL1.repeat_0or1 - Stylet.context.ext_button.btR1.repeat_0or1)
|
864
|
+
# @camera.y += (Stylet.context.ext_button.btL1.repeat_0or1 - Stylet.context.ext_button.btR1.repeat_0or1)
|
865
|
+
# @wall_scroll_distance_x += (Stylet.context.ext_button.btL2.repeat_0or1 - Stylet.context.ext_button.btR2.repeat_0or1)
|
866
|
+
end
|
867
|
+
|
868
|
+
# キャラ同士の反発
|
869
|
+
begin
|
870
|
+
@players.combination(2).each do |p1, p2|
|
871
|
+
diff = p1.pos - p2.pos
|
872
|
+
next if diff.zero? # まったく同じ位置にいる場合 diff.normalize できないため
|
873
|
+
rdiff = (p1.rc.half_w + p2.rc.half_w) - diff.magnitude # めりこみ度 = P1半径+P2の半径 - P1とP2の距離
|
874
|
+
|
875
|
+
unless Stylet.production
|
876
|
+
draw_circle(p1.pos - camera_offset, :radius => p1.rc.half_w)
|
877
|
+
draw_circle(p2.pos - camera_offset, :radius => p2.rc.half_w)
|
878
|
+
end
|
879
|
+
|
880
|
+
if rdiff > 0
|
881
|
+
# 反発すると同時にジャンプボタンを押したら反発力4倍
|
882
|
+
rebound = proc {|p, sign|
|
883
|
+
if true
|
884
|
+
# めり込んでない位置まで反発する(さらに反発するなら処理を減らすためにここはスキップしてもいい)
|
885
|
+
p.pos += diff.normalize * rdiff * sign / 2
|
886
|
+
end
|
887
|
+
if true
|
888
|
+
# さらに反発(rdiff/2だと力がそのままでおもしろくないので増やした方がいいけど、頭上ジャンプがあるならここはスキップしてもいい)
|
889
|
+
p.speed += diff.normalize * rdiff * sign * @rebound_power
|
890
|
+
end
|
891
|
+
if false
|
892
|
+
# ジャンプボタンをタイミングよく押したらもっと跳ねる
|
893
|
+
if (1..@rebound_up_frames).include?(p.button.btD.counter)
|
894
|
+
p.speed += diff.normalize * rdiff * @rebound_up_powner
|
895
|
+
p.jump_process
|
896
|
+
# Stylet::SE["coin"].play
|
897
|
+
end
|
898
|
+
end
|
899
|
+
# スピードベクトルが大きいキャラほど大きく動かす場合
|
900
|
+
# ・物理的にはおかしいけど初代マリオブラザーズっぽい動きになる)
|
901
|
+
# ・これでも頭上で何度もジャンプするのが難しい
|
902
|
+
if false
|
903
|
+
p.speed = diff.normalize * sign * p.speed.magnitude * @head_jump_mul # だんだんスピードが大きくなる
|
904
|
+
end
|
905
|
+
# 頭上でジャンプしやすくする(トランポリンぽくなる)
|
906
|
+
# なるべく縦方向に補正する
|
907
|
+
if true
|
908
|
+
p.jump_count = 1 # 頭上ジャンプする毎に二段ジャンプができる
|
909
|
+
p.jump_process
|
910
|
+
d = diff * sign
|
911
|
+
# FIXME: 真上補正は上向きベクトルがあるもののみにした方がいいかも
|
912
|
+
a = d.angle + Stylet::Magic.angle_diff(from: d.angle, to: Stylet::Magic.clock(12)) * @vertical_correction
|
913
|
+
p.speed = vec2.angle_at(a) * p.speed.magnitude * @head_jump_mul # だんだんスピードが大きくなる
|
914
|
+
end
|
915
|
+
}
|
916
|
+
rebound.call(p1, +1)
|
917
|
+
rebound.call(p2, -1)
|
918
|
+
end
|
919
|
+
end
|
920
|
+
end
|
921
|
+
|
922
|
+
vputs "coins: #{@coins.size}"
|
923
|
+
Utils.draw_hline(@ground_y - camera_offset.y) unless Stylet.production
|
924
|
+
dputs "stg_index: #{@stg_index}"
|
925
|
+
|
926
|
+
dputs "#{@blocks.size}, #{@coins.size}, #{@players.size}, #{@objects.size}"
|
927
|
+
|
928
|
+
update_camera
|
929
|
+
|
930
|
+
scroll_line_check
|
931
|
+
end
|
932
|
+
|
933
|
+
def scroll_line_check
|
934
|
+
return if Stylet.production
|
935
|
+
Utils.draw_vline(srect.min_x + @wall_scroll_distance_x)
|
936
|
+
Utils.draw_vline(srect.max_x - @wall_scroll_distance_x)
|
937
|
+
Utils.draw_hline(srect.min_y + @wall_scroll_distance_y)
|
938
|
+
Utils.draw_hline(srect.max_y - @wall_scroll_distance_y)
|
939
|
+
end
|
940
|
+
|
941
|
+
# スクロールの計算
|
942
|
+
def update_camera
|
943
|
+
# 二人のプレイヤーの真ん中にカメラを合わせる
|
944
|
+
if @state == :edit_mode
|
945
|
+
else
|
946
|
+
if @players.size >= 1
|
947
|
+
@camera_target.x = @players.collect(&:x).reduce(0, :+) / @players.size
|
948
|
+
@camera_target.y = @players.collect(&:y).reduce(0, :+) / @players.size
|
949
|
+
end
|
950
|
+
end
|
951
|
+
|
952
|
+
# 中央にキャラクタが来るように自動的にカメラを動かす方法
|
953
|
+
if @camera_auto
|
954
|
+
d = @camera_target.x - @camera.x # 画面中央とキャラクタの差分
|
955
|
+
@camera.x += d * Stylet.context.camera_speed # 少しずつ差分を減らしていく
|
956
|
+
end
|
957
|
+
|
958
|
+
# 強制スクロールする例(左右に揺らす例)
|
959
|
+
if false
|
960
|
+
movable_width = virtual_rect.w - srect.w # カメラの移動可能な幅
|
961
|
+
@camera.x = virtual_rect.half_w + Stylet::Magic.rsin(1.0 / 512 * frame_counter) * movable_width / 2
|
962
|
+
end
|
963
|
+
|
964
|
+
# キャラに合わせてスクロールする例
|
965
|
+
if true
|
966
|
+
# 左
|
967
|
+
a = @camera.x - srect.half_w # スクリーン左端→仮想座標変換
|
968
|
+
b = @camera_target.x - a # 画面左端から距離
|
969
|
+
d = @wall_scroll_distance_x - b
|
970
|
+
if d > 0
|
971
|
+
@camera.x -= d
|
972
|
+
end
|
973
|
+
|
974
|
+
# 右
|
975
|
+
a = @camera.x + srect.half_w # スクリーン右端の、仮想画面でのX
|
976
|
+
b = a - @camera_target.x # 画面右端との距離
|
977
|
+
d = @wall_scroll_distance_x - b # 画面右端
|
978
|
+
if d > 0
|
979
|
+
@camera.x += d # めり込んだので右から左にスクロール
|
980
|
+
end
|
981
|
+
|
982
|
+
# 下
|
983
|
+
a = @camera.y + srect.half_h # スクリーン右端の、仮想画面でのX
|
984
|
+
b = a - @camera_target.y # 画面右端との距離
|
985
|
+
d = @wall_scroll_distance_y - b # 画面右端
|
986
|
+
if d > 0
|
987
|
+
@camera.y += d # めり込んだので右から左にスクロール
|
988
|
+
end
|
989
|
+
|
990
|
+
# 上
|
991
|
+
a = @camera.y - srect.half_h # スクリーン左端→仮想座標変換
|
992
|
+
b = @camera_target.y - a # 画面左端から距離
|
993
|
+
d = @wall_scroll_distance_y - b
|
994
|
+
if d > 0
|
995
|
+
@camera.y -= d
|
996
|
+
end
|
997
|
+
end
|
998
|
+
|
999
|
+
# スト2のように画面端ではスクロールを止める
|
1000
|
+
if true
|
1001
|
+
if @camera.x < srect.half_w
|
1002
|
+
@camera.x = srect.half_w
|
1003
|
+
end
|
1004
|
+
if @camera.x > @virtual_rect.w - srect.half_w
|
1005
|
+
@camera.x = @virtual_rect.w - srect.half_w
|
1006
|
+
end
|
1007
|
+
if @camera.y < srect.half_h
|
1008
|
+
@camera.y = srect.half_h
|
1009
|
+
end
|
1010
|
+
if @camera.y > @virtual_rect.h - srect.half_h
|
1011
|
+
@camera.y = @virtual_rect.h - srect.half_h
|
1012
|
+
end
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
dputs "camera: #{camera.truncate}"
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
def active_x_range
|
1019
|
+
(@camera.x - srect.half_w - @view_play)...(@camera.x + srect.half_w + @view_play)
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
def active_y_range
|
1023
|
+
(@camera.y - srect.half_h - @view_play)...(@camera.y + srect.half_h + @view_play)
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
# カメラの左上が指すゲーム内X
|
1027
|
+
def camera_offset
|
1028
|
+
@camera - srect.half_wh
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
def background_clear
|
1032
|
+
# # 多重スクロールする場合は奥にあるものから順に表示していく
|
1033
|
+
# if @scene_bg2
|
1034
|
+
# ox = (@scene_bg2.w - srect.w).to_f / (virtual_rect.w - srect.w) * camera_offset.x
|
1035
|
+
# oy = (@scene_bg2.h - srect.h).to_f / (virtual_rect.h - srect.h) * camera_offset.y
|
1036
|
+
# SDL::Surface.blit(@scene_bg2, ox, oy, srect.w, srect.h / 2, @screen, 0, 0)
|
1037
|
+
# end
|
1038
|
+
#
|
1039
|
+
if @bg_mode == :background
|
1040
|
+
draw_rect(srect, :color => :background, :fill => true)
|
1041
|
+
end
|
1042
|
+
if @bg_mode == :image
|
1043
|
+
# カメラと背景画像の関係
|
1044
|
+
# ゲーム内画面幅1280 : 画像幅960 = カメラ左上座標 : ofs
|
1045
|
+
# となるので移項すると ofs = 画像幅960 * カメラ左上座標 / ゲーム内画面幅1280
|
1046
|
+
# offset = @scene_main_bg.w.to_f / virtual_rect.w * camera_offset
|
1047
|
+
# とすのは間違いで、
|
1048
|
+
# ゲーム内画面幅1280-640 : 画像幅960-640 = カメラ左上座標 : ofs
|
1049
|
+
# が正しい。640は画面(カメラ)の幅
|
1050
|
+
# これで右端が画像の右端と一致する
|
1051
|
+
ox = (@scene_main_bg.w - srect.w).to_f / (virtual_rect.w - srect.w) * camera_offset.x
|
1052
|
+
oy = (@scene_main_bg.h - srect.h).to_f / (virtual_rect.h - srect.h) * camera_offset.y
|
1053
|
+
begin
|
1054
|
+
SDL::Surface.blit(@scene_main_bg, ox, oy, srect.w, srect.h, @screen, 0, 0)
|
1055
|
+
rescue RangeError
|
1056
|
+
end
|
1057
|
+
end
|
1058
|
+
if @bg_mode == :ff_effect
|
1059
|
+
# FF7で敵に遭遇したときの画面エフェクト
|
1060
|
+
screen.set_alpha(SDL::SRCALPHA, 128)
|
1061
|
+
SDL::Surface.transform_blit(screen, screen, 1, 1.05, 1.05, *srect.center, *srect.center, SDL::Surface::TRANSFORM_AA | SDL::Surface::TRANSFORM_SAFE)
|
1062
|
+
end
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
def edit_func_init
|
1066
|
+
@edit_cursor ||= vec2[0, 0]
|
1067
|
+
@edit_cursor_rc ||= rect2[32, 32]
|
1068
|
+
@edit_rect ||= rect4[0, 0, virtual_rect.w / @edit_cursor_rc.w, virtual_rect.h / @edit_cursor_rc.h]
|
1069
|
+
@edit_select_object_index ||= 0
|
1070
|
+
|
1071
|
+
@select_blocks = [
|
1072
|
+
SoftBlock.new,
|
1073
|
+
HardBlock.new,
|
1074
|
+
WhiteBlock.new,
|
1075
|
+
Coin.new,
|
1076
|
+
Mario.new,
|
1077
|
+
Luigi.new,
|
1078
|
+
]
|
1079
|
+
end
|
1080
|
+
|
1081
|
+
def edit_func_block_hold
|
1082
|
+
if v = @objects.find {|o|o.pos == @edit_cursor_center}
|
1083
|
+
@hold_block = v
|
1084
|
+
end
|
1085
|
+
end
|
1086
|
+
|
1087
|
+
def edit_func_block_kill
|
1088
|
+
if @hold_block
|
1089
|
+
kill_task @hold_block
|
1090
|
+
@hold_block = nil
|
1091
|
+
end
|
1092
|
+
end
|
1093
|
+
|
1094
|
+
def edit_func_block_hold_new
|
1095
|
+
edit_func_block_kill
|
1096
|
+
@hold_block = @select_blocks[@edit_select_object_index.modulo(@select_blocks.size)]
|
1097
|
+
if @hold_block
|
1098
|
+
@hold_block.pos = @edit_cursor_center.clone # すぐに座標を設定しておくの重要
|
1099
|
+
task_set @hold_block
|
1100
|
+
end
|
1101
|
+
end
|
1102
|
+
|
1103
|
+
def edit_func_block_stamp
|
1104
|
+
task_set @hold_block.class.new(pos: @hold_block.pos) # clone だといろいろ共有されてしまう
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
def edit_func_kill_hold_object
|
1108
|
+
if @hold_block
|
1109
|
+
if obj = @objects.find {|o|o != @hold_block && o.pos == @hold_block.pos}
|
1110
|
+
kill_task obj
|
1111
|
+
end
|
1112
|
+
end
|
1113
|
+
end
|
1114
|
+
|
1115
|
+
def edit_func_kill_object_on_map
|
1116
|
+
unless @hold_block
|
1117
|
+
if obj = @objects.find {|o|o.pos == @edit_cursor_center}
|
1118
|
+
kill_task obj
|
1119
|
+
end
|
1120
|
+
end
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
def edit_func_stage_save
|
1124
|
+
positions = @objects.group_by(&:class).inject({}) {|hash, (klass, objs)|
|
1125
|
+
hash.merge(klass.name => objs.collect {|e| e.pos.round.to_a })
|
1126
|
+
}
|
1127
|
+
attrs = {
|
1128
|
+
:world_wh => @virtual_rect.wh.to_a,
|
1129
|
+
:positions => positions,
|
1130
|
+
}
|
1131
|
+
data = {}
|
1132
|
+
if @stage_file.exist?
|
1133
|
+
data = eval(@stage_file.read)
|
1134
|
+
end
|
1135
|
+
data.update(@stg_index => attrs)
|
1136
|
+
@stage_file.write(data.inspect)
|
1137
|
+
puts "output: #{@stage_file}"
|
1138
|
+
end
|
1139
|
+
|
1140
|
+
def edit_func_stage_reload
|
1141
|
+
@blocks.clone.each {|block|kill_task(block)}
|
1142
|
+
@coins.clone.each {|coin|kill_task(coin)}
|
1143
|
+
@players.clone.each {|player|kill_task(player)}
|
1144
|
+
|
1145
|
+
begin
|
1146
|
+
@stage_file = Pathname("stage_infos.rb").expand_path
|
1147
|
+
@stage_infos = []
|
1148
|
+
if @stage_file.exist?
|
1149
|
+
@stage_infos = eval(@stage_file.read)
|
1150
|
+
end
|
1151
|
+
@one_stage = @stage_infos[@stg_index]
|
1152
|
+
if @one_stage
|
1153
|
+
@one_stage[:positions].each do |klass, positions|
|
1154
|
+
positions.each do |pos|
|
1155
|
+
task_set klass.constantize.new(pos: vec2[*pos])
|
1156
|
+
end
|
1157
|
+
end
|
1158
|
+
end
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
if @stg_index == 0
|
1162
|
+
Stylet::Music.play("assets/musmus_tacos_de_dong.ogg", volume: 0.3)
|
1163
|
+
|
1164
|
+
(m = 4).times.each do |j|
|
1165
|
+
(n = 8).times.each do |i|
|
1166
|
+
if j.even? && (i + j / 2).even?
|
1167
|
+
klass = HardBlock
|
1168
|
+
else
|
1169
|
+
klass = SoftBlock
|
1170
|
+
end
|
1171
|
+
v = vec2[16 + @virtual_rect.w / n * (i + (j.next.modulo(2) * 0.5)), @ground_y - 16 - 32 * 2 - 32 * 3 * j]
|
1172
|
+
task_set klass.new(pos: v)
|
1173
|
+
task_set Coin.new(pos: v + [0, -32])
|
1174
|
+
end
|
1175
|
+
end
|
1176
|
+
@scene_main_bg = Sprite.surface_load("assets/bg960x640_town.png", :mask => false)
|
1177
|
+
if false
|
1178
|
+
# モーションブラー効果
|
1179
|
+
@scene_main_bg.set_alpha(SDL::SRCALPHA, 64)
|
1180
|
+
@scene_main_bg = @scene_main_bg.display_format
|
1181
|
+
end
|
1182
|
+
end
|
1183
|
+
|
1184
|
+
if @stg_index == 1
|
1185
|
+
Stylet::Music.play("assets/musmus_fm_kids.ogg", volume: 0.3)
|
1186
|
+
|
1187
|
+
(m = 5).times.each do |j|
|
1188
|
+
(n = 40).times.each do |i|
|
1189
|
+
task_set Coin.new(pos: vec2[16 + @virtual_rect.w / n * i, @ground_y - 100 - j * 100 - 32])
|
1190
|
+
task_set [*[SoftBlock] * 3, HardBlock].sample.new(pos: vec2[16 + @virtual_rect.w / n * i, @ground_y - 100 - j * 100])
|
1191
|
+
end
|
1192
|
+
end
|
1193
|
+
|
1194
|
+
@scene_main_bg = Sprite.surface_load("assets/bg960x640_red_sky.png", :mask => false)
|
1195
|
+
end
|
1196
|
+
|
1197
|
+
if @stg_index == 2
|
1198
|
+
Stylet::Music.play("assets/musmus_nv36.ogg", volume: 0.3)
|
1199
|
+
@scene_main_bg = Sprite.surface_load("assets/love_live.png", :mask => false)
|
1200
|
+
end
|
1201
|
+
|
1202
|
+
if @scene_main_bg
|
1203
|
+
@bg_mode = :image
|
1204
|
+
else
|
1205
|
+
@bg_mode = :background
|
1206
|
+
end
|
1207
|
+
|
1208
|
+
begin
|
1209
|
+
if @coins.empty?
|
1210
|
+
task_set Coin.new(pos: vec2[32 / 2, @ground_y - 32 / 2])
|
1211
|
+
end
|
1212
|
+
if @players.empty?
|
1213
|
+
task_set Mario.new(pos: vec2[srect.half_w - srect.half_w * 0.1, @ground_y - 32])
|
1214
|
+
task_set Luigi.new(pos: vec2[srect.half_w + srect.half_w * 0.1, @ground_y - 32])
|
1215
|
+
end
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
if @state == :edit_mode
|
1219
|
+
SDL::Mixer.pause_music
|
1220
|
+
end
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
# FIXME: 冗長すぎる
|
1224
|
+
def task_set(v)
|
1225
|
+
if v.is_a? BlockBase
|
1226
|
+
@blocks << v
|
1227
|
+
end
|
1228
|
+
if v.is_a? PlayerBase
|
1229
|
+
@players << v
|
1230
|
+
end
|
1231
|
+
if v.is_a? Coin
|
1232
|
+
@coins << v
|
1233
|
+
end
|
1234
|
+
@objects << v
|
1235
|
+
end
|
1236
|
+
|
1237
|
+
def kill_task(v)
|
1238
|
+
@objects.delete(v)
|
1239
|
+
if v.is_a? BlockBase
|
1240
|
+
@blocks.delete(v)
|
1241
|
+
end
|
1242
|
+
if v.is_a? PlayerBase
|
1243
|
+
@players.delete(v)
|
1244
|
+
end
|
1245
|
+
if v.is_a? Coin
|
1246
|
+
@coins.delete(v)
|
1247
|
+
end
|
1248
|
+
end
|
1249
|
+
|
1250
|
+
run
|
1251
|
+
end
|