-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic first app with boilerplate
- Loading branch information
Showing
8 changed files
with
195 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![allow(unused)] | ||
|
||
pub mod loading; | ||
pub mod player; | ||
pub mod polar; | ||
pub mod state; | ||
pub mod utils; | ||
pub mod world; | ||
|
||
pub mod prelude { | ||
|
||
pub use std::f32::consts::*; | ||
|
||
pub use anyhow::{anyhow, bail, ensure, Result}; | ||
pub use bevy::prelude::*; | ||
|
||
pub use crate::loading::*; | ||
pub use crate::player::*; | ||
pub use crate::polar::*; | ||
pub use crate::state::*; | ||
pub use crate::utils::*; | ||
pub use crate::world::*; | ||
pub use crate::{PLANETS, PLANET_PARTS}; | ||
} | ||
|
||
pub const PLANETS: &str = "planets/planets"; | ||
pub const PLANET_PARTS: &str = "planets/parts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use crate::prelude::*; | ||
|
||
///Will be used to load assets when the game starts, so they are all pre-loaded | ||
/// before the game starts. | ||
pub struct GalaxyLoadingPlugin; | ||
|
||
impl Plugin for GalaxyLoadingPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_system( | ||
load_assets | ||
.in_schedule(OnEnter(EngineState::LoadingAssets)) | ||
.run_if(run_once()), | ||
); | ||
// // While in this state, run the `countdown` system | ||
// .add_system(splash_screen. | ||
// in_set(OnUpdate(EngineState::LoadingAssets))) // When exiting | ||
// the state, despawn everything that was spawned for this screen | ||
// .add_system( | ||
// teardown::<SplashScreen>. | ||
// in_schedule(OnExit(EngineState::LoadingAssets)), ); | ||
} | ||
} | ||
|
||
// #[derive(Component)] | ||
// struct SplashScreen; | ||
|
||
fn load_assets( | ||
mut commands: Commands, | ||
asset_server: Res<AssetServer>, | ||
mut game_state: ResMut<NextState<EngineState>>, | ||
) { | ||
// asset_server.load("planets/planets/planet09.png"); | ||
|
||
commands.spawn(Camera2dBundle::default()); | ||
|
||
game_state.set(EngineState::InGame); | ||
} | ||
|
||
// fn splash_screen(mut commands: Commands, asset_server: Res<AssetServer>) { | ||
|
||
// let icon = asset_server.load("planets/planets/planet09.png"); | ||
|
||
// commands | ||
// .spawn(( | ||
// NodeBundle { | ||
// style: Style { | ||
// align_items: AlignItems::Center, | ||
// justify_content: JustifyContent::Center, | ||
// size: Size::new(Val::Percent(100.0), | ||
// Val::Percent(100.0)), ..default() | ||
// }, | ||
// ..default() | ||
// }, | ||
// SplashScreen, | ||
// )) | ||
// .with_children(|parent| { | ||
// parent.spawn(ImageBundle { | ||
// style: Style { | ||
// // This will set the logo to be 200px wide, and auto | ||
// adjust its height size: Size::new(Val::Px(200.0), | ||
// Val::Auto), ..default() | ||
// }, | ||
// image: UiImage::new(icon), | ||
// ..default() | ||
// }); | ||
// }); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,36 @@ | ||
use bevy::prelude::*; | ||
use bevy_inspector_egui::quick::{StateInspectorPlugin, WorldInspectorPlugin}; | ||
use galaxy::prelude::*; | ||
|
||
fn main() { | ||
App::new().add_system(hello_world).run(); | ||
} | ||
App::new() | ||
.insert_resource(ClearColor(Color::BLACK)) | ||
.add_state::<EngineState>() | ||
.add_state::<GameState>() | ||
.add_plugins( | ||
DefaultPlugins | ||
.set(WindowPlugin { | ||
primary_window: Some(Window { | ||
title: "Cosmic Crew: Galaxy".to_string(), | ||
fit_canvas_to_parent: true, | ||
..default() | ||
}), | ||
|
||
fn hello_world() { | ||
println!("hello world!"); | ||
..default() | ||
}) | ||
.set(AssetPlugin { | ||
watch_for_changes: true, | ||
..default() | ||
}), | ||
) | ||
.add_plugin(WorldInspectorPlugin::default().run_if( | ||
bevy::input::common_conditions::input_toggle_active(true, KeyCode::Slash), | ||
)) | ||
.add_plugin(StateInspectorPlugin::<EngineState>::default().run_if( | ||
bevy::input::common_conditions::input_toggle_active(true, KeyCode::Slash), | ||
)) | ||
.add_plugin(GalaxyPlayerPlugin) | ||
.add_plugin(GalaxyLoadingPlugin) | ||
.add_plugin(GalaxyPolarPlugin) | ||
.add_plugin(GalaxyWorldPlugin) | ||
.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use crate::prelude::*; | ||
|
||
pub struct GalaxyPlayerPlugin; | ||
|
||
impl Plugin for GalaxyPlayerPlugin { | ||
fn build(&self, app: &mut App) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use crate::prelude::*; | ||
|
||
pub struct GalaxyPolarPlugin; | ||
|
||
impl Plugin for GalaxyPolarPlugin { | ||
fn build(&self, app: &mut App) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::prelude::*; | ||
|
||
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States, Reflect)] | ||
pub enum EngineState { | ||
#[default] | ||
LoadingAssets, | ||
// MainMenu, | ||
InGame, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States, Reflect)] | ||
pub enum GameState { | ||
#[default] | ||
Playing, | ||
Paused, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use crate::prelude::*; | ||
|
||
///generic system that takes a component as a parameter, and will despawn | ||
/// (teardown) all entities with that component | ||
pub fn teardown<T: Component>(to_despawn: Query<Entity, With<T>>, mut commands: Commands) { | ||
for entity in &to_despawn { | ||
commands.entity(entity).despawn_recursive(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::prelude::*; | ||
|
||
pub struct GalaxyWorldPlugin; | ||
|
||
#[derive(Component)] | ||
pub struct Loaded; | ||
|
||
impl Plugin for GalaxyWorldPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems(( | ||
setup.in_schedule(OnEnter(EngineState::InGame)), | ||
// game.in_set(OnUpdate(GameState::Game)), | ||
teardown::<Loaded>.in_schedule(OnExit(EngineState::InGame)), | ||
)); | ||
} | ||
} | ||
|
||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | ||
commands.spawn(( | ||
SpriteBundle { | ||
sprite: Sprite { | ||
custom_size: Some(Vec2::new(500., 500.)), | ||
..default() | ||
}, | ||
texture: asset_server.load("planets/planets/planet00.png"), | ||
..default() | ||
}, | ||
Loaded, | ||
)); | ||
} |