Marker components for the ball & paddles

This commit is contained in:
2025-10-21 12:36:47 -05:00
parent 129e9ccc5e
commit 7ac3882e9e

View File

@@ -76,6 +76,7 @@ fn setup_game(
) {
// ball
commands.spawn((
Ball,
Mesh2d(meshes.add(Circle::new(10.0))),
MeshMaterial2d(materials.add(Color::srgb(1.0, 0.0, 0.0))),
Transform::default(),
@@ -85,23 +86,32 @@ fn setup_game(
let paddle_material = materials.add(Color::WHITE);
// Player 1
commands.spawn((
// TODO: Marker component for player
// Maybe one for each player?
// Maybe it can hold the WebSocket, too.
// *Maybe* I can have one struct with an Option<Ws> to know which
// player is the local one (the one with a socket).
Paddle,
Mesh2d(paddle_mesh.clone()),
MeshMaterial2d(paddle_material.clone()),
Transform::from_xyz(-window.width() / 2.0 + PADDLE_GAP, 0.0, 1.0),
));
// Player 2
commands.spawn((
Paddle,
Mesh2d(paddle_mesh),
MeshMaterial2d(paddle_material),
Transform::from_xyz(window.width() / 2.0 - PADDLE_GAP, 0.0, 1.0),
));
}
#[derive(Component)]
struct Ball;
/// Marker component for player paddles
///
/// Maybe one for each player?
/// Maybe it can hold the WebSocket, too.
/// *Maybe* I can have one struct with an Option<Ws> to know which
/// player is the local one (the one with a socket).
#[derive(Component)]
struct Paddle;
/// ECS Component to hold the WebSocket. I guess there's going to be a magic
/// entity that controls the networking.
#[derive(Component)]