generated from hheik/bevy-template
Project init and prototype assets
parent
701e88efa9
commit
4e3ac2d268
|
|
@ -388,17 +388,6 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy-template"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"bevy",
|
|
||||||
"bevy-inspector-egui",
|
|
||||||
"bevy_mod_debugdump",
|
|
||||||
"bevy_rapier2d",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_a11y"
|
name = "bevy_a11y"
|
||||||
version = "0.15.1"
|
version = "0.15.1"
|
||||||
|
|
@ -2408,6 +2397,17 @@ version = "0.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
|
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glorbs"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bevy",
|
||||||
|
"bevy-inspector-egui",
|
||||||
|
"bevy_mod_debugdump",
|
||||||
|
"bevy_rapier2d",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glow"
|
name = "glow"
|
||||||
version = "0.14.2"
|
version = "0.14.2"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bevy-template"
|
name = "glorbs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 425 B |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 560 B |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 519 B |
|
|
@ -9,7 +9,7 @@ impl Plugin for DebugPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.configure_sets(Last, DebugSet.run_if(is_debug_enabled));
|
app.configure_sets(Last, DebugSet.run_if(is_debug_enabled));
|
||||||
|
|
||||||
app.insert_resource(DebugMode::on())
|
app.insert_resource(DebugMode::off())
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
bevy_inspector_egui::quick::WorldInspectorPlugin::new().run_if(is_debug_enabled),
|
bevy_inspector_egui::quick::WorldInspectorPlugin::new().run_if(is_debug_enabled),
|
||||||
bevy_rapier2d::prelude::RapierDebugRenderPlugin::default(),
|
bevy_rapier2d::prelude::RapierDebugRenderPlugin::default(),
|
||||||
|
|
|
||||||
110
src/game.rs
110
src/game.rs
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{debug, game_setup};
|
use crate::{debug, game_setup};
|
||||||
use bevy::prelude::*;
|
use bevy::{prelude::*, sprite::Anchor};
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
|
|
||||||
pub fn init(app: &mut App) {
|
pub fn init(app: &mut App) {
|
||||||
|
|
@ -11,20 +11,51 @@ pub fn init(app: &mut App) {
|
||||||
|
|
||||||
app.add_systems(Startup, setup_2d)
|
app.add_systems(Startup, setup_2d)
|
||||||
.add_systems(Update, demo_2d);
|
.add_systems(Update, demo_2d);
|
||||||
|
|
||||||
// app.add_systems(Startup, setup_3d)
|
|
||||||
// .add_systems(Update, demo_3d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_2d(mut commands: Commands) {
|
fn setup_2d(mut commands: Commands, assets: Res<AssetServer>) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Name::from("Demo 2D camera"),
|
Name::from("Demo 2D camera"),
|
||||||
Camera2d,
|
Camera2d,
|
||||||
Transform::from_xyz(0.0, 0.0, 10.0),
|
Transform::from_xyz(0.0, 0.0, 10.0),
|
||||||
));
|
));
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Name::from("Demo 2D sprite"),
|
Name::from("Glorb"),
|
||||||
Sprite::sized(Vec2::splat(256.0)),
|
Transform::from_xyz(-200.0, 0.0, 0.0),
|
||||||
|
Sprite {
|
||||||
|
image: assets.load("sprites/glorb.png"),
|
||||||
|
anchor: Anchor::BottomCenter,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
commands.spawn((
|
||||||
|
Name::from("Box"),
|
||||||
|
Transform::from_xyz(-200.0, -150.0, 0.0),
|
||||||
|
Sprite {
|
||||||
|
image: assets.load("sprites/box.png"),
|
||||||
|
anchor: Anchor::Custom(Vec2 { x: 0.0, y: -0.375 }),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
commands.spawn((
|
||||||
|
Name::from("Wood"),
|
||||||
|
Sprite {
|
||||||
|
image: assets.load("sprites/wood.png"),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
commands.spawn((
|
||||||
|
Name::from("Tree"),
|
||||||
|
Transform::from_xyz(200.0, 0.0, 0.0),
|
||||||
|
Sprite {
|
||||||
|
image: assets.load("sprites/tree.png"),
|
||||||
|
anchor: Anchor::Custom(Vec2 { x: 0.0, y: -0.375 }),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,68 +82,3 @@ fn demo_2d(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_3d(
|
|
||||||
mut commands: Commands,
|
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
||||||
) {
|
|
||||||
commands.spawn((
|
|
||||||
Name::from("Demo 3D camera"),
|
|
||||||
Camera3d::default(),
|
|
||||||
Transform::from_xyz(0.0, 0.0, 10.0),
|
|
||||||
PointLight::default(),
|
|
||||||
));
|
|
||||||
commands.spawn((
|
|
||||||
Name::from("Demo 3D cuboid"),
|
|
||||||
Mesh3d(meshes.add(Cuboid::from_length(1.0))),
|
|
||||||
MeshMaterial3d(materials.add(Color::from(bevy::color::palettes::css::ORANGE))),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn demo_3d(
|
|
||||||
mut camera_query: Query<&mut Transform, With<Camera3d>>,
|
|
||||||
mut mouse_events: EventReader<bevy::input::mouse::MouseMotion>,
|
|
||||||
mouse_input: Res<ButtonInput<MouseButton>>,
|
|
||||||
key_input: Res<ButtonInput<KeyCode>>,
|
|
||||||
time: Res<Time>,
|
|
||||||
) {
|
|
||||||
let raw_mouse_motion: Vec2 = mouse_events.read().map(|e| e.delta).sum();
|
|
||||||
|
|
||||||
if mouse_input.pressed(MouseButton::Right) {
|
|
||||||
let move_forward = key_input.pressed(KeyCode::KeyW);
|
|
||||||
let move_back = key_input.pressed(KeyCode::KeyS);
|
|
||||||
let move_left = key_input.pressed(KeyCode::KeyA);
|
|
||||||
let move_right = key_input.pressed(KeyCode::KeyD);
|
|
||||||
let move_up = key_input.pressed(KeyCode::Space) || key_input.pressed(KeyCode::KeyE);
|
|
||||||
let move_down = key_input.pressed(KeyCode::ControlLeft) || key_input.pressed(KeyCode::KeyQ);
|
|
||||||
|
|
||||||
let raw_movement = Vec3 {
|
|
||||||
x: match (move_right, move_left) {
|
|
||||||
(true, false) => 1.0,
|
|
||||||
(false, true) => -1.0,
|
|
||||||
_ => 0.0,
|
|
||||||
},
|
|
||||||
y: match (move_up, move_down) {
|
|
||||||
(true, false) => 1.0,
|
|
||||||
(false, true) => -1.0,
|
|
||||||
_ => 0.0,
|
|
||||||
},
|
|
||||||
z: match (move_back, move_forward) {
|
|
||||||
(true, false) => 1.0,
|
|
||||||
(false, true) => -1.0,
|
|
||||||
_ => 0.0,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
for mut transform in camera_query.iter_mut() {
|
|
||||||
let mouse_motion = raw_mouse_motion * Vec2::new(-1.0, -1.0) * 0.002;
|
|
||||||
transform.rotate_axis(Dir3::Y, mouse_motion.x);
|
|
||||||
transform.rotate_local_x(mouse_motion.y);
|
|
||||||
|
|
||||||
let local_movement = raw_movement * time.delta_secs() * 10.0;
|
|
||||||
let movement = transform.rotation * local_movement;
|
|
||||||
transform.translation += movement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ impl Plugin for GameSetupPlugin {
|
||||||
.set(WindowPlugin {
|
.set(WindowPlugin {
|
||||||
primary_window: Some(Window {
|
primary_window: Some(Window {
|
||||||
resolution: WindowResolution::new(512.0 * 2.0, 320.0 * 2.0),
|
resolution: WindowResolution::new(512.0 * 2.0, 320.0 * 2.0),
|
||||||
title: "Bevy template <press P to toggle debug mode>".to_string(), // NOTE: Replace this
|
title: "Glorbs <press P to toggle debug mode>".to_string(), // NOTE: Replace this
|
||||||
resizable: false,
|
resizable: false,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue