You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
use std::f32::consts::PI;
|
|
|
|
use games::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(BaseGamePlugin::default())
|
|
.add_systems(Startup, init_image)
|
|
.run();
|
|
}
|
|
|
|
fn init_image(
|
|
mut commands: Commands,
|
|
server: Res<AssetServer>,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
mut std_materials: ResMut<Assets<StandardMaterial>>,
|
|
) {
|
|
// 2d
|
|
{
|
|
let texture = MeshMaterial2d(materials.add(ColorMaterial {
|
|
color: WHITE.into(),
|
|
alpha_mode: AlphaMode2d::Opaque,
|
|
texture: Some(server.load("flappy/bevy.png")),
|
|
..default()
|
|
}));
|
|
let mesh = Mesh2d(meshes.add(Rectangle::from_size(Vec2::splat(10.0))));
|
|
|
|
// opaque
|
|
// Each sprite should be square with the transparent parts being completely black
|
|
// The blue sprite should be on top with the white and green one behind it
|
|
commands.spawn((Name::new("2D Example"), mesh, texture));
|
|
}
|
|
|
|
// 3d
|
|
{
|
|
let material = MeshMaterial3d(std_materials.add(StandardMaterial {
|
|
base_color_texture: Some(server.load("flappy/bevy.png")),
|
|
base_color: WHITE.with_alpha(0.9).into(),
|
|
alpha_mode: AlphaMode::Blend,
|
|
..default()
|
|
}));
|
|
|
|
let mesh = Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0))));
|
|
|
|
let name = Name::new("3D example");
|
|
|
|
let t = Transform::from_xyz(0.0, 0.0, -10.0).with_rotation(Quat::from_rotation_x(PI / 2.0));
|
|
|
|
commands.spawn((name, mesh, material, t));
|
|
}
|
|
}
|