Skip to content

Commit

Permalink
Merge #158
Browse files Browse the repository at this point in the history
158: Add offset to enemy attacks r=odecay a=odecay

closes #156 

(something weird happened with git here)

Co-authored-by: otis <electricbuck@gmail.com>
  • Loading branch information
bors[bot] and odecay authored Jul 26, 2022
2 parents 8f1d5e1 + 24ef6bf commit ad612cd
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use bevy::{
core::{Time, Timer},
hierarchy::{BuildChildren, Children, DespawnRecursiveExt},
math::Vec2,
math::{Vec2, Vec3},
prelude::{
default, App, AssetServer, Assets, Bundle, Commands, Component, Entity, EventReader,
Handle, Local, Parent, Plugin, Query, Res, Transform, With, Without,
Expand Down Expand Up @@ -395,21 +395,32 @@ fn player_flop(
}

fn enemy_attack(
mut query: Query<(Entity, &mut State, &Handle<FighterMeta>), (With<Enemy>, With<Target>)>,
mut query: Query<
(Entity, &mut State, &Facing, &Handle<FighterMeta>),
(With<Enemy>, With<Target>),
>,
mut event_reader: EventReader<ArrivedEvent>,
mut commands: Commands,
fighter_assets: Res<Assets<FighterMeta>>,
) {
for event in event_reader.iter() {
if let Ok((entity, mut state, fighter_handle)) = query.get_mut(event.0) {
if let Ok((entity, mut state, facing, fighter_handle)) = query.get_mut(event.0) {
if *state != State::Attacking {
if rand::random() && *state != State::Waiting {
state.set(State::Waiting);
} else {
state.set(State::Attacking);

//TODO: remove this offset in favor of offsets defined in fighter assets
let offset = match facing {
Facing::Left => -24.0,
Facing::Right => 24.0,
};

let attack_entity = commands
.spawn_bundle(TransformBundle::default())
.spawn_bundle(TransformBundle::from_transform(
Transform::from_translation(Vec3::new(offset, 0.0, 0.0)),
))
.insert(Sensor(true))
.insert(ActiveEvents::COLLISION_EVENTS)
.insert(
Expand Down

0 comments on commit ad612cd

Please sign in to comment.