diff --git a/src/config.rs b/src/config.rs index d316ca6..d0da040 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,19 +9,21 @@ pub const UI_BUTTON_NORMAL: Color = Color::srgb(0.15, 0.15, 0.15); // Button col pub const UI_BUTTON_HOVERED: Color = Color::srgb(0.25, 0.25, 0.25); // ... when it's hovered pub const UI_BUTTON_PRESSED: Color = Color::srgb(0.55, 0.55, 0.55); // ... when it's pressed -pub(crate) const BACKGROUND_COLOR: Color = Color::srgb(0.3, 0.3, 0.3); +pub(crate) const BACKGROUND_COLOR: Color = Color::srgb(0.1, 0.1, 0.1); pub(crate) const PLAYER_SHIP_COLOR: Color = Color::srgb(1.0, 1.0, 1.0); pub(crate) const SHIP_THRUSTER_COLOR_ACTIVE: Color = Color::srgb(1.0, 0.2, 0.2); pub(crate) const SHIP_THRUSTER_COLOR_INACTIVE: Color = Color::srgb(0.5, 0.5, 0.5); pub(crate) const SHIP_FIRE_RATE: f32 = 3.0; // in bullets-per-second -pub(crate) const ASTEROID_SMALL_COLOR: Color = Color::srgb(1.0, 0., 0.); -pub(crate) const BULLET_COLOR: Color = Color::srgb(0.0, 0.1, 0.9); +pub(crate) const ASTEROID_SMALL_COLOR: Color = Color::srgb(0.9, 0.9, 0.9); +pub(crate) const ASTEROID_MEDIUM_COLOR: Color = Color::srgb(0.8, 0.8, 0.8); +pub(crate) const ASTEROID_LARGE_COLOR: Color = Color::srgb(0.6, 0.6, 0.6); +pub(crate) const BULLET_COLOR: Color = Color::srgb(0.9, 0.9, 0.9); // TODO: asteroid medium & large -pub(crate) const SHIP_THRUST: f32 = 1.0; +pub(crate) const SHIP_THRUST: f32 = 4.0; pub(crate) const SHIP_ROTATION: f32 = 4.0; // +/- rotation speed in... radians per frame -pub(crate) const BULLET_SPEED: f32 = 150.0; +pub(crate) const BULLET_SPEED: f32 = 500.0; pub(crate) const BULLET_LIFETIME: f32 = 2.0; pub(crate) const ASTEROID_LIFETIME: f32 = 40.0; diff --git a/src/lib.rs b/src/lib.rs index e5bd1e4..fd22ed9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,9 +11,9 @@ mod resources; mod widgets; use crate::config::{ - ASTEROID_SMALL_COLOR, BACKGROUND_COLOR, BULLET_COLOR, BULLET_LIFETIME, BULLET_SPEED, - PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, SHIP_THRUSTER_COLOR_ACTIVE, - SHIP_THRUSTER_COLOR_INACTIVE, + ASTEROID_LARGE_COLOR, ASTEROID_MEDIUM_COLOR, ASTEROID_SMALL_COLOR, BACKGROUND_COLOR, + BULLET_COLOR, BULLET_LIFETIME, BULLET_SPEED, PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, + SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE, }; use crate::machinery::AsteroidSpawner; use crate::objects::{Bullet, Ship, Weapon}; diff --git a/src/objects.rs b/src/objects.rs index 30d3f1a..7509101 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -83,9 +83,9 @@ pub fn spawn_asteroid( }; let collider_radius = match spawn.size { - AsteroidSize::Small => 10.0, - AsteroidSize::Medium => 20.0, - AsteroidSize::Large => 40.0, + AsteroidSize::Small => 5.0, + AsteroidSize::Medium => 10.0, + AsteroidSize::Large => 20.0, }; commands.spawn(( diff --git a/src/resources.rs b/src/resources.rs index 0df6ca8..feccdcc 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -9,7 +9,7 @@ use bevy::{ }, math::{ Vec2, - primitives::{Circle, Triangle2d}, + primitives::{Polyline2d, Segment2d, Triangle2d}, }, mesh::Mesh, prelude::{Deref, DerefMut, Reflect, ReflectResource}, @@ -19,8 +19,9 @@ use bevy_inspector_egui::InspectorOptions; use bevy_inspector_egui::inspector_options::ReflectInspectorOptions; use crate::{ - ASTEROID_SMALL_COLOR, BULLET_COLOR, PLAYER_SHIP_COLOR, SHIP_THRUSTER_COLOR_ACTIVE, - SHIP_THRUSTER_COLOR_INACTIVE, config::WINDOW_SIZE, + ASTEROID_LARGE_COLOR, ASTEROID_MEDIUM_COLOR, ASTEROID_SMALL_COLOR, BULLET_COLOR, + PLAYER_SHIP_COLOR, SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE, + config::WINDOW_SIZE, }; #[derive(InspectorOptions, Reflect, Resource, Debug, Deref, Clone, Copy)] @@ -83,15 +84,15 @@ impl GameAssets { } pub fn asteroid_small(&self) -> (Handle, Handle) { - (self.meshes[1].clone(), self.materials[1].clone()) + (self.meshes[1].clone(), self.materials[3].clone()) } pub fn asteroid_medium(&self) -> (Handle, Handle) { - (self.meshes[2].clone(), self.materials[2].clone()) + (self.meshes[2].clone(), self.materials[4].clone()) } pub fn asteroid_large(&self) -> (Handle, Handle) { - (self.meshes[3].clone(), self.materials[3].clone()) + (self.meshes[3].clone(), self.materials[5].clone()) } pub fn bullet(&self) -> (Handle, Handle) { @@ -124,10 +125,63 @@ impl FromWorld for GameAssets { Vec2::new(-0.5, 0.45), Vec2::new(-0.5, -0.45), )), - world_meshes.add(Circle::new(10.0)), - world_meshes.add(Circle::new(20.0)), - world_meshes.add(Circle::new(40.0)), - world_meshes.add(Circle::new(0.2)), + world_meshes.add(Polyline2d::new( + [ + Vec2::new(0.1, 0.0), + Vec2::new(0.8, 0.2), + Vec2::new(0.8, 0.3), + Vec2::new(0.1, 1.0), + Vec2::new(-0.5, 1.0), + Vec2::new(-0.3, 0.3), + Vec2::new(-1.0, 0.3), + Vec2::new(-1.0, -0.2), + Vec2::new(-0.5, -1.0), + Vec2::new(0.1, -0.8), + Vec2::new(0.5, -0.9), + Vec2::new(1.0, -0.4), + Vec2::new(0.1, 0.0), + ] + .into_iter() + .map(|vert| vert * 5.0), + )), + world_meshes.add(Polyline2d::new( + [ + Vec2::new(0.6, 0.3), + Vec2::new(1.0, 0.6), + Vec2::new(0.6, 1.0), + Vec2::new(0.1, 0.8), + Vec2::new(-0.4, 1.0), + Vec2::new(-1.0, 0.6), + Vec2::new(-0.8, -0.1), + Vec2::new(-1.0, -0.5), + Vec2::new(-0.4, -1.0), + Vec2::new(-0.3, -0.7), + Vec2::new(0.6, -1.0), + Vec2::new(1.0, -0.3), + Vec2::new(0.6, 0.3), + ] + .into_iter() + .map(|vert| vert * 10.0), + )), + world_meshes.add(Polyline2d::new( + [ + Vec2::new(1.0, -0.1), + Vec2::new(1.0, 0.3), + Vec2::new(0.4, 1.0), + Vec2::new(-0.2, 1.0), + Vec2::new(-0.9, 0.3), + Vec2::new(-0.5, 0.1), + Vec2::new(-0.9, -0.1), + Vec2::new(-0.5, -1.0), + Vec2::new(0.0, 0.0), + Vec2::new(0.0, -1.0), + Vec2::new(0.5, -1.0), + Vec2::new(1.0, -0.1), + ] + .into_iter() + .map(|vert| vert * 20.0), + )), + world_meshes.add(Segment2d::new(Vec2::new(-0.1, 0.0), Vec2::new(0.1, 0.0))), ]; let mut world_materials = world.resource_mut::>(); let materials = [ @@ -136,8 +190,8 @@ impl FromWorld for GameAssets { world_materials.add(SHIP_THRUSTER_COLOR_ACTIVE), world_materials.add(ASTEROID_SMALL_COLOR), // TODO: asteroid medium and large colors - world_materials.add(ASTEROID_SMALL_COLOR), - world_materials.add(ASTEROID_SMALL_COLOR), + world_materials.add(ASTEROID_MEDIUM_COLOR), + world_materials.add(ASTEROID_LARGE_COLOR), world_materials.add(BULLET_COLOR), ]; let loader = world.resource_mut::();