Very basic entities for battler

main
Elijah Voigt 2 months ago
parent 2a5d7363fe
commit db480af595

@ -40,10 +40,11 @@ fn main() {
.add_systems( .add_systems(
Startup, Startup,
( (
init_world, init_tetris,
init_debug_ui, init_debug_ui,
init_cameras, init_cameras,
init_ui.after(init_cameras), init_ui.after(init_cameras),
init_battler,
), ),
) )
// Input and basic systems // Input and basic systems
@ -276,7 +277,7 @@ impl Display for ShapeStore {
#[derive(Component)] #[derive(Component)]
struct GridBackground; struct GridBackground;
fn init_world( fn init_tetris(
mut commands: Commands, mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>, mut materials: ResMut<Assets<ColorMaterial>>,
@ -313,6 +314,45 @@ fn init_world(
}); });
} }
fn init_battler(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
{
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)] #[derive(Resource, Default)]
struct OutputImages { struct OutputImages {
tetris: Handle<Image>, tetris: Handle<Image>,
@ -366,6 +406,7 @@ fn init_cameras(
Camera { Camera {
order: 1, order: 1,
target, target,
clear_color: ClearColorConfig::Custom(WHITE.into()),
..default() ..default()
}, },
TETRIS, 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 target = {
let handle = images.add(img); let handle = images.add(img);
output_images.battler = handle.clone(); output_images.battler = handle.clone();
@ -390,6 +432,7 @@ fn init_cameras(
Camera { Camera {
order: 2, order: 2,
target, target,
clear_color: ClearColorConfig::Custom(WHITE.into()),
..default() ..default()
}, },
BATTLER, BATTLER,
@ -475,8 +518,8 @@ fn init_ui(mut commands: Commands, output_images: Res<OutputImages>, images: Res
let img = images.get(&output_images.battler).unwrap(); let img = images.get(&output_images.battler).unwrap();
parent.spawn(( parent.spawn((
Node { Node {
width: Val::Px(img.size_f32().x * 0.5), width: Val::Px(img.size_f32().x * 0.75),
height: Val::Px(img.size_f32().y * 0.5), height: Val::Px(img.size_f32().y * 0.75),
..default() ..default()
}, },
ImageNode { ImageNode {

Loading…
Cancel
Save