spawn in player!!!! yay

This commit is contained in:
Schrottkatze 2024-11-23 18:42:52 +01:00
parent 802a81eae7
commit eb85af98d5
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
3 changed files with 22 additions and 5 deletions

View file

@ -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));

View file

@ -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::<PlayerSpawnOneshot>();
app.init_resource::<PlayerSpawnOneshot>();
}
#[derive(Component, Hash, PartialEq, Eq, Default)]
@ -41,6 +40,7 @@ pub fn add_player(
mut materials: ResMut<Assets<ColorMaterial>>,
mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
asset_server: Res<AssetServer>,
player_coords: Res<PlayerCoords>,
) {
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::<Transform>::into(player_coords.clone()),
..Default::default()
},
));

View file

@ -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<Transform> 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(, )