Skip to content

Commit

Permalink
Implement Box Item
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Dec 2, 2022
1 parent 56c9cca commit 5ef739b
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 2 deletions.
4 changes: 4 additions & 0 deletions assets/map/elements/item/crate/crate.atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image: ./crate.png
tile_size: [36, 31]
rows: 1
columns: 1
16 changes: 16 additions & 0 deletions assets/map/elements/item/crate/crate.element.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
name: Crate
category: Weapons
builtin: !Crate
throw_velocity: [7, 5]

atlas: ./crate.atlas.yaml

breaking_atlas: ./crate_breaking.atlas.yaml
breaking_anim_length: 25
breaking_anim_fps: 30

# TODO: Better break sound
break_sound: ./fuse.ogg

body_size: [36, 30]
body_offset: [0, 0]
grab_offset: [14, -2]
break_timeout: 4
Binary file added assets/map/elements/item/crate/crate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/map/elements/item/crate/crate_breaking.atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image: ./crate_breaking.png
tile_size: [128, 128]
rows: 1
columns: 25
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/elements/item/crate/fuse.ogg
Binary file not shown.
9 changes: 7 additions & 2 deletions assets/map/elements/item/grenade/grenade.element.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
name: Grenades
category: Weapons
builtin: !Grenade
atlas: ./grenade.atlas.yaml
explosion_atlas: ./explosion.atlas.yaml
fuse_time: 4.0
throw_velocity: [7, 5]
damage_region_size: [60, 60]
damage_region_lifetime: 0.6

atlas: ./grenade.atlas.yaml

explosion_atlas: ./explosion.atlas.yaml
explosion_lifetime: 1.0
explosion_frames: 12
explosion_fps: 8
explosion_sound: ./explosion.ogg

fuse_sound: ./fuse.ogg

body_size: [18, 18]
grab_offset: [-7, -6]
body_offset: [0, 2]
# TODO: Enable and fix rotation problems
can_rotate: false
4 changes: 4 additions & 0 deletions assets/map/levels/level1.map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,10 @@ layers:
- 536.0
- 309.5
element: ../elements/item/grenade/grenade.element.yaml
- pos:
- 719.0
- 400.5
element: ../elements/item/crate/crate.element.yaml
- pos:
- 292.2272
- 609.5
Expand Down
24 changes: 24 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,30 @@ impl AssetLoader for MapElementMetaLoader {
*handle = sound_handle.typed();
}
}
BuiltinElementKind::Crate {
atlas,
atlas_handle,
breaking_atlas,
breaking_atlas_handle,
break_sound,
break_sound_handle,
..
} => {
for (atlas, atlas_handle) in [
(atlas, atlas_handle),
(breaking_atlas, breaking_atlas_handle),
] {
let (path, handle) = get_relative_asset(load_context, self_path, atlas);
*atlas_handle = AssetHandle::new(path.clone(), handle.typed());
dependencies.push(path);
}

let (sound, handle) = (break_sound, break_sound_handle);
let (sound_path, sound_handle) =
get_relative_asset(load_context, self_path, sound);
dependencies.push(sound_path);
*handle = sound_handle.typed();
}
}

// Load preloaded assets
Expand Down
1 change: 1 addition & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl Plugin for MapPlugin {
/// script.
#[derive(Reflect, Component, Default)]
#[reflect(Component, Default)]
#[component(storage = "SparseSet")]
pub struct MapElementHydrated;

/// If this component and a [`Transform`] component is added to any entity, it will be moved back to
Expand Down
2 changes: 2 additions & 0 deletions src/map/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod player_spawner;
pub mod sproinger;

// Items
pub mod crate_item;
pub mod grenade;
pub mod sword;

Expand All @@ -27,6 +28,7 @@ impl Plugin for MapElementsPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(decoration::DecorationPlugin)
.add_plugin(grenade::GrenadePlugin)
.add_plugin(crate_item::CrateItemPlugin)
.add_plugin(player_spawner::PlayerSpawnerPlugin)
.add_plugin(sproinger::SproingerPlugin)
.add_plugin(sword::SwordPlugin);
Expand Down
Loading

0 comments on commit 5ef739b

Please sign in to comment.