001package com.fs.starfarer.api.impl.campaign.eventide; 002 003public class HitArea implements Cloneable { 004 public float x, y, w, h; 005 006 protected HitArea clone() { 007 try { 008 HitArea copy = (HitArea) super.clone(); 009 return copy; 010 } catch (CloneNotSupportedException e) { 011 throw new RuntimeException(e); 012 } 013 } 014 015 public HitArea getAdjustedForAction(AnimAction action) { 016 HitArea copy = new HitArea(); 017 float sign = action.actor.facing; 018 019 copy.x = action.actor.loc.x + x * action.anim.scale * sign; 020 copy.y = action.actor.loc.y + y * action.anim.scale; 021 copy.h = h * action.anim.scale; 022 if (sign > 0) { 023 copy.w = w * action.anim.scale; 024 } else { 025 copy.x = action.actor.loc.x + x * action.anim.scale * sign - w * action.anim.scale; 026 copy.w = w * action.anim.scale; 027 } 028 029 030 return copy; 031 032 } 033 034 public boolean intersects(HitArea other) { 035 if (x > other.x + other.w) return false; 036 if (x + w < other.x) return false; 037 if (y > other.y + other.h) return false; 038 if (y + h < other.y) return false; 039 return true; 040 } 041}