List of usage examples for com.badlogic.gdx.graphics.g2d Sprite rotate90
public void rotate90(boolean clockwise)
From source file:com.talas777.ZombieLord.Minigames.TowerDefense.Defender.java
License:Open Source License
public void act(LinkedList<Attacker> attackers, float deltaTime) { availableTime += deltaTime;// w w w .jav a 2 s . c o m boolean noAction = true; if (availableTime < actionDelay) { return; // still 'charging' to carry out another action } LinkedList<Attacker> wantToShoot = new LinkedList<Attacker>(); int northmost = 0; int weakest = Integer.MAX_VALUE; int nearest = 99; // Defender strategy: most north, weakest, nearest for (Attacker attacker : attackers) { if (attacker.getY() > northmost) { wantToShoot = new LinkedList<Attacker>(); northmost = attacker.getY(); weakest = attacker.health; nearest = ZombieDefense.getDistanceTo(attacker.getX(), attacker.getY(), this.getX(), this.getY()); wantToShoot.add(attacker); } else if (attacker.getY() == northmost) { if (attacker.health < weakest) { wantToShoot = new LinkedList<Attacker>(); northmost = attacker.getY(); weakest = attacker.health; nearest = ZombieDefense.getDistanceTo(attacker.getX(), attacker.getY(), this.getX(), this.getY()); wantToShoot.add(attacker); } else if (attacker.health == weakest) { int dist = ZombieDefense.getDistanceTo(attacker.getX(), attacker.getY(), this.getX(), this.getY()); if (dist < nearest) { wantToShoot = new LinkedList<Attacker>(); northmost = attacker.getY(); weakest = attacker.health; nearest = ZombieDefense.getDistanceTo(attacker.getX(), attacker.getY(), this.getX(), this.getY()); wantToShoot.add(attacker); } else if (dist == nearest) { wantToShoot.add(attacker); } } } } for (Attacker attacker : wantToShoot) { if (availableTime < actionDelay) return; // no more time left (have to 'charge' again..) if (isInRange(attacker)) { // attack Sprite arrow = new Sprite(arrowTex, 32, 32); int fromx = this.getX() * 32; int fromy = this.getY() * 32; int tox = attacker.getX() * 32; int toy = attacker.getY() * 32; this.shootTimeLeft = 1f; float angle = getRotationDegrees(fromx, fromy, tox, toy); if (angle <= 45 || angle > 315) { // north this.direction = ZombieLord.DIR_NORTH; } else if (angle > 45 && angle <= 135) { // east this.direction = ZombieLord.DIR_WEST; } else if (angle > 135 && angle <= 225) { // south this.direction = ZombieLord.DIR_SOUTH; } else // west this.direction = ZombieLord.DIR_EAST; if (angle == 90) arrow.rotate90(true); else if (angle == 270) arrow.rotate90(false); else arrow.rotate(angle); ZombieLord.sendAnimatedMissile(arrow, fromx, tox, fromy, toy, 5.7f); attacker.health -= damage; availableTime -= actionDelay; noAction = false; } } if (noAction && availableTime > actionDelay) { availableTime = actionDelay; // dont charge for more than 1 shot. } }