Add a bunch of assets

This commit is contained in:
Daniel Flanagan 2023-12-20 22:40:13 -06:00
parent 529258a7d4
commit 7a064fd55a
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
12 changed files with 29 additions and 14 deletions

BIN
assets/img/Plant.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
assets/img/Player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
assets/img/Props.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
assets/img/Shadow Plant.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
assets/img/Shadow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

BIN
assets/img/Struct.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

BIN
assets/img/Tileset Wall.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View file

@ -1,28 +1,42 @@
use bevy::prelude::*; use bevy::prelude::*;
#[derive(Resource, Debug, Default)] #[derive(Resource, Debug, Default)]
pub struct Assets { pub struct AssetLoader {
pub sprites: Sprites, pub sprites: Sprites,
} }
#[derive(Resource, Debug, Default)] #[derive(Resource, Debug, Default)]
pub struct Sprites { 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) { fn build(&self, app: &mut App) {
app.init_resource::<Assets>() app.init_resource::<AssetLoader>()
.add_systems(Startup, load_assets); .add_systems(Startup, load_assets);
} }
} }
fn load_assets(mut sprite_assets: ResMut<Assets>, asset_server: Res<AssetServer>) { fn load_assets(
*sprite_assets = 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 { sprites: Sprites {
square: asset_server.load("img/square.png"), player: player_atlas_handle,
}, },
}; };
} }

View file

@ -17,7 +17,7 @@ fn main() {
})) }))
.add_plugins(( .add_plugins((
camera::Camera, camera::Camera,
assets::AssetLoader, assets::AssetPlugin,
player::Player, player::Player,
movement::Movement, movement::Movement,
)) ))

View file

@ -1,7 +1,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use crate::{ use crate::{
assets::Assets, assets::AssetLoader,
movement::{Heading, Mover, Speed, Velocity}, 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(( commands.spawn((
Player, Player,
SpriteBundle { SpriteSheetBundle {
texture: assets.sprites.square.clone(), texture_atlas: assets.sprites.player.clone(),
transform: Transform::from_xyz(0., 0., 0.), sprite: TextureAtlasSprite::new(1),
transform: Transform::from_scale(Vec3::splat(3.0)),
..Default::default() ..Default::default()
}, },
Mover { Mover {