hi!
I'm working for a similar game (Drone Defense), so I'm happy to share.
First I suppose you already have enemies moving to a single path, from start to end and modelled a tower with a range. Tower could only target one enemy, for simplicity, okay?
And remember I'm using
MarteEngine to build my game, okay?
so let's start:
1) every update of my tower, I check if there is enemy in range and calculate angle to rotate my tower to target
2) if tower have a target, simply create a bullet to kill enemy. Tower shot only 1/2 second at time
3) when enemy is out of range, target become null
some code (from my game, could help you):
Code:
// on render method i simply rotate graphic context, draw and rotate back
// PART of update method, target is an entity, getEntities is only a list of entities
if (target == null) {
for (Entity e : ME.world.getEntities()) {
if (e instanceof Enemy) {
if (getDistance(e) < radius) {
if (target == null) {
angle = (int) calculateAngle(x, y, e.x, e.y);
target = (Enemy) e;
}
}
}
}
} else {
angle = (int) calculateAngle(x, y, target.x, target.y);
if (getDistance(target) > radius) {
target = null;
} else {
// fire at will!
fireTimer += delta;
if (fireTimer > 500) {
fireTimer = 0;
if (isType(Tower.FOTON)) {
ME.world.add(new Bullet(x, y, ResourceManager
.getSpriteSheet("sheet").getSubImage(0, 1),
Bullet.LASER, target, damage));
} else if (isType(Tower.BREEZE)) {
ME.world.add(new Bullet(x, y, ResourceManager
.getSpriteSheet("sheet").getSubImage(1, 1),
Bullet.PHOTON, target, damage));
} else if (isType(Tower.PLASMA)) {
ME.world.add(new Bullet(x, y, ResourceManager
.getSpriteSheet("sheet").getSubImage(1, 1),
Bullet.PHOTON, target, damage));
}
}
if (target.died) {
target = null;
}
}
}
public float getDistance(Entity other) {
return getDistance(new Vector2f(other.x, other.y));
}
// slick's Vector2f !
public float getDistance(Vector2f otherPos) {
Vector2f myPos = new Vector2f(x, y);
return myPos.distance(otherPos);
}
public static float calculateAngle(float x, float y, float x1, float y1) {
double angle = Math.atan2(y - y1, x - x1);
return (float) (Math.toDegrees(angle) - 90);
}
and here result:

* enemies goes from top left and top right to down/right corner
* tower is only thing rotated a bit
* make a decent UI is a pain
