Tower Class:
package Engine;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
public class Tower {
public int x, y, pixX, pixY, id, id1, id2, id3;
public int width = Screen.room.blockSize;
public int height = Screen.room.blockSize;
public int looseTime = 8000, looseFrame = 0;
public int shotMob = -1;
public int towerCircleSize = 130;
public int resalePrice;
public int slope;
public int damage;
public int targetX;
public int targetY;
public long lastIterationTime;
public int delayTime;
public int currentAnimationIndex;
public long shotInterval;
public double continuousDamage = 0;
public int hitDamage;
public int[] radiusUpgradePrice = new int[3];
public int[] damageUpgradePrice = new int[3];
public int[] speedUpgradePrice = new int[3];
public int[] damageUpgradeAmount = new int[3];
public int urPrice;
public int udPrice;
public int usPrice;
public int offset = 1;
public static int callCircleSize;
public boolean shooting = false;
public boolean drawRadius = false;
public boolean inGame = false;
public boolean animated = false;
public boolean upgradeRadiiFirst = false;
public boolean upgradeRadiiSecond = false;
public boolean upgradeRadiiThird = false;
public boolean upgradeDamageFirst = false;
public boolean upgradeDamageSecond = false;
public boolean upgradeDamageThird = false;
public boolean upgradeSpeedFirst = false;
public boolean upgradeSpeedSecond = false;
public boolean upgradeSpeedThird = false;
public Ellipse2D.Double circle;
public Tower() {
}
public void drawTowerAt(int x, int y, int pixX, int pixY, Tower tower) {
Screen.room.block[y][x].airID = id;
if (Screen.room.towers[y][x] == null) {
Screen.room.towers[y][x] = tower;
inGame = true;
}
this.x = x;
this.y = y;
this.pixX = pixX;
this.pixY = pixY;
circle = new Ellipse2D.Double(pixX - (towerCircleSize / 2), pixY - (towerCircleSize / 2), width + (towerCircleSize), height + (towerCircleSize));
}
public void fight(Graphics g) {
}
public void setDamage(int dmg) {
damage = dmg;
}
public void setDamageUpgradeAmount(int d1, int d2, int d3) {
damageUpgradeAmount[0] = d1;
damageUpgradeAmount[1] = d2;
damageUpgradeAmount[2] = d3;
}
public void setAnimated(boolean animated) {
this.animated = animated;
}
public void setResalePrice(int price) {
this.resalePrice = price;
}
public void setTowerId(int id) {
this.id = id;
}
public void setTowerId(int id1, int id2, int id3) {
this.id = id1;
this.id1 = id1;
this.id2 = id2;
this.id3 = id3;
}
public void setRadius(int radius) {
towerCircleSize = radius;
callCircleSize = radius;
}
public void physic() {
}
public void getMoney(int mobID) {
Screen.coinage += Value.deathReward[mobID];
}
public void draw(Graphics g) {
if (animated) {
if ((System.currentTimeMillis() - lastIterationTime) >= (delayTime)) {
lastIterationTime = System.currentTimeMillis();
currentAnimationIndex = (currentAnimationIndex + 1) % Screen.room.towers.length;
if (id == id1) {
id = id2;
} else if (id == id2) {
id = id3;
} else if (id == id3) {
id = id1;
}
Screen.room.block[y][x].airID = id;
}
}
if (Screen.room.block[y][x].contains(Screen.mscf) && !Screen.isDrawingGui) {
drawRadius(true);
Screen.hasSelectedTower = true;
Screen.selectedTower = this;
Block.drawFixedOutline = true;
Block.drawFixedOutline(x, y, g);
Screen.upgrades.setSelectedTower(this);
} else {
Screen.hasSelectedTower = false;
Screen.selectedTower = null;
drawRadius(false);
Block.drawFixedOutline = false;
}
if (Screen.room.block[y][x].contains(Screen.mse) && drawRadius) {
Block.drawOutline = false;
} else {
Block.drawOutline = true;
}
if (drawRadius) {
g.setColor(Color.BLACK);
g.drawOval((int) circle.x, (int) circle.y, (int) circle.width, (int) circle.height);
}
Graphics2D g2d = (Graphics2D) g.create();
double angle = Math.atan2(targetY - pixY, targetX - pixX) * 180 / Math.PI;
g2d.translate(pixX, pixY);
g2d.rotate(angle);
g2d.drawImage(Screen.tileset_air[id], 0, 0, Screen.room.blockSize, Screen.room.blockSize, null);
// g2d.drawImage(Screen.tileset_air[id], pixX, pixY,
// Screen.room.blockSize, Screen.room.blockSize, null);
// g2d.dispose();
circle = new Ellipse2D.Double(circle.x, circle.y, width + (towerCircleSize), height + (towerCircleSize));
}
public void drawRadius(boolean choice) {
if (choice) {
drawRadius = true;
} else {
drawRadius = false;
}
}
public void setFirstUpgradePrice(int first, int second, int third) {
radiusUpgradePrice[0] = first;
radiusUpgradePrice[1] = second;
radiusUpgradePrice[2] = third;
urPrice = first;
}
public void setSecondUpgradePrice(int first, int second, int third) {
damageUpgradePrice[0] = first;
damageUpgradePrice[1] = second;
damageUpgradePrice[2] = third;
udPrice = first;
}
public void sell() {
Screen.coinage += resalePrice;
Screen.room.block[y][x].airID = Value.airAir;
Screen.room.towers[y][x] = null;
}
public int getRadius() {
return towerCircleSize;
}
public void upgradeRadius() {
if (Screen.coinage >= urPrice) {
if (!upgradeRadiiFirst) {
upgradeRadiiFirst = true;
towerCircleSize += 20;
offset += 10;
circle.x -= offset;
circle.y -= offset;
Screen.coinage -= radiusUpgradePrice[0];
urPrice = radiusUpgradePrice[1];
Screen.upgrades.resalePrice = resalePrice;
resalePrice += 3;
return;
} else if (!upgradeRadiiSecond) {
upgradeRadiiSecond = true;
towerCircleSize += 20;
circle.x -= offset;
circle.y -= offset;
urPrice = radiusUpgradePrice[2];
Screen.upgrades.resalePrice = resalePrice;
Screen.coinage -= radiusUpgradePrice[1];
resalePrice += 4;
return;
} else if (!upgradeRadiiThird) {
upgradeRadiiThird = true;
towerCircleSize += 20;
circle.x -= offset;
circle.y -= offset;
urPrice = 0;
Screen.upgrades.resalePrice = resalePrice;
Screen.coinage -= radiusUpgradePrice[2];
resalePrice += 4;
return;
}
}
}
public void upgradeDamage() {
if (Screen.coinage >= udPrice) {
if (!upgradeDamageFirst) {
upgradeDamageFirst = true;
continuousDamage += .58;
damage = damageUpgradeAmount[0];
Screen.coinage -= damageUpgradePrice[0];
udPrice = damageUpgradePrice[1];
delayTime -= 100;
resalePrice += 3;
return;
} else if (!upgradeDamageSecond) {
upgradeDamageSecond = true;
continuousDamage += .58;
damage = damageUpgradeAmount[1];
Screen.coinage -= damageUpgradePrice[1];
udPrice = damageUpgradePrice[2];
delayTime -= 100;
resalePrice += 4;
return;
} else if (!upgradeDamageThird) {
upgradeDamageThird = true;
continuousDamage += .58;
damage = damageUpgradeAmount[2];
Screen.coinage -= damageUpgradePrice[2];
udPrice = 0;
delayTime -= 100;
resalePrice += 4;
return;
}
}
}
public void upgradeSpeed() {
if (Screen.coinage >= udPrice && continuousDamage == 0) {
if (!upgradeSpeedFirst) {
upgradeSpeedFirst = true;
shotInterval += 1;
Screen.coinage -= speedUpgradePrice[0];
udPrice = speedUpgradePrice[1];
delayTime -= 100;
resalePrice += 3;
return;
} else if (!upgradeSpeedSecond) {
upgradeSpeedSecond = true;
shotInterval += 1;
Screen.coinage -= speedUpgradePrice[1];
udPrice = speedUpgradePrice[2];
delayTime -= 100;
resalePrice += 4;
return;
} else if (!upgradeSpeedThird) {
upgradeSpeedThird = true;
shotInterval += 1;
Screen.coinage -= speedUpgradePrice[2];
udPrice = 0;
delayTime -= 100;
resalePrice += 4;
return;
}
}
}
public void updateImage(int id) {
Screen.room.block[y][x].airID = id;
}
}
TowerCannon class:
package Engine;
import java.awt.Graphics;
public class TowerCannon extends Tower {
public int fTime = 0;
public int sTime = 200;
int xPos = (int) Screen.room.block[y][x].x;
int yPos = (int) Screen.room.block[y][x].y;
public TowerCannon(int x, int y) {
setRadius(200);
setDamage(10);
setDamageUpgradeAmount(14, 16, 18);
setTowerId(Value.airTowerCannonUp);
setResalePrice(10);
setFirstUpgradePrice(5, 10, 15);
setSecondUpgradePrice(5, 10, 15);
drawTowerAt(x, y, Screen.room.block[y][x].x, Screen.room.block[y][x].y, this);
}
public void fight(Graphics g) {
if (shooting && !Screen.mobs[shotMob].isDead() && Screen.inGame) {
if (fTime >= sTime) {
if (Screen.gameSpeed == 3) {
sTime = 200;
} else {
sTime = 67;
}
shoot(g);
fTime = 0;
} else {
fTime++;
}
}
}
@Override
public void physic() {
if (shooting) {
for (int i = 0; i < Screen.mobs.length; i++) {
if (Screen.mobs[i].inGame) {
if (Screen.mobs[i] != null && circle != null) {
targetX = Screen.mobs[i].x;
targetY = Screen.mobs[i].y;
/*
* if (targetY == x && targetX > x)
* updateImage(Value.airTowerCannonRight); if (targetY
* == y && x > targetX)
* updateImage(Value.airTowerCannonLeft);
*/
}
}
}
}
if (shotMob != -1 && circle.intersects(Screen.mobs[shotMob])) {
shooting = true;
} else {
shooting = false;
}
if (!shooting) {
if (Screen.room.block[y][x].airID == id) {
for (int i = 0; i < Screen.mobs.length; i++) {
if (Screen.mobs[i].inGame) {
if (Screen.mobs[i] != null && circle != null) {
if (circle.intersects(Screen.mobs[i])) {
shooting = true;
shotMob = i;
}
}
}
}
}
}
}
public void shoot(Graphics g) {
new CannonBall(shotMob, Screen.mobs[shotMob].x, Screen.mobs[shotMob].y, this, g);
}
}