World size configuration
The WorldSize is a Resource so that I can use it in the entity wrapping system. The size is pulled from a public constant in the config.rs file, and the window is made that same size.
This commit is contained in:
@@ -5,6 +5,8 @@ where ever they happen to be needed, I'm concentrating them here.
|
||||
|
||||
use bevy::color::Color;
|
||||
|
||||
pub const WINDOW_SIZE: bevy::prelude::Vec2 = bevy::prelude::Vec2::new(800.0, 600.0);
|
||||
|
||||
pub(crate) const BACKGROUND_COLOR: Color = Color::srgb(0.3, 0.3, 0.3);
|
||||
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);
|
||||
|
||||
14
src/lib.rs
14
src/lib.rs
@@ -1,6 +1,6 @@
|
||||
mod config;
|
||||
pub mod config;
|
||||
|
||||
use crate::config::{BACKGROUND_COLOR, PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST};
|
||||
use crate::config::{BACKGROUND_COLOR, PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, WINDOW_SIZE};
|
||||
|
||||
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
|
||||
use config::{SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE};
|
||||
@@ -11,6 +11,10 @@ impl Plugin for AsteroidPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, (spawn_camera, spawn_player))
|
||||
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
||||
.insert_resource(WorldSize {
|
||||
width: WINDOW_SIZE.x,
|
||||
height: WINDOW_SIZE.y,
|
||||
})
|
||||
.add_systems(FixedUpdate, (input_ship_thruster, input_ship_rotation))
|
||||
.add_systems(
|
||||
FixedPostUpdate,
|
||||
@@ -37,6 +41,12 @@ struct Ship;
|
||||
#[derive(Component)]
|
||||
struct ThrusterColors(Handle<ColorMaterial>, Handle<ColorMaterial>);
|
||||
|
||||
#[derive(Resource)]
|
||||
struct WorldSize {
|
||||
width: f32,
|
||||
height: f32,
|
||||
}
|
||||
|
||||
fn spawn_camera(mut commands: Commands) {
|
||||
commands.spawn(Camera2dBundle::default());
|
||||
}
|
||||
|
||||
12
src/main.rs
12
src/main.rs
@@ -1,10 +1,16 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy::{prelude::*, window::WindowResolution};
|
||||
|
||||
use asteroids::AsteroidPlugin;
|
||||
use asteroids::{config::WINDOW_SIZE, AsteroidPlugin};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
resolution: WindowResolution::new(WINDOW_SIZE.x, WINDOW_SIZE.y),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_plugins(AsteroidPlugin)
|
||||
.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user