spawn in player!!!! yay
This commit is contained in:
parent
802a81eae7
commit
eb85af98d5
3 changed files with 22 additions and 5 deletions
|
@ -11,6 +11,7 @@ mod set;
|
||||||
|
|
||||||
pub const WORLD_DEPTH: f32 = 0.5;
|
pub const WORLD_DEPTH: f32 = 0.5;
|
||||||
pub const PLAYER_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) {
|
pub fn game_plugin(app: &mut App) {
|
||||||
app.add_plugins((player_plugin, scene_plugin));
|
app.add_plugins((player_plugin, scene_plugin));
|
||||||
|
|
|
@ -7,7 +7,7 @@ use bevy_rapier2d::prelude::*;
|
||||||
|
|
||||||
use crate::{AppState, METER};
|
use crate::{AppState, METER};
|
||||||
|
|
||||||
use super::set::IngameSet;
|
use super::{scene::PlayerCoords, set::IngameSet};
|
||||||
|
|
||||||
mod animation;
|
mod animation;
|
||||||
|
|
||||||
|
@ -24,8 +24,7 @@ impl FromWorld for PlayerSpawnOneshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn player_plugin(app: &mut App) {
|
pub(super) fn player_plugin(app: &mut App) {
|
||||||
app.add_systems(OnEnter(AppState::InGame), add_player.in_set(IngameSet))
|
app.init_resource::<PlayerSpawnOneshot>();
|
||||||
.init_resource::<PlayerSpawnOneshot>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Hash, PartialEq, Eq, Default)]
|
#[derive(Component, Hash, PartialEq, Eq, Default)]
|
||||||
|
@ -41,6 +40,7 @@ pub fn add_player(
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
|
mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
|
player_coords: Res<PlayerCoords>,
|
||||||
) {
|
) {
|
||||||
let tex_idle = asset_server.load("idle.png");
|
let tex_idle = asset_server.load("idle.png");
|
||||||
let layout_idle = TextureAtlasLayout::from_grid(UVec2::splat(512), 2, 1, None, None);
|
let layout_idle = TextureAtlasLayout::from_grid(UVec2::splat(512), 2, 1, None, None);
|
||||||
|
@ -83,7 +83,7 @@ pub fn add_player(
|
||||||
mgr: anims,
|
mgr: anims,
|
||||||
},
|
},
|
||||||
SpriteBundle {
|
SpriteBundle {
|
||||||
transform: Transform::from_scale(Vec3::splat(50.)),
|
transform: Into::<Transform>::into(player_coords.clone()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
|
@ -12,17 +12,33 @@ use crate::game::WORLD_DEPTH;
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
use super::player::PlayerSpawnOneshot;
|
use super::player::PlayerSpawnOneshot;
|
||||||
|
use super::{PLAYER_DEPTH, PLAYER_SIZE_FRACTION};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Block;
|
struct Block;
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default, Clone, Copy)]
|
||||||
pub struct PlayerCoords {
|
pub struct PlayerCoords {
|
||||||
x: f32,
|
x: f32,
|
||||||
y: f32,
|
y: f32,
|
||||||
block_size: 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) {
|
pub(super) fn scene_plugin(app: &mut App) {
|
||||||
app.add_plugins(EditorPlugin::default());
|
app.add_plugins(EditorPlugin::default());
|
||||||
// app.add_systems(, )
|
// app.add_systems(, )
|
||||||
|
|
Loading…
Add table
Reference in a new issue