Move to avian physics, stub out flappy bird (with rewind)
parent
df069d0337
commit
9c4b4a79b9
Binary file not shown.
@ -0,0 +1,55 @@
|
|||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
use games::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new()
|
||||||
|
.add_plugins(BaseGamePlugin { name: "flappy bird (with rewind)".into() })
|
||||||
|
.add_systems(Startup, init_bird)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_bird(
|
||||||
|
mut commands: Commands,
|
||||||
|
server: Res<AssetServer>,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
) {
|
||||||
|
let material = MeshMaterial3d(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("bird");
|
||||||
|
|
||||||
|
let t = Transform::from_xyz(0.0, 0.0, -10.0).with_rotation(Quat::from_rotation_x(PI / 2.0));
|
||||||
|
|
||||||
|
let mass = (
|
||||||
|
RigidBody::Dynamic,
|
||||||
|
Collider::capsule(1.0, 1.0),
|
||||||
|
Mass(5.0),
|
||||||
|
);
|
||||||
|
|
||||||
|
commands.spawn((name, mesh, material, mass, t));
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue