Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/map/elements/item/stomp_boots/stomp_boots.atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image: ./stomp_boots.png
tile_size: [96, 80]
rows: 7
columns: 14
9 changes: 9 additions & 0 deletions assets/map/elements/item/stomp_boots/stomp_boots.element.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Sword
category: Weapons
builtin: !StompBoots
map_icon: ./stomp_boots_icon.atlas.yaml
player_decoration: ./stomp_boots.atlas.yaml

body_size: [32, 18]
body_offset: [0, 0]
grab_offset: [-8, -4]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image: ./stomp_boots_icon.png
tile_size: [31, 18]
rows: 1
columns: 1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 4 additions & 8 deletions assets/map/levels/level1.map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,10 @@ layers:
- id: items
kind: !element
elements:
- pos:
- 365
- 110
element: ../elements/item/stomp_boots/stomp_boots.element.yaml
- pos:
- 536.0
- 309.5
Expand Down Expand Up @@ -1270,14 +1274,6 @@ layers:
- 171.5714
- 409.5
element: ../elements/item/kick_bomb/kick_bomb.element.yaml
- pos:
- 712.0
- 393.5
element: ../elements/item/mine/mine.element.yaml
- pos:
- 720.9998
- 121.5
element: ../elements/item/cannon/cannon.element.yaml
- id: spawners
kind: !element
elements:
Expand Down
73 changes: 70 additions & 3 deletions src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct AnimatedSprite {
pub repeat: bool,
pub fps: f32,
pub timer: f32,
pub stacked_atlases: Vec<Handle<TextureAtlas>>,
}

impl Clone for AnimatedSprite {
Expand All @@ -69,6 +70,7 @@ impl Clone for AnimatedSprite {
repeat: self.repeat,
fps: self.fps,
atlas: self.atlas.clone_weak(),
stacked_atlases: self.stacked_atlases.clone(),
timer: self.timer,
}
}
Expand All @@ -90,10 +92,25 @@ pub struct AnimationBank {
pub last_animation: String,
}

fn animate_sprites(mut animated_sprites: Query<(&mut AnimatedSprite, &mut TextureAtlasSprite)>) {
for (mut animated_sprite, mut atlas_sprite) in &mut animated_sprites {
#[derive(Component, Clone, Copy, Default)]
pub struct StackedAtlas;

fn animate_sprites(
mut commands: Commands,
mut animated_sprites: Query<(Entity, &mut AnimatedSprite), With<TextureAtlasSprite>>,
mut texture_atlases: Query<(
&mut TextureAtlasSprite,
&Handle<TextureAtlas>,
Option<&Parent>,
Option<&StackedAtlas>,
)>,
) {
for (sprite_ent, mut animated_sprite) in &mut animated_sprites {
let (mut atlas_sprite, ..) = texture_atlases.get_mut(sprite_ent).unwrap();

animated_sprite.timer += 1.0 / crate::FPS as f32;
atlas_sprite.flip_x = animated_sprite.flip_x;
atlas_sprite.flip_y = animated_sprite.flip_y;

if animated_sprite.timer > 1.0 / animated_sprite.fps {
animated_sprite.timer = 0.0;
Expand All @@ -110,7 +127,57 @@ fn animate_sprites(mut animated_sprites: Query<(&mut AnimatedSprite, &mut Textur
animated_sprite.index %= (animated_sprite.end - animated_sprite.start).max(1);
}

atlas_sprite.index = animated_sprite.start + animated_sprite.index;
let sprite_index = animated_sprite.start + animated_sprite.index;
atlas_sprite.index = sprite_index;

// Now we need to handle all the decorations
let mut pending_stacks = animated_sprite
.stacked_atlases
.iter()
.map(Some)
.collect::<Vec<_>>();

// If there are already spawned images for these stacked atlases, then update them
for (mut sprite, atlas_handle, ..) in
texture_atlases
.iter_mut()
.filter(|(_, _, parent, stacked)| {
parent.map(|x| x.get()) == Some(sprite_ent) && stacked.is_some()
})
{
// Take this sprite out of the list of pending stacks
for item in &mut pending_stacks {
if *item == Some(atlas_handle) {
*item = None;
}
}
sprite.flip_x = animated_sprite.flip_x;
sprite.flip_y = animated_sprite.flip_y;
sprite.index = sprite_index;
}

// For any stacked sprite that we haven't done yet
const STACK_Z_DIFF: f32 = 0.01;
for (i, atlas) in pending_stacks.into_iter().enumerate() {
if let Some(atlas) = atlas {
let stack_ent = commands
.spawn()
.insert_bundle(SpriteSheetBundle {
texture_atlas: atlas.clone_weak(),
sprite: TextureAtlasSprite {
index: sprite_index,
flip_x: animated_sprite.flip_x,
flip_y: animated_sprite.flip_y,
..default()
},
transform: Transform::from_xyz(0.0, 0.0, (i + 1) as f32 * STACK_Z_DIFF),
..default()
})
.insert(StackedAtlas)
.id();
commands.entity(sprite_ent).add_child(stack_ent);
}
}
}
}

Expand Down
32 changes: 31 additions & 1 deletion src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl AssetLoader for PlayerMetaLoader {
load_context: &'a mut bevy::asset::LoadContext,
) -> bevy::utils::BoxedFuture<'a, Result<(), anyhow::Error>> {
Box::pin(async move {
let self_path = load_context.path();
let self_path = &load_context.path().to_owned();
let mut dependencies = Vec::new();
let mut meta: PlayerMeta = if self_path.extension() == Some(OsStr::new("json")) {
serde_json::from_slice(bytes)?
Expand Down Expand Up @@ -271,6 +271,20 @@ impl AssetLoader for PlayerMetaLoader {
.with_dependency(atlas_path.clone()),
);
meta.spritesheet.atlas_handle = AssetHandle::new(atlas_path, atlas_handle);
for (i, decoration) in meta.spritesheet.decorations.iter().enumerate() {
let (path, handle) = get_relative_asset(load_context, self_path, decoration);
dependencies.push(path);
let atlas_handle = load_context.set_labeled_asset(
&format!("decoration_atlas_{}", i),
LoadedAsset::new(TextureAtlas::from_grid(
handle.typed(),
meta.spritesheet.tile_size.as_vec2(),
meta.spritesheet.columns,
meta.spritesheet.rows,
)),
);
meta.spritesheet.decoration_handles.push(atlas_handle);
}

load_context.set_default_asset(LoadedAsset::new(meta).with_dependencies(dependencies));

Expand Down Expand Up @@ -498,6 +512,22 @@ impl AssetLoader for MapElementMetaLoader {
*handle = sound_handle.typed();
}
}
BuiltinElementKind::StompBoots {
map_icon,
map_icon_handle: map_icon_atlas,
player_decoration,
player_decoration_handle,
..
} => {
for (atlas, atlas_handle) in [
(map_icon, map_icon_atlas),
(player_decoration, player_decoration_handle),
] {
let (path, handle) = get_relative_asset(load_context, self_path, atlas);
*atlas_handle = handle.typed();
dependencies.push(path);
}
}
}

// Load preloaded assets
Expand Down
2 changes: 2 additions & 0 deletions src/map/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod sproinger;
pub mod crate_item;
pub mod grenade;
pub mod mine;
pub mod stomp_boots;
pub mod sword;

pub struct MapElementsPlugin;
Expand All @@ -33,6 +34,7 @@ impl Plugin for MapElementsPlugin {
.add_plugin(player_spawner::PlayerSpawnerPlugin)
.add_plugin(sproinger::SproingerPlugin)
.add_plugin(mine::MinePlugin)
.add_plugin(stomp_boots::StompBootsPlugin)
.add_plugin(sword::SwordPlugin);
}
}
5 changes: 4 additions & 1 deletion src/map/elements/player_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ fn pre_update_in_game(
break;
};

let mut spawn_location = spawn_point.translation;
spawn_location.z += i as f32 * 0.1;

commands
.spawn()
.insert(PlayerIdx(i))
.insert(**spawn_point)
.insert(Transform::from_translation(spawn_location))
.insert(Rollback::new(ridp.next_id()));
}
}
Expand Down
Loading