pub fn damage(&mut self, plane: &mut PaperPlane) {
        let dx = self.rect.center_x() - plane.center_x();
        let dy = self.rect.center_y() - plane.center_y();
        let dist = (dx.powi(2) + dy.powi(2)).sqrt();

        if dist < self.range && Date::now() - self.last_dmg_time > self.dmg_interval {
            self.last_dmg_time = Date::now();

            if plane.center_y() > self.rect.center_y() {
                self.rotation = PI - ((dx / dist).acos() + PI * 1.5);
            } else {
                self.rotation = (dx / dist).acos() + PI * 1.5;
            }

            plane.hp_mut().take_damage(self.dmg);
        }
    }
/// Takes a reference to a Plane and applies damage if conditions are met
Takes a reference to a Plane and applies damage if conditions are met
Takes a reference to a Plane and applies damage if conditions are met
pub fn damage(&mut self, plane: &mut PaperPlane) {
        let dx = self.rect.center_x() - plane.center_x();
        let dy = self.rect.center_y() - plane.center_y();
        let dist = (dx.powi(2) + dy.powi(2)).sqrt();
        if dist < self.range && Date::now() - self.last_dmg_time > self.dmg_interval {
            self.last_dmg_time = Date::now();
            if plane.center_y() > self.rect.center_y() {
                self.rotation = PI - ((dx / dist).acos() + PI * 1.5);
            } else {
                self.rotation = (dx / dist).acos() + PI * 1.5;
            }
            plane.hp_mut().take_damage(self.dmg);
        }
    }
pub fn damage ( & mut self , plane : & mut PaperPlane ) { let dx = self . rect . center_x ( ) - plane . center_x ( ) ; let dy = self . rect . center_y ( ) - plane . center_y ( ) ; let dist = ( dx . powi ( 2 ) + dy . powi ( 2 ) ) . sqrt ( ) ; if dist < self . range && Date :: now ( ) - self . last_dmg_time > self . dmg_interval { self . last_dmg_time = Date :: now ( ) ; if plane . center_y ( ) > self . rect . center_y ( ) { self . rotation = PI - ( ( dx / dist ) . acos ( ) + PI * 1.5 ) ; } else { self . rotation = ( dx / dist ) . acos ( ) + PI * 1.5 ; } plane . hp_mut ( ) . take_damage ( self . dmg ) ; } }
Takes a reference to a Plane and applies damage if conditions are met
Takes a reference to a Plane and applies damage if conditions are met
&mut self
plane
&mut PaperPlane
&mut self
plane
&mut PaperPlane