Add a bunch of assets
BIN
assets/img/Plant.png
Normal file
After Width: | Height: | Size: 64 KiB |
BIN
assets/img/Player.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
assets/img/Props.png
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
assets/img/Shadow Plant.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
assets/img/Shadow.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
assets/img/Struct.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
assets/img/Tileset Grass.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
assets/img/Tileset Stone Ground.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
assets/img/Tileset Wall.png
Normal file
After Width: | Height: | Size: 17 KiB |
|
@ -1,28 +1,42 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Resource, Debug, Default)]
|
||||
pub struct Assets {
|
||||
pub struct AssetLoader {
|
||||
pub sprites: Sprites,
|
||||
}
|
||||
|
||||
#[derive(Resource, Debug, Default)]
|
||||
pub struct Sprites {
|
||||
pub square: Handle<Image>,
|
||||
pub player: Handle<TextureAtlas>,
|
||||
}
|
||||
|
||||
pub struct AssetLoader;
|
||||
pub struct AssetPlugin;
|
||||
|
||||
impl Plugin for AssetLoader {
|
||||
impl Plugin for AssetPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<Assets>()
|
||||
app.init_resource::<AssetLoader>()
|
||||
.add_systems(Startup, load_assets);
|
||||
}
|
||||
}
|
||||
|
||||
fn load_assets(mut sprite_assets: ResMut<Assets>, asset_server: Res<AssetServer>) {
|
||||
*sprite_assets = Assets {
|
||||
fn load_assets(
|
||||
mut assets: ResMut<AssetLoader>,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
|
||||
) {
|
||||
let player_img = asset_server.load("img/Player.png");
|
||||
let player_atlas = TextureAtlas::from_grid(
|
||||
player_img,
|
||||
Vec2::new(21.0, 48.0),
|
||||
7,
|
||||
1,
|
||||
Some(Vec2 { x: 33., y: 0. }),
|
||||
Some(Vec2 { x: 6., y: 10. }),
|
||||
);
|
||||
let player_atlas_handle = texture_atlases.add(player_atlas);
|
||||
*assets = AssetLoader {
|
||||
sprites: Sprites {
|
||||
square: asset_server.load("img/square.png"),
|
||||
player: player_atlas_handle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ fn main() {
|
|||
}))
|
||||
.add_plugins((
|
||||
camera::Camera,
|
||||
assets::AssetLoader,
|
||||
assets::AssetPlugin,
|
||||
player::Player,
|
||||
movement::Movement,
|
||||
))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
assets::Assets,
|
||||
assets::AssetLoader,
|
||||
movement::{Heading, Mover, Speed, Velocity},
|
||||
};
|
||||
|
||||
|
@ -17,12 +17,13 @@ impl Plugin for Player {
|
|||
}
|
||||
}
|
||||
|
||||
fn spawn_player(mut commands: Commands, assets: Res<Assets>) {
|
||||
fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>) {
|
||||
commands.spawn((
|
||||
Player,
|
||||
SpriteBundle {
|
||||
texture: assets.sprites.square.clone(),
|
||||
transform: Transform::from_xyz(0., 0., 0.),
|
||||
SpriteSheetBundle {
|
||||
texture_atlas: assets.sprites.player.clone(),
|
||||
sprite: TextureAtlasSprite::new(1),
|
||||
transform: Transform::from_scale(Vec3::splat(3.0)),
|
||||
..Default::default()
|
||||
},
|
||||
Mover {
|
||||
|
|