diff --git a/src/bin/tetris/main.rs b/src/bin/tetris/main.rs index 3c13adc..f0f1dcd 100644 --- a/src/bin/tetris/main.rs +++ b/src/bin/tetris/main.rs @@ -40,10 +40,11 @@ fn main() { .add_systems( Startup, ( - init_world, + init_tetris, init_debug_ui, init_cameras, init_ui.after(init_cameras), + init_battler, ), ) // Input and basic systems @@ -276,7 +277,7 @@ impl Display for ShapeStore { #[derive(Component)] struct GridBackground; -fn init_world( +fn init_tetris( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, @@ -313,6 +314,45 @@ fn init_world( }); } +fn init_battler( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + { + let mat = materials.add(ColorMaterial { + color: BLUE.into(), + ..default() + }); + let mesh = meshes.add(Ellipse::new(SCALE, SCALE * 2.0)); + let t = Transform::from_xyz(-3.0 * SCALE, 0.0, 0.0); + commands.spawn(( + Mesh2d(mesh), + MeshMaterial2d(mat), + t, + BATTLER, + Name::new("Protagonist"), + )); + } + + { + let mat = materials.add(ColorMaterial { + color: RED.into(), + ..default() + }); + let mesh = meshes.add(Ellipse::new(SCALE, SCALE)); + let t = Transform::from_xyz(3.0 * SCALE, 0.0, 0.0); + commands.spawn(( + Mesh2d(mesh), + MeshMaterial2d(mat), + t, + BATTLER, + Name::new("ENEMY"), + )); + } +} + + #[derive(Resource, Default)] struct OutputImages { tetris: Handle, @@ -366,6 +406,7 @@ fn init_cameras( Camera { order: 1, target, + clear_color: ClearColorConfig::Custom(WHITE.into()), ..default() }, TETRIS, @@ -374,7 +415,8 @@ fn init_cameras( } { - let img = render_target_image((512, 512)); + let (width, height) = (SCALE as u32 * Y_MAX as u32, SCALE as u32 * X_MAX as u32); + let img = render_target_image((width, height)); let target = { let handle = images.add(img); output_images.battler = handle.clone(); @@ -390,6 +432,7 @@ fn init_cameras( Camera { order: 2, target, + clear_color: ClearColorConfig::Custom(WHITE.into()), ..default() }, BATTLER, @@ -475,8 +518,8 @@ fn init_ui(mut commands: Commands, output_images: Res, images: Res let img = images.get(&output_images.battler).unwrap(); parent.spawn(( Node { - width: Val::Px(img.size_f32().x * 0.5), - height: Val::Px(img.size_f32().y * 0.5), + width: Val::Px(img.size_f32().x * 0.75), + height: Val::Px(img.size_f32().y * 0.75), ..default() }, ImageNode {