Created
January 5, 2016 22:24
-
-
Save nanonull/a624c6d06346eec75c0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AiStaticAttackHelper { | |
private static final Vector2 posDiff = new Vector2(); | |
public static void step(Entity attackerE, int targetE) { | |
Box2dBodyComponent attackerBody = Box2dBodySystem.components.get(attackerE); | |
Box2dBodyComponent targetBody = Box2dBodySystem.components.get(targetE); | |
Vector2 attackerPos = attackerBody.body.getPosition(); | |
Vector2 targetPos = targetBody.body.getPosition(); | |
posDiff.set(targetPos).sub(attackerPos); | |
float angleRadToTarget = MathUtilsExt.absRadians(posDiff.angleRad()); | |
float attackerAngle = MathUtilsExt.absRadians(attackerBody.body.getAngle()); | |
float angleDiff = MathUtilsExt.diffAbsoluteRadians(attackerAngle, angleRadToTarget); | |
if (Math.abs(angleDiff) < AiDynamicAttackHelper.MAKE_SHOT_ON_ANGLE) { | |
GunComponent gunComponent = GunSystem.components.get(attackerE); | |
gunComponent.makeShot(); | |
} else { | |
StationaryGunComponent stationaryGunComponent = StationaryGunSystem.components.get(attackerE); | |
stationaryGunComponent.setExpectedWorldAngleRadians(angleRadToTarget); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment