diff --git a/Cargo.toml b/Cargo.toml index fd32498..36ac4be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,28 @@ edition = "2024" [dependencies] bevy = "0.19.0" + +[profile.dev] +opt-level = 1 + +[profile.dev.package."*"] +opt-level = 3 + +# Enable more optimization in the release profile at the cost of compile time. +[profile.release] +# Do a second optimization pass over the entire program, including dependencies. +# Slows compile times, marginal improvements. +lto = "thin" +# Compile the entire crate as one unit. +# Slows compile times, marginal improvements. +codegen-units = 1 + +# Optimize for size in the wasm-release profile to reduce load times and bandwidth usage on web. +[profile.wasm-release] +# Default to release profile values. +inherits = "release" +# Optimize with size in mind (also try "z", sometimes it is better). +# Slightly slows compile times, great improvements to file size and runtime performance. +opt-level = "s" +# Strip all debugging information from the binary to slightly reduce file size. +strip = "debuginfo" diff --git a/assets/background.wgsl b/assets/background.wgsl new file mode 100644 index 0000000..f472faf --- /dev/null +++ b/assets/background.wgsl @@ -0,0 +1,10 @@ +#import bevy_sprite::mesh2d_vertex_output::VertexOutput +#import bevy_sprite::mesh2d_view_bindings::globals + +@group(#{MATERIAL_BIND_GROUP}) @binding(0) var base_color_texture: texture_2d; +@group(#{MATERIAL_BIND_GROUP}) @binding(1) var base_color_sampler: sampler; + +@fragment +fn fragment(mesh: VertexOutput) -> @location(0) vec4 { + return textureSample(base_color_texture, base_color_sampler, mesh.uv + vec2(globals.time / 10., 0.)); +} diff --git a/assets/background_color_grass.png b/assets/background_color_grass.png new file mode 100644 index 0000000..87ce76f Binary files /dev/null and b/assets/background_color_grass.png differ diff --git a/assets/bevy-bird.png b/assets/bevy-bird.png new file mode 100644 index 0000000..229ec40 Binary files /dev/null and b/assets/bevy-bird.png differ diff --git a/assets/pipe.png b/assets/pipe.png new file mode 100644 index 0000000..901b10c Binary files /dev/null and b/assets/pipe.png differ diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..77a8149 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,110 @@ +use std::time::Duration; + +use bevy::{image::ImageLoaderSettings, prelude::*, time::common_conditions::on_timer}; + +pub const CANVAS_SIZE: Vec2 = Vec2::new(480., 270.); +pub const PLAYER_SIZE: f32 = 25.0; +pub const PIPE_SPEED: f32 = 200.0; +const PIPE_SIZE: Vec2 = Vec2::new(32., CANVAS_SIZE.y); +const GAP_SIZE: f32 = 100.0; + +#[derive(Component)] +pub struct Pipe; + +#[derive(Component)] +pub struct PipeTop; + +#[derive(Component)] +pub struct PipeBottom; + +#[derive(Component)] +pub struct PointsGate; + +pub struct PipePlugin; + +impl Plugin for PipePlugin { + fn build(&self, app: &mut App) { + app.add_systems( + FixedUpdate, + ( + despawn_pipes, + shift_pipes_to_the_left, + spawn_pipes.run_if(on_timer(Duration::from_secs(1))), + ), + ); + } +} + +fn spawn_pipes(mut commands: Commands, asset_server: Res, time: Res