|
|
|
@ -1,6 +1,7 @@
|
|
|
|
// Bevy basically forces "complex types" with Querys
|
|
|
|
// Bevy basically forces "complex types" with Querys
|
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::hash::BuildHasher;
|
|
|
|
use games::physics2d::*;
|
|
|
|
use games::physics2d::*;
|
|
|
|
use games::*;
|
|
|
|
use games::*;
|
|
|
|
|
|
|
|
|
|
|
|
@ -14,8 +15,8 @@ fn main() {
|
|
|
|
Physics2dPlugin,
|
|
|
|
Physics2dPlugin,
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.insert_resource(Gravity(Vec2::NEG_Y * 9.8 * 100.0))
|
|
|
|
.insert_resource(Gravity(Vec2::NEG_Y * 9.8 * 100.0))
|
|
|
|
.init_resource::<PipeComponents>()
|
|
|
|
.init_resource::<PipeAssets>()
|
|
|
|
.init_resource::<GroundComponents>()
|
|
|
|
.init_resource::<GroundAssets>()
|
|
|
|
.init_resource::<Score>()
|
|
|
|
.init_resource::<Score>()
|
|
|
|
.init_resource::<RewindFrames>()
|
|
|
|
.init_resource::<RewindFrames>()
|
|
|
|
.init_resource::<Flaps>()
|
|
|
|
.init_resource::<Flaps>()
|
|
|
|
@ -250,7 +251,7 @@ fn update_batch_position(
|
|
|
|
fn populate_ground(
|
|
|
|
fn populate_ground(
|
|
|
|
trigger: Trigger<OnAdd, Ground>,
|
|
|
|
trigger: Trigger<OnAdd, Ground>,
|
|
|
|
grounds: Query<&Ground>,
|
|
|
|
grounds: Query<&Ground>,
|
|
|
|
ground_assets: Res<GroundComponents>,
|
|
|
|
ground_assets: Res<GroundAssets>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let Ground(idx) = grounds.get(trigger.target()).unwrap();
|
|
|
|
let Ground(idx) = grounds.get(trigger.target()).unwrap();
|
|
|
|
@ -269,13 +270,31 @@ fn populate_ground(
|
|
|
|
/// Otherwise this just spawns in the center of the batch.
|
|
|
|
/// Otherwise this just spawns in the center of the batch.
|
|
|
|
fn populate_pipe(
|
|
|
|
fn populate_pipe(
|
|
|
|
trigger: Trigger<OnAdd, Pipe>,
|
|
|
|
trigger: Trigger<OnAdd, Pipe>,
|
|
|
|
pipes: Query<&Pipe>,
|
|
|
|
pipes: Query<(&Pipe, &Batch)>,
|
|
|
|
pipe_assets: Res<PipeComponents>,
|
|
|
|
pipe_assets: Res<PipeAssets>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
rand: Res<Rand>
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let pipe_t = match pipes.get(trigger.target()).unwrap() {
|
|
|
|
let pipe_t = {
|
|
|
|
Pipe::Top => Transform::from_xyz(0.0, 200.0, -1.0).with_scale(Vec3::splat(100.0)),
|
|
|
|
let (pipe, Batch(id)) = pipes.get(trigger.target()).unwrap();
|
|
|
|
Pipe::Bottom => Transform::from_xyz(0.0, -200.0, -1.0).with_scale(Vec3::splat(100.0)),
|
|
|
|
|
|
|
|
|
|
|
|
let offset = {
|
|
|
|
|
|
|
|
let val = rand.0.hash_one(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let option = val % 3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match option {
|
|
|
|
|
|
|
|
0 => 100.0,
|
|
|
|
|
|
|
|
1 => 0.0,
|
|
|
|
|
|
|
|
2 => -100.0,
|
|
|
|
|
|
|
|
_ => panic!("Can only pick 1 of 3 pipe offsets"),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match pipe {
|
|
|
|
|
|
|
|
Pipe::Top => Transform::from_xyz(0.0, 200.0 + offset, -1.0).with_scale(Vec3::splat(100.0)),
|
|
|
|
|
|
|
|
Pipe::Bottom => Transform::from_xyz(0.0, -100.0 + offset, -1.0).with_scale(Vec3::splat(100.0)),
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
commands.entity(trigger.target()).insert((
|
|
|
|
commands.entity(trigger.target()).insert((
|
|
|
|
pipe_t,
|
|
|
|
pipe_t,
|
|
|
|
@ -301,13 +320,13 @@ fn populate_hitbox(trigger: Trigger<OnAdd, Hitbox>, mut commands: Commands) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
struct GroundComponents {
|
|
|
|
struct GroundAssets {
|
|
|
|
material: MeshMaterial2d<ColorMaterial>,
|
|
|
|
material: MeshMaterial2d<ColorMaterial>,
|
|
|
|
mesh: Mesh2d,
|
|
|
|
mesh: Mesh2d,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
struct PipeComponents {
|
|
|
|
struct PipeAssets {
|
|
|
|
material: MeshMaterial2d<ColorMaterial>,
|
|
|
|
material: MeshMaterial2d<ColorMaterial>,
|
|
|
|
mesh: Mesh2d,
|
|
|
|
mesh: Mesh2d,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -316,8 +335,8 @@ struct PipeComponents {
|
|
|
|
fn init_obstacle_assets(
|
|
|
|
fn init_obstacle_assets(
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
|
|
mut pipe_assets: ResMut<PipeComponents>,
|
|
|
|
mut pipe_assets: ResMut<PipeAssets>,
|
|
|
|
mut ground_assets: ResMut<GroundComponents>,
|
|
|
|
mut ground_assets: ResMut<GroundAssets>,
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
pipe_assets.material = MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
pipe_assets.material = MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
|