Skip to content

Commit

Permalink
Merge pull request #28 from hyoi/migration_0.13
Browse files Browse the repository at this point in the history
v0.11.0のリリース(Bevy 0.13対応)
  • Loading branch information
hyoi authored Feb 18, 2024
2 parents fbb5ec7 + d2fb72a commit ac91fa3
Show file tree
Hide file tree
Showing 19 changed files with 685 additions and 480 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "tigtag"
version = "0.10.4"
version = "0.11.0"
edition = "2021"

[dependencies]
#bevy = { git = "https://github.com/bevyengine/bevy" } #Master branch
bevy = "0.12"
bevy = "0.13"
once_cell = "1"
rand = "0.8"
regex = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/init_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn update_fps
{ let Ok( mut text ) = qry_text.get_single_mut() else { return };

let fps_avr = diag_store
.get( FrameTimeDiagnosticsPlugin::FPS )
.get( &FrameTimeDiagnosticsPlugin::FPS )
.map_or
( NA3_2.to_string(),
| fps |
Expand Down
6 changes: 3 additions & 3 deletions src/load_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl Plugin for Schedule

//ループ脱出:事前ロードが完了した & 遷移先がセットされている
misc::change_state_with_res::<AfterLoadAssetsTo<MyState>>
.run_if( resource_exists::<LoadingFinished>() ) //フラグ
.run_if( resource_exists::<AfterLoadAssetsTo<MyState>>() ), //遷移先
.run_if( resource_exists::<LoadingFinished> ) //フラグ
.run_if( resource_exists::<AfterLoadAssetsTo<MyState>> ), //遷移先
)
.run_if( in_state( MyState::LoadAssets ) )
)
Expand Down Expand Up @@ -172,7 +172,7 @@ fn move_sprite
let scaling = SCREEN_PIXELS_WIDTH / NOWLOADING.width; //横方向に長いので
let adjuster_y = ( SCREEN_PIXELS_HEIGHT - NOWLOADING.height * scaling ) * -0.5;

qry_transform.for_each_mut
qry_transform.iter_mut().for_each
( | ( mut transform, goal ) |
{ //座標の調整
let mut goal = goal.grid.to_vec2_on_screen() * scaling;
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy::
diagnostic::{ DiagnosticsStore, FrameTimeDiagnosticsPlugin },
sprite::{ Anchor, MaterialMesh2dBundle },
utils::{ HashSet, HashMap },
audio::{ Volume, VolumeLevel },
audio::Volume,
};
use once_cell::sync::Lazy;
use rand::prelude::*;
Expand Down Expand Up @@ -56,7 +56,7 @@ fn main()
//テスト用:オブジェクト表示
debug::spawn_2d_sprites //2D表示テスト
.run_if( DEBUG )
.run_if( not( resource_exists::<Map>() ) ) //debug表示が被るので
.run_if( not( resource_exists::<Map> ) ) //debug表示が被るので
)
)
.init_resource::<TargetGamepad>() //操作を受付けるゲームパッドのID
Expand All @@ -72,7 +72,7 @@ fn main()

//メイン処理
app
.add_state::<MyState>() //Stateを初期化する。enumの#[default]で初期値指定
.init_state::<MyState>() //Stateを初期化する。enumの#[default]で初期値指定
.add_plugins( load_assets::Schedule ) //assetsの事前ロード
.add_plugins( init_app::Schedule ) //ゲーム枠・FPSの表示等、事前処理
.add_plugins( play_game::Schedule ) //ゲームロジック
Expand Down
46 changes: 28 additions & 18 deletions src/play_game/chasers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,48 +58,58 @@ pub fn spawn_sprite
opt_record: Option<Res<Record>>,
mut cmds: Commands,
asset_svr: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
mut texture_atlases_layout: ResMut<Assets<TextureAtlasLayout>>,
)
{ let Some ( record ) = opt_record else { return };

//スプライトがあれば削除する
qry_chaser.for_each( | id | cmds.entity( id ).despawn_recursive() );
qry_chaser.iter().for_each( | id | cmds.entity( id ).despawn_recursive() );

//チェイサーのスプライトを配置する
( 0.. ).zip( CHASER_START_POSITION ).zip( SPRITE_SHEET_CHASERS ).for_each
( | ( ( i, chaser_grid ), asset ) |
{ let chaser_vec2 = chaser_grid.to_vec2_on_map();
let index = ( ( i + record.stage() - 1 ) % 4 ) as usize;
( | ( ( i, chaser_grid ), asset_file ) |
{ let index = ( ( i + record.stage() - 1 ) % 4 ) as usize;
let ( color, opt_fn_chasing ) = COLOR_SPRITE_CHASERS[ index ];

let sprite_vec2 = chaser_grid.to_vec2_on_map();
let translation = sprite_vec2.extend( DEPTH_SPRITE_CHASER );

//チェイサーのComponentを初期化する
let chaser = Chaser
{ grid : *chaser_grid,
next_grid: *chaser_grid,
dx_start : chaser_vec2,
dx_end : chaser_vec2,
dx_start : sprite_vec2,
dx_end : sprite_vec2,
color,
opt_fn_chasing,
..default()
};
let translation = chaser_vec2.extend( DEPTH_SPRITE_CHASER );

//アニメーションするスプライトをspawnする
let texture_atlas = asset_svr.gen_texture_atlas_chaser( asset );
let texture_atlas_hdl = texture_atlases.add( texture_atlas );
let custom_size = Some( SIZE_GRID );
let texture_atlas_sprite = TextureAtlasSprite { custom_size, ..default() };
let layout = texture_atlases_layout.add
( TextureAtlasLayout::from_grid
( SPRITE_SHEET_SIZE_CHASER,
SPRITE_SHEET_COLS_CHASER,
SPRITE_SHEET_ROWS_CHASER,
None, None
)
);
let index = chaser.sprite_sheet_offset( chaser.direction() );
cmds.spawn( ( SpriteSheetBundle::default(), chaser ) )
.insert( texture_atlas_hdl.clone() )
.insert( texture_atlas_sprite )
.insert( Sprite { custom_size, ..default() } )
.insert( asset_svr.load( *asset_file ) as Handle<Image> )
.insert( TextureAtlas { layout, index } )
.insert( Transform::from_translation( translation ) )
;

//正方形のメッシュ
// let custom_size = Some ( SIZE_GRID * MAGNIFY_SPRITE_CHASER );
// //正方形のメッシュ
// let custom_size = Some ( SIZE_GRID * _MAGNIFY_SPRITE_CHASER );
// cmds
// .spawn( ( SpriteBundle::default(), chaser ) )
// .insert( Sprite { color, custom_size, ..default() } )
// .insert( Transform::from_translation( translation ) )
// .insert( TextureAtlasSprite::default() ) //move_sprite()のqry_playerの検索条件を満たすためのdummy
// // .insert( TextureAtlas::default() ) //move_sprite()のqry_playerの検索条件を満たすためのdummy
// ;
}
);
Expand All @@ -117,14 +127,14 @@ pub fn spawn_sprite
// let quat = Quat::from_rotation_z( radian );

// //回転させる
// qry_chaser.for_each_mut( | mut transform | transform.rotate( quat ) );
// qry_chaser.iter_mut().for_each( | mut transform | transform.rotate( quat ) );
// }

////////////////////////////////////////////////////////////////////////////////

//チェイサーを移動させる
pub fn move_sprite
( mut qry_chaser: Query<( &mut Chaser, &mut Transform, &mut TextureAtlasSprite )>,
( mut qry_chaser: Query<( &mut Chaser, &mut Transform, &mut TextureAtlas )>,
opt_map: Option<Res<Map>>,
qry_player: Query<&Player>,
mut evt_clear : EventReader<EventClear>,
Expand Down
12 changes: 6 additions & 6 deletions src/play_game/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub fn catch_player_operation
( qry_player: Query<&Player>,
opt_cross: Option<ResMut<CrossDirection>>,
opt_gamepad: Option<Res<TargetGamepad>>,
keys: Res<Input<KeyCode>>,
buttons: Res<Input<GamepadButton>>,
keys: Res<ButtonInput<KeyCode>>,
buttons: Res<ButtonInput<GamepadButton>>,
)
{ let Ok ( player ) = qry_player.get_single() else { return };

Expand Down Expand Up @@ -57,10 +57,10 @@ pub fn catch_player_operation
.filter_map
( | keycode |
match keycode
{ KeyCode::Up => Some ( News::North ),
KeyCode::Right => Some ( News::East ),
KeyCode::Left => Some ( News::West ),
KeyCode::Down => Some ( News::South ),
{ KeyCode::ArrowUp => Some ( News::North ),
KeyCode::ArrowRight => Some ( News::East ),
KeyCode::ArrowLeft => Some ( News::West ),
KeyCode::ArrowDown => Some ( News::South ),
_ => None,
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/play_game/judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn scoring_and_stageclear
map.remaining_dots -= 1;

//1度beepを鳴らす(despawn処理付き)
let volume = Volume::Relative ( VolumeLevel::new( VOLUME_SOUND_BEEP ) );
let volume = Volume::new( VOLUME_SOUND_BEEP );
let sound_beep = AudioBundle
{ source: asset_svr.load( ASSETS_SOUND_BEEP ),
settings: PlaybackSettings::DESPAWN.with_volume( volume ),
Expand Down Expand Up @@ -94,7 +94,7 @@ pub fn detect_collisions

//直前の判定でクリアしていたら衝突判定しない
if evt_clear.read().next().is_some() { return }

//衝突判定が真なら
if is_collision( qry_player, qry_chaser )
{ //衝突処理
Expand Down
18 changes: 9 additions & 9 deletions src/play_game/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn make_new_data
)
{ let Some ( mut map ) = opt_map else { return };
let Some ( mut record ) = opt_record else { return };

let half_w = MAP_GRIDS_WIDTH / 2;
let half_h = MAP_GRIDS_HEIGHT / 2;
let short_side = if half_w >= half_h { half_h } else { half_w };
Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn spawn_sprite
{ let Some ( mut map ) = opt_map else { return };

//スプライトがあれば削除する
qry_entity.for_each( | id | cmds.entity( id ).despawn_recursive() );
qry_entity.iter().for_each( | id | cmds.entity( id ).despawn_recursive() );

//壁とドットのスプライトを配置する
let custom_size = Some( SIZE_GRID );
Expand All @@ -114,15 +114,15 @@ pub fn spawn_sprite
{ #[cfg( debug_assertions )]
{ let value = format!( "{:02}\n{:02}", x, y ).to_string();
let style = TextStyle
{ font : asset_svr.load( ASSETS_FONT_PRESSSTART2P_REGULAR ),
font_size: PIXELS_PER_GRID * 0.3,
{ font_size: PIXELS_PER_GRID * 0.4,
color : Color::YELLOW,
..default()
};
let sections = vec![ TextSection { value, style } ];
let alignment = TextAlignment::Center;
let sections = vec![ TextSection { value, style } ];
let justify = JustifyText::Center;

_cmds.spawn( Text2dBundle::default() )
.insert( Text { sections, alignment, ..default() } )
.insert( Text { sections, justify, ..default() } )
.insert( Transform::from_translation( Vec3::Z ) )
;
}
Expand All @@ -132,7 +132,7 @@ pub fn spawn_sprite

if map.is_space( grid )
{ let circle = MaterialMesh2dBundle //type annotations neededが出ないからこの書き方が良い
{ mesh: meshes.add( shape::Circle::new( radius ).into() ).into(),
{ mesh: meshes.add( Circle::new( radius ).mesh().resolution( 64 ).build() ).into(),
material: materials.add( ColorMaterial::from( COLOR_SPRITE_DOT ) ),
..default()
};
Expand Down
4 changes: 2 additions & 2 deletions src/play_game/pause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ fn pause
opt_gamepad: Option<Res<TargetGamepad>>,
mut state: ResMut<State<MyState>>,
mut saved_in: Local<MyState>,
inkey: Res<Input<KeyCode>>,
inbtn: Res<Input<GamepadButton>>,
inkey: Res<ButtonInput<KeyCode>>,
inbtn: Res<ButtonInput<GamepadButton>>,
)
{ //キーの状態
let mut is_pressed = inkey.just_pressed( PAUSE_KEY );
Expand Down
42 changes: 27 additions & 15 deletions src/play_game/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pub fn spawn_sprite
opt_map: Option<ResMut<Map>>,
mut cmds: Commands,
asset_svr: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
mut texture_atlases_layout: ResMut<Assets<TextureAtlasLayout>>,
// mut meshes: ResMut<Assets<Mesh>>,
// mut materials: ResMut<Assets<ColorMaterial>>,
)
{ let Some ( mut map ) = opt_map else { return };

//スプライトがあれば削除する
qry_player.for_each( | id | cmds.entity( id ).despawn_recursive() );
qry_player.iter().for_each( | id | cmds.entity( id ).despawn_recursive() );

//乱数で初期位置を決める(マップ中央付近の通路)
let half_w = MAP_GRIDS_WIDTH / 2;
Expand All @@ -35,7 +35,7 @@ pub fn spawn_sprite
let sprite_vec2 = player_grid.to_vec2_on_map();
let translation = sprite_vec2.extend( DEPTH_SPRITE_PLAYER );

//プレイヤーのスプライトを配置する
//プレイヤーのComponentを初期化する
let player = Player
{ grid : player_grid,
next_grid: player_grid,
Expand All @@ -46,41 +46,53 @@ pub fn spawn_sprite
};

//アニメーションするスプライトをspawnする
let texture_atlas = asset_svr.gen_texture_atlas_player();
let texture_atlas_hdl = texture_atlases.add( texture_atlas );
let custom_size = Some( SIZE_GRID );
let layout = texture_atlases_layout.add
( TextureAtlasLayout::from_grid
( SPRITE_SHEET_SIZE_PLAYER,
SPRITE_SHEET_COLS_PLAYER,
SPRITE_SHEET_ROWS_PLAYER,
None, None
)
);
let index = player.sprite_sheet_offset( player.direction() );
let texture_atlas_sprite = TextureAtlasSprite { custom_size, index, ..default() };
cmds.spawn( ( SpriteSheetBundle::default(), player ) )
.insert( texture_atlas_hdl )
.insert( texture_atlas_sprite )
.insert( Sprite { custom_size, ..default() } )
.insert( asset_svr.load( ASSETS_SPRITE_SHEET_PLAYER ) as Handle<Image> )
.insert( TextureAtlas { layout, index } )
.insert( Transform::from_translation( translation ) )
;

//三角形のメッシュ
// let radius = PIXELS_PER_GRID * MAGNIFY_SPRITE_PLAYER;
// let shape = shape::RegularPolygon::new( radius, 3 ).into();
// //三角形のメッシュ
// let radius = PIXELS_PER_GRID * _MAGNIFY_SPRITE_PLAYER;
// let shape = RegularPolygon::new( radius, 3 ).mesh();
// let triangle = MaterialMesh2dBundle
// { mesh: meshes.add( shape ).into(),
// material: materials.add( COLOR_SPRITE_PLAYER.into() ),
// material: materials.add( _COLOR_SPRITE_PLAYER ),
// ..default()
// };
// let quat = Quat::from_rotation_z( PI ); //News::South
// cmds.spawn( ( triangle, player ) )
// .insert( Transform::from_translation( translation ).with_rotation( quat ) )
// .insert( TextureAtlasSprite::default() ) //move_sprite()のqry_playerの検索条件を満たすためのdummy
// .insert( TextureAtlas::default() ) //move_sprite()のqry_playerの検索条件を満たすためのdummy
// ;
// cmds.insert_resource( FlagPlayerTriangle ); //move_sprite()内処理の切替用フラグ
}

//三角形メッシュを使う場合のフラグResource
#[derive( Resource )]
pub struct FlagPlayerTriangle;

////////////////////////////////////////////////////////////////////////////////

//プレイヤーを移動させる
#[allow(clippy::too_many_arguments)]
pub fn move_sprite
( mut qry_player: Query<( &mut Player, &mut Transform, &mut TextureAtlasSprite )>,
( mut qry_player: Query<( &mut Player, &mut Transform, &mut TextureAtlas )>,
opt_input: Option<Res<input::CrossDirection>>,
opt_map: Option<Res<Map>>,
opt_demo: Option<Res<DemoMapParams>>,
opt_triangle: Option<Res<FlagPlayerTriangle>>,
qry_chasers: Query<&Chaser>,
state: ResMut<State<MyState>>,
mut evt_clear: EventReader<EventClear>,
Expand Down Expand Up @@ -159,7 +171,7 @@ pub fn move_sprite

//プレイヤーの進む向きが変わったらスプライトを回転させる
if player.direction != new_side
{ if sprite.custom_size.is_some()
{ if opt_triangle.is_none()
{ let old_offset = player.sprite_sheet_offset( player.direction );
let new_offset = player.sprite_sheet_offset( new_side );
sprite.index = sprite.index - old_offset + new_offset;
Expand Down
4 changes: 2 additions & 2 deletions src/play_game/ui/center.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ pub fn spawn_title
let component = Title::default();
let mut ui_title = misc::text_ui( component.title(), &asset_svr );
let mut ui_demo = misc::text_ui( component.demo (), &asset_svr );
ui_title.text.alignment = TextAlignment::Right; //右寄せ
ui_demo.text.alignment = TextAlignment::Center; //センタリング
ui_title.text.justify = JustifyText::Right; //右寄せ
ui_demo.text.justify = JustifyText::Center; //センタリング
ui_title.style.position_type = PositionType::Relative;
ui_demo.style.position_type = PositionType::Relative;
ui_title.visibility = Visibility::Inherited; //親のvisibility.is_visibleで表示を制御する
Expand Down
4 changes: 2 additions & 2 deletions src/play_game/ui/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ pub fn hit_any_key<T: Component + HitAnyKey>
( qry_ui: Query<&T>,
opt_gamepad: Option<Res<TargetGamepad>>,
mut next_state: ResMut<NextState<MyState>>,
inkey: Res<Input<KeyCode>>,
inbtn: Res<Input<GamepadButton>>,
inkey: Res<ButtonInput<KeyCode>>,
inbtn: Res<ButtonInput<GamepadButton>>,
)
{ let Ok ( ui ) = qry_ui.get_single() else { return };

Expand Down
Loading

0 comments on commit ac91fa3

Please sign in to comment.