-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
180b8c5
commit 7ad0517
Showing
18 changed files
with
144 additions
and
46 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use bevy::prelude::*; | ||
use bevy_asset_loader::prelude::*; | ||
use rand::seq::SliceRandom; | ||
use rand::Rng; | ||
|
||
pub struct SpritePackPlugin; | ||
|
||
impl Plugin for SpritePackPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.register_type::<SpritePackAssets>() | ||
.init_collection::<SpritePackAssets>(); | ||
} | ||
} | ||
|
||
pub enum SpritePack { | ||
None(Vec<Color>), | ||
OneBit(Vec<(Color, usize)>), | ||
} | ||
|
||
impl Default for SpritePack { | ||
fn default() -> Self { | ||
Self::None(vec![Color::BLACK, Color::WHITE]) | ||
} | ||
} | ||
|
||
impl SpritePack { | ||
pub fn add_skin(&mut self, mut rng: impl Rng) { | ||
let color = Color::Rgba { | ||
red: rng.gen_range(0.0..1.0), | ||
green: rng.gen_range(0.0..1.0), | ||
blue: rng.gen_range(0.0..1.0), | ||
alpha: 1.0, | ||
}; | ||
match self { | ||
Self::None(colors) => { | ||
colors.push(color); | ||
}, | ||
// TODO: Curate the tiles. | ||
// FIXME: Prevent duplicates. | ||
Self::OneBit(tiles) => tiles.push((color, rng.gen_range(0..=5))), | ||
} | ||
} | ||
|
||
pub fn apply( | ||
&self, | ||
commands: &mut Commands, | ||
entity: Entity, | ||
assets: &SpritePackAssets, | ||
size: Vec2, | ||
mut rng: impl Rng, | ||
) { | ||
let (color, index) = match self { | ||
Self::None(colors) => { | ||
commands.entity(entity).insert(Sprite { | ||
color: *colors.choose(&mut rng).unwrap(), | ||
custom_size: Some(size), | ||
..default() | ||
}); | ||
return; | ||
}, | ||
Self::OneBit(tiles) => *tiles.choose(&mut rng).unwrap(), | ||
}; | ||
let handle = match self { | ||
Self::None(..) => unreachable!(), | ||
Self::OneBit(..) => assets.one_bit_food.clone(), | ||
}; | ||
|
||
commands.entity(entity).insert(( | ||
TextureAtlasSprite { | ||
color, | ||
index, | ||
custom_size: Some(size), | ||
..default() | ||
}, | ||
handle, | ||
)); | ||
} | ||
} | ||
|
||
#[derive(AssetCollection, Resource, Reflect, Default)] | ||
#[reflect(Resource)] | ||
pub struct SpritePackAssets { | ||
#[asset(texture_atlas(tile_size_x = 10.0, tile_size_y = 10.0, rows = 5, columns = 17))] | ||
#[asset(path = "image/entity/1-bit/Food.png")] | ||
pub one_bit_food: Handle<TextureAtlas>, | ||
#[asset(texture_atlas(tile_size_x = 10.0, tile_size_y = 10.0, rows = 11, columns = 13))] | ||
#[asset(path = "image/entity/1-bit/Weapons.png")] | ||
pub one_bit_weapons: Handle<TextureAtlas>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters