Skip to content

Commit

Permalink
dev: the basics are still kicking my ass
Browse files Browse the repository at this point in the history
  • Loading branch information
philiplinden committed Aug 6, 2024
1 parent 8638309 commit d2a9fbc
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 38 deletions.
86 changes: 86 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@ log = { version = "0.4.22", features = [
"release_max_level_warn",
] }
bevy_egui = { version = "0.28.0", features = ["serde"] }
avian2d = { version = "0.1.1", default-features = false, features = [
"2d",
"bevy_scene",
"f64",
"parallel",
"parry-f64",
avian2d = { version = "0.1.1", features = [
"default-collider",
"enhanced-determinism",
"serialize",
] }
bevy_lit = "0.2.2"
bevy-inspector-egui = { version = "0.25.1", features = ["highlight_changes"] }
bevy_pancam = { version = "0.13.0", features = ["bevy_egui"] }
bevy_prototype_lyon = "0.12.0"

[dev-dependencies]
bevy-inspector-egui = { version = "0.25.1", features = ["highlight_changes"] }
Expand Down
8 changes: 5 additions & 3 deletions docs/devlog/v0.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Verdict: **[egui](https://www.egui.rs/) now, [lunex](https://bytestring-net.gith
## Summary
- Decided to stick with 2D.
- Decided to use `bevy_egui` for now, and come back to stylized UI later with `bevy_lunex`.
- Added `bevy_pancam`, `bevy-inspector-egui`, and `bevy_lit` as dependencies.
- Selected f64 features for `avian2d`.
- Made a basic UI
- Added `bevy_pancam`, `bevy-inspector-egui`, `bevy_prototype_lyon`, and `bevy_lit` as dependencies.
- Selected f64 features for `avian2d`, then went back to f32.
- Made a basic UI with egui
- Added basic entity spawner
- Added [todo.md](../todo.md)
13 changes: 13 additions & 0 deletions docs/todo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Physics
- [ ] Spawn a central body and an orbiting body.
- [ ] Speed up or slow down the simulation clock.

# UI
- [ ] Add panning and zooming to the camera.
- [ ] Allow the camera to follow an entity, and to change which entity is followed.

# Config
- [ ] Set up systems to save and load scenes as RON files.

# Docs
- [ ] Take a look at [mdBook](https://github.com/rust-lang/mdBook) as an alternative to in-code docs.
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ nav:
- simulation_limits: design/simulation_limits.md
- technical: technical/
- devlog:
- latest: devlog/v0.2.0.md
- v0.2.0: devlog/v0.2.0.md
- v0.1.0: devlog/v0.1.0.md
- v0.0.0: devlog/v0.0.0.md
- to-dos: todo.md
theme:
name: material
font:
Expand Down
46 changes: 46 additions & 0 deletions src/components/bodies.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use avian2d::prelude::*;
use bevy::prelude::*;
use bevy_prototype_lyon::prelude::*;

#[derive(Component)]
pub struct Planetoid;

#[derive(Bundle)]
pub struct PlanetoidBundle {
physics_body: RigidBody,
collider_shape: Collider,
graphics_shape: ShapeBundle,
fill: Fill,
}

impl Default for PlanetoidBundle {
fn default() -> Self {
let default_radius = 10.0;
Self::from_radius(default_radius)
}
}

impl PlanetoidBundle {
pub fn from_radius(radius: f32) -> Self {
let points = [
Vec2::new(1.0, -1.0),
Vec2::new(1.0, 1.0),
Vec2::new(-1.0, 1.0),
Vec2::new(-1.0, -1.0),
].map(|x| x * radius);
let shape = shapes::RoundedPolygon {
points: points.into_iter().collect(),
radius: radius,
..default()
};
PlanetoidBundle {
physics_body: RigidBody::Dynamic,
collider_shape: Collider::circle(radius),
graphics_shape: ShapeBundle {
path: GeometryBuilder::build_as(&shape),
..default()
},
fill: Fill::color(bevy::color::palettes::basic::WHITE),
}
}
}
8 changes: 8 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use bevy::prelude::*;
use bevy_prototype_lyon::plugin::ShapePlugin;

pub mod bodies;

pub(super) fn plugin(app: &mut App) {
app.add_plugins(ShapePlugin);
}
26 changes: 24 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
mod physics;
mod ui;
pub mod components;
pub mod spawners;
pub mod palette;

use bevy::prelude::*;
use spawners::SpawnPlanetoid;
pub struct AppPlugin;

impl Plugin for AppPlugin {
Expand All @@ -21,11 +25,17 @@ impl Plugin for AppPlugin {
.into(),
..default()
})
.set(ImagePlugin::default_nearest()),
.set(ImagePlugin::default_nearest()), // to make pixel art crisp
);

// Add custom plugins.
app.add_plugins(ui::UserInterfacePlugins);
app.add_plugins((
ui::UserInterfacePlugins,
spawners::plugin,
physics::plugin,
components::plugin,
));
app.add_systems(PostStartup, initialize);

// Initialize the app state enum
app.init_state::<AppState>();
Expand All @@ -38,7 +48,19 @@ impl Plugin for AppPlugin {

#[derive(Resource, Debug, Clone, Eq, PartialEq, Hash, States, Default)]
pub enum AppState {
Splash,
Loading,
Paused,
#[default]
Running,
}

fn initialize(mut events: EventWriter<SpawnPlanetoid>) {
// spawn center body
events.send(spawners::SpawnPlanetoid {
position: Vec2::new(0.0, 0.0),
velocity: Vec2::new(0.0, 0.0),
mass: 100_000.0,
radius: 10.0,
});
}
File renamed without changes.
9 changes: 9 additions & 0 deletions src/physics/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use avian2d::prelude::*;
use bevy::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.add_plugins(PhysicsPlugins::default().with_length_unit(1.0));

// we will handle gravity ourselves
app.insert_resource(Gravity(Vec2::ZERO.into()));
}
21 changes: 21 additions & 0 deletions src/spawners/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::components::bodies::PlanetoidBundle;
use bevy::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.add_event::<SpawnPlanetoid>();
app.add_systems(Update, spawn_planetoid);
}

#[derive(Event)]
pub struct SpawnPlanetoid {
pub position: Vec2,
pub velocity: Vec2,
pub mass: f32,
pub radius: f32,
}

fn spawn_planetoid(mut commands: Commands, mut events: EventReader<SpawnPlanetoid>) {
for e in events.read(){
commands.spawn(PlanetoidBundle::from_radius(e.radius));
}
}
24 changes: 10 additions & 14 deletions src/ui/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use bevy::prelude::*;
use bevy_mod_picking::prelude::*;

pub struct CursorPlugin;

impl Plugin for CursorPlugin {
fn build(&self, app: &mut App) {
let debug_level: DebugPickingMode;
#[cfg(not(feature = "dev"))]
{
debug_level = DebugPickingMode::Disabled;
}
#[cfg(feature = "dev")]
{
debug_level = DebugPickingMode::Normal;
}
app.add_plugins(DefaultPickingPlugins).insert_resource(debug_level);
pub(super) fn plugin(app: &mut App) {
let debug_level: DebugPickingMode;
#[cfg(not(feature = "dev"))]
{
debug_level = DebugPickingMode::Disabled;
}
#[cfg(feature = "dev")]
{
debug_level = DebugPickingMode::Normal;
}
app.add_plugins(DefaultPickingPlugins).insert_resource(debug_level);
}
Loading

0 comments on commit d2a9fbc

Please sign in to comment.