diff --git a/src/game.rs b/src/game.rs index 528bc10..f3df4f0 100644 --- a/src/game.rs +++ b/src/game.rs @@ -11,6 +11,7 @@ mod set; pub const WORLD_DEPTH: f32 = 0.5; pub const PLAYER_DEPTH: f32 = 0.5; +pub const PLAYER_SIZE_FRACTION: f32 = 0.8; pub fn game_plugin(app: &mut App) { app.add_plugins((player_plugin, scene_plugin)); diff --git a/src/game/player.rs b/src/game/player.rs index 9078dcb..cf17cf2 100644 --- a/src/game/player.rs +++ b/src/game/player.rs @@ -7,7 +7,7 @@ use bevy_rapier2d::prelude::*; use crate::{AppState, METER}; -use super::set::IngameSet; +use super::{scene::PlayerCoords, set::IngameSet}; mod animation; @@ -24,8 +24,7 @@ impl FromWorld for PlayerSpawnOneshot { } pub(super) fn player_plugin(app: &mut App) { - app.add_systems(OnEnter(AppState::InGame), add_player.in_set(IngameSet)) - .init_resource::(); + app.init_resource::(); } #[derive(Component, Hash, PartialEq, Eq, Default)] @@ -41,6 +40,7 @@ pub fn add_player( mut materials: ResMut>, mut texture_atlas_layouts: ResMut>, asset_server: Res, + player_coords: Res, ) { let tex_idle = asset_server.load("idle.png"); let layout_idle = TextureAtlasLayout::from_grid(UVec2::splat(512), 2, 1, None, None); @@ -83,7 +83,7 @@ pub fn add_player( mgr: anims, }, SpriteBundle { - transform: Transform::from_scale(Vec3::splat(50.)), + transform: Into::::into(player_coords.clone()), ..Default::default() }, )); diff --git a/src/game/scene.rs b/src/game/scene.rs index a950d96..c218632 100644 --- a/src/game/scene.rs +++ b/src/game/scene.rs @@ -12,17 +12,33 @@ use crate::game::WORLD_DEPTH; use crate::AppState; use super::player::PlayerSpawnOneshot; +use super::{PLAYER_DEPTH, PLAYER_SIZE_FRACTION}; #[derive(Component)] struct Block; -#[derive(Resource, Default)] +#[derive(Resource, Default, Clone, Copy)] pub struct PlayerCoords { x: f32, y: f32, block_size: f32, } +impl Into for PlayerCoords { + fn into(self) -> Transform { + let PlayerCoords { x, y, block_size } = self; + Transform { + translation: Vec3 { + x, + y, + z: PLAYER_DEPTH, + }, + scale: Vec3::splat(self.block_size * PLAYER_SIZE_FRACTION), + ..Default::default() + } + } +} + pub(super) fn scene_plugin(app: &mut App) { app.add_plugins(EditorPlugin::default()); // app.add_systems(, )