Add statues to confirm camera is working
This commit is contained in:
parent
9af299544f
commit
781d8da5de
|
@ -8,6 +8,7 @@ pub struct AssetLoader {
|
|||
#[derive(Resource, Debug, Default)]
|
||||
pub struct Sprites {
|
||||
pub player: Handle<TextureAtlas>,
|
||||
pub statue: Handle<TextureAtlas>,
|
||||
}
|
||||
|
||||
pub struct AssetPlugin;
|
||||
|
@ -25,6 +26,8 @@ fn load_assets(
|
|||
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
|
||||
) {
|
||||
let player_img = asset_server.load("img/Player.png");
|
||||
let props_img = asset_server.load("img/Props.png");
|
||||
|
||||
let player_atlas = TextureAtlas::from_grid(
|
||||
player_img,
|
||||
Vec2::new(32.0, 64.0),
|
||||
|
@ -33,10 +36,22 @@ fn load_assets(
|
|||
Some(Vec2 { x: 0., y: 0. }),
|
||||
Some(Vec2 { x: 0., y: 0. }),
|
||||
);
|
||||
let statue_atlas = TextureAtlas::from_grid(
|
||||
props_img,
|
||||
Vec2::new(40., 74.),
|
||||
1,
|
||||
1,
|
||||
None,
|
||||
Some(Vec2::new(443., 20.)),
|
||||
);
|
||||
|
||||
let player_atlas_handle = texture_atlases.add(player_atlas);
|
||||
let statue_atlas_handle = texture_atlases.add(statue_atlas);
|
||||
|
||||
*assets = AssetLoader {
|
||||
sprites: Sprites {
|
||||
player: player_atlas_handle,
|
||||
statue: statue_atlas_handle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,15 +1,30 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::player;
|
||||
|
||||
pub struct Camera;
|
||||
|
||||
impl Plugin for Camera {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_camera);
|
||||
app.add_systems(Startup, spawn)
|
||||
.add_systems(PostUpdate, focus);
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_camera(mut commands: Commands) {
|
||||
fn spawn(mut commands: Commands) {
|
||||
let mut bundle = Camera2dBundle::default();
|
||||
bundle.projection.scale = 1.;
|
||||
bundle.projection.scale = 0.25;
|
||||
commands.spawn(bundle);
|
||||
}
|
||||
|
||||
fn focus(
|
||||
player: Query<&Transform, With<player::Player>>,
|
||||
mut camera: Query<
|
||||
&mut Transform,
|
||||
(With<bevy::render::camera::Camera>, Without<player::Player>),
|
||||
>,
|
||||
) {
|
||||
let ply = player.single();
|
||||
let mut camt = camera.single_mut();
|
||||
camt.translation = ply.translation
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ mod assets;
|
|||
mod camera;
|
||||
mod movement;
|
||||
mod player;
|
||||
mod statue;
|
||||
|
||||
fn main() {
|
||||
let mut app = App::new();
|
||||
|
@ -20,6 +21,7 @@ fn main() {
|
|||
.set(ImagePlugin::default_nearest()),
|
||||
)
|
||||
.add_plugins((
|
||||
statue::Statue,
|
||||
camera::Camera,
|
||||
assets::AssetPlugin,
|
||||
player::Player,
|
||||
|
|
|
@ -23,7 +23,6 @@ fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>) {
|
|||
SpriteSheetBundle {
|
||||
texture_atlas: assets.sprites.player.clone(),
|
||||
sprite: TextureAtlasSprite::new(0),
|
||||
transform: Transform::from_scale(Vec3::splat(3.0)),
|
||||
..Default::default()
|
||||
},
|
||||
Mover {
|
||||
|
|
33
src/statue.rs
Normal file
33
src/statue.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::assets::AssetLoader;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Statue;
|
||||
|
||||
impl Plugin for Statue {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(PostStartup, spawn_statue);
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_statue(mut commands: Commands, assets: Res<AssetLoader>) {
|
||||
commands.spawn((
|
||||
Statue,
|
||||
SpriteSheetBundle {
|
||||
texture_atlas: assets.sprites.statue.clone(),
|
||||
sprite: TextureAtlasSprite::new(0),
|
||||
transform: Transform::from_translation(Vec3::new(50., 50., 0.)),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
commands.spawn((
|
||||
Statue,
|
||||
SpriteSheetBundle {
|
||||
texture_atlas: assets.sprites.statue.clone(),
|
||||
sprite: TextureAtlasSprite::new(0),
|
||||
transform: Transform::from_translation(Vec3::new(50., 100., 0.)),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
}
|
Loading…
Reference in a new issue