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
2 changes: 1 addition & 1 deletion src/map/elements/sword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn update_in_game(
SwordState::Idle => (),
SwordState::Swinging { frame } => {
// If we're at the end of the swinging animation
if sprite.index >= sprite.end - sprite.start - 1 {
if sprite.index >= sprite.end.saturating_sub(sprite.start).saturating_sub(1) {
// Go to cooldown frames
next_state = Some(SwordState::Cooldown { frame: 0 });

Expand Down
13 changes: 8 additions & 5 deletions src/player/state/states/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn player_state_transition(
pub fn handle_player_state(
mut commands: Commands,
player_inputs: Res<PlayerInputs>,
items: Query<Option<&Parent>, With<Item>>,
items: Query<(Option<&Parent>, &KinematicBody), (With<Item>, Without<PlayerIdx>)>,
mut players: Query<(
Entity,
&PlayerState,
Expand All @@ -51,7 +51,7 @@ pub fn handle_player_state(

// Check for item in player inventory
let mut has_item = false;
'items: for item_parent in &items {
'items: for (item_parent, ..) in &items {
if item_parent.filter(|x| x.get() == player_ent).is_some() {
has_item = true;
break 'items;
Expand All @@ -65,9 +65,12 @@ pub fn handle_player_state(
// For each actor colliding with the player
'colliders: for collider in collision_world.actor_collisions(player_ent) {
// If this is an item
if items.contains(collider) {
commands.add(PlayerSetInventoryCommand::new(player_ent, Some(collider)));
break 'colliders;
if let Ok((.., item_body)) = items.get(collider) {
if !item_body.is_deactivated {
commands
.add(PlayerSetInventoryCommand::new(player_ent, Some(collider)));
break 'colliders;
}
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/player/state/states/midair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn player_state_transition(mut players: Query<(&mut PlayerState, &KinematicB
pub fn handle_player_state(
mut commands: Commands,
player_inputs: Res<PlayerInputs>,
items: Query<Option<&Parent>, With<Item>>,
items: Query<(Option<&Parent>, &KinematicBody), (With<Item>, Without<PlayerIdx>)>,
mut players: Query<(
Entity,
&PlayerState,
Expand All @@ -44,7 +44,7 @@ pub fn handle_player_state(

// Check for item in player inventory
let mut has_item = false;
'items: for item_parent in &items {
'items: for (item_parent, ..) in &items {
if item_parent.filter(|x| x.get() == player_ent).is_some() {
has_item = true;
break 'items;
Expand All @@ -57,10 +57,12 @@ pub fn handle_player_state(
if !has_item {
// For each actor colliding with the player
'colliders: for collider in collision_world.actor_collisions(player_ent) {
// If this is an item
if items.contains(collider) {
commands.add(PlayerSetInventoryCommand::new(player_ent, Some(collider)));
break 'colliders;
if let Ok((.., item_body)) = items.get(collider) {
if !item_body.is_deactivated {
commands
.add(PlayerSetInventoryCommand::new(player_ent, Some(collider)));
break 'colliders;
}
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/player/state/states/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn player_state_transition(
pub fn handle_player_state(
mut commands: Commands,
player_inputs: Res<PlayerInputs>,
items: Query<Option<&Parent>, With<Item>>,
items: Query<(Option<&Parent>, &KinematicBody), (With<Item>, Without<PlayerIdx>)>,
mut players: Query<(
Entity,
&PlayerState,
Expand All @@ -52,7 +52,7 @@ pub fn handle_player_state(

// Check for item in player inventory
let mut has_item = false;
'items: for item_parent in &items {
'items: for (item_parent, ..) in &items {
if item_parent.filter(|x| x.get() == player_ent).is_some() {
has_item = true;
break 'items;
Expand All @@ -66,9 +66,12 @@ pub fn handle_player_state(
// For each actor colliding with the player
'colliders: for collider in collision_world.actor_collisions(player_ent) {
// If this is an item
if items.contains(collider) {
commands.add(PlayerSetInventoryCommand::new(player_ent, Some(collider)));
break 'colliders;
if let Ok((.., item_body)) = items.get(collider) {
if !item_body.is_deactivated {
commands
.add(PlayerSetInventoryCommand::new(player_ent, Some(collider)));
break 'colliders;
}
}
}

Expand Down