Skip to content
Closed
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
2 changes: 1 addition & 1 deletion assets/elements/item/crate/crate.element.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Crate
category: Weapons
builtin: !Crate
throw_velocity: [7, 5]
throw_velocity: 10

atlas: ./crate.atlas.yaml

Expand Down
2 changes: 1 addition & 1 deletion assets/elements/item/grenade/grenade.element.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ editor:
grab_size: [30, 30]
builtin: !Grenade
fuse_time: 4.0
throw_velocity: [7, 6]
throw_velocity: 12
damage_region_size: [60, 60]
damage_region_lifetime: 0.6

Expand Down
3 changes: 2 additions & 1 deletion assets/elements/item/kick_bomb/kick_bomb.element.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Kick Bomb
category: Weapons
builtin: !KickBomb
fuse_time: 8.0
throw_velocity: [10, 6]
kick_velocity: [10, 6]
throw_velocity: 10
damage_region_size: [60, 60]
damage_region_lifetime: 0.6

Expand Down
2 changes: 1 addition & 1 deletion assets/elements/item/mine/mine.element.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ builtin: !Mine
damage_region_size: [60, 60]
damage_region_lifetime: 0.6
arm_delay: 0.5
throw_velocity: [7, 5]
throw_velocity: 9

atlas: ./mine.atlas.yaml

Expand Down
2 changes: 1 addition & 1 deletion assets/elements/item/musket/musket.element.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ builtin: !Musket
body_size: [32, 8]
fin_anim: grab_2
angular_velocity: 0.1
throw_velocity: [7, 6]
throw_velocity: 6
grab_offset: [23 , 0]
2 changes: 1 addition & 1 deletion assets/elements/item/sword/sword.element.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ builtin: !Sword
angular_velocity: -0.04
can_rotate: true
bounciness: 0.32
throw_velocity: [1.5, 6]
throw_velocity: 9
cooldown_frames: 22
3 changes: 1 addition & 2 deletions core/src/bullet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ fn update(

player_indexes: Comp<PlayerIdx>,
collision_world: CollisionWorld,
mut player_events: ResMut<PlayerEvents>,
mut transforms: CompMut<Transform>,
mut bullets: CompMut<Bullet>,
mut audio_events: ResMut<AudioEvents>,
Expand Down Expand Up @@ -121,7 +120,7 @@ fn update(
.filter(|&x| player_indexes.contains(x))
.for_each(|player| {
hit_player = true;
player_events.kill(player, Some(position.translation.xy()));
commands.add(PlayerCommand::kill(player, Some(position.translation.xy())));
});

// check solid tile collisions
Expand Down
7 changes: 5 additions & 2 deletions core/src/damage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ pub struct DamageRegionOwner(pub Entity);
/// System that will eliminate players that are intersecting with a damage region.
fn kill_players_in_damage_region(
entities: Res<Entities>,
mut commands: Commands,
player_indexes: Comp<PlayerIdx>,
transforms: Comp<Transform>,
damage_regions: Comp<DamageRegion>,
damage_region_owners: Comp<DamageRegionOwner>,
bodies: Comp<KinematicBody>,
mut player_events: ResMut<PlayerEvents>,
) {
for (player_ent, (_idx, transform, body)) in
entities.iter_with((&player_indexes, &transforms, &bodies))
Expand All @@ -59,7 +59,10 @@ fn kill_players_in_damage_region(

let damage_rect = damage_region.collider_rect(transform.translation);
if player_rect.overlaps(&damage_rect) {
player_events.kill(player_ent, Some(transform.translation.xy()));
commands.add(PlayerCommand::kill(
player_ent,
Some(transform.translation.xy()),
));
}
}
}
Expand Down
70 changes: 9 additions & 61 deletions core/src/elements/crate_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn hydrate_crates(
mut bodies: CompMut<KinematicBody>,
mut transforms: CompMut<Transform>,
mut items: CompMut<Item>,
mut item_throws: CompMut<ItemThrow>,
mut respawn_points: CompMut<DehydrateOutOfBounds>,
) {
let mut not_hydrated_bitset = hydrated.bitset().clone();
Expand All @@ -53,6 +54,7 @@ fn hydrate_crates(
let BuiltinElementKind::Crate{
atlas,
body_size,
throw_velocity,
bounciness,
..
} = &element_meta.builtin else{
Expand All @@ -64,6 +66,7 @@ fn hydrate_crates(
let entity = entities.create();
items.insert(entity, Item);
idle_crates.insert(entity, IdleCrate);
item_throws.insert(entity, ItemThrow::strength(*throw_velocity));
atlas_sprites.insert(entity, AtlasSprite::new(atlas.clone()));
respawn_points.insert(entity, DehydrateOutOfBounds(spawner));
transforms.insert(entity, transform);
Expand All @@ -89,17 +92,13 @@ fn update_idle_crates(
entities: Res<Entities>,
element_handles: Comp<ElementHandle>,
element_assets: BevyAssets<ElementMeta>,
mut transforms: CompMut<Transform>,
mut items_used: CompMut<ItemUsed>,
mut idle_crates: CompMut<IdleCrate>,
mut sprites: CompMut<AtlasSprite>,
mut bodies: CompMut<KinematicBody>,
mut items_used: CompMut<ItemUsed>,
mut items_dropped: CompMut<ItemDropped>,
mut attachments: CompMut<PlayerBodyAttachment>,
mut player_layers: CompMut<PlayerLayers>,
player_inventories: PlayerInventories,
mut commands: Commands,
mut player_events: ResMut<PlayerEvents>,
) {
for (entity, (_idle_crate, element_handle)) in
entities.iter_with((&mut idle_crates, &element_handles))
Expand All @@ -110,7 +109,6 @@ fn update_idle_crates(

let BuiltinElementKind::Crate{
grab_offset,
throw_velocity,
fin_anim,
..
} = &element_meta.builtin else {
Expand Down Expand Up @@ -138,28 +136,7 @@ fn update_idle_crates(

if items_used.get(entity).is_some() {
items_used.remove(entity);
player_events.set_inventory(player, None);
attachments.remove(entity);

let player_velocity = bodies.get(player).unwrap().velocity;
let player_sprite = sprites.get_mut(player).unwrap();
let player_translation = transforms.get(player).unwrap().translation;

let body = bodies.get_mut(entity).unwrap();

let horizontal_flip_factor = if player_sprite.flip_x {
Vec2::new(-1.0, 1.0)
} else {
Vec2::ONE
};

body.velocity = *throw_velocity * horizontal_flip_factor + player_velocity;
body.is_deactivated = false;

let transform = transforms.get_mut(entity).unwrap();
transform.translation =
player_translation + (*grab_offset * horizontal_flip_factor).extend(0.0);

commands.add(PlayerCommand::set_inventory(player, None));
commands.add(
move |mut idle: CompMut<IdleCrate>, mut thrown: CompMut<ThrownCrate>| {
idle.remove(entity);
Expand All @@ -176,37 +153,6 @@ fn update_idle_crates(
);
}
}

if let Some(dropped) = items_dropped.get(entity).copied() {
let player = dropped.player;

items_dropped.remove(entity);
attachments.remove(entity);

let player_translation = transforms.get(player).unwrap().translation;
let player_sprite = sprites.get_mut(player).unwrap();
let player_velocity = bodies.get(player).unwrap().velocity;

let body = bodies.get_mut(entity).unwrap();

body.is_deactivated = false;
body.is_spawning = true;

let horizontal_flip_factor = if player_sprite.flip_x {
Vec2::new(-1.0, 1.0)
} else {
Vec2::ONE
};

if player_velocity != Vec2::ZERO {
body.velocity =
*throw_velocity / 5.0 * horizontal_flip_factor + player_velocity / 5.0;
}

let transform = transforms.get_mut(entity).unwrap();
transform.translation =
player_translation + (*grab_offset * horizontal_flip_factor).extend(0.0);
}
}
}

Expand All @@ -220,7 +166,6 @@ fn update_thrown_crates(
mut atlas_sprites: CompMut<AtlasSprite>,
players: Comp<PlayerIdx>,
collision_world: CollisionWorld,
mut player_events: ResMut<PlayerEvents>,
mut bodies: CompMut<KinematicBody>,
mut audio_events: ResMut<AudioEvents>,
transforms: Comp<Transform>,
Expand Down Expand Up @@ -297,7 +242,10 @@ fn update_thrown_crates(
.collect::<Vec<_>>();

for player_entity in &colliding_with_players {
player_events.kill(*player_entity, Some(transform.translation.xy()));
commands.add(PlayerCommand::kill(
*player_entity,
Some(transform.translation.xy()),
));
}

if !colliding_with_players.is_empty()
Expand Down
81 changes: 8 additions & 73 deletions core/src/elements/grenade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn hydrate(
mut bodies: CompMut<KinematicBody>,
mut transforms: CompMut<Transform>,
mut items: CompMut<Item>,
mut item_throws: CompMut<ItemThrow>,
mut respawn_points: CompMut<DehydrateOutOfBounds>,
) {
let mut not_hydrated_bitset = hydrated.bitset().clone();
Expand All @@ -53,6 +54,8 @@ fn hydrate(
body_diameter,
can_rotate,
bounciness,
throw_velocity,
angular_velocity,
..
} = &element_meta.builtin
{
Expand All @@ -61,6 +64,10 @@ fn hydrate(
let entity = entities.create();
items.insert(entity, Item);
idle_grenades.insert(entity, IdleGrenade);
item_throws.insert(
entity,
ItemThrow::strength(*throw_velocity).with_spin(*angular_velocity),
);
atlas_sprites.insert(entity, AtlasSprite::new(atlas.clone()));
respawn_points.insert(entity, DehydrateOutOfBounds(spawner_ent));
transforms.insert(entity, transform);
Expand Down Expand Up @@ -90,13 +97,10 @@ fn update_idle_grenades(
element_handles: Comp<ElementHandle>,
element_assets: BevyAssets<ElementMeta>,
mut audio_events: ResMut<AudioEvents>,
mut transforms: CompMut<Transform>,
mut idle_grenades: CompMut<IdleGrenade>,
mut sprites: CompMut<AtlasSprite>,
mut animated_sprites: CompMut<AnimatedSprite>,
mut bodies: CompMut<KinematicBody>,
mut items_used: CompMut<ItemUsed>,
mut items_dropped: CompMut<ItemDropped>,
mut attachments: CompMut<PlayerBodyAttachment>,
mut player_layers: CompMut<PlayerLayers>,
player_inventories: PlayerInventories,
Expand All @@ -111,10 +115,8 @@ fn update_idle_grenades(

let BuiltinElementKind::Grenade {
grab_offset,
angular_velocity,
fuse_sound,
fuse_sound_volume,
throw_velocity,
fin_anim,
..
} = &element_meta.builtin else {
Expand Down Expand Up @@ -153,7 +155,6 @@ fn update_idle_grenades(
animated_sprite.frames = Arc::from([3, 4, 5]);
animated_sprite.repeat = true;
animated_sprite.fps = 8.0;
body.angular_velocity = *angular_velocity;
commands.add(
move |mut idle: CompMut<IdleGrenade>, mut lit: CompMut<LitGrenade>| {
idle.remove(entity);
Expand All @@ -162,50 +163,17 @@ fn update_idle_grenades(
);
}
}

// If the item was dropped
if let Some(dropped) = items_dropped.get(entity).copied() {
let player = dropped.player;

items_dropped.remove(entity);
attachments.remove(entity);
let player_translation = transforms.get(dropped.player).unwrap().translation;
let player_velocity = bodies.get(player).unwrap().velocity;

let body = bodies.get_mut(entity).unwrap();
let player_sprite = sprites.get_mut(player).unwrap();

// Re-activate physics
body.is_deactivated = false;

let horizontal_flip_factor = if player_sprite.flip_x {
Vec2::new(-1.0, 1.0)
} else {
Vec2::ONE
};
body.velocity = *throw_velocity * horizontal_flip_factor + player_velocity;
body.angular_velocity =
*angular_velocity * if player_sprite.flip_x { -1.0 } else { 1.0 };

body.is_spawning = true;

let transform = transforms.get_mut(entity).unwrap();
transform.translation =
player_translation + (*grab_offset * horizontal_flip_factor).extend(0.0);
}
}
}

fn update_lit_grenades(
entities: Res<Entities>,
element_handles: Comp<ElementHandle>,
element_assets: BevyAssets<ElementMeta>,
transforms: CompMut<Transform>,
mut audio_events: ResMut<AudioEvents>,
mut transforms: CompMut<Transform>,
mut lit_grenades: CompMut<LitGrenade>,
mut sprites: CompMut<AtlasSprite>,
mut bodies: CompMut<KinematicBody>,
mut items_dropped: CompMut<ItemDropped>,
mut hydrated: CompMut<MapElementHydrated>,
mut attachments: CompMut<PlayerBodyAttachment>,
mut emote_regions: CompMut<EmoteRegion>,
Expand All @@ -223,10 +191,8 @@ fn update_lit_grenades(

let BuiltinElementKind::Grenade {
grab_offset,
angular_velocity,
explosion_sound,
explosion_volume,
throw_velocity,
fuse_time,
damage_region_lifetime,
damage_region_size,
Expand Down Expand Up @@ -285,37 +251,6 @@ fn update_lit_grenades(
emote_region.active = true;
}

// If the item was dropped
if let Some(dropped) = items_dropped.get(entity).copied() {
let player = dropped.player;

items_dropped.remove(entity);
attachments.remove(entity);
let player_translation = transforms.get(dropped.player).unwrap().translation;
let player_velocity = bodies.get(player).unwrap().velocity;

let body = bodies.get_mut(entity).unwrap();
let player_sprite = sprites.get_mut(player).unwrap();

// Re-activate physics
body.is_deactivated = false;

let horizontal_flip_factor = if player_sprite.flip_x {
Vec2::new(-1.0, 1.0)
} else {
Vec2::ONE
};
body.velocity = *throw_velocity * horizontal_flip_factor + player_velocity;
body.angular_velocity =
*angular_velocity * if player_sprite.flip_x { -1.0 } else { 1.0 };

body.is_spawning = true;

let transform = transforms.get_mut(entity).unwrap();
transform.translation =
player_translation + (*grab_offset * horizontal_flip_factor).extend(0.0);
}

// If it's time to explode
if grenade.age >= *fuse_time {
audio_events.play(explosion_sound.clone(), *explosion_volume);
Expand Down
Loading